# HG changeset patch # User Thinker K.F. Li # Date 1236522294 -28800 # Node ID 04d22dc38bc0cf23d6d23177386d8cc1d52aaafd # Parent b247beaac4f0d079644498f8130927738fe5d6db Change declaration of sh_image_set_img_data(). - x, y, w, h are not passed to sh_image_set_img_data() any more. - Applications should manage life-cycle of mb_img_data_t, paint_image_t do not manage it for applications any more. diff -r b247beaac4f0 -r 04d22dc38bc0 examples/menu/filebrowser.c --- a/examples/menu/filebrowser.c Sun Mar 08 21:57:15 2009 +0800 +++ b/examples/menu/filebrowser.c Sun Mar 08 22:24:54 2009 +0800 @@ -71,11 +71,19 @@ 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); + 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)); } diff -r b247beaac4f0 -r 04d22dc38bc0 include/mb_shapes.h --- a/include/mb_shapes.h Sun Mar 08 21:57:15 2009 +0800 +++ b/include/mb_shapes.h Sun Mar 08 22:24:54 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); /* @} */ /* @} */ diff -r b247beaac4f0 -r 04d22dc38bc0 src/paint.c --- a/src/paint.c Sun Mar 08 21:57:15 2009 +0800 +++ b/src/paint.c Sun Mar 08 22:24:54 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) { diff -r b247beaac4f0 -r 04d22dc38bc0 src/shape_image.c --- a/src/shape_image.c Sun Mar 08 21:57:15 2009 +0800 +++ b/src/shape_image.c Sun Mar 08 22:24:54 2009 +0800 @@ -207,11 +207,12 @@ 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; - r = _sh_image_set_img_data(shape, img_data, x, y, w, h); + r = _sh_image_set_img_data(shape, img_data, + img->x, img->y, img->w, img->h); return r; }