changeset 160:147c93163ef0

Fix bug of tank that bullet is not hidden when go out the map.
author Thinker K.F. Li <thinker@branda.to>
date Wed, 08 Oct 2008 03:57:56 +0800
parents b90abd31a281
children 0299cdb004a1
files examples/tank/tank_main.c src/mb_types.h src/redraw_man.c
diffstat 3 files changed, 33 insertions(+), 34 deletions(-) [+]
line wrap: on
line diff
--- a/examples/tank/tank_main.c	Sun Oct 05 23:32:58 2008 +0800
+++ b/examples/tank/tank_main.c	Wed Oct 08 03:57:56 2008 +0800
@@ -320,19 +320,9 @@
 static void bullet_go_out_map_and_redraw(event_t *event, void *arg) {
     tank_t *tank = (tank_t *)arg;
     tank_bullet_t *bullet;
-#if 0
-    ob_factory_t *factory;
-    subject_t *redraw;
-#endif
 
     bullet = tank->bullet;
     mb_progm_free(bullet->progm);
-    rdman_force_clean(bullet->rdman);
-#if 0
-    factory = rdman_get_ob_factory(bullet->rdman);
-    redraw = rdman_get_redraw_subject(bullet->rdman);
-    subject_remove_observer(factory, redraw, bullet->ob_redraw);
-#endif
     tank_bullet_free(tank->bullet);
     tank->bullet = NULL;
 }
@@ -341,10 +331,6 @@
     tank_t *tank = (tank_t *)arg;
     tank_bullet_t *bullet;
     redraw_man_t *rdman;
-#if 0
-    subject_t *redraw;
-    ob_factory_t *factory;
-#endif
 
     bullet = tank->bullet;
     rdman = bullet->rdman;
@@ -356,13 +342,7 @@
     rdman_coord_changed(rdman, bullet->coord_pos);
     
     /*! \todo Simplify the procdure of using observer pattern. */
-#if 0
-    factory = rdman_get_ob_factory(rdman);
-    redraw = rdman_get_redraw_subject(rdman);
-    bullet->ob_redraw =
-	subject_add_observer(factory, redraw,
-			     bullet_go_out_map_and_redraw, tank);
-#endif
+
     bullet_go_out_map_and_redraw(NULL, tank);
 }
 
--- a/src/mb_types.h	Sun Oct 05 23:32:58 2008 +0800
+++ b/src/mb_types.h	Wed Oct 08 03:57:56 2008 +0800
@@ -58,7 +58,7 @@
     subject_t *mouse_event;
 };
 #define GEF_DIRTY 0x1
-#define GEF_HIDDEN 0x2
+#define GEF_HIDDEN 0x2		/*!< The geo is hidden. */
 #define GEF_FREE 0x4
 
 extern int is_overlay(area_t *r1, area_t *r2);
@@ -123,11 +123,11 @@
     subject_t *mouse_event;
 } coord_t;
 #define COF_DIRTY 0x1
-#define COF_HIDDEN 0x2
+#define COF_HIDDEN 0x2	        /*!< A coord is hidden. */
 #define COF_OWN_CANVAS 0x4	/*!< A coord owns a canvas or inherit it
-				 * from an ancestor.
+				 * from an ancestor. 
 				 */
-#define COF_SKIP_TRIVAL 0x8	/*!< Temporary skip descendants
+#define COF_SKIP_TRIVAL 0x8	/*!< temporary skip descendants
 				 * when trivaling.
 				 */
 #define COF_FREE 0x10
@@ -142,7 +142,10 @@
 extern void preorder_coord_skip_subtree(coord_t *subroot);
 #define preorder_coord_skip_subtree(sub)		\
     do { (sub)->flags |= COF_SKIP_TRIVAL; } while(0)
-#define coord_hide(co) do { co->flags |= COF_HIDDEN; } while(0)
+#define coord_hide(co)		      \
+    do {			      \
+	(co)->flags |= COF_HIDDEN;    \
+    } while(0)
 #define coord_show(co) do { co->flags &= ~COF_HIDDEN; } while(0)
 #define coord_get_mouse_event(coord) ((coord)->mouse_event)
 
