changeset 116:1d74eb3861b7

move animation actions from animate.c to files.
author Thinker K.F. Li <thinker@branda.to>
date Sun, 14 Sep 2008 09:42:07 +0800
parents 3895d2224e67
children e4e47d2cdbcd
files src/Makefile src/animate.c src/animate.h src/chgcolor.c src/shift.c src/visibility.c
diffstat 6 files changed, 304 insertions(+), 275 deletions(-) [+]
line wrap: on
line diff
--- a/src/Makefile	Sun Sep 14 02:17:57 2008 +0800
+++ b/src/Makefile	Sun Sep 14 09:42:07 2008 +0800
@@ -1,6 +1,7 @@
 SRCS =	coord.c geo.c shape_path.c shape_text.c shape_rect.c \
 	redraw_man.c timer.c animate.c paint.c event.c observer.c \
-	X_supp.c timertool.c tools.c
+	X_supp.c timertool.c tools.c shift.c chgcolor.c \
+	visibility.c
 OBJS = ${SRCS:C/(.*)\.c/\1.o/g}
 TESTCASE_OBJS = ${SRCS:C/(.*)\.c/testcase-\1.o/g}
 CFLAGS+=	-Wall -I/usr/local/include `pkg-config --cflags cairo`
--- a/src/animate.c	Sun Sep 14 02:17:57 2008 +0800
+++ b/src/animate.c	Sun Sep 14 09:42:07 2008 +0800
@@ -62,33 +62,6 @@
     mb_word_t words[1];
 };
 
-/*! \brief Basic class of nnimation actions.
- *
- * A action must implement following 4 functions.
- * \li start,
- * \li step,
- * \li stop,
- * \li free, and
- * \li *_new().
- *
- * *_new() must invokes mb_word_add_action() to add new object
- * as one of actions in the word specified as an argument of it.
- * It also means *_new() must have an argument with type of
- * (mb_word_t *).
- */
-struct _mb_action {
-    void (*start)(mb_action_t *act,
-		  const mb_timeval_t *now,
-		  const mb_timeval_t *playing_time,
-		  redraw_man_t *rdman);
-    void (*step)(mb_action_t *act, const mb_timeval_t *now,
-		 redraw_man_t *rdman);
-    void (*stop)(mb_action_t *act, const mb_timeval_t *now,
-		 redraw_man_t *rdman);
-    void (*free)(mb_action_t *act);
-    mb_action_t *next;
-};
-
 mb_progm_t *mb_progm_new(int max_words, redraw_man_t *rdman) {
     mb_progm_t *progm;
     int i;
@@ -145,7 +118,7 @@
     return word;
 }
 
