Mercurial > MadButterfly
changeset 332:f90c60967a9c
Add mb_progm_finish to terminate the current animation and put all objects in the final position.
It seems that not all words are executed correctly. We need to figure out why.
author | wycc |
---|---|
date | Sat, 07 Mar 2009 08:33:01 +0800 |
parents | 2a8bf3efbc67 |
children | bdf36a26e420 01038b8d8f05 |
files | examples/menu/animated_menu.c examples/menu/animated_menu.h src/animate.c |
diffstat | 3 files changed, 27 insertions(+), 4 deletions(-) [+] |
line wrap: on
line diff
--- a/examples/menu/animated_menu.c Fri Mar 06 23:02:32 2009 +0800 +++ b/examples/menu/animated_menu.c Sat Mar 07 08:33:01 2009 +0800 @@ -77,7 +77,7 @@ group = (coord_t *) m->objects[m->items[8]]; set_text(group, m->titles[m->top]); - progm = mb_progm_new(2, MBAPP_RDMAN(m->app)); + m->progm = progm = mb_progm_new(2, MBAPP_RDMAN(m->app)); MB_TIMEVAL_SET(&start, 0, 0); MB_TIMEVAL_SET(&playing, 0, m->speed); word = mb_progm_next_word(progm, &start, &playing); @@ -139,7 +139,7 @@ // fill new item set_text((coord_t *)m->objects[m->items[8]], m->titles[m->top+7]); - progm = mb_progm_new(2, MBAPP_RDMAN(m->app)); + m->progm = progm = mb_progm_new(2, MBAPP_RDMAN(m->app)); MB_TIMEVAL_SET(&start, 0, 0); MB_TIMEVAL_SET(&playing, 0, m->speed); word = mb_progm_next_word(progm, &start, &playing); @@ -184,7 +184,7 @@ coord_t *group; coord_t *lightbar; - progm = mb_progm_new(1, MBAPP_RDMAN(m->app)); + m->progm = progm = mb_progm_new(1, MBAPP_RDMAN(m->app)); MB_TIMEVAL_SET(&start, 0, 0); MB_TIMEVAL_SET(&playing, 0, m->speed); word = mb_progm_next_word(progm, &start, &playing); @@ -248,6 +248,15 @@ m->callback(m,m->top+m->cur); } +// Send the pending key in the animation progm complete callback +static void mb_animated_menu_keyHandler(event_t *ev, void *arg); +static void mb_animated_menu_send_pending_key(event_t *ev,void *arg) +{ + mb_animated_menu_t *m = (mb_animated_menu_t *) arg; + + if (m->ready<=0) + mb_animated_menu_keyHandler((event_t *) &m->pending_key,m); +} static void mb_animated_menu_keyHandler(event_t *ev, void *arg) { mb_animated_menu_t *m = (mb_animated_menu_t *) arg; @@ -256,7 +265,12 @@ return; } printf("read=%d\n",m->ready); - if (m->ready<=0) return; + if (m->ready<=0) { + subject_add_observer(mb_progm_get_complete(m->progm), mb_animated_menu_send_pending_key,m); + mb_progm_finish(m->progm); + m->pending_key = *xkey; + return; + } switch(xkey->sym) { case 0xff51: /* left */ break;
--- a/examples/menu/animated_menu.h Fri Mar 06 23:02:32 2009 +0800 +++ b/examples/menu/animated_menu.h Sat Mar 07 08:33:01 2009 +0800 @@ -14,6 +14,8 @@ mb_obj_t **objects; mb_obj_t *lightbar; void (*callback)(struct _mb_animated_menu *m, int sel); + mb_progm_t *progm; + X_kb_event_t pending_key; } mb_animated_menu_t; /** \brief Create an instace of animated menu. *
--- a/src/animate.c Fri Mar 06 23:02:32 2009 +0800 +++ b/src/animate.c Sat Mar 07 08:33:01 2009 +0800 @@ -336,6 +336,13 @@ progm->cur_timer = timer; } +void mb_progm_finish(mb_progm_t *progm) { + mb_timeval_t infi; + + mb_progm_abort(progm); + MB_TIMEVAL_SET(&infi, 0x7fffffff,0); + mb_progm_step(&progm->start_time, &infi,progm); +} void mb_progm_abort(mb_progm_t *progm) { /*! \todo Make sure abort release resources. */ if(progm->cur_timer) {