changeset 57:ab028c9f0930

Ability to hidden shapes and action of visibility.
author Thinker K.F. Li <thinker@branda.to>
date Sun, 10 Aug 2008 20:25:14 +0800
parents e444a8c01735
children 1ca417f741f1
files src/X_main.c src/animate.c src/animate.h src/mb_types.h src/redraw_man.c
diffstat 5 files changed, 90 insertions(+), 0 deletions(-) [+]
line wrap: on
line diff
--- a/src/X_main.c	Sun Aug 10 18:27:52 2008 +0800
+++ b/src/X_main.c	Sun Aug 10 20:25:14 2008 +0800
@@ -220,6 +220,7 @@
 
 	act = mb_shift_new(0, 20, coord1, word);
 	act = mb_shift_new(0, -20, coord2, word);
+	act = mb_visibility_new(VIS_HIDDEN, coord3, word);
 	
 	MB_TIMEVAL_SET(&start, 3, 0);
 	MB_TIMEVAL_SET(&playing, 2, 0);
@@ -229,6 +230,7 @@
 	act = mb_shift_new(0, 20, coord2, word);
 	act = mb_chgcolor_new(0, 0, 1, 0.5, fill1, word);
 	act = mb_chgcolor_new(1, 0, 0, 0.5, fill2, word);
+	act = mb_visibility_new(VIS_VISIBLE, coord3, word);
 	
 	gettimeofday(&tv, NULL);
 	MB_TIMEVAL_SET(&mbtv, tv.tv_sec, tv.tv_usec);
@@ -236,6 +238,7 @@
 
 	handle_connection(display, tman, &rdman, w, h);
 
+	mb_progm_free(progm);
 	mb_tman_free(tman);
     }
 
--- a/src/animate.c	Sun Aug 10 18:27:52 2008 +0800
+++ b/src/animate.c	Sun Aug 10 20:25:14 2008 +0800
@@ -450,6 +450,67 @@
     return (mb_action_t *)chg;
 }
 
+
+typedef struct _mb_visibility mb_visibility_t;
+
+struct _mb_visibility {
+    mb_action_t action;
+    int visibility;
+    coord_t *coord;
+};
+
+static void mb_visibility_start(mb_action_t *act,
+				const mb_timeval_t *now,
+				const mb_timeval_t *playing_time,
+				redraw_man_t *rdman) {
+    mb_visibility_t *visibility = (mb_visibility_t *)act;
+
+    switch(visibility->visibility) {
+    case VIS_VISIBLE:
+	coord_show(visibility->coord);
+	break;
+    case VIS_HIDDEN:
+	coord_hide(visibility->coord);
+	break;
+    }
+    rdman_coord_changed(rdman, visibility->coord);
+}
+
+static void mb_visibility_step(mb_action_t *act,
+			       const mb_timeval_t *now,
+			       redraw_man_t *rdman) {
+}
+
+static void mb_visibility_stop(mb_action_t *act,
+			       const mb_timeval_t *now,
+			       redraw_man_t *rdman) {
+}
+
+static void mb_visibility_free(mb_action_t *act) {
+    free(act);
+}
+
+mb_action_t *mb_visibility_new(int visib, coord_t *coord,
+			       mb_word_t *word) {
+    mb_visibility_t *visibility;
+
+    visibility = (mb_visibility_t *)malloc(sizeof(mb_visibility_t));
+    if(visibility == NULL)
+	return NULL;
+
+    visibility->visibility = visib;
+    visibility->coord = coord;
+
+    visibility->action.start = mb_visibility_start;
+    visibility->action.step = mb_visibility_step;
+    visibility->action.stop = mb_visibility_stop;
+    visibility->action.free = mb_visibility_free;
+
+    mb_word_add_action(word, (mb_action_t *)visibility);
+
+    return (mb_action_t *)visibility;
+}
+
 #ifdef UNITTEST
 
 #include <CUnit/Basic.h>
--- a/src/animate.h	Sun Aug 10 18:27:52 2008 +0800
+++ b/src/animate.h	Sun Aug 10 20:25:14 2008 +0800
@@ -24,5 +24,9 @@
 				    co_comp_t b, co_comp_t a,
 				    paint_t *paint, mb_word_t *word);
 
+enum { VIS_VISIBLE, VIS_HIDDEN };
+extern mb_action_t *mb_visibility_new(int visib, coord_t *coord,
+				      mb_word_t *word);
+
 
 #endif /* __ANIMATE_H_ */
--- a/src/mb_types.h	Sun Aug 10 18:27:52 2008 +0800
+++ b/src/mb_types.h	Sun Aug 10 20:25:14 2008 +0800
@@ -41,6 +41,7 @@
     area_t areas[2];
 };
 #define GEF_DIRTY 0x1
+#define GEF_HIDDEN 0x2
 
 extern int is_overlay(area_t *r1, area_t *r2);
 extern void area_init(area_t *area, int n_pos, co_aix pos[][2]);
@@ -89,6 +90,7 @@
     STAILQ(shape_t) members;	/*!< All shape_t objects in this coord. */
 } coord_t;
 #define COF_DIRTY 0x1
+#define COF_HIDDEN 0x2
 
 extern void coord_init(coord_t *co, coord_t *parent);
 extern void coord_trans_pos(coord_t *co, co_aix *x, co_aix *y);
@@ -96,6 +98,8 @@
 extern void compute_aggr_of_coord(coord_t *coord);
 extern void update_aggr_matrix(coord_t *start);
 extern coord_t *preorder_coord_subtree(coord_t *root, coord_t *last);
+#define coord_hide(co) do { co->flags |= COF_HIDDEN; } while(0)
+#define coord_show(co) do { co->flags &= ~COF_HIDDEN; } while(0)
 
 
 /*! \brief A grahpic shape.
--- a/src/redraw_man.c	Sun Aug 10 18:27:52 2008 +0800
+++ b/src/redraw_man.c	Sun Aug 10 20:25:14 2008 +0800
@@ -395,6 +395,15 @@
 
 /* Clean dirties */
 
+static int is_coord_subtree_hidden(coord_t *coord) {
+    while(coord) {
+	if(coord->flags & COF_HIDDEN)
+	    return 1;
+	coord = coord->parent;
+    }
+    return 0;
+}
+
 static void clean_shape(shape_t *shape) {
     switch(shape->sh_type) {
     case SHT_PATH:
@@ -413,6 +422,11 @@
 #endif /* UNITTEST */
     }
     shape->geo->flags &= ~GEF_DIRTY;
+
+    if(is_coord_subtree_hidden(shape->coord))
+	shape->geo->flags |= GEF_HIDDEN;
+    else
+	shape->geo->flags &= ~GEF_HIDDEN;
 }
 
 static int clean_coord(coord_t *coord) {
@@ -651,6 +665,8 @@
 	visit_geo = STAILQ_NEXT(geo_t, next, visit_geo)) {
 	if(visit_geo->flags & GEF_DIRTY)
 	    clean_shape(visit_geo->shape);
+	if(visit_geo->flags & GEF_HIDDEN)
+	    continue;
 	for(i = 0; i < n_areas; i++) {
 	    if(is_overlay(visit_geo->cur_area, areas[i])) {
 		draw_shape(rdman, visit_geo->shape);
@@ -733,6 +749,8 @@
     for(geo = STAILQ_HEAD(rdman->all_geos);
 	geo != NULL;
 	geo = STAILQ_NEXT(geo_t, next, geo)) {
+	if(geo->flags & GEF_HIDDEN)
+	    continue;
 	draw_shape(rdman, geo->shape);
     }
     copy_cr_2_backend(rdman, 0, NULL);