Mercurial > MadButterfly
comparison src/paint.c @ 159:b90abd31a281
Postponse free of coords, shapes, and paints when the rdman is dirty.
- Life-cycle of shapes and paints are managed by rdman.
- Add redraw_man_t::free_objs to collect objects their freeing are
postonsed.
Know Issue:
- Bullet of tank are not removed from screen when it is go out the range
of the map.
author | Thinker K.F. Li <thinker@branda.to> |
---|---|
date | Sun, 05 Oct 2008 23:32:58 +0800 |
parents | 6ce68c1f7405 |
children | c7e5b8779bb5 |
comparison
equal
deleted
inserted
replaced
158:c1cdd3fcd28f | 159:b90abd31a281 |
---|---|
8 /*! \brief Solid color paint. | 8 /*! \brief Solid color paint. |
9 */ | 9 */ |
10 typedef struct _paint_color { | 10 typedef struct _paint_color { |
11 paint_t paint; | 11 paint_t paint; |
12 co_comp_t r, g, b, a; | 12 co_comp_t r, g, b, a; |
13 redraw_man_t *rdman; | |
14 } paint_color_t; | 13 } paint_color_t; |
15 | 14 |
16 int _paint_color_size = sizeof(paint_color_t); | 15 int _paint_color_size = sizeof(paint_color_t); |
17 | 16 |
18 | 17 |
20 paint_color_t *color = (paint_color_t *)paint; | 19 paint_color_t *color = (paint_color_t *)paint; |
21 | 20 |
22 cairo_set_source_rgba(cr, color->r, color->g, color->b, color->a); | 21 cairo_set_source_rgba(cr, color->r, color->g, color->b, color->a); |
23 } | 22 } |
24 | 23 |
25 static void paint_color_free(paint_t *paint) { | 24 static void paint_color_free(redraw_man_t *rdman, paint_t *paint) { |
26 paint_color_t *color = (paint_color_t *)paint; | 25 shnode_list_free(rdman, paint->members); |
27 | 26 elmpool_elm_free(rdman->paint_color_pool, paint); |
28 shnode_list_free(color->rdman, paint->members); | 27 } |
29 elmpool_elm_free(color->rdman->paint_color_pool, paint); | 28 |
30 } | 29 paint_t *rdman_paint_color_new(redraw_man_t *rdman, |
31 | 30 co_comp_t r, co_comp_t g, |
32 paint_t *paint_color_new(redraw_man_t *rdman, | 31 co_comp_t b, co_comp_t a) { |
33 co_comp_t r, co_comp_t g, | |
34 co_comp_t b, co_comp_t a) { | |
35 paint_color_t *color; | 32 paint_color_t *color; |
36 | 33 |
37 color = (paint_color_t *)elmpool_elm_alloc(rdman->paint_color_pool); | 34 color = (paint_color_t *)elmpool_elm_alloc(rdman->paint_color_pool); |
38 if(color == NULL) | 35 if(color == NULL) |
39 return NULL; | 36 return NULL; |
40 color->rdman = rdman; | |
41 color->r = r; | 37 color->r = r; |
42 color->g = g; | 38 color->g = g; |
43 color->b = b; | 39 color->b = b; |
44 color->a = a; | 40 color->a = a; |
45 paint_init(&color->paint, paint_color_prepare, paint_color_free); | 41 paint_init(&color->paint, paint_color_prepare, paint_color_free); |
105 } | 101 } |
106 | 102 |
107 cairo_set_source(cr, ptn); | 103 cairo_set_source(cr, ptn); |
108 } | 104 } |
109 | 105 |
110 static void paint_linear_free(paint_t *paint) { | 106 static void paint_linear_free(redraw_man_t *rdman, paint_t *paint) { |
111 paint_linear_t *linear = (paint_linear_t *)paint; | 107 paint_linear_t *linear = (paint_linear_t *)paint; |
112 | 108 |
113 if(linear->ptn) | 109 if(linear->ptn) |
114 cairo_pattern_destroy(linear->ptn); | 110 cairo_pattern_destroy(linear->ptn); |
115 free(paint); | 111 free(paint); |
116 } | 112 } |
117 | 113 |
118 paint_t *paint_linear_new(redraw_man_t *rdman, | 114 paint_t *rdman_paint_linear_new(redraw_man_t *rdman, |
119 co_aix x1, co_aix y1, co_aix x2, co_aix y2) { | 115 co_aix x1, co_aix y1, |
116 co_aix x2, co_aix y2) { | |
120 paint_linear_t *linear; | 117 paint_linear_t *linear; |
121 | 118 |
122 linear = (paint_linear_t *)malloc(sizeof(paint_linear_t)); | 119 linear = (paint_linear_t *)malloc(sizeof(paint_linear_t)); |
123 if(linear == NULL) | 120 if(linear == NULL) |
124 return NULL; | 121 return NULL; |
194 radial->ptn = ptn; | 191 radial->ptn = ptn; |
195 } | 192 } |
196 cairo_set_source(cr, radial->ptn); | 193 cairo_set_source(cr, radial->ptn); |
197 } | 194 } |
198 | 195 |
199 static void paint_radial_free(paint_t *paint) { | 196 static void paint_radial_free(redraw_man_t *rdman, paint_t *paint) { |
200 paint_radial_t *radial = (paint_radial_t *)paint; | 197 paint_radial_t *radial = (paint_radial_t *)paint; |
201 | 198 |
202 if(radial->ptn) | 199 if(radial->ptn) |
203 cairo_pattern_destroy(radial->ptn); | 200 cairo_pattern_destroy(radial->ptn); |
204 free(paint); | 201 free(paint); |
205 } | 202 } |
206 | 203 |
207 paint_t *paint_radial_new(redraw_man_t *rdman, | 204 paint_t *rdman_paint_radial_new(redraw_man_t *rdman, |
208 co_aix cx, co_aix cy, co_aix r) { | 205 co_aix cx, co_aix cy, co_aix r) { |
209 paint_radial_t *radial; | 206 paint_radial_t *radial; |
210 | 207 |
211 radial = O_ALLOC(paint_radial_t); | 208 radial = O_ALLOC(paint_radial_t); |
212 if(radial == NULL) | 209 if(radial == NULL) |
213 return NULL; | 210 return NULL; |