-static void mb_word_add_action(mb_word_t *word, mb_action_t *act) {
+void mb_word_add_action(mb_word_t *word, mb_action_t *act) {
     STAILQ_INS_TAIL(word->actions, mb_action_t, next, act);
 }
 
@@ -276,252 +249,6 @@
 void mb_progm_abort(mb_progm_t *progm, mb_tman_t *tman) {
 }
 
-typedef struct _mb_shift mb_shift_t;
-/*! \brief Animation action for shift a coordination. */
-struct _mb_shift {
-    mb_action_t action;
-
-    co_aix x, y;
-    coord_t *coord;
-
-    mb_timeval_t start_time;
-    co_aix saved_matrix[6];
-    const mb_timeval_t *playing_time;
-};
-
-static float comp_mb_timeval_ratio(const mb_timeval_t *a,
-				   const mb_timeval_t *b) {
-    float ratio;
-
-    ratio = (float)MB_TIMEVAL_SEC(a) * 1000000.0 + (float)MB_TIMEVAL_USEC(a);
-    ratio /= (float)MB_TIMEVAL_SEC(b) * 1000000.0 + (float)MB_TIMEVAL_USEC(b);
-    return ratio;
-}
-
-static void mb_shift_start(mb_action_t *act,
-			   const mb_timeval_t *now,
-			   const mb_timeval_t *playing_time,
-			   redraw_man_t *rdman) {
-    mb_shift_t *shift = (mb_shift_t *)act;
-    coord_t *coord;
-
-    MB_TIMEVAL_CP(&shift->start_time, now);
-    coord = shift->coord;
-    memcpy(&shift->saved_matrix, coord->matrix, sizeof(co_aix[6]));
-    shift->playing_time = playing_time;
-}
-
-static void mb_shift_step(mb_action_t *act, const mb_timeval_t *now,
-			  redraw_man_t *rdman) {
-    mb_shift_t *shift = (mb_shift_t *)act;
-    mb_timeval_t diff;
-    coord_t *coord;
-    float ratio;
-
-    
-    MB_TIMEVAL_CP(&diff, now);
-    MB_TIMEVAL_DIFF(&diff, &shift->start_time);
-    ratio = comp_mb_timeval_ratio(&diff, shift->playing_time);
-
-    coord = shift->coord;
-    coord->matrix[2] = shift->saved_matrix[2] + shift->x * ratio;
-    coord->matrix[5] = shift->saved_matrix[5] + shift->y * ratio;
-
-    rdman_coord_changed(rdman, coord);
-}
-
-static void mb_shift_stop(mb_action_t *act, const mb_timeval_t *now,
-			  redraw_man_t *rdman) {
-    mb_shift_t *shift = (mb_shift_t *)act;
-    coord_t *coord;
-
-    coord = shift->coord;
-    coord->matrix[2] = shift->saved_matrix[2] + shift->x;
-    coord->matrix[5] = shift->saved_matrix[5] + shift->y;
-
-    rdman_coord_changed(rdman, coord);
-}
-
-
-static void mb_shift_free(mb_action_t *act) {
-    free(act);
-}
-
-mb_action_t *mb_shift_new(co_aix x, co_aix y, coord_t *coord,
-			  mb_word_t *word) {
-    mb_shift_t *shift;
-
-    shift = (mb_shift_t *)malloc(sizeof(mb_shift_t));
-    if(shift == NULL)
-	return (mb_action_t *)shift;
-
-    shift->x = x;
-    shift->y = y;
-    shift->coord = coord;
-
-    shift->action.start = mb_shift_start;
-    shift->action.step = mb_shift_step;
-    shift->action.stop = mb_shift_stop;
-    shift->action.free = mb_shift_free;
-
-    mb_word_add_action(word, (mb_action_t *)shift);
-
-    return (mb_action_t *)shift;
-}
-
-
-#include "paint.h"
-typedef struct _mb_chgcolor mb_chgcolor_t;
-
-struct _mb_chgcolor {
-    mb_action_t action;
-
-    co_comp_t r, g, b, a;
-    paint_t *paint;
-
-    mb_timeval_t start_time;
-    const mb_timeval_t *playing_time;
-    co_comp_t s_r, s_g, s_b, s_a; /*!< saved RGBA values. */
-};
-
-static void mb_chgcolor_start(mb_action_t *act,
-			      const mb_timeval_t *now,
-			      const mb_timeval_t *playing_time,
-			      redraw_man_t *rdman) {
-    mb_chgcolor_t *chg = (mb_chgcolor_t *)act;
-
-    MB_TIMEVAL_CP(&chg->start_time, now);
-    chg->playing_time = playing_time; /* playing_time is in word,
-				       * it live time is as long as
-				       * actions. */
-    paint_color_get(chg->paint,
-		    &chg->s_r, &chg->s_g,
-		    &chg->s_b, &chg->s_a);
-}
-
-static void mb_chgcolor_step(mb_action_t *act,
-			     const mb_timeval_t *now,
-			     redraw_man_t *rdman) {
-    mb_chgcolor_t *chg = (mb_chgcolor_t *)act;
-    mb_timeval_t diff;
-    co_comp_t r, g, b, a;
-    float ratio, comp;
-
-    MB_TIMEVAL_CP(&diff, now);
-    MB_TIMEVAL_DIFF(&diff, &chg->start_time);
-    ratio = comp_mb_timeval_ratio(&diff, chg->playing_time);
-    comp = 1 - ratio;
-
-    r = chg->s_r * comp + ratio * chg->r;
-    g = chg->s_g * comp + ratio * chg->g;
-    b = chg->s_b * comp + ratio * chg->b;
-    a = chg->s_a * comp + ratio * chg->a;
-    paint_color_set(chg->paint, r, g, b, a);
-
-    rdman_paint_changed(rdman, chg->paint);
-}
-
-static void mb_chgcolor_stop(mb_action_t *act,
-			     const mb_timeval_t *now,
-			     redraw_man_t *rdman) {
-    mb_chgcolor_t *chg = (mb_chgcolor_t *)act;
-
-    paint_color_set(chg->paint, chg->r, chg->g, chg->b, chg->a);
-
-    rdman_paint_changed(rdman, chg->paint);
-}
-
-static void mb_chgcolor_free(mb_action_t *act) {
-    free(act);
-}
-
-mb_action_t *mb_chgcolor_new(co_comp_t r, co_comp_t g,
-			     co_comp_t b, co_comp_t a,
-			     paint_t *paint, mb_word_t *word) {
-    mb_chgcolor_t *chg;
-
-    chg = (mb_chgcolor_t *)malloc(sizeof(mb_chgcolor_t));
-    if(chg == NULL)
-	return NULL;
-
-    chg->r = r;
-    chg->g = g;
-    chg->b = b;
-    chg->a = a;
-
-    chg->paint = paint;
-
-    chg->action.start = mb_chgcolor_start;
-    chg->action.step = mb_chgcolor_step;
-    chg->action.stop = mb_chgcolor_stop;
-    chg->action.free = mb_chgcolor_free;
-
-    mb_word_add_action(word, (mb_action_t *)chg);
-
-    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 Sep 14 02:17:57 2008 +0800
+++ b/src/animate.h	Sun Sep 14 09:42:07 2008 +0800
@@ -14,6 +14,39 @@
 typedef struct _mb_action mb_action_t;
 typedef struct _mb_progm_state mb_progm_state_t;
 
+/*! \defgroup act_support Action Supports.
+ * @{
+ */
+/*! \brief Basic class of nnimation actions.
+ *
+ * A action must implement following 4 functions.
+ * \li start,
+ * \li step,
+ * \li stop,
+ * \li free, and
+ * \li *_new().
+ *
+ * *_new() must invokes mb_word_add_action() to add new object
+ * as one of actions in the word specified as an argument of it.
+ * It also means *_new() must have an argument with type of
+ * (mb_word_t *).
+ */
+struct _mb_action {
+    void (*start)(mb_action_t *act,
+		  const mb_timeval_t *now,
+		  const mb_timeval_t *playing_time,
+		  redraw_man_t *rdman);
+    void (*step)(mb_action_t *act, const mb_timeval_t *now,
+		 redraw_man_t *rdman);
+    void (*stop)(mb_action_t *act, const mb_timeval_t *now,
+		 redraw_man_t *rdman);
+    void (*free)(mb_action_t *act);
+    mb_action_t *next;
+};
+
+extern void mb_word_add_action(mb_word_t *word, mb_action_t *act);
+/* @} */
+
 extern mb_progm_t *mb_progm_new(int max_words, redraw_man_t *rdman);
 extern void mb_progm_free(mb_progm_t *progm);
 extern mb_word_t *mb_progm_next_word(mb_progm_t *progm,
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/src/chgcolor.c	Sun Sep 14 09:42:07 2008 +0800
@@ -0,0 +1,105 @@
+#include <stdio.h>
+#include <stdlib.h>
+#include "animate.h"
+#include "paint.h"
+
+static float comp_mb_timeval_ratio(const mb_timeval_t *a,
+				   const mb_timeval_t *b) {
+    float ratio;
+
+    ratio = (float)MB_TIMEVAL_SEC(a) * 1000000.0 + (float)MB_TIMEVAL_USEC(a);
+    ratio /= (float)MB_TIMEVAL_SEC(b) * 1000000.0 + (float)MB_TIMEVAL_USEC(b);
+    return ratio;
+}
+
+typedef struct _mb_chgcolor mb_chgcolor_t;
+
+struct _mb_chgcolor {
+    mb_action_t action;
+
+    co_comp_t r, g, b, a;
+    paint_t *paint;
+
+    mb_timeval_t start_time;
+    const mb_timeval_t *playing_time;
+    co_comp_t s_r, s_g, s_b, s_a; /*!< saved RGBA values. */
+};
+
+static void mb_chgcolor_start(mb_action_t *act,
+			      const mb_timeval_t *now,
+			      const mb_timeval_t *playing_time,
+			      redraw_man_t *rdman) {
+    mb_chgcolor_t *chg = (mb_chgcolor_t *)act;
+
+    MB_TIMEVAL_CP(&chg->start_time, now);
+    chg->playing_time = playing_time; /* playing_time is in word,
+				       * it live time is as long as
+				       * actions. */
+    paint_color_get(chg->paint,
+		    &chg->s_r, &chg->s_g,
+		    &chg->s_b, &chg->s_a);
+}
+
+static void mb_chgcolor_step(mb_action_t *act,
+			     const mb_timeval_t *now,
+			     redraw_man_t *rdman) {
+    mb_chgcolor_t *chg = (mb_chgcolor_t *)act;
+    mb_timeval_t diff;
+    co_comp_t r, g, b, a;
+    float ratio, comp;
+
+    MB_TIMEVAL_CP(&diff, now);
+    MB_TIMEVAL_DIFF(&diff, &chg->start_time);
+    ratio = comp_mb_timeval_ratio(&diff, chg->playing_time);
+    comp = 1 - ratio;
+
+    r = chg->s_r * comp + ratio * chg->r;
+    g = chg->s_g * comp + ratio * chg->g;
+    b = chg->s_b * comp + ratio * chg->b;
+    a = chg->s_a * comp + ratio * chg->a;
+    paint_color_set(chg->paint, r, g, b, a);
+
+    rdman_paint_changed(rdman, chg->paint);
+}
+
+static void mb_chgcolor_stop(mb_action_t *act,
+			     const mb_timeval_t *now,
+			     redraw_man_t *rdman) {
+    mb_chgcolor_t *chg = (mb_chgcolor_t *)act;
+
+    paint_color_set(chg->paint, chg->r, chg->g, chg->b, chg->a);
+
+    rdman_paint_changed(rdman, chg->paint);
+}
+
+static void mb_chgcolor_free(mb_action_t *act) {
+    free(act);
+}
+
+mb_action_t *mb_chgcolor_new(co_comp_t r, co_comp_t g,
+			     co_comp_t b, co_comp_t a,
+			     paint_t *paint, mb_word_t *word) {
+    mb_chgcolor_t *chg;
+
+    chg = (mb_chgcolor_t *)malloc(sizeof(mb_chgcolor_t));
+    if(chg == NULL)
+	return NULL;
+
+    chg->r = r;
+    chg->g = g;
+    chg->b = b;
+    chg->a = a;
+
+    chg->paint = paint;
+
+    chg->action.start = mb_chgcolor_start;
+    chg->action.step = mb_chgcolor_step;
+    chg->action.stop = mb_chgcolor_stop;
+    chg->action.free = mb_chgcolor_free;
+
+    mb_word_add_action(word, (mb_action_t *)chg);
+
+    return (mb_action_t *)chg;
+}
+
+
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/src/shift.c	Sun Sep 14 09:42:07 2008 +0800
@@ -0,0 +1,99 @@
+#include <stdio.h>
+#include <stdlib.h>
+#include <string.h>
+#include "animate.h"
+
+static float comp_mb_timeval_ratio(const mb_timeval_t *a,
+				   const mb_timeval_t *b) {
+    float ratio;
+
+    ratio = (float)MB_TIMEVAL_SEC(a) * 1000000.0 + (float)MB_TIMEVAL_USEC(a);
+    ratio /= (float)MB_TIMEVAL_SEC(b) * 1000000.0 + (float)MB_TIMEVAL_USEC(b);
+    return ratio;
+}
+
+typedef struct _mb_shift mb_shift_t;
+/*! \brief Animation action for shift a coordination. */
+struct _mb_shift {
+    mb_action_t action;
+
+    co_aix x, y;
+    coord_t *coord;
+
+    mb_timeval_t start_time;
+    co_aix saved_matrix[6];
+    const mb_timeval_t *playing_time;
+};
+
+static void mb_shift_start(mb_action_t *act,
+			   const mb_timeval_t *now,
+			   const mb_timeval_t *playing_time,
+			   redraw_man_t *rdman) {
+    mb_shift_t *shift = (mb_shift_t *)act;
+    coord_t *coord;
+
+    MB_TIMEVAL_CP(&shift->start_time, now);
+    coord = shift->coord;
+    memcpy(&shift->saved_matrix, coord->matrix, sizeof(co_aix[6]));
+    shift->playing_time = playing_time;
+}
+
+static void mb_shift_step(mb_action_t *act, const mb_timeval_t *now,
+			  redraw_man_t *rdman) {
+    mb_shift_t *shift = (mb_shift_t *)act;
+    mb_timeval_t diff;
+    coord_t *coord;
+    float ratio;
+
+    
+    MB_TIMEVAL_CP(&diff, now);
+    MB_TIMEVAL_DIFF(&diff, &shift->start_time);
+    ratio = comp_mb_timeval_ratio(&diff, shift->playing_time);
+
+    coord = shift->coord;
+    coord->matrix[2] = shift->saved_matrix[2] + shift->x * ratio;
+    coord->matrix[5] = shift->saved_matrix[5] + shift->y * ratio;
+
+    rdman_coord_changed(rdman, coord);
+}
+
+static void mb_shift_stop(mb_action_t *act, const mb_timeval_t *now,
+			  redraw_man_t *rdman) {
+    mb_shift_t *shift = (mb_shift_t *)act;
+    coord_t *coord;
+
+    coord = shift->coord;
+    coord->matrix[2] = shift->saved_matrix[2] + shift->x;
+    coord->matrix[5] = shift->saved_matrix[5] + shift->y;
+
+    rdman_coord_changed(rdman, coord);
+}
+
+
+static void mb_shift_free(mb_action_t *act) {
+    free(act);
+}
+
+mb_action_t *mb_shift_new(co_aix x, co_aix y, coord_t *coord,
+			  mb_word_t *word) {
+    mb_shift_t *shift;
+
+    shift = (mb_shift_t *)malloc(sizeof(mb_shift_t));
+    if(shift == NULL)
+	return (mb_action_t *)shift;
+
+    shift->x = x;
+    shift->y = y;
+    shift->coord = coord;
+
+    shift->action.start = mb_shift_start;
+    shift->action.step = mb_shift_step;
+    shift->action.stop = mb_shift_stop;
+    shift->action.free = mb_shift_free;
+
+    mb_word_add_action(word, (mb_action_t *)shift);
+
+    return (mb_action_t *)shift;
+}
+
+
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/src/visibility.c	Sun Sep 14 09:42:07 2008 +0800
@@ -0,0 +1,64 @@
+#include <stdio.h>
+#include <stdlib.h>
+#include "animate.h"
+
+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;
+}
+