comparison src/shape_image.c @ 346:b391722bf20e

sh_image_t::img_data is managed by paint_image_t. - sh_image_t should not try to free it. - call sh_text_P_generate_layout() in sh_text_transform() - remove calling from other functions.
author Thinker K.F. Li <thinker@branda.to>
date Sun, 08 Mar 2009 14:44:41 +0800
parents bb6e964da1c8
children 04d22dc38bc0
comparison
equal deleted inserted replaced
345:d04085404583 346:b391722bf20e
63 redraw_man_t *rdman; 63 redraw_man_t *rdman;
64 } sh_image_t; 64 } sh_image_t;
65 65
66 static void sh_image_free(shape_t *shape); 66 static void sh_image_free(shape_t *shape);
67 67
68 int _sh_image_set_img_data(shape_t *shape, mb_img_data_t *img_data,
69 co_aix x, co_aix y, co_aix w, co_aix h) {
70 sh_image_t *img = (sh_image_t *)shape;
71 paint_t *paint;
72
73 ASSERT(img_data != NULL);
74 ASSERT(shape->obj.obj_type == MBO_IMAGE);
75
76 paint = rdman_paint_image_new(img->rdman, img_data);
77 if(paint == NULL)
78 return ERR;
79
80 if(img->paint)
81 rdman_paint_free(img->rdman, img->paint);
82
83 img->img_data = img_data;
84 img->x = x;
85 img->y = y;
86 img->w = w;
87 img->h = h;
88 img->paint = paint;
89 rdman_paint_fill(img->rdman, paint, (shape_t *)img);
90
91 return OK;
92 }
93
68 /*! \brief Creae a new image shape. 94 /*! \brief Creae a new image shape.
69 * 95 *
70 * \param img_data is image data whose owner-ship is transfered. 96 * \param img_data is image data whose owner-ship is transfered.
71 */ 97 */
72 shape_t *rdman_shape_image_new(redraw_man_t *rdman, mb_img_data_t *img_data, 98 shape_t *rdman_shape_image_new(redraw_man_t *rdman, mb_img_data_t *img_data,
83 memset(img, 0, sizeof(sh_image_t)); 109 memset(img, 0, sizeof(sh_image_t));
84 mb_obj_init((mb_obj_t *)img, MBO_IMAGE); 110 mb_obj_init((mb_obj_t *)img, MBO_IMAGE);
85 img->rdman = rdman; 111 img->rdman = rdman;
86 img->shape.free = sh_image_free; 112 img->shape.free = sh_image_free;
87 113
88 r = sh_image_set_img_data((shape_t *)img, img_data, x, y, w, h); 114 r = _sh_image_set_img_data((shape_t *)img, img_data, x, y, w, h);
89 if(r != OK) { 115 if(r != OK) {
90 mb_obj_destroy((shape_t *)img); 116 mb_obj_destroy((shape_t *)img);
91 free(img); 117 free(img);
92 return NULL; 118 return NULL;
93 } 119 }
98 void sh_image_free(shape_t *shape) { 124 void sh_image_free(shape_t *shape) {
99 sh_image_t *img = (sh_image_t *)shape; 125 sh_image_t *img = (sh_image_t *)shape;
100 126
101 rdman_paint_free(img->rdman, img->paint); 127 rdman_paint_free(img->rdman, img->paint);
102 mb_obj_destroy(shape); 128 mb_obj_destroy(shape);
103 MB_IMG_DATA_FREE(img->img_data);
104 free(img); 129 free(img);
105 } 130 }
106 131
107 void sh_image_transform(shape_t *shape) { 132 void sh_image_transform(shape_t *shape) {
108 sh_image_t *img = (sh_image_t *)shape; 133 sh_image_t *img = (sh_image_t *)shape;
182 img->h = h; 207 img->h = h;
183 } 208 }
184 209
185 int sh_image_set_img_data(shape_t *shape, mb_img_data_t *img_data, 210 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) { 211 co_aix x, co_aix y, co_aix w, co_aix h) {
187 sh_image_t *img = (sh_image_t *)shape; 212 int r;
188 paint_t *paint; 213
189 214 r = _sh_image_set_img_data(shape, img_data, x, y, w, h);
190 ASSERT(img_data != NULL); 215 return r;
216 }
217
218 mb_img_data_t *sh_image_get_img_data(shape_t *shape) {
219 sh_image_t *img = (sh_image_t *)shape;
220
191 ASSERT(shape->obj.obj_type == MBO_IMAGE); 221 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
213 mb_img_data_t *sh_image_get_img_data(shape_t *shape) {
214 sh_image_t *img = (sh_image_t *)shape;
215
216 ASSERT(shape->obj.obj_type == MBO_IMAGE);
217 222
218 return img->img_data; 223 return img->img_data;
219 } 224 }