changeset 202:75ec0124202a

Commit merged between 200 and 201
author wycc@wycc-desktop
date Tue, 09 Dec 2008 23:34:05 +0800
parents 31933f9ee70e (current diff) c234ee745ceb (diff)
children 1d485bf96480
files examples/drag/Makefile.in src/observer.c src/shape_path.c
diffstat 15 files changed, 144 insertions(+), 30 deletions(-) [+]
line wrap: on
line diff
--- a/examples/drag/Makefile.in	Sun Dec 07 18:00:06 2008 +0800
+++ b/examples/drag/Makefile.in	Tue Dec 09 23:34:05 2008 +0800
@@ -35,7 +35,7 @@
 DIST_COMMON = $(srcdir)/Makefile.am $(srcdir)/Makefile.in \
 	$(top_srcdir)/config.mk
 noinst_PROGRAMS = ex1$(EXEEXT)
-subdir = examples/animated-menu
+subdir = examples/drag
 ACLOCAL_M4 = $(top_srcdir)/aclocal.m4
 am__aclocal_m4_deps = $(top_srcdir)/configure.ac
 am__configure_deps = $(am__aclocal_m4_deps) $(CONFIGURE_DEPENDENCIES) \
@@ -203,9 +203,9 @@
 	      exit 1;; \
 	  esac; \
 	done; \
-	echo ' cd $(top_srcdir) && $(AUTOMAKE) --foreign  examples/animated-menu/Makefile'; \
+	echo ' cd $(top_srcdir) && $(AUTOMAKE) --foreign  examples/drag/Makefile'; \
 	cd $(top_srcdir) && \
-	  $(AUTOMAKE) --foreign  examples/animated-menu/Makefile
+	  $(AUTOMAKE) --foreign  examples/drag/Makefile
 .PRECIOUS: Makefile
 Makefile: $(srcdir)/Makefile.in $(top_builddir)/config.status
 	@case '$?' in \
--- a/examples/tank/tank_main.c	Sun Dec 07 18:00:06 2008 +0800
+++ b/examples/tank/tank_main.c	Tue Dec 09 23:34:05 2008 +0800
@@ -392,7 +392,14 @@
     word = mb_progm_next_word(progm, &start, &playing);
     mb_visibility_new(VIS_VISIBLE, bang->root_coord, word);
 
-    /*! \todo Remove bang and program when program stops. */
+    MB_TIMEVAL_SET(&start, 2, 500000);
+    word = mb_progm_next_word(progm, &start, &playing);
+    mb_visibility_new(VIS_HIDDEN, bang->root_coord, word);
+
+    mb_subtree_free_new(bang->root_coord, word);
+
+    mb_progm_free_completed(progm);
+
     get_now(&now);
     mb_progm_start(progm, tman, &now);
 }
--- a/include/mb_animate.h	Sun Dec 07 18:00:06 2008 +0800
+++ b/include/mb_animate.h	Tue Dec 09 23:34:05 2008 +0800
@@ -56,6 +56,8 @@
 				    paint_t *paint, mb_word_t *word);
 extern mb_action_t *mb_rotate_new(float angle1, float angle2,
 				  coord_t *coord, mb_word_t *word);
