Mercurial > MadButterfly
annotate examples/menu/main.c @ 307:b6891068109f
Fix the boundary condition for scroll down
author | wycc |
---|---|
date | Sat, 21 Feb 2009 21:51:05 +0800 |
parents | c981e561ac37 |
children | 9e1d72eca57b |
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 |
306 | 20 typedef struct _mb_animated_menu { |
302 | 21 char **titles; |
22 int *menus_y; | |
23 int *items; | |
24 int top; | |
25 int cur; | |
26 int max; | |
27 int ready; | |
306 | 28 int speed; |
302 | 29 MBApp *app; |
30 mb_sprite_t *sprite; | |
31 mb_obj_t **objects; | |
32 mb_obj_t *lightbar; | |
306 | 33 void (*callback)(struct _mb_animated_menu *m, int sel); |
302 | 34 } mb_animated_menu_t; |
35 | |
296
2e97e8082d83
* Fix the symbol definition code which does not assume the id is the same as the mbname.
wycc
parents:
diff
changeset
|
36 char *menus[] = { |
2e97e8082d83
* Fix the symbol definition code which does not assume the id is the same as the mbname.
wycc
parents:
diff
changeset
|
37 "Item 1", |
2e97e8082d83
* Fix the symbol definition code which does not assume the id is the same as the mbname.
wycc
parents:
diff
changeset
|
38 "Item 2", |
2e97e8082d83
* Fix the symbol definition code which does not assume the id is the same as the mbname.
wycc
parents:
diff
changeset
|
39 "Item 3", |
2e97e8082d83
* Fix the symbol definition code which does not assume the id is the same as the mbname.
wycc
parents:
diff
changeset
|
40 "Item 4", |
2e97e8082d83
* Fix the symbol definition code which does not assume the id is the same as the mbname.
wycc
parents:
diff
changeset
|
41 "Item 5", |
2e97e8082d83
* Fix the symbol definition code which does not assume the id is the same as the mbname.
wycc
parents:
diff
changeset
|
42 "Item 6", |
2e97e8082d83
* Fix the symbol definition code which does not assume the id is the same as the mbname.
wycc
parents:
diff
changeset
|
43 "Item 7", |
2e97e8082d83
* Fix the symbol definition code which does not assume the id is the same as the mbname.
wycc
parents:
diff
changeset
|
44 "Item 8", |
2e97e8082d83
* Fix the symbol definition code which does not assume the id is the same as the mbname.
wycc
parents:
diff
changeset
|
45 "Item 9", |
2e97e8082d83
* Fix the symbol definition code which does not assume the id is the same as the mbname.
wycc
parents:
diff
changeset
|
46 "Item 10", |
2e97e8082d83
* Fix the symbol definition code which does not assume the id is the same as the mbname.
wycc
parents:
diff
changeset
|
47 "Item 11", |
2e97e8082d83
* Fix the symbol definition code which does not assume the id is the same as the mbname.
wycc
parents:
diff
changeset
|
48 "Item 12", |
2e97e8082d83
* Fix the symbol definition code which does not assume the id is the same as the mbname.
wycc
parents:
diff
changeset
|
49 "Item 13", |
2e97e8082d83
* Fix the symbol definition code which does not assume the id is the same as the mbname.
wycc
parents:
diff
changeset
|
50 "Item 14", |
2e97e8082d83
* Fix the symbol definition code which does not assume the id is the same as the mbname.
wycc
parents:
diff
changeset
|
51 "Item 15", |
2e97e8082d83
* Fix the symbol definition code which does not assume the id is the same as the mbname.
wycc
parents:
diff
changeset
|
52 "Item 16", |
2e97e8082d83
* Fix the symbol definition code which does not assume the id is the same as the mbname.
wycc
parents:
diff
changeset
|
53 "Item 17", |
2e97e8082d83
* Fix the symbol definition code which does not assume the id is the same as the mbname.
wycc
parents:
diff
changeset
|
54 "Item 18", |
2e97e8082d83
* Fix the symbol definition code which does not assume the id is the same as the mbname.
wycc
parents:
diff
changeset
|
55 }; |
2e97e8082d83
* Fix the symbol definition code which does not assume the id is the same as the mbname.
wycc
parents:
diff
changeset
|
56 |
2e97e8082d83
* Fix the symbol definition code which does not assume the id is the same as the mbname.
wycc
parents:
diff
changeset
|
57 typedef struct { |
302 | 58 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
|
59 }MyAppData; |
2e97e8082d83
* Fix the symbol definition code which does not assume the id is the same as the mbname.
wycc
parents:
diff
changeset
|
60 |
2e97e8082d83
* Fix the symbol definition code which does not assume the id is the same as the mbname.
wycc
parents:
diff
changeset
|
61 MBApp *myApp; |
2e97e8082d83
* Fix the symbol definition code which does not assume the id is the same as the mbname.
wycc
parents:
diff
changeset
|
62 |
302 | 63 |
64 static void set_text(coord_t *g, char *text) | |
65 { | |
66 geo_t *geo; | |
67 shape_t *shape; | |
68 | |
69 FOR_COORD_MEMBERS(g, geo) { | |
70 shape = geo_get_shape(geo); | |
71 if(shape->obj.obj_type == MBO_TEXT) { | |
72 sh_text_set_text(shape, text); | |
73 } | |
74 } | |
75 } | |
76 | |
77 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
|
78 { |
2e97e8082d83
* Fix the symbol definition code which does not assume the id is the same as the mbname.
wycc
parents:
diff
changeset
|
79 int i; |
297 | 80 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
|
81 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
|
82 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
|
83 coord_t *lightbar; |
297 | 84 int tmp; |
85 mb_timeval_t start, playing, now; | |
86 mb_progm_t *progm; | |
87 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
|
88 |
297 | 89 |
90 // 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
|
91 for(i=0;i<8;i++) { |
302 | 92 text = (shape_t *) m->objects[m->items[i]]; |
93 set_text(text, m->titles[m->top+i]); | |
94 //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
|
95 } |
297 | 96 |
97 | |
302 | 98 textgroup = (coord_t *) m->objects[m->items[i]]; |
297 | 99 coord_hide(textgroup); |
302 | 100 rdman_coord_changed(MBAPP_RDMAN(m->app),textgroup); |
297 | 101 |
302 | 102 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
|
103 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
|
104 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
|
105 coord_y(lightbar) = coord_y(group); |
302 | 106 rdman_redraw_changed(MBAPP_RDMAN(m->app)); |
297 | 107 } |
108 | |
305
0231b05552fe
Wait for the last animation done before we send the next one.
wycc
parents:
304
diff
changeset
|
109 static void mb_animated_menu_complete(event_t *ev,void *arg) |
302 | 110 { |
111 mb_animated_menu_t *m = (mb_animated_menu_t *) arg; | |
112 | |
113 m->ready++; | |
305
0231b05552fe
Wait for the last animation done before we send the next one.
wycc
parents:
304
diff
changeset
|
114 printf("animated done ready=%d\n", m->ready); |
302 | 115 } |
116 | |
117 static void mb_animated_menu_fillMenuContentUp(mb_animated_menu_t *m) | |
297 | 118 { |
119 int i; | |
120 coord_t *textgroup; | |
121 shape_t *text; | |
122 coord_t *group; | |
123 coord_t *lightbar; | |
124 int tmp; | |
125 mb_timeval_t start, playing, now; | |
126 mb_progm_t *progm; | |
127 mb_word_t *word; | |
128 | |
129 | |
130 // fill new item | |
302 | 131 text = (shape_t *) m->objects[m->items[8]]; |
132 set_text(text, m->titles[m->top]); | |
297 | 133 |
302 | 134 progm = mb_progm_new(2, MBAPP_RDMAN(m->app)); |
297 | 135 MB_TIMEVAL_SET(&start, 0, 0); |
306 | 136 MB_TIMEVAL_SET(&playing, 0, m->speed); |
297 | 137 word = mb_progm_next_word(progm, &start, &playing); |
138 get_now(&now); | |
139 | |
140 for(i=0;i<7;i++) { | |
141 //shift to the next item | |
302 | 142 textgroup = (coord_t *) m->objects[m->items[i]]; |
143 mb_shift_new(0,m->menus_y[i+1]-coord_y(textgroup), textgroup,word); | |
297 | 144 } |
145 // fade out the item[7] | |
302 | 146 textgroup = (coord_t *) m->objects[m->items[7]]; |
297 | 147 mb_shift_new(0,100, textgroup,word); |
148 | |
149 // fade in the item[8] | |
302 | 150 textgroup = (coord_t *) m->objects[m->items[8]]; |
151 group = (coord_t *) m->objects[m->items[0]]; | |
152 coord_y(textgroup) = m->menus_y[0]-100; | |
297 | 153 coord_show(textgroup); |
154 mb_shift_new(0,100, textgroup,word); | |
155 | |
302 | 156 lightbar = (coord_t *) m->lightbar; |
157 mb_shift_new(0,m->menus_y[m->cur]-coord_y(lightbar),lightbar,word); | |
297 | 158 |
306 | 159 MB_TIMEVAL_SET(&start, 0, m->speed); |
297 | 160 MB_TIMEVAL_SET(&playing, 0, 0); |
161 word = mb_progm_next_word(progm, &start, &playing); | |
302 | 162 textgroup = (coord_t *) m->objects[m->items[7]]; |
299 | 163 mb_visibility_new(VIS_HIDDEN, textgroup,word); |
297 | 164 |
165 mb_progm_free_completed(progm); | |
302 | 166 m->ready--; |
167 subject_add_observer(mb_progm_get_complete(progm), mb_animated_menu_complete,m); | |
168 mb_progm_start(progm, X_MB_tman(MBAPP_RDMAN(m->app)->rt), &now); | |
169 rdman_redraw_changed(MBAPP_RDMAN(m->app)); | |
170 tmp = m->items[8]; | |
297 | 171 for(i=8;i>0;i--) { |
302 | 172 m->items[i] = m->items[i-1]; |
297 | 173 } |
302 | 174 m->items[0] = tmp; |
297 | 175 } |
302 | 176 |
177 | |
178 static void mb_animated_menu_fillMenuContentDown(mb_animated_menu_t *m) | |
297 | 179 { |
180 int i; | |
181 coord_t *textgroup; | |
182 shape_t *text; | |
183 coord_t *group; | |
184 coord_t *lightbar; | |
185 char name[255]; | |
186 int tmp; | |
187 mb_timeval_t start, playing, now; | |
188 mb_progm_t *progm; | |
189 mb_word_t *word; | |
190 | |
191 | |
192 // fill new item | |
302 | 193 set_text(m->objects[m->items[8]], m->titles[m->top+7]); |
297 | 194 |
302 | 195 progm = mb_progm_new(2, MBAPP_RDMAN(m->app)); |
297 | 196 MB_TIMEVAL_SET(&start, 0, 0); |
306 | 197 MB_TIMEVAL_SET(&playing, 0, m->speed); |
297 | 198 word = mb_progm_next_word(progm, &start, &playing); |
199 get_now(&now); | |
200 | |
201 for(i=1;i<8;i++) { | |
202 //shift to the next item | |
302 | 203 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 | 204 } |
205 // fade out the item[0] | |
302 | 206 mb_shift_new(0,-100, (coord_t *)m->objects[m->items[0]],word); |
297 | 207 |
208 // fade in the item[8] | |
302 | 209 coord_y((coord_t *)m->objects[m->items[8]]) = m->menus_y[7]+100; |
210 coord_show(((coord_t *)(m->objects[m->items[8]]))); | |
211 mb_shift_new(0,-100, (coord_t *)m->objects[m->items[8]],word); | |
297 | 212 |
302 | 213 mb_shift_new(0,m->menus_y[m->cur]-coord_y((coord_t *)m->lightbar),((coord_t *)(m->lightbar)),word); |
297 | 214 |
306 | 215 MB_TIMEVAL_SET(&start, 0, m->speed); |
297 | 216 MB_TIMEVAL_SET(&playing, 0, 0); |
217 word = mb_progm_next_word(progm, &start, &playing); | |
302 | 218 mb_visibility_new(VIS_VISIBLE, (coord_t *) m->objects[m->items[0]],word); |
297 | 219 |
220 mb_progm_free_completed(progm); | |
302 | 221 m->ready--; |
222 subject_add_observer(mb_progm_get_complete(progm), mb_animated_menu_complete,m); | |
223 mb_progm_start(progm, X_MB_tman(MBAPP_RDMAN(m->app)->rt), &now); | |
224 rdman_redraw_changed(MBAPP_RDMAN(m->app)); | |
225 tmp = m->items[0]; | |
297 | 226 for(i=0;i<8;i++) { |
302 | 227 m->items[i] = m->items[i+1]; |
297 | 228 } |
302 | 229 m->items[8] = tmp; |
297 | 230 } |
231 | |
302 | 232 void mb_animated_menu_moveLightBar(mb_animated_menu_t *m) |
297 | 233 { |
234 mb_timeval_t start, playing, now; | |
235 mb_progm_t *progm; | |
236 mb_word_t *word; | |
237 coord_t *group; | |
238 coord_t *lightbar; | |
239 | |
302 | 240 progm = mb_progm_new(1, MBAPP_RDMAN(m->app)); |
297 | 241 MB_TIMEVAL_SET(&start, 0, 0); |
306 | 242 MB_TIMEVAL_SET(&playing, 0, m->speed); |
297 | 243 word = mb_progm_next_word(progm, &start, &playing); |
244 get_now(&now); | |
245 | |
302 | 246 lightbar = (coord_t *) m->lightbar; |
305
0231b05552fe
Wait for the last animation done before we send the next one.
wycc
parents:
304
diff
changeset
|
247 mb_shift_new(0,m->menus_y[m->cur]-coord_y(lightbar),lightbar,word); |
297 | 248 mb_progm_free_completed(progm); |
305
0231b05552fe
Wait for the last animation done before we send the next one.
wycc
parents:
304
diff
changeset
|
249 m->ready--; |
0231b05552fe
Wait for the last animation done before we send the next one.
wycc
parents:
304
diff
changeset
|
250 subject_add_observer(mb_progm_get_complete(progm), mb_animated_menu_complete,m); |
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 |
305
0231b05552fe
Wait for the last animation done before we send the next one.
wycc
parents:
304
diff
changeset
|
275 if (m->cur < 5) { |
302 | 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 { |
307 | 281 if ((m->top+8) < m->max-1) { |
302 | 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 { |
307 | 285 if (m->cur+m->top < m->max-2) { |
302 | 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 } |
306 | 293 |
294 void mb_animated_menu_set_callback(mb_animated_menu_t *m, void (*f)(mb_animated_menu_t *m, int sel)) | |
295 { | |
296 m->callback = f; | |
297 } | |
302 | 298 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
|
299 { |
306 | 300 if (m->callback) |
301 m->callback(m,m->top+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
|
302 } |
2e97e8082d83
* Fix the symbol definition code which does not assume the id is the same as the mbname.
wycc
parents:
diff
changeset
|
303 |
302 | 304 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
|
305 { |
302 | 306 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
|
307 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
|
308 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
|
309 return; |
2e97e8082d83
* Fix the symbol definition code which does not assume the id is the same as the mbname.
wycc
parents:
diff
changeset
|
310 } |
305
0231b05552fe
Wait for the last animation done before we send the next one.
wycc
parents:
304
diff
changeset
|
311 printf("read=%d\n",m->ready); |
0231b05552fe
Wait for the last animation done before we send the next one.
wycc
parents:
304
diff
changeset
|
312 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
|
313 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
|
314 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
|
315 break; |
2e97e8082d83
* Fix the symbol definition code which does not assume the id is the same as the mbname.
wycc
parents:
diff
changeset
|
316 |
2e97e8082d83
* Fix the symbol definition code which does not assume the id is the same as the mbname.
wycc
parents:
diff
changeset
|
317 case 0xff52: /* up */ |
302 | 318 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
|
319 break; |
2e97e8082d83
* Fix the symbol definition code which does not assume the id is the same as the mbname.
wycc
parents:
diff
changeset
|
320 |
2e97e8082d83
* Fix the symbol definition code which does not assume the id is the same as the mbname.
wycc
parents:
diff
changeset
|
321 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
|
322 break; |
2e97e8082d83
* Fix the symbol definition code which does not assume the id is the same as the mbname.
wycc
parents:
diff
changeset
|
323 |
2e97e8082d83
* Fix the symbol definition code which does not assume the id is the same as the mbname.
wycc
parents:
diff
changeset
|
324 case 0xff54: /* down */ |
302 | 325 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
|
326 break; |
2e97e8082d83
* Fix the symbol definition code which does not assume the id is the same as the mbname.
wycc
parents:
diff
changeset
|
327 |
2e97e8082d83
* Fix the symbol definition code which does not assume the id is the same as the mbname.
wycc
parents:
diff
changeset
|
328 case 0xff0d: /* enter */ |
302 | 329 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
|
330 break; |
2e97e8082d83
* Fix the symbol definition code which does not assume the id is the same as the mbname.
wycc
parents:
diff
changeset
|
331 default: |
2e97e8082d83
* Fix the symbol definition code which does not assume the id is the same as the mbname.
wycc
parents:
diff
changeset
|
332 return; |
2e97e8082d83
* Fix the symbol definition code which does not assume the id is the same as the mbname.
wycc
parents:
diff
changeset
|
333 } |
2e97e8082d83
* Fix the symbol definition code which does not assume the id is the same as the mbname.
wycc
parents:
diff
changeset
|
334 } |
2e97e8082d83
* Fix the symbol definition code which does not assume the id is the same as the mbname.
wycc
parents:
diff
changeset
|
335 |
302 | 336 /** \brief Create an instace of animated menu. |
337 * | |
338 * The objectnames is used to extract symbols from the SVG file. | |
339 * ${objectnames}0 - ${objectnames}8 is the text object. | |
340 * ${objectnames}_lightbar is the lightbar. | |
341 * | |
342 */ | |
343 mb_animated_menu_t *mb_animated_menu_new(MBApp *app,mb_sprite_t *sp,char *objnames,char *menus[]) | |
344 { | |
345 mb_animated_menu_t *m; | |
346 int i,len; | |
347 char name[255]; | |
348 mb_obj_t *l; | |
349 | |
350 for(i=0;menus[i];i++); | |
351 len = i; | |
352 | |
353 m = (mb_animated_menu_t *) malloc(sizeof(mb_animated_menu_t)+sizeof(int)*len*2+sizeof(mb_obj_t *)*len); | |
354 m->app = app; | |
355 m->sprite = sp; | |
356 m->top = 0; | |
357 m->cur = 0; | |
358 m->ready = 1; | |
359 m->max = len; | |
360 m->items = (int *) (m+1); | |
361 m->menus_y = (int *) (m->items+len); | |
362 m->objects = (mb_obj_t **) (m->menus_y+len); | |
306 | 363 m->callback = NULL; |
364 m->speed = 300000; | |
302 | 365 for(i=0;i<9;i++) { |
366 m->items[i] = i; | |
367 snprintf(name,sizeof(name),"%s%d", objnames, i+1); | |
368 l = MB_SPRITE_GET_OBJ(sp,name); | |
369 if (l == NULL) { | |
370 fprintf(stderr,"Can not find symbol %s\n",name); | |
371 } | |
372 m->objects[i] = (mb_obj_t *) l; | |
373 m->menus_y[i] = coord_y((coord_t*)l); | |
374 } | |
375 m->titles = menus; | |
376 snprintf(name,sizeof(name), "%s_lightbar", objnames); | |
377 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
|
378 if (m->lightbar==NULL) |
302 | 379 fprintf(stderr,"Can not find object %s\n",name); |
380 mb_animated_menu_fillMenuContent(m); | |
381 subject_add_observer(MBAPP_keySubject(myApp), mb_animated_menu_keyHandler,m); | |
382 return m; | |
383 } | |
384 | |
306 | 385 |
386 void mb_animated_menu_set_speed(mb_animated_menu_t *m,int speed) | |
387 { | |
388 m->speed = speed*1000; | |
389 } | |
390 | |
391 int mb_animated_menu_get_speed(mb_animated_menu_t *m) | |
392 { | |
393 return m->speed/1000; | |
394 } | |
395 | |
396 void myselect(mb_animated_menu_t *m, int select) | |
397 { | |
398 printf("menu %d is selected\n", select); | |
399 } | |
400 | |
401 | |
296
2e97e8082d83
* Fix the symbol definition code which does not assume the id is the same as the mbname.
wycc
parents:
diff
changeset
|
402 MyApp_InitContent() |
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 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
|
405 subject_t *key = MBAPP_keySubject(myApp); |
297 | 406 char name[255]; |
407 coord_t *l; | |
408 int i; | |
409 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
|
410 |
302 | 411 data->m = mb_animated_menu_new(myApp,myApp->rootsprite,"item",menus); |
306 | 412 mb_animated_menu_set_callback(data->m, myselect); |
296
2e97e8082d83
* Fix the symbol definition code which does not assume the id is the same as the mbname.
wycc
parents:
diff
changeset
|
413 } |
2e97e8082d83
* Fix the symbol definition code which does not assume the id is the same as the mbname.
wycc
parents:
diff
changeset
|
414 |
2e97e8082d83
* Fix the symbol definition code which does not assume the id is the same as the mbname.
wycc
parents:
diff
changeset
|
415 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
|
416 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
|
417 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
|
418 MyAppData data; |
2e97e8082d83
* Fix the symbol definition code which does not assume the id is the same as the mbname.
wycc
parents:
diff
changeset
|
419 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
|
420 |
2e97e8082d83
* Fix the symbol definition code which does not assume the id is the same as the mbname.
wycc
parents:
diff
changeset
|
421 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
|
422 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
|
423 else |
2e97e8082d83
* Fix the symbol definition code which does not assume the id is the same as the mbname.
wycc
parents:
diff
changeset
|
424 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
|
425 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
|
426 MyApp_InitContent(); |
2e97e8082d83
* Fix the symbol definition code which does not assume the id is the same as the mbname.
wycc
parents:
diff
changeset
|
427 |
2e97e8082d83
* Fix the symbol definition code which does not assume the id is the same as the mbname.
wycc
parents:
diff
changeset
|
428 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
|
429 |
2e97e8082d83
* Fix the symbol definition code which does not assume the id is the same as the mbname.
wycc
parents:
diff
changeset
|
430 return 0; |
2e97e8082d83
* Fix the symbol definition code which does not assume the id is the same as the mbname.
wycc
parents:
diff
changeset
|
431 } |
2e97e8082d83
* Fix the symbol definition code which does not assume the id is the same as the mbname.
wycc
parents:
diff
changeset
|
432 |
2e97e8082d83
* Fix the symbol definition code which does not assume the id is the same as the mbname.
wycc
parents:
diff
changeset
|
433 /* vim: set ts=4 */ |