Mercurial > MadButterfly
annotate examples/menu/main.c @ 297:e885dc875f30
Implement animation menu
author | wycc |
---|---|
date | Wed, 04 Feb 2009 01:23:45 +0800 |
parents | 2e97e8082d83 |
children | 959c4ac544a1 |
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 |
2e97e8082d83
* Fix the symbol definition code which does not assume the id is the same as the mbname.
wycc
parents:
diff
changeset
|
19 char *menus[] = { |
2e97e8082d83
* Fix the symbol definition code which does not assume the id is the same as the mbname.
wycc
parents:
diff
changeset
|
20 "Item 1", |
2e97e8082d83
* Fix the symbol definition code which does not assume the id is the same as the mbname.
wycc
parents:
diff
changeset
|
21 "Item 2", |
2e97e8082d83
* Fix the symbol definition code which does not assume the id is the same as the mbname.
wycc
parents:
diff
changeset
|
22 "Item 3", |
2e97e8082d83
* Fix the symbol definition code which does not assume the id is the same as the mbname.
wycc
parents:
diff
changeset
|
23 "Item 4", |
2e97e8082d83
* Fix the symbol definition code which does not assume the id is the same as the mbname.
wycc
parents:
diff
changeset
|
24 "Item 5", |
2e97e8082d83
* Fix the symbol definition code which does not assume the id is the same as the mbname.
wycc
parents:
diff
changeset
|
25 "Item 6", |
2e97e8082d83
* Fix the symbol definition code which does not assume the id is the same as the mbname.
wycc
parents:
diff
changeset
|
26 "Item 7", |
2e97e8082d83
* Fix the symbol definition code which does not assume the id is the same as the mbname.
wycc
parents:
diff
changeset
|
27 "Item 8", |
2e97e8082d83
* Fix the symbol definition code which does not assume the id is the same as the mbname.
wycc
parents:
diff
changeset
|
28 "Item 9", |
2e97e8082d83
* Fix the symbol definition code which does not assume the id is the same as the mbname.
wycc
parents:
diff
changeset
|
29 "Item 10", |
2e97e8082d83
* Fix the symbol definition code which does not assume the id is the same as the mbname.
wycc
parents:
diff
changeset
|
30 "Item 11", |
2e97e8082d83
* Fix the symbol definition code which does not assume the id is the same as the mbname.
wycc
parents:
diff
changeset
|
31 "Item 12", |
2e97e8082d83
* Fix the symbol definition code which does not assume the id is the same as the mbname.
wycc
parents:
diff
changeset
|
32 "Item 13", |
2e97e8082d83
* Fix the symbol definition code which does not assume the id is the same as the mbname.
wycc
parents:
diff
changeset
|
33 "Item 14", |
2e97e8082d83
* Fix the symbol definition code which does not assume the id is the same as the mbname.
wycc
parents:
diff
changeset
|
34 "Item 15", |
2e97e8082d83
* Fix the symbol definition code which does not assume the id is the same as the mbname.
wycc
parents:
diff
changeset
|
35 "Item 16", |
2e97e8082d83
* Fix the symbol definition code which does not assume the id is the same as the mbname.
wycc
parents:
diff
changeset
|
36 "Item 17", |
2e97e8082d83
* Fix the symbol definition code which does not assume the id is the same as the mbname.
wycc
parents:
diff
changeset
|
37 "Item 18", |
2e97e8082d83
* Fix the symbol definition code which does not assume the id is the same as the mbname.
wycc
parents:
diff
changeset
|
38 }; |
2e97e8082d83
* Fix the symbol definition code which does not assume the id is the same as the mbname.
wycc
parents:
diff
changeset
|
39 |
297 | 40 int menus_y[10]; |
41 int items[10]; | |
42 | |
43 | |
296
2e97e8082d83
* Fix the symbol definition code which does not assume the id is the same as the mbname.
wycc
parents:
diff
changeset
|
44 typedef struct { |
2e97e8082d83
* Fix the symbol definition code which does not assume the id is the same as the mbname.
wycc
parents:
diff
changeset
|
45 int top; |
2e97e8082d83
* Fix the symbol definition code which does not assume the id is the same as the mbname.
wycc
parents:
diff
changeset
|
46 int cur; |
2e97e8082d83
* Fix the symbol definition code which does not assume the id is the same as the mbname.
wycc
parents:
diff
changeset
|
47 int max; |
2e97e8082d83
* Fix the symbol definition code which does not assume the id is the same as the mbname.
wycc
parents:
diff
changeset
|
48 }MyAppData; |
2e97e8082d83
* Fix the symbol definition code which does not assume the id is the same as the mbname.
wycc
parents:
diff
changeset
|
49 |
2e97e8082d83
* Fix the symbol definition code which does not assume the id is the same as the mbname.
wycc
parents:
diff
changeset
|
50 MBApp *myApp; |
2e97e8082d83
* Fix the symbol definition code which does not assume the id is the same as the mbname.
wycc
parents:
diff
changeset
|
51 |
2e97e8082d83
* Fix the symbol definition code which does not assume the id is the same as the mbname.
wycc
parents:
diff
changeset
|
52 static void fillMenuContent() |
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 int i; |
2e97e8082d83
* Fix the symbol definition code which does not assume the id is the same as the mbname.
wycc
parents:
diff
changeset
|
55 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
|
56 mb_sprite_t *sprite=myApp->rootsprite; |
297 | 57 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
|
58 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
|
59 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
|
60 coord_t *lightbar; |
2e97e8082d83
* Fix the symbol definition code which does not assume the id is the same as the mbname.
wycc
parents:
diff
changeset
|
61 char name[255]; |
297 | 62 int tmp; |
63 mb_timeval_t start, playing, now; | |
64 mb_progm_t *progm; | |
65 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
|
66 |
297 | 67 |
68 // 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
|
69 for(i=0;i<8;i++) { |
297 | 70 snprintf(name, sizeof(name),"item%dtext", items[i]); |
71 text = (shape_t *) MB_SPRITE_GET_OBJ(sprite,name); | |
72 sh_text_set_text(text, menus[data->top+i]); | |
73 rdman_shape_changed(MBAPP_RDMAN(myApp),text); | |
296
2e97e8082d83
* Fix the symbol definition code which does not assume the id is the same as the mbname.
wycc
parents:
diff
changeset
|
74 } |
297 | 75 |
76 | |
77 snprintf(name, sizeof(name),"item%d", items[i]); | |
78 textgroup = (coord_t *) MB_SPRITE_GET_OBJ(sprite,name); | |
79 coord_hide(textgroup); | |
80 rdman_coord_changed(MBAPP_RDMAN(myApp),textgroup); | |
81 | |
296
2e97e8082d83
* Fix the symbol definition code which does not assume the id is the same as the mbname.
wycc
parents:
diff
changeset
|
82 lightbar = (coord_t *) MB_SPRITE_GET_OBJ(sprite, "lightbar"); |
2e97e8082d83
* Fix the symbol definition code which does not assume the id is the same as the mbname.
wycc
parents:
diff
changeset
|
83 snprintf(name,sizeof(name),"item%d", data->cur+1); |
2e97e8082d83
* Fix the symbol definition code which does not assume the id is the same as the mbname.
wycc
parents:
diff
changeset
|
84 group = (coord_t *) MB_SPRITE_GET_OBJ(sprite, name); |
2e97e8082d83
* Fix the symbol definition code which does not assume the id is the same as the mbname.
wycc
parents:
diff
changeset
|
85 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
|
86 coord_y(lightbar) = coord_y(group); |
297 | 87 rdman_redraw_changed(MBAPP_RDMAN(myApp)); |
88 } | |
89 | |
90 static void fillMenuContentUp() | |
91 { | |
92 int i; | |
93 MyAppData *data = MBAPP_DATA(myApp,MyAppData); | |
94 mb_sprite_t *sprite=myApp->rootsprite; | |
95 coord_t *textgroup; | |
96 shape_t *text; | |
97 coord_t *group; | |
98 coord_t *lightbar; | |
99 char name[255]; | |
100 int tmp; | |
101 mb_timeval_t start, playing, now; | |
102 mb_progm_t *progm; | |
103 mb_word_t *word; | |
104 | |
105 | |
106 // fill new item | |
107 snprintf(name, sizeof(name),"item%dtext", items[8]); | |
108 text = (shape_t *) MB_SPRITE_GET_OBJ(sprite,name); | |
109 sh_text_set_text(text, menus[data->top]); | |
110 | |
111 progm = mb_progm_new(2, MBAPP_RDMAN(myApp)); | |
112 MB_TIMEVAL_SET(&start, 0, 0); | |
113 MB_TIMEVAL_SET(&playing, 0, 300000); | |
114 word = mb_progm_next_word(progm, &start, &playing); | |
115 get_now(&now); | |
116 | |
117 for(i=0;i<7;i++) { | |
118 //shift to the next item | |
119 snprintf(name, sizeof(name),"item%d", items[i]); | |
120 textgroup = (coord_t *) MB_SPRITE_GET_OBJ(sprite,name); | |
121 mb_shift_new(0,menus_y[i+1]-coord_y(textgroup), textgroup,word); | |
122 } | |
123 // fade out the item[7] | |
124 snprintf(name, sizeof(name),"item%d", items[7]); | |
125 textgroup = (coord_t *) MB_SPRITE_GET_OBJ(sprite,name); | |
126 mb_shift_new(0,100, textgroup,word); | |
127 mb_visibility_new(VIS_HIDDEN, textgroup,word); | |
128 | |
129 // fade in the item[8] | |
130 snprintf(name, sizeof(name),"item%d", items[8]); | |
131 textgroup = (coord_t *) MB_SPRITE_GET_OBJ(sprite,name); | |
132 snprintf(name,sizeof(name),"item%d", items[0]); | |
133 group = (coord_t *) MB_SPRITE_GET_OBJ(sprite,name); | |
134 coord_y(textgroup) = menus_y[0]-100; | |
135 coord_show(textgroup); | |
136 mb_shift_new(0,100, textgroup,word); | |
137 | |
138 lightbar = (coord_t *) MB_SPRITE_GET_OBJ(sprite, "lightbar"); | |
139 mb_shift_new(0,menus_y[data->cur]-coord_y(lightbar),lightbar,word); | |
140 | |
141 MB_TIMEVAL_SET(&start, 0, 300000); | |
142 MB_TIMEVAL_SET(&playing, 0, 0); | |
143 word = mb_progm_next_word(progm, &start, &playing); | |
144 snprintf(name, sizeof(name),"item%d", items[8]); | |
145 textgroup = (coord_t *) MB_SPRITE_GET_OBJ(sprite,name); | |
146 mb_visibility_new(VIS_VISIBLE, textgroup,word); | |
147 | |
148 mb_progm_free_completed(progm); | |
149 mb_progm_start(progm, X_MB_tman(MBAPP_RDMAN(myApp)->rt), &now); | |
150 rdman_redraw_changed(MBAPP_RDMAN(myApp)); | |
151 tmp = items[8]; | |
152 for(i=8;i>0;i--) { | |
153 items[i] = items[i-1]; | |
154 } | |
155 items[0] = tmp; | |
156 } | |
157 static void fillMenuContentDown() | |
158 { | |
159 int i; | |
160 MyAppData *data = MBAPP_DATA(myApp,MyAppData); | |
161 mb_sprite_t *sprite=myApp->rootsprite; | |
162 coord_t *textgroup; | |
163 shape_t *text; | |
164 coord_t *group; | |
165 coord_t *lightbar; | |
166 char name[255]; | |
167 int tmp; | |
168 mb_timeval_t start, playing, now; | |
169 mb_progm_t *progm; | |
170 mb_word_t *word; | |
171 | |
172 | |
173 // fill new item | |
174 snprintf(name, sizeof(name),"item%dtext", items[8]); | |
175 text = (shape_t *) MB_SPRITE_GET_OBJ(sprite,name); | |
176 sh_text_set_text(text, menus[data->top+7]); | |
177 | |
178 progm = mb_progm_new(2, MBAPP_RDMAN(myApp)); | |
179 MB_TIMEVAL_SET(&start, 0, 0); | |
180 MB_TIMEVAL_SET(&playing, 0, 300000); | |
181 word = mb_progm_next_word(progm, &start, &playing); | |
182 get_now(&now); | |
183 | |
184 for(i=1;i<8;i++) { | |
185 //shift to the next item | |
186 snprintf(name, sizeof(name),"item%d", items[i]); | |
187 textgroup = (coord_t *) MB_SPRITE_GET_OBJ(sprite,name); | |
188 mb_shift_new(0,menus_y[i-1]-coord_y(textgroup), textgroup,word); | |
189 } | |
190 // fade out the item[0] | |
191 snprintf(name, sizeof(name),"item%d", items[0]); | |
192 textgroup = (coord_t *) MB_SPRITE_GET_OBJ(sprite,name); | |
193 mb_shift_new(0,-100, textgroup,word); | |
194 | |
195 // fade in the item[8] | |
196 snprintf(name, sizeof(name),"item%d", items[8]); | |
197 textgroup = (coord_t *) MB_SPRITE_GET_OBJ(sprite,name); | |
198 coord_y(textgroup) = menus_y[7]+100; | |
199 coord_show(textgroup); | |
200 mb_shift_new(0,-100, textgroup,word); | |
201 | |
202 lightbar = (coord_t *) MB_SPRITE_GET_OBJ(sprite, "lightbar"); | |
203 mb_shift_new(0,menus_y[data->cur]-coord_y(lightbar),lightbar,word); | |
204 | |
205 MB_TIMEVAL_SET(&start, 0, 300001); | |
206 MB_TIMEVAL_SET(&playing, 0, 0); | |
207 word = mb_progm_next_word(progm, &start, &playing); | |
208 snprintf(name, sizeof(name),"item%d", items[0]); | |
209 textgroup = (coord_t *) MB_SPRITE_GET_OBJ(sprite,name); | |
210 mb_visibility_new(VIS_VISIBLE, textgroup,word); | |
211 | |
212 mb_progm_free_completed(progm); | |
213 mb_progm_start(progm, X_MB_tman(MBAPP_RDMAN(myApp)->rt), &now); | |
214 rdman_redraw_changed(MBAPP_RDMAN(myApp)); | |
215 tmp = items[0]; | |
216 for(i=0;i<8;i++) { | |
217 items[i] = items[i+1]; | |
218 } | |
219 items[8] = tmp; | |
220 } | |
221 | |
222 MoveLightBar() | |
223 { | |
224 mb_sprite_t *sprite=myApp->rootsprite; | |
225 MyAppData *data = MBAPP_DATA(myApp,MyAppData); | |
226 mb_timeval_t start, playing, now; | |
227 mb_progm_t *progm; | |
228 mb_word_t *word; | |
229 coord_t *group; | |
230 coord_t *lightbar; | |
231 char name[255]; | |
232 | |
233 progm = mb_progm_new(1, MBAPP_RDMAN(myApp)); | |
234 MB_TIMEVAL_SET(&start, 0, 0); | |
235 MB_TIMEVAL_SET(&playing, 0, 200000); | |
236 word = mb_progm_next_word(progm, &start, &playing); | |
237 get_now(&now); | |
238 | |
239 lightbar = (coord_t *) MB_SPRITE_GET_OBJ(sprite, "lightbar"); | |
240 snprintf(name,sizeof(name),"item%d", items[data->cur]); | |
241 group = (coord_t *) MB_SPRITE_GET_OBJ(sprite, name); | |
242 mb_shift_new(coord_x(group)-coord_x(lightbar),coord_y(group)-coord_y(lightbar),lightbar,word); | |
243 mb_progm_free_completed(progm); | |
244 mb_progm_start(progm, X_MB_tman(MBAPP_RDMAN(myApp)->rt), &now); | |
296
2e97e8082d83
* Fix the symbol definition code which does not assume the id is the same as the mbname.
wycc
parents:
diff
changeset
|
245 rdman_redraw_changed(MBAPP_RDMAN(myApp)); |
2e97e8082d83
* Fix the symbol definition code which does not assume the id is the same as the mbname.
wycc
parents:
diff
changeset
|
246 } |
2e97e8082d83
* Fix the symbol definition code which does not assume the id is the same as the mbname.
wycc
parents:
diff
changeset
|
247 |
2e97e8082d83
* Fix the symbol definition code which does not assume the id is the same as the mbname.
wycc
parents:
diff
changeset
|
248 void menu_up() |
2e97e8082d83
* Fix the symbol definition code which does not assume the id is the same as the mbname.
wycc
parents:
diff
changeset
|
249 { |
2e97e8082d83
* Fix the symbol definition code which does not assume the id is the same as the mbname.
wycc
parents:
diff
changeset
|
250 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
|
251 |
297 | 252 if (data->cur > 5) { |
296
2e97e8082d83
* Fix the symbol definition code which does not assume the id is the same as the mbname.
wycc
parents:
diff
changeset
|
253 data->cur--; |
297 | 254 MoveLightBar(); |
255 } else { | |
296
2e97e8082d83
* Fix the symbol definition code which does not assume the id is the same as the mbname.
wycc
parents:
diff
changeset
|
256 if (data->top > 0) { |
2e97e8082d83
* Fix the symbol definition code which does not assume the id is the same as the mbname.
wycc
parents:
diff
changeset
|
257 data->top--; |
297 | 258 fillMenuContentUp(); |
296
2e97e8082d83
* Fix the symbol definition code which does not assume the id is the same as the mbname.
wycc
parents:
diff
changeset
|
259 } else { |
2e97e8082d83
* Fix the symbol definition code which does not assume the id is the same as the mbname.
wycc
parents:
diff
changeset
|
260 if (data->cur == 0) |
2e97e8082d83
* Fix the symbol definition code which does not assume the id is the same as the mbname.
wycc
parents:
diff
changeset
|
261 return; |
2e97e8082d83
* Fix the symbol definition code which does not assume the id is the same as the mbname.
wycc
parents:
diff
changeset
|
262 data->cur--; |
297 | 263 MoveLightBar(); |
296
2e97e8082d83
* Fix the symbol definition code which does not assume the id is the same as the mbname.
wycc
parents:
diff
changeset
|
264 } |
2e97e8082d83
* Fix the symbol definition code which does not assume the id is the same as the mbname.
wycc
parents:
diff
changeset
|
265 } |
2e97e8082d83
* Fix the symbol definition code which does not assume the id is the same as the mbname.
wycc
parents:
diff
changeset
|
266 } |
2e97e8082d83
* Fix the symbol definition code which does not assume the id is the same as the mbname.
wycc
parents:
diff
changeset
|
267 void menu_down() |
2e97e8082d83
* Fix the symbol definition code which does not assume the id is the same as the mbname.
wycc
parents:
diff
changeset
|
268 { |
2e97e8082d83
* Fix the symbol definition code which does not assume the id is the same as the mbname.
wycc
parents:
diff
changeset
|
269 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
|
270 |
297 | 271 if (data->cur < 4) { |
272 if (data->top+data->cur <= data->max) { | |
296
2e97e8082d83
* Fix the symbol definition code which does not assume the id is the same as the mbname.
wycc
parents:
diff
changeset
|
273 data->cur++; |
297 | 274 MoveLightBar(); |
275 } | |
296
2e97e8082d83
* Fix the symbol definition code which does not assume the id is the same as the mbname.
wycc
parents:
diff
changeset
|
276 } else { |
2e97e8082d83
* Fix the symbol definition code which does not assume the id is the same as the mbname.
wycc
parents:
diff
changeset
|
277 if ((data->top+8) < data->max) { |
2e97e8082d83
* Fix the symbol definition code which does not assume the id is the same as the mbname.
wycc
parents:
diff
changeset
|
278 data->top++; |
297 | 279 fillMenuContentDown(); |
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 { |
297 | 281 if (data->cur+data->top < data->max-1) { |
296
2e97e8082d83
* Fix the symbol definition code which does not assume the id is the same as the mbname.
wycc
parents:
diff
changeset
|
282 data->cur++; |
297 | 283 MoveLightBar(); |
284 } else | |
296
2e97e8082d83
* Fix the symbol definition code which does not assume the id is the same as the mbname.
wycc
parents:
diff
changeset
|
285 return; |
2e97e8082d83
* Fix the symbol definition code which does not assume the id is the same as the mbname.
wycc
parents:
diff
changeset
|
286 } |
2e97e8082d83
* Fix the symbol definition code which does not assume the id is the same as the mbname.
wycc
parents:
diff
changeset
|
287 } |
2e97e8082d83
* Fix the symbol definition code which does not assume the id is the same as the mbname.
wycc
parents:
diff
changeset
|
288 } |
2e97e8082d83
* Fix the symbol definition code which does not assume the id is the same as the mbname.
wycc
parents:
diff
changeset
|
289 void menu_select() |
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 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
|
292 |
2e97e8082d83
* Fix the symbol definition code which does not assume the id is the same as the mbname.
wycc
parents:
diff
changeset
|
293 printf("menu '%s' is selected\n", menus[data->top+data->cur]); |
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 void keyHandler(event_t *ev, void *arg) |
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 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
|
299 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
|
300 return; |
2e97e8082d83
* Fix the symbol definition code which does not assume the id is the same as the mbname.
wycc
parents:
diff
changeset
|
301 } |
2e97e8082d83
* Fix the symbol definition code which does not assume the id is the same as the mbname.
wycc
parents:
diff
changeset
|
302 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
|
303 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
|
304 break; |
2e97e8082d83
* Fix the symbol definition code which does not assume the id is the same as the mbname.
wycc
parents:
diff
changeset
|
305 |
2e97e8082d83
* Fix the symbol definition code which does not assume the id is the same as the mbname.
wycc
parents:
diff
changeset
|
306 case 0xff52: /* up */ |
2e97e8082d83
* Fix the symbol definition code which does not assume the id is the same as the mbname.
wycc
parents:
diff
changeset
|
307 menu_up(); |
2e97e8082d83
* Fix the symbol definition code which does not assume the id is the same as the mbname.
wycc
parents:
diff
changeset
|
308 break; |
2e97e8082d83
* Fix the symbol definition code which does not assume the id is the same as the mbname.
wycc
parents:
diff
changeset
|
309 |
2e97e8082d83
* Fix the symbol definition code which does not assume the id is the same as the mbname.
wycc
parents:
diff
changeset
|
310 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
|
311 break; |
2e97e8082d83
* Fix the symbol definition code which does not assume the id is the same as the mbname.
wycc
parents:
diff
changeset
|
312 |
2e97e8082d83
* Fix the symbol definition code which does not assume the id is the same as the mbname.
wycc
parents:
diff
changeset
|
313 case 0xff54: /* down */ |
2e97e8082d83
* Fix the symbol definition code which does not assume the id is the same as the mbname.
wycc
parents:
diff
changeset
|
314 menu_down(); |
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 0xff0d: /* enter */ |
2e97e8082d83
* Fix the symbol definition code which does not assume the id is the same as the mbname.
wycc
parents:
diff
changeset
|
318 menu_select(); |
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 default: |
2e97e8082d83
* Fix the symbol definition code which does not assume the id is the same as the mbname.
wycc
parents:
diff
changeset
|
321 return; |
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 } |
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 MyApp_InitContent() |
2e97e8082d83
* Fix the symbol definition code which does not assume the id is the same as the mbname.
wycc
parents:
diff
changeset
|
326 { |
2e97e8082d83
* Fix the symbol definition code which does not assume the id is the same as the mbname.
wycc
parents:
diff
changeset
|
327 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
|
328 subject_t *key = MBAPP_keySubject(myApp); |
297 | 329 char name[255]; |
330 coord_t *l; | |
331 int i; | |
332 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
|
333 |
2e97e8082d83
* Fix the symbol definition code which does not assume the id is the same as the mbname.
wycc
parents:
diff
changeset
|
334 data->top = 0; |
2e97e8082d83
* Fix the symbol definition code which does not assume the id is the same as the mbname.
wycc
parents:
diff
changeset
|
335 data->cur = 0; |
2e97e8082d83
* Fix the symbol definition code which does not assume the id is the same as the mbname.
wycc
parents:
diff
changeset
|
336 data->max = sizeof(menus)/sizeof(int)-1; |
297 | 337 for(i=0;i<9;i++) { |
338 items[i] = i+1; | |
339 snprintf(name,255,"item%d", i+1); | |
340 l = (coord_t *) MB_SPRITE_GET_OBJ(sprite,name); | |
341 menus_y[i] = coord_y(l); | |
342 } | |
296
2e97e8082d83
* Fix the symbol definition code which does not assume the id is the same as the mbname.
wycc
parents:
diff
changeset
|
343 |
2e97e8082d83
* Fix the symbol definition code which does not assume the id is the same as the mbname.
wycc
parents:
diff
changeset
|
344 fillMenuContent(); |
2e97e8082d83
* Fix the symbol definition code which does not assume the id is the same as the mbname.
wycc
parents:
diff
changeset
|
345 subject_add_observer(key, keyHandler,NULL); |
2e97e8082d83
* Fix the symbol definition code which does not assume the id is the same as the mbname.
wycc
parents:
diff
changeset
|
346 } |
2e97e8082d83
* Fix the symbol definition code which does not assume the id is the same as the mbname.
wycc
parents:
diff
changeset
|
347 |
2e97e8082d83
* Fix the symbol definition code which does not assume the id is the same as the mbname.
wycc
parents:
diff
changeset
|
348 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
|
349 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
|
350 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
|
351 MyAppData data; |
2e97e8082d83
* Fix the symbol definition code which does not assume the id is the same as the mbname.
wycc
parents:
diff
changeset
|
352 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
|
353 |
2e97e8082d83
* Fix the symbol definition code which does not assume the id is the same as the mbname.
wycc
parents:
diff
changeset
|
354 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
|
355 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
|
356 else |
2e97e8082d83
* Fix the symbol definition code which does not assume the id is the same as the mbname.
wycc
parents:
diff
changeset
|
357 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
|
358 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
|
359 MyApp_InitContent(); |
2e97e8082d83
* Fix the symbol definition code which does not assume the id is the same as the mbname.
wycc
parents:
diff
changeset
|
360 |
2e97e8082d83
* Fix the symbol definition code which does not assume the id is the same as the mbname.
wycc
parents:
diff
changeset
|
361 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
|
362 |
2e97e8082d83
* Fix the symbol definition code which does not assume the id is the same as the mbname.
wycc
parents:
diff
changeset
|
363 return 0; |
2e97e8082d83
* Fix the symbol definition code which does not assume the id is the same as the mbname.
wycc
parents:
diff
changeset
|
364 } |
2e97e8082d83
* Fix the symbol definition code which does not assume the id is the same as the mbname.
wycc
parents:
diff
changeset
|
365 |
2e97e8082d83
* Fix the symbol definition code which does not assume the id is the same as the mbname.
wycc
parents:
diff
changeset
|
366 /* vim: set ts=4 */ |