comparison src/redraw_man.c @ 154:6ce68c1f7405

Tank can fire bullet. 1. Add the redraw subject on redraw_man_t. 2. mb_c_source.m4 & mb_c_header.m4 are changed to free & remove shapes. 3. Add rdman_coord_subtree_free() to remove a subtree of coords. 4. Fix bug of rdman_remove_shape().
author Thinker K.F. Li <thinker@branda.to>
date Tue, 30 Sep 2008 02:44:06 +0800
parents 2b316b5d65f9
children c1cdd3fcd28f
comparison
equal deleted inserted replaced
153:9870b049b7f6 154:6ce68c1f7405
269 rdman->ob_factory.subject_free = ob_subject_free; 269 rdman->ob_factory.subject_free = ob_subject_free;
270 rdman->ob_factory.observer_alloc = ob_observer_alloc; 270 rdman->ob_factory.observer_alloc = ob_observer_alloc;
271 rdman->ob_factory.observer_free = ob_observer_free; 271 rdman->ob_factory.observer_free = ob_observer_free;
272 rdman->ob_factory.get_parent_subject = ob_get_parent_subject; 272 rdman->ob_factory.get_parent_subject = ob_get_parent_subject;
273 273
274 rdman->redraw =
275 subject_new(&rdman->ob_factory, rdman, OBJT_RDMAN);
276
274 rdman->root_coord = elmpool_elm_alloc(rdman->coord_pool); 277 rdman->root_coord = elmpool_elm_alloc(rdman->coord_pool);
275 if(rdman->root_coord == NULL) 278 if(rdman->root_coord == NULL)
276 redraw_man_destroy(rdman); 279 redraw_man_destroy(rdman);
277 rdman->n_coords = 1; 280 rdman->n_coords = 1;
278 coord_init(rdman->root_coord, NULL); 281 coord_init(rdman->root_coord, NULL);
362 return OK; 365 return OK;
363 } 366 }
364 367
365 /*! \brief Remove a shape object from redraw manager. 368 /*! \brief Remove a shape object from redraw manager.
366 * 369 *
370 * \note Shapes should be removed after redrawing or when rdman is in clean.
367 * \todo redraw shape objects that overlaid with removed one. 371 * \todo redraw shape objects that overlaid with removed one.
372 * \todo To allow shapes be removed at anytime.
368 */ 373 */
369 int rdman_remove_shape(redraw_man_t *rdman, shape_t *shape) { 374 int rdman_remove_shape(redraw_man_t *rdman, shape_t *shape) {
370 geo_t *geo; 375 geo_t *geo;
371 coord_t *coord; 376 coord_t *coord;
372 377
373 geo = shape->geo; 378 geo = shape->geo;
374 coord = shape->coord; 379 coord = shape->coord;
375 geo_detach_coord(geo, coord); 380 geo_detach_coord(geo, coord);
376 subject_free(&rdman->ob_factory, geo->mouse_event); 381 subject_free(&rdman->ob_factory, geo->mouse_event);
377 sh_detach_geo(shape); 382 sh_detach_geo(shape);
378 elmpool_elm_free(rdman->geo_pool, shape->geo); 383 elmpool_elm_free(rdman->geo_pool, geo);
379 sh_detach_coord(shape); 384 sh_detach_coord(shape);
380 return OK; 385 return OK;
381 } 386 }
382 387
383 coord_t *rdman_coord_new(redraw_man_t *rdman, coord_t *parent) { 388 coord_t *rdman_coord_new(redraw_man_t *rdman, coord_t *parent) {
443 448
444 RM_CHILD(parent, coord); 449 RM_CHILD(parent, coord);
445 subject_free(&rdman->ob_factory, coord->mouse_event); 450 subject_free(&rdman->ob_factory, coord->mouse_event);
446 elmpool_elm_free(rdman->coord_pool, coord); 451 elmpool_elm_free(rdman->coord_pool, coord);
447 rdman->n_coords--; 452 rdman->n_coords--;
453
454 return OK;
455 }
456
457 int rdman_coord_subtree_free(redraw_man_t *rdman, coord_t *subtree) {
458 coord_t *coord, *prev_coord;
459 int r;
460
461 if(subtree == NULL)
462 return OK;
463
464 prev_coord = postorder_coord_subtree(subtree, NULL);
465 for(coord = postorder_coord_subtree(subtree, prev_coord);
466 coord != NULL;
467 coord = postorder_coord_subtree(subtree, coord)) {
468 r = rdman_coord_free(rdman, prev_coord);
469 if(r != OK)
470 return ERR;
471 prev_coord = coord;
472 }
473 r = rdman_coord_free(rdman, prev_coord);
474 if(r != OK)
475 return ERR;
448 476
449 return OK; 477 return OK;
450 } 478 }
451 479
452 /*! \brief Mark a coord is changed. 480 /*! \brief Mark a coord is changed.
919 */ 947 */
920 int rdman_redraw_changed(redraw_man_t *rdman) { 948 int rdman_redraw_changed(redraw_man_t *rdman) {
921 int r; 949 int r;
922 int n_dirty_areas; 950 int n_dirty_areas;
923 area_t **dirty_areas; 951 area_t **dirty_areas;
952 event_t event;
953 ob_factory_t *factory;
954 subject_t *redraw;
924 955
925 r = clean_rdman_dirties(rdman); 956 r = clean_rdman_dirties(rdman);
926 if(r != OK) 957 if(r != OK)
927 return ERR; 958 return ERR;
928 959
937 copy_cr_2_backend(rdman, rdman->n_dirty_areas, rdman->dirty_areas); 968 copy_cr_2_backend(rdman, rdman->n_dirty_areas, rdman->dirty_areas);
938 rdman->n_dirty_areas = 0; 969 rdman->n_dirty_areas = 0;
939 reset_clip(rdman); 970 reset_clip(rdman);
940 } 971 }
941 rdman->n_dirty_areas = 0; 972 rdman->n_dirty_areas = 0;
973
974 factory = rdman_get_ob_factory(rdman);
975 redraw = rdman_get_redraw_subject(rdman);
976 event.type = EVT_RDMAN_REDRAW;
977 event.tgt = event.cur_tgt = redraw;
978 subject_notify(factory, redraw, &event);
942 979
943 return OK; 980 return OK;
944 } 981 }
945 982
946 /* NOTE: Before redrawing, the canvas/surface must be cleaned. 983 /* NOTE: Before redrawing, the canvas/surface must be cleaned.