Mercurial > MadButterfly
changeset 123:9e2316dc6ecb
Program completion events
author | Thinker K.F. Li <thinker@branda.to> |
---|---|
date | Tue, 16 Sep 2008 14:19:26 +0800 |
parents | 17e97e92b76e |
children | ad5ab8e61c2b |
files | src/Makefile src/animate.c src/animate.h src/observer.h |
diffstat | 4 files changed, 56 insertions(+), 28 deletions(-) [+] |
line wrap: on
line diff
--- a/src/Makefile Mon Sep 15 20:33:06 2008 +0800 +++ b/src/Makefile Tue Sep 16 14:19:26 2008 +0800 @@ -50,7 +50,7 @@ $(CC) $(CFLAGS) `pkg-config --cflags cairo` -c $(.ALLSRC) clean: - for i in *.o *~ *.core $(SHAPE_OBJS) $(BINS); do \ + for i in *.o *~ *.core $(SHAPE_OBJS) $(BINS) testcase; do \ echo "delete $$i"; \ rm -f $$i; \ done
--- a/src/animate.c Mon Sep 15 20:33:06 2008 +0800 +++ b/src/animate.c Tue Sep 16 14:19:26 2008 +0800 @@ -97,6 +97,7 @@ mb_timeval_t start_time; int first_playing; /*!< first playing word. */ mb_tman_t *tman; + subject_t *complete; /*!< notify when a program is completed. */ int n_words; int max_words; @@ -110,6 +111,7 @@ */ mb_progm_t *mb_progm_new(int max_words, redraw_man_t *rdman) { mb_progm_t *progm; + ob_factory_t *factory; int i; progm = (mb_progm_t *)malloc(sizeof(mb_progm_t) + @@ -118,6 +120,10 @@ return NULL; progm->rdman = rdman; + + factory = rdman_get_ob_factory(rdman); + progm->complete = subject_new(factory, progm, OBJT_PROGM); + progm->n_words = 0; progm->max_words = max_words; for(i = 0; i < max_words; i++) @@ -215,6 +221,8 @@ const mb_timeval_t *now, void *arg) { mb_progm_t *progm = (mb_progm_t *)arg; + ob_factory_t *factory; + mb_progm_complete_t comp_evt; mb_timeval_t next_tmo; mb_word_t *word; mb_timer_t *timer; @@ -264,6 +272,12 @@ MB_TIMEVAL_CP(&next_tmo, &word->abs_start); timer = mb_tman_timeout(progm->tman, &next_tmo, mb_progm_step, progm); + } else { + factory = rdman_get_ob_factory(progm->rdman); + comp_evt.event.type = EVT_PROGM_COMPLETE; + comp_evt.event.tgt = comp_evt.event.cur_tgt = progm->complete; + comp_evt.progm = progm; + subject_notify(factory, progm->complete, &comp_evt.event); } } @@ -301,6 +315,12 @@ void mb_progm_abort(mb_progm_t *progm, mb_tman_t *tman) { } +/*! \brief Return event subject for completion of a program. + */ +subject_t *mb_progm_get_complete(mb_progm_t *progm) { + return progm->complete; +} + #ifdef UNITTEST #include <CUnit/Basic.h>
--- a/src/animate.h Mon Sep 15 20:33:06 2008 +0800 +++ b/src/animate.h Tue Sep 16 14:19:26 2008 +0800 @@ -28,10 +28,42 @@ typedef struct _mb_word mb_word_t; typedef struct _mb_action mb_action_t; +struct _mb_progm_complete { + event_t event; + mb_progm_t *progm; +}; +typedef struct _mb_progm_complete mb_progm_complete_t; + +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, + const mb_timeval_t *start, + const mb_timeval_t *playing); +extern void mb_progm_start(mb_progm_t *progm, mb_tman_t *tman, + mb_timeval_t *now); +extern void mb_progm_abort(mb_progm_t *progm, mb_tman_t *tman); +extern subject_t *mb_progm_get_complete(mb_progm_t *progm); + +/*! \defgroup ani_actions Animation Actions + * @{ + */ +extern mb_action_t *mb_shift_new(co_aix x, co_aix y, coord_t *coord, + mb_word_t *word); +extern 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); +extern mb_action_t *mb_rotate_new(float angle1, float angle2, + coord_t *coord, 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); +/* @} */ + /*! \defgroup act_support Action Supports. * @{ */ -/*! \brief Basic class of nnimation actions. +/*! \brief Basic class of animation actions. * * \sa \ref def_action */ @@ -51,30 +83,6 @@ 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, - const mb_timeval_t *start, - const mb_timeval_t *playing); -extern void mb_progm_start(mb_progm_t *progm, mb_tman_t *tman, - mb_timeval_t *now); -extern void mb_progm_abort(mb_progm_t *progm, mb_tman_t *tman); -/*! \defgroup ani_actions Animation Actions - * @{ - */ -extern mb_action_t *mb_shift_new(co_aix x, co_aix y, coord_t *coord, - mb_word_t *word); -extern 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); -extern mb_action_t *mb_rotate_new(float angle1, float angle2, - coord_t *coord, 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/observer.h Mon Sep 15 20:33:06 2008 +0800 +++ b/src/observer.h Tue Sep 16 14:19:26 2008 +0800 @@ -40,7 +40,7 @@ /*! \brief Flag that make a subject to propagate events to parents. */ #define SUBF_STOP_PROPAGATE 0x1 -enum {OBJT_GEO, OBJT_COORD, OBJT_KB}; +enum {OBJT_GEO, OBJT_COORD, OBJT_KB, OBJT_PROGM}; struct _mouse_event { event_t event; @@ -70,7 +70,7 @@ enum {EVT_MOUSE_OVER, EVT_MOUSE_OUT, EVT_MOUSE_MOVE, EVT_MOUSE_BUT_PRESS, EVT_MOUSE_BUT_RELEASE, - EVT_KB_PRESS, EVT_KB_RELEASE}; + EVT_KB_PRESS, EVT_KB_RELEASE, EVT_PROGM_COMPLETE}; extern subject_t *subject_new(ob_factory_t *factory, void *obj, int obj_type);