Mercurial > MadButterfly
comparison src/paint.c @ 356:3e84458968ec
Move mb_img_data_t out from argument list of rdman_shape_image_new().
- Application should specify content of sh_image_t by fill the shape
with a paint_image_t.
author | Thinker K.F. Li <thinker@branda.to> |
---|---|
date | Mon, 09 Mar 2009 23:05:57 +0800 |
parents | 04d22dc38bc0 |
children | 16116d84bc5e |
comparison
equal
deleted
inserted
replaced
355:958b67d911db | 356:3e84458968ec |
---|---|
37 return NULL; | 37 return NULL; |
38 color->r = r; | 38 color->r = r; |
39 color->g = g; | 39 color->g = g; |
40 color->b = b; | 40 color->b = b; |
41 color->a = a; | 41 color->a = a; |
42 paint_init(&color->paint, paint_color_prepare, paint_color_free); | 42 paint_init(&color->paint, MBP_COLOR, |
43 paint_color_prepare, paint_color_free); | |
43 return (paint_t *)color; | 44 return (paint_t *)color; |
44 } | 45 } |
45 | 46 |
46 void paint_color_set(paint_t *paint, | 47 void paint_color_set(paint_t *paint, |
47 co_comp_t r, co_comp_t g, | 48 co_comp_t r, co_comp_t g, |
120 | 121 |
121 linear = (paint_linear_t *)malloc(sizeof(paint_linear_t)); | 122 linear = (paint_linear_t *)malloc(sizeof(paint_linear_t)); |
122 if(linear == NULL) | 123 if(linear == NULL) |
123 return NULL; | 124 return NULL; |
124 | 125 |
125 paint_init(&linear->paint, paint_linear_prepare, paint_linear_free); | 126 paint_init(&linear->paint, MBP_LINEAR, |
127 paint_linear_prepare, paint_linear_free); | |
126 | 128 |
127 linear->x1 = x1; | 129 linear->x1 = x1; |
128 linear->y1 = y1; | 130 linear->y1 = y1; |
129 linear->x2 = x2; | 131 linear->x2 = x2; |
130 linear->y2 = y2; | 132 linear->y2 = y2; |
210 | 212 |
211 radial = O_ALLOC(paint_radial_t); | 213 radial = O_ALLOC(paint_radial_t); |
212 if(radial == NULL) | 214 if(radial == NULL) |
213 return NULL; | 215 return NULL; |
214 | 216 |
215 paint_init(&radial->paint, paint_radial_prepare, paint_radial_free); | 217 paint_init(&radial->paint, MBP_RADIAL, |
218 paint_radial_prepare, paint_radial_free); | |
216 radial->cx = cx; | 219 radial->cx = cx; |
217 radial->cy = cy; | 220 radial->cy = cy; |
218 radial->r = r; | 221 radial->r = r; |
219 radial->n_stops = 0; | 222 radial->n_stops = 0; |
220 radial->stops = NULL; | 223 radial->stops = NULL; |
270 paint_image_t *paint_img = (paint_image_t *)paint; | 273 paint_image_t *paint_img = (paint_image_t *)paint; |
271 mb_img_data_t *img_data; | 274 mb_img_data_t *img_data; |
272 | 275 |
273 cairo_surface_destroy(paint_img->surf); | 276 cairo_surface_destroy(paint_img->surf); |
274 img_data = paint_img->img; | 277 img_data = paint_img->img; |
278 MB_IMG_DATA_FREE(img_data); | |
275 paint_destroy(&paint_img->paint); | 279 paint_destroy(&paint_img->paint); |
276 free(paint); | 280 free(paint); |
277 } | 281 } |
278 | 282 |
279 /*! \brief Create an image painter. | 283 /*! \brief Create an image painter. |
280 * | 284 * |
281 * Create a painter that fill/stroke shapes with an image. | 285 * Create a painter that fill/stroke shapes with an image. |
282 * | 286 * |
283 * \param img is image data return by image load. Life-cycle of img | 287 * \param img is image data return by image load. |
284 * is managed by application code. | 288 * Owner-ship of img is transfered. |
285 */ | 289 */ |
286 paint_t *rdman_paint_image_new(redraw_man_t *rdman, | 290 paint_t *rdman_paint_image_new(redraw_man_t *rdman, |
287 mb_img_data_t *img) { | 291 mb_img_data_t *img) { |
288 paint_image_t *paint; | 292 paint_image_t *paint; |
289 int fmt; | 293 int fmt; |
307 | 311 |
308 paint = O_ALLOC(paint_image_t); | 312 paint = O_ALLOC(paint_image_t); |
309 if(paint == NULL) | 313 if(paint == NULL) |
310 return NULL; | 314 return NULL; |
311 | 315 |
312 paint_init(&paint->paint, paint_image_prepare, paint_image_free); | 316 paint_init(&paint->paint, MBP_IMAGE, |
317 paint_image_prepare, paint_image_free); | |
313 paint->img = img; | 318 paint->img = img; |
314 paint->surf = cairo_image_surface_create_for_data(img->content, | 319 paint->surf = cairo_image_surface_create_for_data(img->content, |
315 fmt, | 320 fmt, |
316 img->w, | 321 img->w, |
317 img->h, | 322 img->h, |
349 cmatrix.yx = matrix[3]; | 354 cmatrix.yx = matrix[3]; |
350 cmatrix.yy = matrix[4]; | 355 cmatrix.yy = matrix[4]; |
351 cmatrix.y0 = matrix[5]; | 356 cmatrix.y0 = matrix[5]; |
352 cairo_pattern_set_matrix(img_paint->ptn, &cmatrix); | 357 cairo_pattern_set_matrix(img_paint->ptn, &cmatrix); |
353 } | 358 } |
359 | |
360 void paint_image_get_size(paint_t *paint, int *w, int *h) { | |
361 paint_image_t *ipaint = (paint_image_t *)paint; | |
362 | |
363 ASSERT(paint->pnt_type == MBP_IMAGE); | |
364 *w = ipaint->img->w; | |
365 *h = ipaint->img->h; | |
366 } |