Mercurial > MadButterfly
comparison src/shape_image.c @ 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 | 43900cae1d49 |
children | bb6e964da1c8 |
comparison
equal
deleted
inserted
replaced
337:55e0b22b919e | 338:6a1b36738d3d |
---|---|
72 shape_t *rdman_shape_image_new(redraw_man_t *rdman, mb_img_data_t *img_data, | 72 shape_t *rdman_shape_image_new(redraw_man_t *rdman, mb_img_data_t *img_data, |
73 co_aix x, co_aix y, co_aix w, co_aix h) { | 73 co_aix x, co_aix y, co_aix w, co_aix h) { |
74 sh_image_t *img; | 74 sh_image_t *img; |
75 cairo_format_t fmt; | 75 cairo_format_t fmt; |
76 paint_t *paint; | 76 paint_t *paint; |
77 int r; | |
77 | 78 |
78 img = O_ALLOC(sh_image_t); | 79 img = O_ALLOC(sh_image_t); |
79 if(img == NULL) | 80 if(img == NULL) |
80 return NULL; | 81 return NULL; |
81 | 82 |
82 memset(img, 0, sizeof(sh_image_t)); | 83 memset(img, 0, sizeof(sh_image_t)); |
83 | 84 mb_obj_init((mb_obj_t *)img, MBO_IMAGE); |
85 img->rdman = rdman; | |
84 img->shape.free = sh_image_free; | 86 img->shape.free = sh_image_free; |
85 mb_obj_init((mb_obj_t *)img, MBO_IMAGE); | 87 |
86 img->x = x; | 88 r = sh_image_set_img_data((shape_t *)img, img_data, x, y, w, h); |
87 img->y = y; | 89 if(r != OK) { |
88 img->w = w; | 90 mb_obj_destroy((shape_t *)img); |
89 img->h = h; | 91 free(img); |
90 img->img_data = img_data; | 92 return NULL; |
91 | 93 } |
92 paint = rdman_paint_image_new(rdman, img_data); | |
93 rdman_paint_fill(rdman, paint, (shape_t *)img); | |
94 img->paint = paint; | |
95 img->rdman = rdman; | |
96 | 94 |
97 return (shape_t *)img; | 95 return (shape_t *)img; |
98 } | 96 } |
99 | 97 |
100 void sh_image_free(shape_t *shape) { | 98 void sh_image_free(shape_t *shape) { |
181 img->x = x; | 179 img->x = x; |
182 img->y = y; | 180 img->y = y; |
183 img->w = w; | 181 img->w = w; |
184 img->h = h; | 182 img->h = h; |
185 } | 183 } |
184 | |
185 int sh_image_set_img_data(shape_t *shape, mb_img_data_t *img_data, | |
186 co_aix x, co_aix y, co_aix w, co_aix h) { | |
187 sh_image_t *img = (sh_image_t *)shape; | |
188 paint_t *paint; | |
189 | |
190 ASSERT(img_data != NULL); | |
191 ASSERT(shape->obj.obj_type == MBO_IMAGE); | |
192 | |
193 paint = rdman_paint_image_new(img->rdman, img_data); | |
194 if(paint == NULL) | |
195 return ERR; | |
196 | |
197 if(img->paint) { | |
198 rdman_paint_free(img->rdman, img->paint); | |
199 MB_IMG_DATA_FREE(img->img_data); | |
200 } | |
201 | |
202 img->img_data = img_data; | |
203 img->x = x; | |
204 img->y = y; | |
205 img->w = w; | |
206 img->h = h; | |
207 img->paint = paint; | |
208 rdman_paint_fill(img->rdman, paint, (shape_t *)img); | |
209 | |
210 return OK; | |
211 } | |
212 |