Mercurial > MadButterfly
annotate examples/menu/main.c @ 305:0231b05552fe
Wait for the last animation done before we send the next one.
author | wycc |
---|---|
date | Sun, 15 Feb 2009 09:19:59 +0800 |
parents | c8f31eef947b |
children | c981e561ac37 |
rev | line source |
---|---|
296
2e97e8082d83
* Fix the symbol definition code which does not assume the id is the same as the mbname.
wycc
parents:
diff
changeset
|
1 /*! \file |
2e97e8082d83
* Fix the symbol definition code which does not assume the id is the same as the mbname.
wycc
parents:
diff
changeset
|
2 * |
2e97e8082d83
* Fix the symbol definition code which does not assume the id is the same as the mbname.
wycc
parents:
diff
changeset
|
3 * This is the demo program for the animated menu. We will use to test the MBAF API. |
297 | 4 * We need to have group item1-item9 in the SVG file. Initially, we will show |
5 * item1-item8 only. When a up/down key is pressed, we will draw the next item in item9 and | |
6 * add two words to move item1-item9 smoothly. The first word move items to the 3/4 position | |
7 * fastly. The second will move it from 3/4 to the final position slowly to make retard effect. | |
8 * | |
9 * If we press another key before the second words finish, we will delete the word and replace | |
10 * it with a word to move it fastly to the final position and then we will repeat the procedure | |
11 * to add another two words to move it to the next position. | |
296
2e97e8082d83
* Fix the symbol definition code which does not assume the id is the same as the mbname.
wycc
parents:
diff
changeset
|
12 */ |
2e97e8082d83
* Fix the symbol definition code which does not assume the id is the same as the mbname.
wycc
parents:
diff
changeset
|
13 #include <stdio.h> |
2e97e8082d83
* Fix the symbol definition code which does not assume the id is the same as the mbname.
wycc
parents:
diff
changeset
|
14 #include <mb.h> |
2e97e8082d83
* Fix the symbol definition code which does not assume the id is the same as the mbname.
wycc
parents:
diff
changeset
|
15 #include <string.h> |
2e97e8082d83
* Fix the symbol definition code which does not assume the id is the same as the mbname.
wycc
parents:
diff
changeset
|
16 #include "menu.h" |
2e97e8082d83
* Fix the symbol definition code which does not assume the id is the same as the mbname.
wycc
parents:
diff
changeset
|
17 #include "mbapp.h" |
2e97e8082d83
* Fix the symbol definition code which does not assume the id is the same as the mbname.
wycc
parents:
diff
changeset
|
18 |
302 | 19 |
20 typedef struct { | |
21 char **titles; | |
22 int *menus_y; | |
23 int *items; | |
24 int top; | |
25 int cur; | |
26 int max; | |
27 int ready; | |
28 MBApp *app; | |
29 mb_sprite_t *sprite; | |
30 mb_obj_t **objects; | |
31 mb_obj_t *lightbar; | |
32 } mb_animated_menu_t; | |
33 | |
296
2e97e8082d83
* Fix the symbol definition code which does not assume the id is the same as the mbname.
wycc
parents:
diff
changeset
|
34 char *menus[] = { |
2e97e8082d83
* Fix the symbol definition code which does not assume the id is the same as the mbname.
wycc
parents:
diff
changeset
|
35 "Item 1", |
2e97e8082d83
* Fix the symbol definition code which does not assume the id is the same as the mbname.
wycc
parents:
diff
changeset
|
36 "Item 2", |
2e97e8082d83
* Fix the symbol definition code which does not assume the id is the same as the mbname.
wycc
parents:
diff
changeset
|
37 "Item 3", |
2e97e8082d83
* Fix the symbol definition code which does not assume the id is the same as the mbname.
wycc
parents:
diff
changeset
|
38 "Item 4", |
2e97e8082d83
* Fix the symbol definition code which does not assume the id is the same as the mbname.
wycc
parents:
diff
changeset
|
39 "Item 5", |
2e97e8082d83
* Fix the symbol definition code which does not assume the id is the same as the mbname.
wycc
parents:
diff
changeset
|
40 "Item 6", |
2e97e8082d83
* Fix the symbol definition code which does not assume the id is the same as the mbname.
wycc
parents:
diff
changeset
|
41 "Item 7", |
2e97e8082d83
* Fix the symbol definition code which does not assume the id is the same as the mbname.
wycc
parents:
diff
changeset
|
42 "Item 8", |
2e97e8082d83
* Fix the symbol definition code which does not assume the id is the same as the mbname.
wycc
parents:
diff
changeset
|
43 "Item 9", |
2e97e8082d83
* Fix the symbol definition code which does not assume the id is the same as the mbname.
wycc
parents:
diff
changeset
|
44 "Item 10", |
2e97e8082d83
* Fix the symbol definition code which does not assume the id is the same as the mbname.
wycc
parents:
diff
changeset
|
45 "Item 11", |
2e97e8082d83
* Fix the symbol definition code which does not assume the id is the same as the mbname.
wycc
parents:
diff
changeset
|
46 "Item 12", |
2e97e8082d83
* Fix the symbol definition code which does not assume the id is the same as the mbname.
wycc
parents:
diff
changeset
|
47 "Item 13", |
2e97e8082d83
* Fix the symbol definition code which does not assume the id is the same as the mbname.
wycc
parents:
diff
changeset
|
48 "Item 14", |
2e97e8082d83
* Fix the symbol definition code which does not assume the id is the same as the mbname.
wycc
parents:
diff
changeset
|
49 "Item 15", |
2e97e8082d83
* Fix the symbol definition code which does not assume the id is the same as the mbname.
wycc
parents:
diff
changeset
|
50 "Item 16", |
2e97e8082d83
* Fix the symbol definition code which does not assume the id is the same as the mbname.
wycc
parents:
diff
changeset
|
51 "Item 17", |
2e97e8082d83
* Fix the symbol definition code which does not assume the id is the same as the mbname.
wycc
parents:
diff
changeset
|
52 "Item 18", |
2e97e8082d83
* Fix the symbol definition code which does not assume the id is the same as the mbname.
wycc
parents:
diff
changeset
|
53 }; |
2e97e8082d83
* Fix the symbol definition code which does not assume the id is the same as the mbname.
wycc
parents:
diff
changeset
|
54 |
297 | 55 int menus_y[10]; |
56 int items[10]; | |
305
0231b05552fe
Wait for the last animation done before we send the next one.
wycc
parents:
304
diff
changeset
|
57 #define SPEED 300000 |
297 | 58 |
296
2e97e8082d83
* Fix the symbol definition code which does not assume the id is the same as the mbname.
wycc
parents:
diff
changeset
|
59 typedef struct { |
302 | 60 mb_animated_menu_t *m; |
296
2e97e8082d83
* Fix the symbol definition code which does not assume the id is the same as the mbname.
wycc
parents:
diff
changeset
|
61 }MyAppData; |
2e97e8082d83
* Fix the symbol definition code which does not assume the id is the same as the mbname.
wycc
parents:
diff
changeset
|
62 |
2e97e8082d83
* Fix the symbol definition code which does not assume the id is the same as the mbname.
wycc
parents:
diff
changeset
|
63 MBApp *myApp; |
2e97e8082d83
* Fix the symbol definition code which does not assume the id is the same as the mbname.
wycc
parents:
diff
changeset
|
64 |
302 | 65 |
66 static void set_text(coord_t *g, char *text) | |
67 { | |
68 geo_t *geo; | |
69 shape_t *shape; | |
70 | |
71 FOR_COORD_MEMBERS(g, geo) { | |
72 shape = geo_get_shape(geo); | |
73 if(shape->obj.obj_type == MBO_TEXT) { | |
74 sh_text_set_text(shape, text); | |
75 } | |
76 } | |
77 } | |
78 | |
79 static void mb_animated_menu_fillMenuContent(mb_animated_menu_t *m) | |
296
2e97e8082d83
* Fix the symbol definition code which does not assume the id is the same as the mbname.
wycc
parents:
diff
changeset
|
80 { |
2e97e8082d83
* Fix the symbol definition code which does not assume the id is the same as the mbname.
wycc
parents:
diff
changeset
|
81 int i; |
297 | 82 coord_t *textgroup; |
296
2e97e8082d83
* Fix the symbol definition code which does not assume the id is the same as the mbname.
wycc
parents:
diff
changeset
|
83 shape_t *text; |
2e97e8082d83
* Fix the symbol definition code which does not assume the id is the same as the mbname.
wycc
parents:
diff
changeset
|
84 coord_t *group; |
2e97e8082d83
* Fix the symbol definition code which does not assume the id is the same as the mbname.
wycc
parents:
diff
changeset
|
85 coord_t *lightbar; |
297 | 86 int tmp; |
87 mb_timeval_t start, playing, now; | |
88 mb_progm_t *progm; | |
89 mb_word_t *word; | |
296
2e97e8082d83
* Fix the symbol definition code which does not assume the id is the same as the mbname.
wycc
parents:
diff
changeset
|
90 |
297 | 91 |
92 // fill new item | |
296
2e97e8082d83
* Fix the symbol definition code which does not assume the id is the same as the mbname.
wycc
parents:
diff
changeset
|
93 for(i=0;i<8;i++) { |
302 | 94 text = (shape_t *) m->objects[m->items[i]]; |
95 set_text(text, m->titles[m->top+i]); | |
96 //rdman_shape_changed(MBAPP_RDMAN(m->app),text); | |
296
2e97e8082d83
* Fix the symbol definition code which does not assume the id is the same as the mbname.
wycc
parents:
diff
changeset
|
97 } |
297 | 98 |
99 | |
302 | 100 textgroup = (coord_t *) m->objects[m->items[i]]; |
297 | 101 coord_hide(textgroup); |
302 | 102 rdman_coord_changed(MBAPP_RDMAN(m->app),textgroup); |
297 | 103 |
302 | 104 lightbar = (coord_t *) m->lightbar; |
304
c8f31eef947b
Fix the initial drawn position issue. We will draw the lightbar in the right posityion.
wycc
parents:
302
diff
changeset
|
105 group = (coord_t *) m->objects[m->cur]; |
296
2e97e8082d83
* Fix the symbol definition code which does not assume the id is the same as the mbname.
wycc
parents:
diff
changeset
|
106 coord_x(lightbar) = coord_x(group); |
2e97e8082d83
* Fix the symbol definition code which does not assume the id is the same as the mbname.
wycc
parents:
diff
changeset
|
107 coord_y(lightbar) = coord_y(group); |
302 | 108 rdman_redraw_changed(MBAPP_RDMAN(m->app)); |
297 | 109 } |
110 | |
305
0231b05552fe
Wait for the last animation done before we send the next one.
wycc
parents:
304
diff
changeset
|
111 static void mb_animated_menu_complete(event_t *ev,void *arg) |
302 | 112 { |
113 mb_animated_menu_t *m = (mb_animated_menu_t *) arg; | |
114 | |
115 m->ready++; | |
305
0231b05552fe
Wait for the last animation done before we send the next one.
wycc
parents:
304
diff
changeset
|
116 printf("animated done ready=%d\n", m->ready); |
302 | 117 } |
118 | |
119 static void mb_animated_menu_fillMenuContentUp(mb_animated_menu_t *m) | |
297 | 120 { |
121 int i; | |
122 coord_t *textgroup; | |
123 shape_t *text; | |
124 coord_t *group; | |
125 coord_t *lightbar; | |
126 int tmp; | |
127 mb_timeval_t start, playing, now; | |
128 mb_progm_t *progm; | |
129 mb_word_t *word; | |
130 | |
131 | |
132 // fill new item | |
302 | 133 text = (shape_t *) m->objects[m->items[8]]; |
134 set_text(text, m->titles[m->top]); | |
297 | 135 |
302 | 136 progm = mb_progm_new(2, MBAPP_RDMAN(m->app)); |
297 | 137 MB_TIMEVAL_SET(&start, 0, 0); |
298 | 138 MB_TIMEVAL_SET(&playing, 0, SPEED); |
297 | 139 word = mb_progm_next_word(progm, &start, &playing); |
140 get_now(&now); | |
141 | |
142 for(i=0;i<7;i++) { | |
143 //shift to the next item | |
302 | 144 textgroup = (coord_t *) m->objects[m->items[i]]; |
145 mb_shift_new(0,m->menus_y[i+1]-coord_y(textgroup), textgroup,word); | |
297 | 146 } |
147 // fade out the item[7] | |
302 | 148 textgroup = (coord_t *) m->objects[m->items[7]]; |
297 | 149 mb_shift_new(0,100, textgroup,word); |
150 | |
151 // fade in the item[8] | |
302 | 152 textgroup = (coord_t *) m->objects[m->items[8]]; |
153 group = (coord_t *) m->objects[m->items[0]]; | |
154 coord_y(textgroup) = m->menus_y[0]-100; | |
297 | 155 coord_show(textgroup); |
156 mb_shift_new(0,100, textgroup,word); | |
157 | |
302 | 158 lightbar = (coord_t *) m->lightbar; |
159 mb_shift_new(0,m->menus_y[m->cur]-coord_y(lightbar),lightbar,word); | |
297 | 160 |
298 | 161 MB_TIMEVAL_SET(&start, 0, SPEED); |
297 | 162 MB_TIMEVAL_SET(&playing, 0, 0); |
163 word = mb_progm_next_word(progm, &start, &playing); | |
302 | 164 textgroup = (coord_t *) m->objects[m->items[7]]; |
299 | 165 mb_visibility_new(VIS_HIDDEN, textgroup,word); |
297 | 166 |
167 mb_progm_free_completed(progm); | |
302 | 168 m->ready--; |
169 subject_add_observer(mb_progm_get_complete(progm), mb_animated_menu_complete,m); | |
170 mb_progm_start(progm, X_MB_tman(MBAPP_RDMAN(m->app)->rt), &now); | |
171 rdman_redraw_changed(MBAPP_RDMAN(m->app)); | |
172 tmp = m->items[8]; | |
297 | 173 for(i=8;i>0;i--) { |
302 | 174 m->items[i] = m->items[i-1]; |
297 | 175 } |
302 | 176 m->items[0] = tmp; |
297 | 177 } |
302 | 178 |
179 | |
180 static void mb_animated_menu_fillMenuContentDown(mb_animated_menu_t *m) | |
297 | 181 { |
182 int i; | |
183 coord_t *textgroup; | |
184 shape_t *text; | |
185 coord_t *group; | |
186 coord_t *lightbar; | |
187 char name[255]; | |
188 int tmp; | |
189 mb_timeval_t start, playing, now; | |
190 mb_progm_t *progm; | |
191 mb_word_t *word; | |
192 | |
193 | |
194 // fill new item | |
302 | 195 set_text(m->objects[m->items[8]], m->titles[m->top+7]); |
297 | 196 |
302 | 197 progm = mb_progm_new(2, MBAPP_RDMAN(m->app)); |
297 | 198 MB_TIMEVAL_SET(&start, 0, 0); |
298 | 199 MB_TIMEVAL_SET(&playing, 0, SPEED); |
297 | 200 word = mb_progm_next_word(progm, &start, &playing); |
201 get_now(&now); | |
202 | |
203 for(i=1;i<8;i++) { | |
204 //shift to the next item | |
302 | 205 mb_shift_new(0,m->menus_y[i-1]-coord_y((coord_t *)m->objects[m->items[i]]), (coord_t *) m->objects[m->items[i]],word); |
297 | 206 } |
207 // fade out the item[0] | |
302 | 208 mb_shift_new(0,-100, (coord_t *)m->objects[m->items[0]],word); |
297 | 209 |
210 // fade in the item[8] | |
302 | 211 coord_y((coord_t *)m->objects[m->items[8]]) = m->menus_y[7]+100; |
212 coord_show(((coord_t *)(m->objects[m->items[8]]))); | |
213 mb_shift_new(0,-100, (coord_t *)m->objects[m->items[8]],word); | |
297 | 214 |
302 | 215 mb_shift_new(0,m->menus_y[m->cur]-coord_y((coord_t *)m->lightbar),((coord_t *)(m->lightbar)),word); |
297 | 216 |
298 | 217 MB_TIMEVAL_SET(&start, 0, SPEED); |
297 | 218 MB_TIMEVAL_SET(&playing, 0, 0); |
219 word = mb_progm_next_word(progm, &start, &playing); | |
302 | 220 mb_visibility_new(VIS_VISIBLE, (coord_t *) m->objects[m->items[0]],word); |
297 | 221 |
222 mb_progm_free_completed(progm); | |
302 | 223 m->ready--; |
224 subject_add_observer(mb_progm_get_complete(progm), mb_animated_menu_complete,m); | |
225 mb_progm_start(progm, X_MB_tman(MBAPP_RDMAN(m->app)->rt), &now); | |
226 rdman_redraw_changed(MBAPP_RDMAN(m->app)); | |
227 tmp = m->items[0]; | |
297 | 228 for(i=0;i<8;i++) { |
302 | 229 m->items[i] = m->items[i+1]; |
297 | 230 } |
302 | 231 m->items[8] = tmp; |
297 | 232 } |
233 | |
302 | 234 void mb_animated_menu_moveLightBar(mb_animated_menu_t *m) |
297 | 235 { |
236 mb_timeval_t start, playing, now; | |
237 mb_progm_t *progm; | |
238 mb_word_t *word; | |
239 coord_t *group; | |
240 coord_t *lightbar; | |
241 | |
302 | 242 progm = mb_progm_new(1, MBAPP_RDMAN(m->app)); |
297 | 243 MB_TIMEVAL_SET(&start, 0, 0); |
305
0231b05552fe
Wait for the last animation done before we send the next one.
wycc
parents:
304
diff
changeset
|
244 MB_TIMEVAL_SET(&playing, 0, SPEED); |
297 | 245 word = mb_progm_next_word(progm, &start, &playing); |
246 get_now(&now); | |
247 | |
302 | 248 lightbar = (coord_t *) m->lightbar; |
305
0231b05552fe
Wait for the last animation done before we send the next one.
wycc
parents:
304
diff
changeset
|
249 mb_shift_new(0,m->menus_y[m->cur]-coord_y(lightbar),lightbar,word); |
297 | 250 mb_progm_free_completed(progm); |
305
0231b05552fe
Wait for the last animation done before we send the next one.
wycc
parents:
304
diff
changeset
|
251 m->ready--; |
0231b05552fe
Wait for the last animation done before we send the next one.
wycc
parents:
304
diff
changeset
|
252 subject_add_observer(mb_progm_get_complete(progm), mb_animated_menu_complete,m); |
302 | 253 mb_progm_start(progm, X_MB_tman(MBAPP_RDMAN(m->app)->rt), &now); |
254 rdman_redraw_changed(MBAPP_RDMAN(m->app)); | |
296
2e97e8082d83
* Fix the symbol definition code which does not assume the id is the same as the mbname.
wycc
parents:
diff
changeset
|
255 } |
2e97e8082d83
* Fix the symbol definition code which does not assume the id is the same as the mbname.
wycc
parents:
diff
changeset
|
256 |
302 | 257 void mb_animated_menu_up(mb_animated_menu_t *m) |
296
2e97e8082d83
* Fix the symbol definition code which does not assume the id is the same as the mbname.
wycc
parents:
diff
changeset
|
258 { |
302 | 259 if (m->cur > 5) { |
260 m->cur--; | |
261 mb_animated_menu_moveLightBar(m); | |
297 | 262 } else { |
302 | 263 if (m->top > 0) { |
264 m->top--; | |
265 mb_animated_menu_fillMenuContentUp(m); | |
296
2e97e8082d83
* Fix the symbol definition code which does not assume the id is the same as the mbname.
wycc
parents:
diff
changeset
|
266 } else { |
302 | 267 if (m->cur == 0) |
296
2e97e8082d83
* Fix the symbol definition code which does not assume the id is the same as the mbname.
wycc
parents:
diff
changeset
|
268 return; |
302 | 269 m->cur--; |
270 mb_animated_menu_moveLightBar(m); | |
296
2e97e8082d83
* Fix the symbol definition code which does not assume the id is the same as the mbname.
wycc
parents:
diff
changeset
|
271 } |
2e97e8082d83
* Fix the symbol definition code which does not assume the id is the same as the mbname.
wycc
parents:
diff
changeset
|
272 } |
2e97e8082d83
* Fix the symbol definition code which does not assume the id is the same as the mbname.
wycc
parents:
diff
changeset
|
273 } |
302 | 274 void mb_animated_menu_down(mb_animated_menu_t *m) |
296
2e97e8082d83
* Fix the symbol definition code which does not assume the id is the same as the mbname.
wycc
parents:
diff
changeset
|
275 { |
2e97e8082d83
* Fix the symbol definition code which does not assume the id is the same as the mbname.
wycc
parents:
diff
changeset
|
276 |
305
0231b05552fe
Wait for the last animation done before we send the next one.
wycc
parents:
304
diff
changeset
|
277 if (m->cur < 5) { |
302 | 278 if (m->top+m->cur <= m->max) { |
279 m->cur++; | |
280 mb_animated_menu_moveLightBar(m); | |
297 | 281 } |
296
2e97e8082d83
* Fix the symbol definition code which does not assume the id is the same as the mbname.
wycc
parents:
diff
changeset
|
282 } else { |
302 | 283 if ((m->top+8) < m->max) { |
284 m->top++; | |
285 mb_animated_menu_fillMenuContentDown(m); | |
296
2e97e8082d83
* Fix the symbol definition code which does not assume the id is the same as the mbname.
wycc
parents:
diff
changeset
|
286 } else { |
302 | 287 if (m->cur+m->top < m->max-1) { |
288 m->cur++; | |
289 mb_animated_menu_moveLightBar(m); | |
297 | 290 } else |
296
2e97e8082d83
* Fix the symbol definition code which does not assume the id is the same as the mbname.
wycc
parents:
diff
changeset
|
291 return; |
2e97e8082d83
* Fix the symbol definition code which does not assume the id is the same as the mbname.
wycc
parents:
diff
changeset
|
292 } |
2e97e8082d83
* Fix the symbol definition code which does not assume the id is the same as the mbname.
wycc
parents:
diff
changeset
|
293 } |
2e97e8082d83
* Fix the symbol definition code which does not assume the id is the same as the mbname.
wycc
parents:
diff
changeset
|
294 } |
302 | 295 void mb_animated_menu_select(mb_animated_menu_t *m) |
296
2e97e8082d83
* Fix the symbol definition code which does not assume the id is the same as the mbname.
wycc
parents:
diff
changeset
|
296 { |
2e97e8082d83
* Fix the symbol definition code which does not assume the id is the same as the mbname.
wycc
parents:
diff
changeset
|
297 } |
2e97e8082d83
* Fix the symbol definition code which does not assume the id is the same as the mbname.
wycc
parents:
diff
changeset
|
298 |
302 | 299 void mb_animated_menu_keyHandler(event_t *ev, void *arg) |
296
2e97e8082d83
* Fix the symbol definition code which does not assume the id is the same as the mbname.
wycc
parents:
diff
changeset
|
300 { |
302 | 301 mb_animated_menu_t *m = (mb_animated_menu_t *) arg; |
296
2e97e8082d83
* Fix the symbol definition code which does not assume the id is the same as the mbname.
wycc
parents:
diff
changeset
|
302 X_kb_event_t *xkey = (X_kb_event_t *)ev; |
2e97e8082d83
* Fix the symbol definition code which does not assume the id is the same as the mbname.
wycc
parents:
diff
changeset
|
303 if(xkey->event.type != EVT_KB_PRESS) { |
2e97e8082d83
* Fix the symbol definition code which does not assume the id is the same as the mbname.
wycc
parents:
diff
changeset
|
304 return; |
2e97e8082d83
* Fix the symbol definition code which does not assume the id is the same as the mbname.
wycc
parents:
diff
changeset
|
305 } |
305
0231b05552fe
Wait for the last animation done before we send the next one.
wycc
parents:
304
diff
changeset
|
306 printf("read=%d\n",m->ready); |
0231b05552fe
Wait for the last animation done before we send the next one.
wycc
parents:
304
diff
changeset
|
307 if (m->ready<=0) return; |
296
2e97e8082d83
* Fix the symbol definition code which does not assume the id is the same as the mbname.
wycc
parents:
diff
changeset
|
308 switch(xkey->sym) { |
2e97e8082d83
* Fix the symbol definition code which does not assume the id is the same as the mbname.
wycc
parents:
diff
changeset
|
309 case 0xff51: /* left */ |
2e97e8082d83
* Fix the symbol definition code which does not assume the id is the same as the mbname.
wycc
parents:
diff
changeset
|
310 break; |
2e97e8082d83
* Fix the symbol definition code which does not assume the id is the same as the mbname.
wycc
parents:
diff
changeset
|
311 |
2e97e8082d83
* Fix the symbol definition code which does not assume the id is the same as the mbname.
wycc
parents:
diff
changeset
|
312 case 0xff52: /* up */ |
302 | 313 mb_animated_menu_up(m); |
296
2e97e8082d83
* Fix the symbol definition code which does not assume the id is the same as the mbname.
wycc
parents:
diff
changeset
|
314 break; |
2e97e8082d83
* Fix the symbol definition code which does not assume the id is the same as the mbname.
wycc
parents:
diff
changeset
|
315 |
2e97e8082d83
* Fix the symbol definition code which does not assume the id is the same as the mbname.
wycc
parents:
diff
changeset
|
316 case 0xff53: /* right */ |
2e97e8082d83
* Fix the symbol definition code which does not assume the id is the same as the mbname.
wycc
parents:
diff
changeset
|
317 break; |
2e97e8082d83
* Fix the symbol definition code which does not assume the id is the same as the mbname.
wycc
parents:
diff
changeset
|
318 |
2e97e8082d83
* Fix the symbol definition code which does not assume the id is the same as the mbname.
wycc
parents:
diff
changeset
|
319 case 0xff54: /* down */ |
302 | 320 mb_animated_menu_down(m); |
296
2e97e8082d83
* Fix the symbol definition code which does not assume the id is the same as the mbname.
wycc
parents:
diff
changeset
|
321 break; |
2e97e8082d83
* Fix the symbol definition code which does not assume the id is the same as the mbname.
wycc
parents:
diff
changeset
|
322 |
2e97e8082d83
* Fix the symbol definition code which does not assume the id is the same as the mbname.
wycc
parents:
diff
changeset
|
323 case 0xff0d: /* enter */ |
302 | 324 mb_animated_menu_select(m); |
296
2e97e8082d83
* Fix the symbol definition code which does not assume the id is the same as the mbname.
wycc
parents:
diff
changeset
|
325 break; |
2e97e8082d83
* Fix the symbol definition code which does not assume the id is the same as the mbname.
wycc
parents:
diff
changeset
|
326 default: |
2e97e8082d83
* Fix the symbol definition code which does not assume the id is the same as the mbname.
wycc
parents:
diff
changeset
|
327 return; |
2e97e8082d83
* Fix the symbol definition code which does not assume the id is the same as the mbname.
wycc
parents:
diff
changeset
|
328 } |
2e97e8082d83
* Fix the symbol definition code which does not assume the id is the same as the mbname.
wycc
parents:
diff
changeset
|
329 } |
2e97e8082d83
* Fix the symbol definition code which does not assume the id is the same as the mbname.
wycc
parents:
diff
changeset
|
330 |
302 | 331 /** \brief Create an instace of animated menu. |
332 * | |
333 * The objectnames is used to extract symbols from the SVG file. | |
334 * ${objectnames}0 - ${objectnames}8 is the text object. | |
335 * ${objectnames}_lightbar is the lightbar. | |
336 * | |
337 */ | |
338 mb_animated_menu_t *mb_animated_menu_new(MBApp *app,mb_sprite_t *sp,char *objnames,char *menus[]) | |
339 { | |
340 mb_animated_menu_t *m; | |
341 int i,len; | |
342 char name[255]; | |
343 mb_obj_t *l; | |
344 | |
345 for(i=0;menus[i];i++); | |
346 len = i; | |
347 | |
348 m = (mb_animated_menu_t *) malloc(sizeof(mb_animated_menu_t)+sizeof(int)*len*2+sizeof(mb_obj_t *)*len); | |
349 m->app = app; | |
350 m->sprite = sp; | |
351 m->top = 0; | |
352 m->cur = 0; | |
353 m->ready = 1; | |
354 m->max = len; | |
355 m->items = (int *) (m+1); | |
356 m->menus_y = (int *) (m->items+len); | |
357 m->objects = (mb_obj_t **) (m->menus_y+len); | |
358 for(i=0;i<9;i++) { | |
359 m->items[i] = i; | |
360 snprintf(name,sizeof(name),"%s%d", objnames, i+1); | |
361 l = MB_SPRITE_GET_OBJ(sp,name); | |
362 if (l == NULL) { | |
363 fprintf(stderr,"Can not find symbol %s\n",name); | |
364 } | |
365 m->objects[i] = (mb_obj_t *) l; | |
366 m->menus_y[i] = coord_y((coord_t*)l); | |
367 } | |
368 m->titles = menus; | |
369 snprintf(name,sizeof(name), "%s_lightbar", objnames); | |
370 m->lightbar = (mb_obj_t *) MB_SPRITE_GET_OBJ(sp,name); | |
305
0231b05552fe
Wait for the last animation done before we send the next one.
wycc
parents:
304
diff
changeset
|
371 if (m->lightbar==NULL) |
302 | 372 fprintf(stderr,"Can not find object %s\n",name); |
373 mb_animated_menu_fillMenuContent(m); | |
374 subject_add_observer(MBAPP_keySubject(myApp), mb_animated_menu_keyHandler,m); | |
375 return m; | |
376 } | |
377 | |
296
2e97e8082d83
* Fix the symbol definition code which does not assume the id is the same as the mbname.
wycc
parents:
diff
changeset
|
378 MyApp_InitContent() |
2e97e8082d83
* Fix the symbol definition code which does not assume the id is the same as the mbname.
wycc
parents:
diff
changeset
|
379 { |
2e97e8082d83
* Fix the symbol definition code which does not assume the id is the same as the mbname.
wycc
parents:
diff
changeset
|
380 MyAppData *data = MBAPP_DATA(myApp,MyAppData); |
2e97e8082d83
* Fix the symbol definition code which does not assume the id is the same as the mbname.
wycc
parents:
diff
changeset
|
381 subject_t *key = MBAPP_keySubject(myApp); |
297 | 382 char name[255]; |
383 coord_t *l; | |
384 int i; | |
385 mb_sprite_t *sprite=myApp->rootsprite; | |
296
2e97e8082d83
* Fix the symbol definition code which does not assume the id is the same as the mbname.
wycc
parents:
diff
changeset
|
386 |
302 | 387 data->m = mb_animated_menu_new(myApp,myApp->rootsprite,"item",menus); |
296
2e97e8082d83
* Fix the symbol definition code which does not assume the id is the same as the mbname.
wycc
parents:
diff
changeset
|
388 } |
2e97e8082d83
* Fix the symbol definition code which does not assume the id is the same as the mbname.
wycc
parents:
diff
changeset
|
389 |
2e97e8082d83
* Fix the symbol definition code which does not assume the id is the same as the mbname.
wycc
parents:
diff
changeset
|
390 int main(int argc, char * const argv[]) { |
2e97e8082d83
* Fix the symbol definition code which does not assume the id is the same as the mbname.
wycc
parents:
diff
changeset
|
391 subject_t *subject; |
2e97e8082d83
* Fix the symbol definition code which does not assume the id is the same as the mbname.
wycc
parents:
diff
changeset
|
392 mb_obj_t *button; |
2e97e8082d83
* Fix the symbol definition code which does not assume the id is the same as the mbname.
wycc
parents:
diff
changeset
|
393 MyAppData data; |
2e97e8082d83
* Fix the symbol definition code which does not assume the id is the same as the mbname.
wycc
parents:
diff
changeset
|
394 mb_timeval_t tmo,interval; |
2e97e8082d83
* Fix the symbol definition code which does not assume the id is the same as the mbname.
wycc
parents:
diff
changeset
|
395 |
2e97e8082d83
* Fix the symbol definition code which does not assume the id is the same as the mbname.
wycc
parents:
diff
changeset
|
396 if (argc > 1) |
2e97e8082d83
* Fix the symbol definition code which does not assume the id is the same as the mbname.
wycc
parents:
diff
changeset
|
397 myApp = MBApp_Init(argv[1]); |
2e97e8082d83
* Fix the symbol definition code which does not assume the id is the same as the mbname.
wycc
parents:
diff
changeset
|
398 else |
2e97e8082d83
* Fix the symbol definition code which does not assume the id is the same as the mbname.
wycc
parents:
diff
changeset
|
399 myApp = MBApp_Init("list"); |
2e97e8082d83
* Fix the symbol definition code which does not assume the id is the same as the mbname.
wycc
parents:
diff
changeset
|
400 MBApp_setData(myApp,&data); |
2e97e8082d83
* Fix the symbol definition code which does not assume the id is the same as the mbname.
wycc
parents:
diff
changeset
|
401 MyApp_InitContent(); |
2e97e8082d83
* Fix the symbol definition code which does not assume the id is the same as the mbname.
wycc
parents:
diff
changeset
|
402 |
2e97e8082d83
* Fix the symbol definition code which does not assume the id is the same as the mbname.
wycc
parents:
diff
changeset
|
403 MBApp_loop(myApp); |
2e97e8082d83
* Fix the symbol definition code which does not assume the id is the same as the mbname.
wycc
parents:
diff
changeset
|
404 |
2e97e8082d83
* Fix the symbol definition code which does not assume the id is the same as the mbname.
wycc
parents:
diff
changeset
|
405 return 0; |
2e97e8082d83
* Fix the symbol definition code which does not assume the id is the same as the mbname.
wycc
parents:
diff
changeset
|
406 } |
2e97e8082d83
* Fix the symbol definition code which does not assume the id is the same as the mbname.
wycc
parents:
diff
changeset
|
407 |
2e97e8082d83
* Fix the symbol definition code which does not assume the id is the same as the mbname.
wycc
parents:
diff
changeset
|
408 /* vim: set ts=4 */ |