Mercurial > MadButterfly
changeset 455:58b6337fb3b2
Fix bugs of pending keys of animated menu.
- When more than one pending key, the animation would be stoped.
- Now, we have a cyclic queue to keep at most 15 pending keys to
make sure pending keys being dispatched without stop current animation
program.
author | Thinker K.F. Li <thinker@branda.to> |
---|---|
date | Thu, 06 Aug 2009 13:15:57 +0800 |
parents | 9b8dda201ccb |
children | 26c302b47de1 |
files | examples/menu/list.svg include/animated_menu.h src/mbaf/animated_menu.c |
diffstat | 3 files changed, 22 insertions(+), 17 deletions(-) [+] |
line wrap: on
line diff
--- a/examples/menu/list.svg Thu Aug 06 09:38:51 2009 +0800 +++ b/examples/menu/list.svg Thu Aug 06 13:15:57 2009 +0800 @@ -32,12 +32,12 @@ inkscape:cx="267.0313" inkscape:cy="228.90269" inkscape:document-units="px" - inkscape:current-layer="item7" + inkscape:current-layer="layer4" showgrid="false" - inkscape:window-width="1124" - inkscape:window-height="867" - inkscape:window-x="212" - inkscape:window-y="90" /> + inkscape:window-width="1024" + inkscape:window-height="768" + inkscape:window-x="0" + inkscape:window-y="0" /> <defs id="defs4"> <linearGradient @@ -277,7 +277,7 @@ inkscape:label="lightbar"> <g mbname="item_lightbar" - transform="matrix(0.9148913,0,0,1,167.44763,103.34853)" + transform="matrix(0.9148913,0,0,1,168.41407,93.684101)" id="item_lightbar" style="stroke:none"> <rect
--- a/include/animated_menu.h Thu Aug 06 09:38:51 2009 +0800 +++ b/include/animated_menu.h Thu Aug 06 13:15:57 2009 +0800 @@ -16,7 +16,8 @@ void (*callback)(struct _mb_animated_menu *m, int sel); void (*update_callback)(struct _mb_animated_menu *m, int sel); mb_progm_t *progm; - X_kb_event_t pending_key; + X_kb_event_t pending_keys[16]; + int pending_pos, pending_last; } mb_animated_menu_t; /** \brief Create an instace of animated menu. *
--- a/src/mbaf/animated_menu.c Thu Aug 06 09:38:51 2009 +0800 +++ b/src/mbaf/animated_menu.c Thu Aug 06 13:15:57 2009 +0800 @@ -30,7 +30,6 @@ mb_progm_t *progm; mb_word_t *word; - printf("max item is %d\n", m->max); // fill new item for(i=0;i<8;i++) { group = (coord_t *) m->objects[m->items[i]]; @@ -58,7 +57,6 @@ mb_animated_menu_t *m = (mb_animated_menu_t *) arg; m->ready++; - printf("animated done ready=%d\n", m->ready); } static void mb_animated_menu_fillMenuContentUp(mb_animated_menu_t *m) @@ -119,7 +117,6 @@ m->items[i] = m->items[i-1]; } m->items[0] = tmp; - printf("fill menu\n"); } @@ -270,9 +267,11 @@ 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); + X_kb_event_t *xkey; + + xkey = &m->pending_keys[m->pending_pos]; + m->pending_pos = (m->pending_pos + 1) & 0xf; + mb_animated_menu_keyHandler((event_t *) xkey, m); } static void mb_animated_menu_keyHandler(event_t *ev, void *arg) { @@ -281,11 +280,15 @@ if(xkey->event.type != EVT_KB_PRESS) { return; } - printf("read=%d\n",m->ready); 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; + m->pending_keys[m->pending_last++] = *xkey; + m->pending_last &= 0xf; + if(m->pending_last == m->pending_pos) + m->pending_last = (m->pending_last - 1) & 0xf; + else + subject_add_observer(mb_progm_get_complete(m->progm), + mb_animated_menu_send_pending_key, + m); return; } switch(xkey->sym) { @@ -360,6 +363,7 @@ m->lightbar = (mb_obj_t *) MB_SPRITE_GET_OBJ(sp,name); if (m->lightbar==NULL) fprintf(stderr,"Can not find object %s\n",name); + m->pending_pos = m->pending_last = 0; mb_animated_menu_fillMenuContent(m); subject_add_observer(MBAF_KB_SUBJECT(app), mb_animated_menu_keyHandler,m); return m;