diff 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
line wrap: on
line diff
--- a/src/redraw_man.c	Sat Sep 27 02:40:42 2008 +0800
+++ b/src/redraw_man.c	Tue Sep 30 02:44:06 2008 +0800
@@ -271,6 +271,9 @@
     rdman->ob_factory.observer_free = ob_observer_free;
     rdman->ob_factory.get_parent_subject = ob_get_parent_subject;
 
+    rdman->redraw =
+	subject_new(&rdman->ob_factory, rdman, OBJT_RDMAN);
+
     rdman->root_coord = elmpool_elm_alloc(rdman->coord_pool);
     if(rdman->root_coord == NULL)
 	redraw_man_destroy(rdman);
@@ -364,7 +367,9 @@
 
 /*! \brief Remove a shape object from redraw manager.
  *
+ * \note Shapes should be removed after redrawing or when rdman is in clean.
  * \todo redraw shape objects that overlaid with removed one.
+ * \todo To allow shapes be removed at anytime.
  */
 int rdman_remove_shape(redraw_man_t *rdman, shape_t *shape) {
     geo_t *geo;
@@ -375,7 +380,7 @@
     geo_detach_coord(geo, coord);
     subject_free(&rdman->ob_factory, geo->mouse_event);
     sh_detach_geo(shape);
-    elmpool_elm_free(rdman->geo_pool, shape->geo);
+    elmpool_elm_free(rdman->geo_pool, geo);
     sh_detach_coord(shape);
     return OK;
 }
@@ -449,6 +454,29 @@
     return OK;
 }
 
+int rdman_coord_subtree_free(redraw_man_t *rdman, coord_t *subtree) {
+    coord_t *coord, *prev_coord;
+    int r;
+
+    if(subtree == NULL)
+	return OK;
+
+    prev_coord = postorder_coord_subtree(subtree, NULL);
+    for(coord = postorder_coord_subtree(subtree, prev_coord);
+	coord != NULL;
+	coord = postorder_coord_subtree(subtree, coord)) {
+	r = rdman_coord_free(rdman, prev_coord);
+	if(r != OK)
+	    return ERR;
+	prev_coord = coord;
+    }
+    r = rdman_coord_free(rdman, prev_coord);
+    if(r != OK)
+	return ERR;
+
+    return OK;
+}
+
 /*! \brief Mark a coord is changed.
  *
  * A changed coord_t object is marked as dirty and put
@@ -921,6 +949,9 @@
     int r;
     int n_dirty_areas;
     area_t **dirty_areas;
+    event_t event;
+    ob_factory_t *factory;
+    subject_t *redraw;
 
     r = clean_rdman_dirties(rdman);
     if(r != OK)
@@ -940,6 +971,12 @@
     }
     rdman->n_dirty_areas = 0;
 
+    factory = rdman_get_ob_factory(rdman);
+    redraw = rdman_get_redraw_subject(rdman);
+    event.type = EVT_RDMAN_REDRAW;
+    event.tgt = event.cur_tgt = redraw;
+    subject_notify(factory, redraw, &event);
+
     return OK;
 }