+extern mb_action_t *mb_subtree_free_new(coord_t *coord,
+					mb_word_t *word);
 
 enum { VIS_VISIBLE, VIS_HIDDEN };
 extern mb_action_t *mb_visibility_new(int visib, coord_t *coord,
--- a/include/mb_types.h	Sun Dec 07 18:00:06 2008 +0800
+++ b/include/mb_types.h	Tue Dec 09 23:34:05 2008 +0800
@@ -11,9 +11,27 @@
 typedef struct _area area_t;
 typedef struct _shnode shnode_t;
 typedef struct _paint paint_t;
+typedef struct _mb_obj mb_obj_t;
 
 struct _redraw_man;
 
+struct _mb_obj {
+    int obj_type;
+};
+
+enum { MBO_DUMMY,
+       MBO_COORD,
+       MBO_SHAPES=0x1000,
+       MBO_PATH,
+       MBO_TEXT,
+       MBO_RECT
+};
+#define MBO_CLASS_MASK 0xf000
+#define MBO_CLASS(x) (((mb_obj_t *)(x))->obj_type & MBO_CLASS_MASK)
+#define MBO_TYPE(x) (((mb_obj_t *)(x))->obj_type)
+#define IS_MBO_SHAPES(obj) (MBO_CLASS(obj) == MBO_SHAPES)
+#define IS_MBO_COORD(obj) (MBO_TYPE(obj) == MB_COORD)
+
 /*! \brief Base of paint types.
  *
  * Paints should be freed by users by calling rdman_paint_free() of
@@ -93,6 +111,7 @@
  * \enddot
  */
 typedef struct _coord {
+    mb_obj_t obj;
     unsigned int order;
     unsigned int flags;
     co_aix opacity;
@@ -161,7 +180,7 @@
  * \enddot
  */
 struct _shape {
-    int sh_type;
+    mb_obj_t obj;
     geo_t *geo;
     coord_t *coord;
     paint_t *fill, *stroke;
@@ -171,7 +190,7 @@
     struct _shape *sh_next;	/*!< Link all shapes of a rdman together. */
     void (*free)(shape_t *shape);
 };
-enum { SHT_UNKNOW, SHT_PATH, SHT_TEXT, SHT_RECT };
+/* enum { SHT_UNKNOW, SHT_PATH, SHT_TEXT, SHT_RECT }; */
 
 #define sh_get_mouse_event_subject(sh) ((sh)->geo->mouse_event)
 #define sh_hide(sh)			     \
--- a/src/Makefile.am	Sun Dec 07 18:00:06 2008 +0800
+++ b/src/Makefile.am	Tue Dec 09 23:34:05 2008 +0800
@@ -4,7 +4,10 @@
 
 noinst_PROGRAMS = X_main
 
-libmbfly_la_SOURCES = animate.c chgcolor.c coord.c event.c geo.c observer.c paint.c redraw_man.c rotate.c shape_path.c shape_rect.c shape_text.c shift.c timer.c timertool.c tools.c visibility.c X_supp.c
+libmbfly_la_SOURCES = animate.c chgcolor.c coord.c event.c geo.c	\
+	observer.c paint.c redraw_man.c rotate.c shape_path.c		\
+	shape_rect.c shape_text.c shift.c subtree_free.c timer.c 	\
+	timertool.c tools.c visibility.c X_supp.c
 libmbfly_la_CPPFLAGS = @cairo_CFLAGS@
 libmbfly_la_LDFLAGS = @cairo_LIBS@
 
--- a/src/animate.c	Sun Dec 07 18:00:06 2008 +0800
+++ b/src/animate.c	Tue Dec 09 23:34:05 2008 +0800
@@ -127,6 +127,10 @@
 #ifndef UNITTEST
     factory = rdman_get_ob_factory(rdman);
     progm->complete = subject_new(factory, progm, OBJT_PROGM);
+    if(progm->complete == NULL) {
+	free(progm);
+	return NULL;
+    }
 #endif /* UNITTEST */
 
     progm->n_words = 0;
--- a/src/coord.c	Sun Dec 07 18:00:06 2008 +0800
+++ b/src/coord.c	Tue Dec 09 23:34:05 2008 +0800
@@ -90,6 +90,7 @@
 	co->parent = parent;
 	STAILQ_INS_TAIL(parent->children, coord_t, sibling, co);
     }
+    MBO_TYPE(co) = MBO_COORD;
     co->matrix[0] = 1;
     co->matrix[4] = 1;
     co->aggr_matrix[0] = 1;
--- a/src/event.c	Sun Dec 07 18:00:06 2008 +0800
+++ b/src/event.c	Tue Dec 09 23:34:05 2008 +0800
@@ -52,14 +52,14 @@
 }
 
 static void draw_shape_path(shape_t *shape, cairo_t *cr) {
-    switch(shape->sh_type) {
-    case SHT_PATH:
+    switch(MBO_TYPE(shape)) {
+    case MBO_PATH:
 	sh_path_draw(shape, cr);
 	break;
-    case SHT_TEXT:
+    case MBO_TEXT:
 	sh_text_draw(shape, cr);
 	break;
-    case SHT_RECT:
+    case MBO_RECT:
 	sh_rect_draw(shape, cr);
 	break;
     }
--- a/src/observer.c	Sun Dec 07 18:00:06 2008 +0800
+++ b/src/observer.c	Tue Dec 09 23:34:05 2008 +0800
@@ -51,6 +51,7 @@
 void subject_notify(subject_t *subject, event_t *evt) {
     ob_factory_t *factory = subject->factory;
     observer_t *observer;
+    subject_t *old_subject;
 
     evt->tgt = subject;
     while(subject) {
@@ -70,15 +71,16 @@
 	}
 
 	subject->flags &= ~SUBF_BUSY;
-	if(subject->flags & SUBF_FREE)
-	    subject_free(subject);
+
+	old_subject = subject;
+	subject = factory->get_parent_subject(factory, subject);
 
-	if(subject->flags & SUBF_STOP_PROPAGATE)
+	if(old_subject->flags & SUBF_FREE)
+	    subject_free(old_subject);
+
+	if(old_subject->flags & SUBF_STOP_PROPAGATE)
 	    break;
-
-	subject = factory->get_parent_subject(factory, subject);
     }
-
 }
 
 observer_t *subject_add_observer(subject_t *subject,
--- a/src/redraw_man.c	Sun Dec 07 18:00:06 2008 +0800
+++ b/src/redraw_man.c	Tue Dec 09 23:34:05 2008 +0800
@@ -613,6 +613,24 @@
     return OK;
 }
 
+static _rdman_coord_free_members(redraw_man_t *rdman, coord_t *coord) {
+    geo_t *member;
+    shape_t *shape;
+    int r;
+
+    FORMEMBERS(coord, member) {
+	shape = geo_get_shape(member);
+	r = rdman_shape_free(rdman, shape);
+	if(r != OK)
+	    return ERR;
+    }
+    return OK;
+}
+
+/*! \brief Free descendant coords and shapes of a coord.
+ *
+ * The specified coord is also freed.
+ */
 int rdman_coord_subtree_free(redraw_man_t *rdman, coord_t *subtree) {
     coord_t *coord, *prev_coord;
     int r;
@@ -625,6 +643,10 @@
 	coord != NULL;
 	coord = postorder_coord_subtree(subtree, coord)) {
 	if(!(prev_coord->flags & COF_FREE)) {
+	    r = _rdman_coord_free_members(rdman, prev_coord);
+	    if(r != OK)
+		return ERR;
+
 	    r = rdman_coord_free(rdman, prev_coord);
 	    if(r != OK)
 		return ERR;
@@ -632,6 +654,10 @@
 	prev_coord = coord;
     }
     if(!(prev_coord->flags & COF_FREE)) {
+	r = _rdman_coord_free_members(rdman, prev_coord);
+	if(r != OK)
+	    return ERR;
+
 	r = rdman_coord_free(rdman, prev_coord);
 	if(r != OK)
 	    return ERR;
@@ -724,14 +750,14 @@
 }
 
 static void clean_shape(shape_t *shape) {
-    switch(shape->sh_type) {
-    case SHT_PATH:
+    switch(MBO_TYPE(shape)) {
+    case MBO_PATH:
 	sh_path_transform(shape);
 	break;
-    case SHT_TEXT:
+    case MBO_TEXT:
 	sh_text_transform(shape);
 	break;
-    case SHT_RECT:
+    case MBO_RECT:
 	sh_rect_transform(shape);
 	break;
 #ifdef UNITTEST
@@ -924,14 +950,14 @@
      *	operators for them.
      */
     if(shape->fill || shape->stroke) {
-	switch(shape->sh_type) {
-	case SHT_PATH:
+	switch(MBO_TYPE(shape)) {
+	case MBO_PATH:
 	    sh_path_draw(shape, cr);
 	    break;
-	case SHT_TEXT:
+	case MBO_TEXT:
 	    sh_text_draw(shape, cr);
 	    break;
-	case SHT_RECT:
+	case MBO_RECT:
 	    sh_rect_draw(shape, cr);
 	    break;
 #ifdef UNITTEST
--- a/src/shape_path.c	Sun Dec 07 18:00:06 2008 +0800
+++ b/src/shape_path.c	Tue Dec 09 23:34:05 2008 +0800
@@ -682,7 +682,7 @@
     path = (sh_path_t *)malloc(sizeof(sh_path_t));
     /*! \todo Remove this memset()? */
     memset(&path->shape, 0, sizeof(shape_t));
-    path->shape.sh_type = SHT_PATH;
+    MBO_TYPE(path) = MBO_PATH;
     path->cmd_len = cmd_cnt;
     path->arg_len = arg_cnt;
     path->fix_arg_len = fix_arg_cnt;
@@ -722,7 +722,7 @@
     path = (sh_path_t *)malloc(sizeof(sh_path_t));
     /*! \todo Remove this memset()? */
     memset(&path->shape, 0, sizeof(shape_t));
-    path->shape.sh_type = SHT_PATH;
+    MBO_TYPE(path) = MBO_PATH;
     path->cmd_len = strlen(commands);
     path->arg_len = arg_cnt;
     path->fix_arg_len = fix_arg_cnt;
--- a/src/shape_rect.c	Sun Dec 07 18:00:06 2008 +0800
+++ b/src/shape_rect.c	Tue Dec 09 23:34:05 2008 +0800
@@ -27,7 +27,7 @@
 
     memset(rect, 0, sizeof(sh_rect_t));
 
-    rect->shape.sh_type = SHT_RECT;
+    MBO_TYPE(rect) = MBO_RECT;
     rect->x = x;
     rect->y = y;
     rect->w = w;
--- a/src/shape_text.c	Sun Dec 07 18:00:06 2008 +0800
+++ b/src/shape_text.c	Tue Dec 09 23:34:05 2008 +0800
@@ -42,7 +42,7 @@
 	return NULL;
 
     memset(text, 0, sizeof(sh_text_t));
-    text->shape.sh_type = SHT_TEXT;
+    MBO_TYPE(text) = MBO_TEXT;
     text->data = strdup(txt);
     if(text->data == NULL) {
 	free(text);
--- a/src/shift.c	Sun Dec 07 18:00:06 2008 +0800
+++ b/src/shift.c	Tue Dec 09 23:34:05 2008 +0800
@@ -80,7 +80,7 @@
 
     shift = (mb_shift_t *)malloc(sizeof(mb_shift_t));
     if(shift == NULL)
-	return (mb_action_t *)shift;
+	return NULL;
 
     shift->x = x;
     shift->y = y;
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/src/subtree_free.c	Tue Dec 09 23:34:05 2008 +0800
@@ -0,0 +1,50 @@
+#include "mb_redraw_man.h"
+#include "mb_animate.h"
+
+struct _subtree_free {
+    mb_action_t action;
+
+    coord_t *coord;
+};
+
+typedef struct _subtree_free subtree_free_t;
+
+void mb_subtree_free_start(mb_action_t *action,
+			   const mb_timeval_t *now,
+			   const mb_timeval_t *playing_time,
+			   redraw_man_t *rdman) {
+    subtree_free_t *sfree = (subtree_free_t *)action;
+
+    rdman_coord_subtree_free(rdman, sfree->coord);
+}
+
+void mb_subtree_free_step(mb_action_t *act, const mb_timeval_t *now,
+			  redraw_man_t *rdman) {
+}
+
+void mb_subtree_free_stop(mb_action_t *act, const mb_timeval_t *now,
+			  redraw_man_t *rdman) {
+}
+
+void mb_subtree_free_free(mb_action_t *act) {
+    free(act);
+}
+
+mb_action_t *mb_subtree_free_new(coord_t *coord,
+				 mb_word_t *word) {
+    subtree_free_t *sfree;
+
+    sfree = (subtree_free_t *)malloc(sizeof(subtree_free_t));
+    if(sfree == NULL)
+	return NULL;
+
+    sfree->action.start = mb_subtree_free_start;
+    sfree->action.step = mb_subtree_free_step;
+    sfree->action.stop = mb_subtree_free_stop;
+    sfree->action.free = mb_subtree_free_free;
+    sfree->coord = coord;
+
+    mb_word_add_action(word, (mb_action_t *)sfree);
+
+    return (mb_action_t *)sfree;
+}