comparison src/X_main.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 a6763f080da5
children c7e5b8779bb5
comparison
equal deleted inserted replaced
158:c1cdd3fcd28f 159:b90abd31a281
146 redraw_man_init(&rdman, tmpcr, cr); 146 redraw_man_init(&rdman, tmpcr, cr);
147 coord1 = rdman_coord_new(&rdman, rdman.root_coord); 147 coord1 = rdman_coord_new(&rdman, rdman.root_coord);
148 coord2 = rdman_coord_new(&rdman, rdman.root_coord); 148 coord2 = rdman_coord_new(&rdman, rdman.root_coord);
149 coord3 = rdman_coord_new(&rdman, rdman.root_coord); 149 coord3 = rdman_coord_new(&rdman, rdman.root_coord);
150 150
151 fill1 = paint_color_new(&rdman, 1, 1, 0, 0.5); 151 fill1 = rdman_paint_color_new(&rdman, 1, 1, 0, 0.5);
152 fill2 = paint_color_new(&rdman, 0, 1, 1, 0.5); 152 fill2 = rdman_paint_color_new(&rdman, 0, 1, 1, 0.5);
153 stroke = paint_color_new(&rdman, 0.4, 0.4, 0.4, 1); 153 stroke = rdman_paint_color_new(&rdman, 0.4, 0.4, 0.4, 1);
154 text_stroke = paint_color_new(&rdman, 0.5, 0.5, 0.5, 1); 154 text_stroke = rdman_paint_color_new(&rdman, 0.5, 0.5, 0.5, 1);
155 155
156 face = cairo_get_font_face(tmpcr); 156 face = cairo_get_font_face(tmpcr);
157 text = sh_text_new("hello \xe6\xbc\xa2\xe5\xad\x97", 10, h / 4, 157 text = rdman_shape_text_new(&rdman, "hello \xe6\xbc\xa2\xe5\xad\x97",
158 36.0, face); 158 10, h / 4, 36.0, face);
159 text_fill = paint_radial_new(&rdman, 100, h / 4, 70); 159 text_fill = rdman_paint_radial_new(&rdman, 100, h / 4, 70);
160 grad_stop_init(text_stops, 0, 0.2, 0.9, 0.2, 1); 160 grad_stop_init(text_stops, 0, 0.2, 0.9, 0.2, 1);
161 grad_stop_init(text_stops + 1, 1, 0.9, 0.2, 0.2, 0.1); 161 grad_stop_init(text_stops + 1, 1, 0.9, 0.2, 0.2, 0.1);
162 paint_radial_stops(text_fill, 2, text_stops); 162 paint_radial_stops(text_fill, 2, text_stops);
163 rdman_paint_stroke(&rdman, text_stroke, text); 163 rdman_paint_stroke(&rdman, text_stroke, text);
164 text->stroke_width = 0.5; 164 text->stroke_width = 0.5;
165 rdman_paint_fill(&rdman, text_fill, text); 165 rdman_paint_fill(&rdman, text_fill, text);
166 rdman_add_shape(&rdman, text, coord3); 166 rdman_add_shape(&rdman, text, coord3);
167 167
168 path1 = sh_path_new("M 22,89.36218 C -34,-0.63782 39,-9.637817 82,12.36218 C 125,34.36218 142,136.36218 142,136.36218 C 100.66667,125.36218 74.26756,123.42795 22,89.36218 z "); 168 path1 = rdman_shape_path_new(&rdman, "M 22,89.36218 C -34,-0.63782 39,-9.637817 82,12.36218 C 125,34.36218 142,136.36218 142,136.36218 C 100.66667,125.36218 74.26756,123.42795 22,89.36218 z ");
169 rdman_paint_fill(&rdman, fill1, path1); 169 rdman_paint_fill(&rdman, fill1, path1);
170 rdman_paint_stroke(&rdman, stroke, path1); 170 rdman_paint_stroke(&rdman, stroke, path1);
171 coord1->matrix[0] = 0.8; 171 coord1->matrix[0] = 0.8;
172 coord1->matrix[1] = 0; 172 coord1->matrix[1] = 0;
173 coord1->matrix[2] = 20; 173 coord1->matrix[2] = 20;
174 coord1->matrix[4] = 0.8; 174 coord1->matrix[4] = 0.8;
175 coord1->matrix[5] = 20; 175 coord1->matrix[5] = 20;
176 176
177 path2 = sh_path_new("M 22,89.36218 C -34,-0.63782 39,-9.637817 82,12.36218 C 125,34.36218 142,136.36218 142,136.36218 C 100.66667,125.36218 74.26756,123.42795 22,89.36218 z "); 177 path2 = rdman_shape_path_new(&rdman, "M 22,89.36218 C -34,-0.63782 39,-9.637817 82,12.36218 C 125,34.36218 142,136.36218 142,136.36218 C 100.66667,125.36218 74.26756,123.42795 22,89.36218 z ");
178 rdman_paint_fill(&rdman, fill2, path2); 178 rdman_paint_fill(&rdman, fill2, path2);
179 rdman_paint_stroke(&rdman, stroke, path2); 179 rdman_paint_stroke(&rdman, stroke, path2);
180 coord2->matrix[0] = -0.8; 180 coord2->matrix[0] = -0.8;
181 coord2->matrix[1] = 0; 181 coord2->matrix[1] = 0;
182 coord2->matrix[2] = 180; 182 coord2->matrix[2] = 180;
187 rdman_coord_changed(&rdman, coord2); 187 rdman_coord_changed(&rdman, coord2);
188 rdman_add_shape(&rdman, (shape_t *)path1, coord1); 188 rdman_add_shape(&rdman, (shape_t *)path1, coord1);
189 rdman_add_shape(&rdman, (shape_t *)path2, coord2); 189 rdman_add_shape(&rdman, (shape_t *)path2, coord2);
190 190
191 191
192 fill3 = paint_linear_new(&rdman, 50, 50, 150, 150); 192 fill3 = rdman_paint_linear_new(&rdman, 50, 50, 150, 150);
193 grad_stop_init(fill3_stops, 0, 1, 0, 0, 0.5); 193 grad_stop_init(fill3_stops, 0, 1, 0, 0, 0.5);
194 grad_stop_init(fill3_stops + 1, 0.5, 0, 1, 0, 0.5); 194 grad_stop_init(fill3_stops + 1, 0.5, 0, 1, 0, 0.5);
195 grad_stop_init(fill3_stops + 2, 1, 0, 0, 1, 0.5); 195 grad_stop_init(fill3_stops + 2, 1, 0, 0, 1, 0.5);
196 paint_linear_stops(fill3, 3, fill3_stops); 196 paint_linear_stops(fill3, 3, fill3_stops);
197 rect = sh_rect_new(50, 50, 100, 100, 20, 20); 197 rect = rdman_shape_rect_new(&rdman, 50, 50, 100, 100, 20, 20);
198 rdman_paint_fill(&rdman, fill3, rect); 198 rdman_paint_fill(&rdman, fill3, rect);
199 rdman_add_shape(&rdman, (shape_t *)rect, rdman.root_coord); 199 rdman_add_shape(&rdman, (shape_t *)rect, rdman.root_coord);
200 200
201 rdman_redraw_all(&rdman); 201 rdman_redraw_all(&rdman);
202 202
241 241
242 mb_progm_free(progm); 242 mb_progm_free(progm);
243 mb_tman_free(tman); 243 mb_tman_free(tman);
244 } 244 }
245 245
246 fill1->free(fill1); 246 rdman_paint_free(&rdman, fill1);
247 fill2->free(fill2); 247 rdman_paint_free(&rdman, fill2);
248 stroke->free(stroke); 248 rdman_paint_free(&rdman, stroke);
249 text_stroke->free(text_stroke); 249 rdman_paint_free(&rdman, text_stroke);
250 text_fill->free(text_fill); 250 rdman_paint_free(&rdman, text_fill);
251 rdman_shape_free(&rdman, path1);
252 rdman_shape_free(&rdman, path2);
253 rdman_shape_free(&rdman, rect);
254 rdman_shape_free(&rdman, text);
251 redraw_man_destroy(&rdman); 255 redraw_man_destroy(&rdman);
252 path1->free(path1);
253 path2->free(path2);
254 rect->free(rect);
255 text->free(text);
256 cairo_destroy(tmpcr); 256 cairo_destroy(tmpcr);
257 cairo_surface_destroy(tmpsuf); 257 cairo_surface_destroy(tmpsuf);
258 } 258 }
259 259
260 void drawing(cairo_surface_t *surface, int w, int h) { 260 void drawing(cairo_surface_t *surface, int w, int h) {