Mercurial > MadButterfly
changeset 354:92e8f9965f9a
merge
author | wycc |
---|---|
date | Mon, 09 Mar 2009 01:30:19 +0800 |
parents | 3d03451be435 (current diff) 892f4efe2e48 (diff) |
children | 958b67d911db |
files | |
diffstat | 8 files changed, 73 insertions(+), 40 deletions(-) [+] |
line wrap: on
line diff
--- a/examples/menu/filebrowser.c Mon Mar 09 01:28:56 2009 +0800 +++ b/examples/menu/filebrowser.c Mon Mar 09 01:30:19 2009 +0800 @@ -67,14 +67,23 @@ void mypreview(MyAppData *data, char *path) { - mb_img_data_t *img = MB_IMG_LDR_LOAD(rdman_img_ldr(MBAPP_RDMAN(myApp)), path); + redraw_man_t *rdman = MBAPP_RDMAN(myApp); + mb_img_ldr_t *ldr = rdman_img_ldr(rdman); + mb_img_data_t *img = MB_IMG_LDR_LOAD(ldr, path); shape_t *obj = (shape_t *) MB_SPRITE_GET_OBJ(myApp->rootsprite, "previewimg"); + mb_img_data_t *previewimg_img_data; + mb_img_data_t *old_img; + previewimg_img_data = + (mb_img_data_t *)MB_SPRITE_GET_OBJ(myApp->rootsprite, + "previewimg_img_data"); printf("Preview %s\n",path); if (img) { printf("image %d %d\n",img->w,img->h); - sh_image_set_img_data(obj,img,0,0,img->w,img->h); - sh_image_transform(obj); + old_img = sh_image_get_img_data(obj); + sh_image_set_img_data(obj,img); + if(old_img != previewimg_img_data) + MB_IMG_DATA_FREE(old_img); rdman_shape_changed(MBAPP_RDMAN(myApp),obj); rdman_redraw_changed(MBAPP_RDMAN(myApp)); }
--- a/include/mb_shapes.h Mon Mar 09 01:28:56 2009 +0800 +++ b/include/mb_shapes.h Mon Mar 09 01:30:19 2009 +0800 @@ -242,8 +242,7 @@ extern void sh_image_draw(shape_t *shape, cairo_t *cr); extern void sh_image_set_geometry(shape_t *shape, co_aix x, co_aix y, co_aix w, co_aix h); -extern int sh_image_set_img_data(shape_t *shape, mb_img_data_t *img_data, - co_aix x, co_aix y, co_aix w, co_aix h); +extern int sh_image_set_img_data(shape_t *shape, mb_img_data_t *img_data); extern mb_img_data_t *sh_image_get_img_data(shape_t *shape); /* @} */ /* @} */
--- a/src/X_supp.c Mon Mar 09 01:28:56 2009 +0800 +++ b/src/X_supp.c Mon Mar 09 01:30:19 2009 +0800 @@ -177,7 +177,7 @@ static void handle_x_event(X_MB_runtime_t *rt) { Display *display = rt->display; redraw_man_t *rdman = rt->rdman; - XEvent evt; + XEvent evt, peek_evt; XMotionEvent *mevt; XButtonEvent *bevt; XExposeEvent *eevt; @@ -231,6 +231,17 @@ break; case MotionNotify: + while(XEventsQueued(display, QueuedAfterReading) > 0) { + r = XPeekEvent(display, &peek_evt); + if(r == -1) + break; + if(peek_evt.type != MotionNotify) + break; + XNextEvent(display, &evt); + } + if(r == -1) + break; + mevt = (XMotionEvent *)&evt; x = mevt->x; y = mevt->y; @@ -454,7 +465,7 @@ xmb_rt->tman = mb_tman_new(); - img_ldr = simple_mb_img_ldr_new("./"); + img_ldr = simple_mb_img_ldr_new(""); xmb_rt->img_ldr = img_ldr; rdman_set_img_ldr(xmb_rt->rdman, img_ldr);
--- a/src/img_ldr.c Mon Mar 09 01:28:56 2009 +0800 +++ b/src/img_ldr.c Mon Mar 09 01:30:19 2009 +0800 @@ -113,7 +113,7 @@ return NULL; } strcpy((char *)ldr->repo, img_repository); - if(img_repository[sz - 1] != '/') { + if(img_repository[sz - 1] != '/' && strlen(img_repository) != 0) { ((char *)ldr->repo)[sz] = '/'; ((char *)ldr->repo)[sz + 1] = 0; }
--- a/src/paint.c Mon Mar 09 01:28:56 2009 +0800 +++ b/src/paint.c Mon Mar 09 01:30:19 2009 +0800 @@ -272,7 +272,6 @@ cairo_surface_destroy(paint_img->surf); img_data = paint_img->img; - MB_IMG_DATA_FREE(img_data); paint_destroy(&paint_img->paint); free(paint); } @@ -280,6 +279,9 @@ /*! \brief Create an image painter. * * Create a painter that fill/stroke shapes with an image. + * + * \param img is image data return by image load. Life-cycle of img + * is managed by application code. */ paint_t *rdman_paint_image_new(redraw_man_t *rdman, mb_img_data_t *img) {
--- a/src/shape_image.c Mon Mar 09 01:28:56 2009 +0800 +++ b/src/shape_image.c Mon Mar 09 01:30:19 2009 +0800 @@ -65,6 +65,32 @@ static void sh_image_free(shape_t *shape); +int _sh_image_set_img_data(shape_t *shape, mb_img_data_t *img_data, + co_aix x, co_aix y, co_aix w, co_aix h) { + sh_image_t *img = (sh_image_t *)shape; + paint_t *paint; + + ASSERT(img_data != NULL); + ASSERT(shape->obj.obj_type == MBO_IMAGE); + + paint = rdman_paint_image_new(img->rdman, img_data); + if(paint == NULL) + return ERR; + + if(img->paint) + rdman_paint_free(img->rdman, img->paint); + + img->img_data = img_data; + img->x = x; + img->y = y; + img->w = w; + img->h = h; + img->paint = paint; + rdman_paint_fill(img->rdman, paint, (shape_t *)img); + + return OK; +} + /*! \brief Creae a new image shape. * * \param img_data is image data whose owner-ship is transfered. @@ -85,7 +111,7 @@ img->rdman = rdman; img->shape.free = sh_image_free; - r = sh_image_set_img_data((shape_t *)img, img_data, x, y, w, h); + r = _sh_image_set_img_data((shape_t *)img, img_data, x, y, w, h); if(r != OK) { mb_obj_destroy((shape_t *)img); free(img); @@ -100,7 +126,6 @@ rdman_paint_free(img->rdman, img->paint); mb_obj_destroy(shape); - MB_IMG_DATA_FREE(img->img_data); free(img); } @@ -182,32 +207,13 @@ img->h = h; } -int sh_image_set_img_data(shape_t *shape, mb_img_data_t *img_data, - co_aix x, co_aix y, co_aix w, co_aix h) { +int sh_image_set_img_data(shape_t *shape, mb_img_data_t *img_data) { + int r; sh_image_t *img = (sh_image_t *)shape; - paint_t *paint; - - ASSERT(img_data != NULL); - ASSERT(shape->obj.obj_type == MBO_IMAGE); - paint = rdman_paint_image_new(img->rdman, img_data); - if(paint == NULL) - return ERR; - - if(img->paint) { - rdman_paint_free(img->rdman, img->paint); - MB_IMG_DATA_FREE(img->img_data); - } - - img->img_data = img_data; - img->x = x; - img->y = y; - img->w = w; - img->h = h; - img->paint = paint; - rdman_paint_fill(img->rdman, paint, (shape_t *)img); - - return OK; + r = _sh_image_set_img_data(shape, img_data, + img->x, img->y, img->w, img->h); + return r; } mb_img_data_t *sh_image_get_img_data(shape_t *shape) {
--- a/src/shape_text.c Mon Mar 09 01:28:56 2009 +0800 +++ b/src/shape_text.c Mon Mar 09 01:30:19 2009 +0800 @@ -65,8 +65,7 @@ text->layout = NULL; text->attrs = attrs; text->align = TEXTALIGN_START; - sh_text_P_generate_layout(text, rdman->cr); - + rdman_shape_man(rdman, (shape_t *)text); return (shape_t *)text; @@ -207,6 +206,8 @@ void sh_text_transform(shape_t *shape) { sh_text_t *text; + coord_t *coord; + canvas_t *canvas; co_aix x, y; co_aix shw; PangoRectangle extents; @@ -214,8 +215,12 @@ int r; text = (sh_text_t *)shape; - + text->d_font_size = coord_trans_size(shape->coord, text->font_size); + + coord = sh_get_coord(shape); + canvas = _coord_get_canvas(coord); + sh_text_P_generate_layout(text, (cairo_t *)canvas); x = text->x; y = text->y; @@ -259,7 +264,6 @@ printf("text=%s\n",text->data); } static void draw_text(sh_text_t *text, cairo_t *cr) { - sh_text_P_generate_layout(text, cr); cairo_move_to(cr, text->d_x, text->d_y); pango_cairo_layout_path(cr,text->layout); }
--- a/tools/mb_c_source.m4 Mon Mar 09 01:28:56 2009 +0800 +++ b/tools/mb_c_source.m4 Mon Mar 09 01:30:19 2009 +0800 @@ -300,7 +300,7 @@ define([F_ADD_IMAGE],[[ rdman_shape_free(rdman, obj->$1); - MB_IMAGE_DATA_FREE(obj->$1_img_data); + MB_IMG_DATA_FREE(obj->$1_img_data); ]]) define([F_PANGO_BEGIN_TEXT],[[ rdman_shape_free(rdman, obj->$1); @@ -328,6 +328,7 @@ FIMPORT([ADD_PATH],) FIMPORT([ADD_RECT]) FIMPORT([ADD_TEXT]) +FIMPORT([ADD_IMAGE]) FIMPORT([PANGO_BEGIN_TEXT]) FIMPORT([FILL_SHAPE]) FIMPORT([STROKE_SHAPE]) @@ -355,6 +356,7 @@ RIMPORT([ADD_RECT]) RIMPORT([ADD_COORD]) RIMPORT([ADD_TEXT]) +RIMPORT([ADD_IMAGE]) RIMPORT([PANGO_BEGIN_TEXT]) RIMPORT([FILL_SHAPE]) RIMPORT([STROKE_SHAPE])