# HG changeset patch # User wycc # Date 1236385981 -28800 # Node ID f90c60967a9c0563926a871f8aa9978b1438ebdd # Parent 2a8bf3efbc676aa1b80b9b563213ba1e066f6441 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. diff -r 2a8bf3efbc67 -r f90c60967a9c examples/menu/animated_menu.c --- 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; diff -r 2a8bf3efbc67 -r f90c60967a9c examples/menu/animated_menu.h --- 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. * diff -r 2a8bf3efbc67 -r f90c60967a9c src/animate.c --- 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) {