@@ -173,8 +176,14 @@
 enum { SHT_UNKNOW, SHT_PATH, SHT_TEXT, SHT_RECT };
 
 #define sh_get_mouse_event_subject(sh) ((sh)->geo->mouse_event)
-#define sh_hide(sh) do { (sh)->geo->flags |= GEF_HIDDEN; } while(0)
-#define sh_show(sh) do { (sh)->geo->flags &= ~GEF_HIDDEN; } while(0)
+#define sh_hide(sh)			     \
+    do {				     \
+	(sh)->geo->flags |= GEF_HIDDEN;	     \
+    } while(0)
+#define sh_show(sh)					\
+    do {						\
+	(sh)->geo->flags &= ~GEF_HIDDEN;		\
+    } while(0)
 
 
 #endif /* __MB_TYPES_H_ */
--- a/src/redraw_man.c	Sun Oct 05 23:32:58 2008 +0800
+++ b/src/redraw_man.c	Wed Oct 08 03:57:56 2008 +0800
@@ -428,7 +428,8 @@
 	if(geo->flags & GEF_FREE)
 	    return ERR;
 
-	geo->flags |= GEF_FREE | GEF_HIDDEN;
+	geo->flags |= GEF_FREE;
+	sh_hide(shape);
 	if(!(geo->flags & GEF_DIRTY)) {
 	    r = add_dirty_geo(rdman, geo);
 	    if(r != OK)
@@ -575,7 +576,8 @@
 	    if(!(member->flags & GEF_FREE))
 		return ERR;
 	}
-	coord->flags |= COF_FREE | COF_HIDDEN;
+	coord->flags |= COF_FREE;
+	coord_hide(coord);
 	if(!(coord->flags & COF_DIRTY)) {
 	    r = add_dirty_coord(rdman, coord);
 	    if(r != OK)
@@ -635,7 +637,9 @@
 /*! \brief Mark a coord is changed.
  *
  * A changed coord_t object is marked as dirty and put
- * into dirty_coords list.
+ * into dirty_coords list.  rdman_coord_changed() should be called
+ * for a coord after it been changed to notify redraw manager to
+ * redraw shapes grouped by it.
  */
 int rdman_coord_changed(redraw_man_t *rdman, coord_t *coord) {
     coord_t *child;
@@ -645,6 +649,9 @@
 
     add_dirty_coord(rdman, coord);
 
+    if(coord->flags & COF_HIDDEN)
+	return OK;
+
     /* Make child coords dirty. */
     for(child = preorder_coord_subtree(coord, coord);
 	child != NULL;
@@ -728,9 +735,9 @@
     shape->geo->flags &= ~GEF_DIRTY;
 
     if(is_coord_subtree_hidden(shape->coord))
-	shape->geo->flags |= GEF_HIDDEN;
+	sh_hide(shape);
     else
-	shape->geo->flags &= ~GEF_HIDDEN;
+	sh_show(shape);
 }
 
 /*! \brief Setup canvas for the coord.
@@ -1029,6 +1036,9 @@
     cairo_t *canvas;
     int mem_idx;
 
+    if(coord->flags & COF_HIDDEN)
+	return OK;
+
     canvas = coord->canvas;
     member = FIRST_MEMBER(coord);
     mem_idx = 0;
@@ -1045,6 +1055,7 @@
 		draw_shape(rdman, canvas, member->shape);
 		dirty = 1;
 	    }
+
 	    member = NEXT_MEMBER(member);
 	    mem_idx++;
 	}
@@ -1119,7 +1130,6 @@
 	draw_shapes_in_areas(rdman, n_dirty_areas, dirty_areas);
 	copy_cr_2_backend(rdman, rdman->dirty_areas.num,
 			  rdman->dirty_areas.ds);
-	rdman->dirty_areas.num = 0;
 	reset_clip(rdman);
     }
     rdman->dirty_areas.num = 0;