Mercurial > MadButterfly
changeset 338:6a1b36738d3d
sh_image_set_img_data() is a function to change content of a sh_image_t.
author | Thinker K.F. Li <thinker@branda.to> |
---|---|
date | Sun, 08 Mar 2009 00:15:21 +0800 |
parents | 55e0b22b919e |
children | 9c006581f0cd |
files | include/mb_shapes.h src/shape_image.c |
diffstat | 2 files changed, 41 insertions(+), 12 deletions(-) [+] |
line wrap: on
line diff
--- a/include/mb_shapes.h Sat Mar 07 22:59:11 2009 +0800 +++ b/include/mb_shapes.h Sun Mar 08 00:15:21 2009 +0800 @@ -242,6 +242,8 @@ 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); /* @} */ /* @} */
--- a/src/shape_image.c Sat Mar 07 22:59:11 2009 +0800 +++ b/src/shape_image.c Sun Mar 08 00:15:21 2009 +0800 @@ -74,25 +74,23 @@ sh_image_t *img; cairo_format_t fmt; paint_t *paint; + int r; img = O_ALLOC(sh_image_t); if(img == NULL) return NULL; memset(img, 0, sizeof(sh_image_t)); - + mb_obj_init((mb_obj_t *)img, MBO_IMAGE); + img->rdman = rdman; img->shape.free = sh_image_free; - mb_obj_init((mb_obj_t *)img, MBO_IMAGE); - img->x = x; - img->y = y; - img->w = w; - img->h = h; - img->img_data = img_data; - - paint = rdman_paint_image_new(rdman, img_data); - rdman_paint_fill(rdman, paint, (shape_t *)img); - img->paint = paint; - img->rdman = rdman; + + 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); + return NULL; + } return (shape_t *)img; } @@ -183,3 +181,32 @@ img->w = w; 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) { + 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; +} +