Mercurial > MadButterfly
annotate examples/menu/main.c @ 302:8b45e7b374b8
Rewrite the menu as a widget style
author | wycc |
---|---|
date | Sun, 15 Feb 2009 08:33:47 +0800 |
parents | 5bf503270419 |
children | c8f31eef947b |
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]; | |
298 | 57 #define SPEED 600000 |
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; |
105 group = (coord_t *) m->objects[m->cur+1]; | |
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 | |
302 | 111 static void mb_animated_menu_complete(void *arg) |
112 { | |
113 mb_animated_menu_t *m = (mb_animated_menu_t *) arg; | |
114 | |
115 m->ready++; | |
116 } | |
117 | |
118 static void mb_animated_menu_fillMenuContentUp(mb_animated_menu_t *m) | |
297 | 119 { |
120 int i; | |
121 coord_t *textgroup; | |
122 shape_t *text; | |
123 coord_t *group; | |
124 coord_t *lightbar; | |
125 int tmp; | |
126 mb_timeval_t start, playing, now; | |
127 mb_progm_t *progm; | |
128 mb_word_t *word; | |
129 | |
130 | |
131 // fill new item | |
302 | 132 text = (shape_t *) m->objects[m->items[8]]; |
133 set_text(text, m->titles[m->top]); | |
297 | 134 |
302 | 135 progm = mb_progm_new(2, MBAPP_RDMAN(m->app)); |
297 | 136 MB_TIMEVAL_SET(&start, 0, 0); |
298 | 137 MB_TIMEVAL_SET(&playing, 0, SPEED); |
297 | 138 word = mb_progm_next_word(progm, &start, &playing); |
139 get_now(&now); | |
140 | |
141 for(i=0;i<7;i++) { | |
142 //shift to the next item | |
302 | 143 textgroup = (coord_t *) m->objects[m->items[i]]; |
144 mb_shift_new(0,m->menus_y[i+1]-coord_y(textgroup), textgroup,word); | |
297 | 145 } |
146 // fade out the item[7] | |
302 | 147 textgroup = (coord_t *) m->objects[m->items[7]]; |
297 | 148 mb_shift_new(0,100, textgroup,word); |
149 | |
150 // fade in the item[8] | |
302 | 151 textgroup = (coord_t *) m->objects[m->items[8]]; |
152 group = (coord_t *) m->objects[m->items[0]]; | |
153 coord_y(textgroup) = m->menus_y[0]-100; | |
297 | 154 coord_show(textgroup); |
155 mb_shift_new(0,100, textgroup,word); | |
156 | |
302 | 157 lightbar = (coord_t *) m->lightbar; |
158 mb_shift_new(0,m->menus_y[m->cur]-coord_y(lightbar),lightbar,word); | |
297 | 159 |
298 | 160 MB_TIMEVAL_SET(&start, 0, SPEED); |
297 | 161 MB_TIMEVAL_SET(&playing, 0, 0); |
162 word = mb_progm_next_word(progm, &start, &playing); | |
302 | 163 textgroup = (coord_t *) m->objects[m->items[7]]; |
299 | 164 mb_visibility_new(VIS_HIDDEN, textgroup,word); |
297 | 165 |
166 mb_progm_free_completed(progm); | |
302 | 167 m->ready--; |
168 subject_add_observer(mb_progm_get_complete(progm), mb_animated_menu_complete,m); | |
169 mb_progm_start(progm, X_MB_tman(MBAPP_RDMAN(m->app)->rt), &now); | |
170 rdman_redraw_changed(MBAPP_RDMAN(m->app)); | |
171 tmp = m->items[8]; | |
297 | 172 for(i=8;i>0;i--) { |
302 | 173 m->items[i] = m->items[i-1]; |
297 | 174 } |
302 | 175 m->items[0] = tmp; |
297 | 176 } |
302 | 177 |
178 | |
179 static void mb_animated_menu_fillMenuContentDown(mb_animated_menu_t *m) | |
297 | 180 { |
181 int i; | |
182 coord_t *textgroup; | |
183 shape_t *text; | |
184 coord_t *group; | |
185 coord_t *lightbar; | |
186 char name[255]; | |
187 int tmp; | |
188 mb_timeval_t start, playing, now; | |
189 mb_progm_t *progm; | |
190 mb_word_t *word; | |
191 | |
192 | |
193 // fill new item | |
302 | 194 set_text(m->objects[m->items[8]], m->titles[m->top+7]); |
297 | 195 |
302 | 196 progm = mb_progm_new(2, MBAPP_RDMAN(m->app)); |
297 | 197 MB_TIMEVAL_SET(&start, 0, 0); |
298 | 198 MB_TIMEVAL_SET(&playing, 0, SPEED); |
297 | 199 word = mb_progm_next_word(progm, &start, &playing); |
200 get_now(&now); | |
201 | |
202 for(i=1;i<8;i++) { | |
203 //shift to the next item | |
302 | 204 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 | 205 } |
206 // fade out the item[0] | |
302 | 207 mb_shift_new(0,-100, (coord_t *)m->objects[m->items[0]],word); |
297 | 208 |
209 // fade in the item[8] | |
302 | 210 coord_y((coord_t *)m->objects[m->items[8]]) = m->menus_y[7]+100; |
211 coord_show(((coord_t *)(m->objects[m->items[8]]))); | |
212 mb_shift_new(0,-100, (coord_t *)m->objects[m->items[8]],word); | |
297 | 213 |
302 | 214 mb_shift_new(0,m->menus_y[m->cur]-coord_y((coord_t *)m->lightbar),((coord_t *)(m->lightbar)),word); |
297 | 215 |
298 | 216 MB_TIMEVAL_SET(&start, 0, SPEED); |
297 | 217 MB_TIMEVAL_SET(&playing, 0, 0); |
218 word = mb_progm_next_word(progm, &start, &playing); | |
302 | 219 mb_visibility_new(VIS_VISIBLE, (coord_t *) m->objects[m->items[0]],word); |
297 | 220 |
221 mb_progm_free_completed(progm); | |
302 | 222 m->ready--; |
223 subject_add_observer(mb_progm_get_complete(progm), mb_animated_menu_complete,m); | |
224 mb_progm_start(progm, X_MB_tman(MBAPP_RDMAN(m->app)->rt), &now); | |
225 rdman_redraw_changed(MBAPP_RDMAN(m->app)); | |
226 tmp = m->items[0]; | |
297 | 227 for(i=0;i<8;i++) { |
302 | 228 m->items[i] = m->items[i+1]; |
297 | 229 } |
302 | 230 m->items[8] = tmp; |
297 | 231 } |
232 | |
302 | 233 void mb_animated_menu_moveLightBar(mb_animated_menu_t *m) |
297 | 234 { |
235 mb_timeval_t start, playing, now; | |
236 mb_progm_t *progm; | |
237 mb_word_t *word; | |
238 coord_t *group; | |
239 coord_t *lightbar; | |
240 | |
302 | 241 progm = mb_progm_new(1, MBAPP_RDMAN(m->app)); |
297 | 242 MB_TIMEVAL_SET(&start, 0, 0); |
243 MB_TIMEVAL_SET(&playing, 0, 200000); | |
244 word = mb_progm_next_word(progm, &start, &playing); | |
245 get_now(&now); | |
246 | |
302 | 247 lightbar = (coord_t *) m->lightbar; |
248 group = (coord_t *) m->objects[m->cur]; | |
297 | 249 mb_shift_new(coord_x(group)-coord_x(lightbar),coord_y(group)-coord_y(lightbar),lightbar,word); |
250 mb_progm_free_completed(progm); | |
302 | 251 mb_progm_start(progm, X_MB_tman(MBAPP_RDMAN(m->app)->rt), &now); |
252 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
|
253 } |
2e97e8082d83
* Fix the symbol definition code which does not assume the id is the same as the mbname.
wycc
parents:
diff
changeset
|
254 |
302 | 255 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
|
256 { |
302 | 257 if (m->cur > 5) { |
258 m->cur--; | |
259 mb_animated_menu_moveLightBar(m); | |
297 | 260 } else { |
302 | 261 if (m->top > 0) { |
262 m->top--; | |
263 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
|
264 } else { |
302 | 265 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
|
266 return; |
302 | 267 m->cur--; |
268 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
|
269 } |
2e97e8082d83
* Fix the symbol definition code which does not assume the id is the same as the mbname.
wycc
parents:
diff
changeset
|
270 } |
2e97e8082d83
* Fix the symbol definition code which does not assume the id is the same as the mbname.
wycc
parents:
diff
changeset
|
271 } |
302 | 272 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
|
273 { |
2e97e8082d83
* Fix the symbol definition code which does not assume the id is the same as the mbname.
wycc
parents:
diff
changeset
|
274 |
302 | 275 if (m->cur < 4) { |
276 if (m->top+m->cur <= m->max) { | |
277 m->cur++; | |
278 mb_animated_menu_moveLightBar(m); | |
297 | 279 } |
296
2e97e8082d83
* Fix the symbol definition code which does not assume the id is the same as the mbname.
wycc
parents:
diff
changeset
|
280 } else { |
302 | 281 if ((m->top+8) < m->max) { |
282 m->top++; | |
283 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
|
284 } else { |
302 | 285 if (m->cur+m->top < m->max-1) { |
286 m->cur++; | |
287 mb_animated_menu_moveLightBar(m); | |
297 | 288 } else |
296
2e97e8082d83
* Fix the symbol definition code which does not assume the id is the same as the mbname.
wycc
parents:
diff
changeset
|
289 return; |
2e97e8082d83
* Fix the symbol definition code which does not assume the id is the same as the mbname.
wycc
parents:
diff
changeset
|
290 } |
2e97e8082d83
* Fix the symbol definition code which does not assume the id is the same as the mbname.
wycc
parents:
diff
changeset
|
291 } |
2e97e8082d83
* Fix the symbol definition code which does not assume the id is the same as the mbname.
wycc
parents:
diff
changeset
|
292 } |
302 | 293 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
|
294 { |
2e97e8082d83
* Fix the symbol definition code which does not assume the id is the same as the mbname.
wycc
parents:
diff
changeset
|
295 } |
2e97e8082d83
* Fix the symbol definition code which does not assume the id is the same as the mbname.
wycc
parents:
diff
changeset
|
296 |
302 | 297 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
|
298 { |
302 | 299 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
|
300 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
|
301 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
|
302 return; |
2e97e8082d83
* Fix the symbol definition code which does not assume the id is the same as the mbname.
wycc
parents:
diff
changeset
|
303 } |
2e97e8082d83
* Fix the symbol definition code which does not assume the id is the same as the mbname.
wycc
parents:
diff
changeset
|
304 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
|
305 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
|
306 break; |
2e97e8082d83
* Fix the symbol definition code which does not assume the id is the same as the mbname.
wycc
parents:
diff
changeset
|
307 |
2e97e8082d83
* Fix the symbol definition code which does not assume the id is the same as the mbname.
wycc
parents:
diff
changeset
|
308 case 0xff52: /* up */ |
302 | 309 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
|
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 0xff53: /* right */ |
2e97e8082d83
* Fix the symbol definition code which does not assume the id is the same as the mbname.
wycc
parents:
diff
changeset
|
313 break; |
2e97e8082d83
* Fix the symbol definition code which does not assume the id is the same as the mbname.
wycc
parents:
diff
changeset
|
314 |
2e97e8082d83
* Fix the symbol definition code which does not assume the id is the same as the mbname.
wycc
parents:
diff
changeset
|
315 case 0xff54: /* down */ |
302 | 316 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
|
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 0xff0d: /* enter */ |
302 | 320 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
|
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 default: |
2e97e8082d83
* Fix the symbol definition code which does not assume the id is the same as the mbname.
wycc
parents:
diff
changeset
|
323 return; |
2e97e8082d83
* Fix the symbol definition code which does not assume the id is the same as the mbname.
wycc
parents:
diff
changeset
|
324 } |
2e97e8082d83
* Fix the symbol definition code which does not assume the id is the same as the mbname.
wycc
parents:
diff
changeset
|
325 } |
2e97e8082d83
* Fix the symbol definition code which does not assume the id is the same as the mbname.
wycc
parents:
diff
changeset
|
326 |
302 | 327 /** \brief Create an instace of animated menu. |
328 * | |
329 * The objectnames is used to extract symbols from the SVG file. | |
330 * ${objectnames}0 - ${objectnames}8 is the text object. | |
331 * ${objectnames}_lightbar is the lightbar. | |
332 * | |
333 */ | |
334 mb_animated_menu_t *mb_animated_menu_new(MBApp *app,mb_sprite_t *sp,char *objnames,char *menus[]) | |
335 { | |
336 mb_animated_menu_t *m; | |
337 int i,len; | |
338 char name[255]; | |
339 mb_obj_t *l; | |
340 | |
341 for(i=0;menus[i];i++); | |
342 len = i; | |
343 | |
344 m = (mb_animated_menu_t *) malloc(sizeof(mb_animated_menu_t)+sizeof(int)*len*2+sizeof(mb_obj_t *)*len); | |
345 m->app = app; | |
346 m->sprite = sp; | |
347 m->top = 0; | |
348 m->cur = 0; | |
349 m->ready = 1; | |
350 m->max = len; | |
351 m->items = (int *) (m+1); | |
352 m->menus_y = (int *) (m->items+len); | |
353 m->objects = (mb_obj_t **) (m->menus_y+len); | |
354 for(i=0;i<9;i++) { | |
355 m->items[i] = i; | |
356 snprintf(name,sizeof(name),"%s%d", objnames, i+1); | |
357 l = MB_SPRITE_GET_OBJ(sp,name); | |
358 if (l == NULL) { | |
359 fprintf(stderr,"Can not find symbol %s\n",name); | |
360 } | |
361 m->objects[i] = (mb_obj_t *) l; | |
362 m->menus_y[i] = coord_y((coord_t*)l); | |
363 } | |
364 m->titles = menus; | |
365 snprintf(name,sizeof(name), "%s_lightbar", objnames); | |
366 m->lightbar = (mb_obj_t *) MB_SPRITE_GET_OBJ(sp,name); | |
367 if (m->lightbar) | |
368 fprintf(stderr,"Can not find object %s\n",name); | |
369 mb_animated_menu_fillMenuContent(m); | |
370 subject_add_observer(MBAPP_keySubject(myApp), mb_animated_menu_keyHandler,m); | |
371 return m; | |
372 } | |
373 | |
296
2e97e8082d83
* Fix the symbol definition code which does not assume the id is the same as the mbname.
wycc
parents:
diff
changeset
|
374 MyApp_InitContent() |
2e97e8082d83
* Fix the symbol definition code which does not assume the id is the same as the mbname.
wycc
parents:
diff
changeset
|
375 { |
2e97e8082d83
* Fix the symbol definition code which does not assume the id is the same as the mbname.
wycc
parents:
diff
changeset
|
376 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
|
377 subject_t *key = MBAPP_keySubject(myApp); |
297 | 378 char name[255]; |
379 coord_t *l; | |
380 int i; | |
381 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
|
382 |
302 | 383 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
|
384 } |
2e97e8082d83
* Fix the symbol definition code which does not assume the id is the same as the mbname.
wycc
parents:
diff
changeset
|
385 |
2e97e8082d83
* Fix the symbol definition code which does not assume the id is the same as the mbname.
wycc
parents:
diff
changeset
|
386 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
|
387 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
|
388 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
|
389 MyAppData data; |
2e97e8082d83
* Fix the symbol definition code which does not assume the id is the same as the mbname.
wycc
parents:
diff
changeset
|
390 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
|
391 |
2e97e8082d83
* Fix the symbol definition code which does not assume the id is the same as the mbname.
wycc
parents:
diff
changeset
|
392 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
|
393 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
|
394 else |
2e97e8082d83
* Fix the symbol definition code which does not assume the id is the same as the mbname.
wycc
parents:
diff
changeset
|
395 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
|
396 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
|
397 MyApp_InitContent(); |
2e97e8082d83
* Fix the symbol definition code which does not assume the id is the same as the mbname.
wycc
parents:
diff
changeset
|
398 |
2e97e8082d83
* Fix the symbol definition code which does not assume the id is the same as the mbname.
wycc
parents:
diff
changeset
|
399 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
|
400 |
2e97e8082d83
* Fix the symbol definition code which does not assume the id is the same as the mbname.
wycc
parents:
diff
changeset
|
401 return 0; |
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 |
2e97e8082d83
* Fix the symbol definition code which does not assume the id is the same as the mbname.
wycc
parents:
diff
changeset
|
404 /* vim: set ts=4 */ |