comparison src/mbaf/animated_menu.c @ 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
comparison
equal deleted inserted replaced
454:9b8dda201ccb 455:58b6337fb3b2
28 int tmp; 28 int tmp;
29 mb_timeval_t start, playing, now; 29 mb_timeval_t start, playing, now;
30 mb_progm_t *progm; 30 mb_progm_t *progm;
31 mb_word_t *word; 31 mb_word_t *word;
32 32
33 printf("max item is %d\n", m->max);
34 // fill new item 33 // fill new item
35 for(i=0;i<8;i++) { 34 for(i=0;i<8;i++) {
36 group = (coord_t *) m->objects[m->items[i]]; 35 group = (coord_t *) m->objects[m->items[i]];
37 if (i < m->max) 36 if (i < m->max)
38 set_text(group, m->titles[m->top+i]); 37 set_text(group, m->titles[m->top+i]);
56 static void mb_animated_menu_complete(event_t *ev,void *arg) 55 static void mb_animated_menu_complete(event_t *ev,void *arg)
57 { 56 {
58 mb_animated_menu_t *m = (mb_animated_menu_t *) arg; 57 mb_animated_menu_t *m = (mb_animated_menu_t *) arg;
59 58
60 m->ready++; 59 m->ready++;
61 printf("animated done ready=%d\n", m->ready);
62 } 60 }
63 61
64 static void mb_animated_menu_fillMenuContentUp(mb_animated_menu_t *m) 62 static void mb_animated_menu_fillMenuContentUp(mb_animated_menu_t *m)
65 { 63 {
66 int i; 64 int i;
117 tmp = m->items[8]; 115 tmp = m->items[8];
118 for(i=8;i>0;i--) { 116 for(i=8;i>0;i--) {
119 m->items[i] = m->items[i-1]; 117 m->items[i] = m->items[i-1];
120 } 118 }
121 m->items[0] = tmp; 119 m->items[0] = tmp;
122 printf("fill menu\n");
123 } 120 }
124 121
125 122
126 static void mb_animated_menu_fillMenuContentDown(mb_animated_menu_t *m) 123 static void mb_animated_menu_fillMenuContentDown(mb_animated_menu_t *m)
127 { 124 {
268 // Send the pending key in the animation progm complete callback 265 // Send the pending key in the animation progm complete callback
269 static void mb_animated_menu_keyHandler(event_t *ev, void *arg); 266 static void mb_animated_menu_keyHandler(event_t *ev, void *arg);
270 static void mb_animated_menu_send_pending_key(event_t *ev,void *arg) 267 static void mb_animated_menu_send_pending_key(event_t *ev,void *arg)
271 { 268 {
272 mb_animated_menu_t *m = (mb_animated_menu_t *) arg; 269 mb_animated_menu_t *m = (mb_animated_menu_t *) arg;
273 270 X_kb_event_t *xkey;
274 if (m->ready<=0) 271
275 mb_animated_menu_keyHandler((event_t *) &m->pending_key,m); 272 xkey = &m->pending_keys[m->pending_pos];
273 m->pending_pos = (m->pending_pos + 1) & 0xf;
274 mb_animated_menu_keyHandler((event_t *) xkey, m);
276 } 275 }
277 static void mb_animated_menu_keyHandler(event_t *ev, void *arg) 276 static void mb_animated_menu_keyHandler(event_t *ev, void *arg)
278 { 277 {
279 mb_animated_menu_t *m = (mb_animated_menu_t *) arg; 278 mb_animated_menu_t *m = (mb_animated_menu_t *) arg;
280 X_kb_event_t *xkey = (X_kb_event_t *)ev; 279 X_kb_event_t *xkey = (X_kb_event_t *)ev;
281 if(xkey->event.type != EVT_KB_PRESS) { 280 if(xkey->event.type != EVT_KB_PRESS) {
282 return; 281 return;
283 } 282 }
284 printf("read=%d\n",m->ready);
285 if (m->ready<=0) { 283 if (m->ready<=0) {
286 subject_add_observer(mb_progm_get_complete(m->progm), mb_animated_menu_send_pending_key,m); 284 m->pending_keys[m->pending_last++] = *xkey;
287 mb_progm_finish(m->progm); 285 m->pending_last &= 0xf;
288 m->pending_key = *xkey; 286 if(m->pending_last == m->pending_pos)
287 m->pending_last = (m->pending_last - 1) & 0xf;
288 else
289 subject_add_observer(mb_progm_get_complete(m->progm),
290 mb_animated_menu_send_pending_key,
291 m);
289 return; 292 return;
290 } 293 }
291 switch(xkey->sym) { 294 switch(xkey->sym) {
292 case 0xff51: /* left */ 295 case 0xff51: /* left */
293 break; 296 break;
358 m->titles = menus; 361 m->titles = menus;
359 snprintf(name,sizeof(name), "%s_lightbar", objnames); 362 snprintf(name,sizeof(name), "%s_lightbar", objnames);
360 m->lightbar = (mb_obj_t *) MB_SPRITE_GET_OBJ(sp,name); 363 m->lightbar = (mb_obj_t *) MB_SPRITE_GET_OBJ(sp,name);
361 if (m->lightbar==NULL) 364 if (m->lightbar==NULL)
362 fprintf(stderr,"Can not find object %s\n",name); 365 fprintf(stderr,"Can not find object %s\n",name);
366 m->pending_pos = m->pending_last = 0;
363 mb_animated_menu_fillMenuContent(m); 367 mb_animated_menu_fillMenuContent(m);
364 subject_add_observer(MBAF_KB_SUBJECT(app), mb_animated_menu_keyHandler,m); 368 subject_add_observer(MBAF_KB_SUBJECT(app), mb_animated_menu_keyHandler,m);
365 return m; 369 return m;
366 } 370 }
367 371