Mercurial > MadButterfly
annotate examples/menu/main.c @ 299:5bf503270419
Fix the Fade out issue in scroll up.
author | wycc |
---|---|
date | Wed, 04 Feb 2009 09:12:02 +0800 |
parents | 959c4ac544a1 |
children | 8b45e7b374b8 |
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]; | |
298 | 42 #define SPEED 600000 |
297 | 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); | |
298 | 113 MB_TIMEVAL_SET(&playing, 0, SPEED); |
297 | 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 | |
128 // fade in the item[8] | |
129 snprintf(name, sizeof(name),"item%d", items[8]); | |
130 textgroup = (coord_t *) MB_SPRITE_GET_OBJ(sprite,name); | |
131 snprintf(name,sizeof(name),"item%d", items[0]); | |
132 group = (coord_t *) MB_SPRITE_GET_OBJ(sprite,name); | |
133 coord_y(textgroup) = menus_y[0]-100; | |
134 coord_show(textgroup); | |
135 mb_shift_new(0,100, textgroup,word); | |
136 | |
137 lightbar = (coord_t *) MB_SPRITE_GET_OBJ(sprite, "lightbar"); | |
138 mb_shift_new(0,menus_y[data->cur]-coord_y(lightbar),lightbar,word); | |
139 | |
298 | 140 MB_TIMEVAL_SET(&start, 0, SPEED); |
297 | 141 MB_TIMEVAL_SET(&playing, 0, 0); |
142 word = mb_progm_next_word(progm, &start, &playing); | |
299 | 143 snprintf(name, sizeof(name),"item%d", items[7]); |
297 | 144 textgroup = (coord_t *) MB_SPRITE_GET_OBJ(sprite,name); |
299 | 145 mb_visibility_new(VIS_HIDDEN, textgroup,word); |
297 | 146 |
147 mb_progm_free_completed(progm); | |
148 mb_progm_start(progm, X_MB_tman(MBAPP_RDMAN(myApp)->rt), &now); | |
149 rdman_redraw_changed(MBAPP_RDMAN(myApp)); | |
150 tmp = items[8]; | |
151 for(i=8;i>0;i--) { | |
152 items[i] = items[i-1]; | |
153 } | |
154 items[0] = tmp; | |
155 } | |
156 static void fillMenuContentDown() | |
157 { | |
158 int i; | |
159 MyAppData *data = MBAPP_DATA(myApp,MyAppData); | |
160 mb_sprite_t *sprite=myApp->rootsprite; | |
161 coord_t *textgroup; | |
162 shape_t *text; | |
163 coord_t *group; | |
164 coord_t *lightbar; | |
165 char name[255]; | |
166 int tmp; | |
167 mb_timeval_t start, playing, now; | |
168 mb_progm_t *progm; | |
169 mb_word_t *word; | |
170 | |
171 | |
172 // fill new item | |
173 snprintf(name, sizeof(name),"item%dtext", items[8]); | |
174 text = (shape_t *) MB_SPRITE_GET_OBJ(sprite,name); | |
175 sh_text_set_text(text, menus[data->top+7]); | |
176 | |
177 progm = mb_progm_new(2, MBAPP_RDMAN(myApp)); | |
178 MB_TIMEVAL_SET(&start, 0, 0); | |
298 | 179 MB_TIMEVAL_SET(&playing, 0, SPEED); |
297 | 180 word = mb_progm_next_word(progm, &start, &playing); |
181 get_now(&now); | |
182 | |
183 for(i=1;i<8;i++) { | |
184 //shift to the next item | |
185 snprintf(name, sizeof(name),"item%d", items[i]); | |
186 textgroup = (coord_t *) MB_SPRITE_GET_OBJ(sprite,name); | |
187 mb_shift_new(0,menus_y[i-1]-coord_y(textgroup), textgroup,word); | |
188 } | |
189 // fade out the item[0] | |
190 snprintf(name, sizeof(name),"item%d", items[0]); | |
191 textgroup = (coord_t *) MB_SPRITE_GET_OBJ(sprite,name); | |
192 mb_shift_new(0,-100, textgroup,word); | |
193 | |
194 // fade in the item[8] | |
195 snprintf(name, sizeof(name),"item%d", items[8]); | |
196 textgroup = (coord_t *) MB_SPRITE_GET_OBJ(sprite,name); | |
197 coord_y(textgroup) = menus_y[7]+100; | |
198 coord_show(textgroup); | |
199 mb_shift_new(0,-100, textgroup,word); | |
200 | |
201 lightbar = (coord_t *) MB_SPRITE_GET_OBJ(sprite, "lightbar"); | |
202 mb_shift_new(0,menus_y[data->cur]-coord_y(lightbar),lightbar,word); | |
203 | |
298 | 204 MB_TIMEVAL_SET(&start, 0, SPEED); |
297 | 205 MB_TIMEVAL_SET(&playing, 0, 0); |
206 word = mb_progm_next_word(progm, &start, &playing); | |
207 snprintf(name, sizeof(name),"item%d", items[0]); | |
208 textgroup = (coord_t *) MB_SPRITE_GET_OBJ(sprite,name); | |
209 mb_visibility_new(VIS_VISIBLE, textgroup,word); | |
210 | |
211 mb_progm_free_completed(progm); | |
212 mb_progm_start(progm, X_MB_tman(MBAPP_RDMAN(myApp)->rt), &now); | |
213 rdman_redraw_changed(MBAPP_RDMAN(myApp)); | |
214 tmp = items[0]; | |
215 for(i=0;i<8;i++) { | |
216 items[i] = items[i+1]; | |
217 } | |
218 items[8] = tmp; | |
219 } | |
220 | |
221 MoveLightBar() | |
222 { | |
223 mb_sprite_t *sprite=myApp->rootsprite; | |
224 MyAppData *data = MBAPP_DATA(myApp,MyAppData); | |
225 mb_timeval_t start, playing, now; | |
226 mb_progm_t *progm; | |
227 mb_word_t *word; | |
228 coord_t *group; | |
229 coord_t *lightbar; | |
230 char name[255]; | |
231 | |
232 progm = mb_progm_new(1, MBAPP_RDMAN(myApp)); | |
233 MB_TIMEVAL_SET(&start, 0, 0); | |
234 MB_TIMEVAL_SET(&playing, 0, 200000); | |
235 word = mb_progm_next_word(progm, &start, &playing); | |
236 get_now(&now); | |
237 | |
238 lightbar = (coord_t *) MB_SPRITE_GET_OBJ(sprite, "lightbar"); | |
239 snprintf(name,sizeof(name),"item%d", items[data->cur]); | |
240 group = (coord_t *) MB_SPRITE_GET_OBJ(sprite, name); | |
241 mb_shift_new(coord_x(group)-coord_x(lightbar),coord_y(group)-coord_y(lightbar),lightbar,word); | |
242 mb_progm_free_completed(progm); | |
243 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
|
244 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
|
245 } |
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 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
|
248 { |
2e97e8082d83
* Fix the symbol definition code which does not assume the id is the same as the mbname.
wycc
parents:
diff
changeset
|
249 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
|
250 |
297 | 251 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
|
252 data->cur--; |
297 | 253 MoveLightBar(); |
254 } else { | |
296
2e97e8082d83
* Fix the symbol definition code which does not assume the id is the same as the mbname.
wycc
parents:
diff
changeset
|
255 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
|
256 data->top--; |
297 | 257 fillMenuContentUp(); |
296
2e97e8082d83
* Fix the symbol definition code which does not assume the id is the same as the mbname.
wycc
parents:
diff
changeset
|
258 } else { |
2e97e8082d83
* Fix the symbol definition code which does not assume the id is the same as the mbname.
wycc
parents:
diff
changeset
|
259 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
|
260 return; |
2e97e8082d83
* Fix the symbol definition code which does not assume the id is the same as the mbname.
wycc
parents:
diff
changeset
|
261 data->cur--; |
297 | 262 MoveLightBar(); |
296
2e97e8082d83
* Fix the symbol definition code which does not assume the id is the same as the mbname.
wycc
parents:
diff
changeset
|
263 } |
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 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
|
267 { |
2e97e8082d83
* Fix the symbol definition code which does not assume the id is the same as the mbname.
wycc
parents:
diff
changeset
|
268 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
|
269 |
297 | 270 if (data->cur < 4) { |
271 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
|
272 data->cur++; |
297 | 273 MoveLightBar(); |
274 } | |
296
2e97e8082d83
* Fix the symbol definition code which does not assume the id is the same as the mbname.
wycc
parents:
diff
changeset
|
275 } else { |
2e97e8082d83
* Fix the symbol definition code which does not assume the id is the same as the mbname.
wycc
parents:
diff
changeset
|
276 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
|
277 data->top++; |
297 | 278 fillMenuContentDown(); |
296
2e97e8082d83
* Fix the symbol definition code which does not assume the id is the same as the mbname.
wycc
parents:
diff
changeset
|
279 } else { |
297 | 280 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
|
281 data->cur++; |
297 | 282 MoveLightBar(); |
283 } else | |
296
2e97e8082d83
* Fix the symbol definition code which does not assume the id is the same as the mbname.
wycc
parents:
diff
changeset
|
284 return; |
2e97e8082d83
* Fix the symbol definition code which does not assume the id is the same as the mbname.
wycc
parents:
diff
changeset
|
285 } |
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 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
|
289 { |
2e97e8082d83
* Fix the symbol definition code which does not assume the id is the same as the mbname.
wycc
parents:
diff
changeset
|
290 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
|
291 |
2e97e8082d83
* Fix the symbol definition code which does not assume the id is the same as the mbname.
wycc
parents:
diff
changeset
|
292 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
|
293 } |
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 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
|
296 { |
2e97e8082d83
* Fix the symbol definition code which does not assume the id is the same as the mbname.
wycc
parents:
diff
changeset
|
297 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
|
298 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
|
299 return; |
2e97e8082d83
* Fix the symbol definition code which does not assume the id is the same as the mbname.
wycc
parents:
diff
changeset
|
300 } |
2e97e8082d83
* Fix the symbol definition code which does not assume the id is the same as the mbname.
wycc
parents:
diff
changeset
|
301 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
|
302 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
|
303 break; |
2e97e8082d83
* Fix the symbol definition code which does not assume the id is the same as the mbname.
wycc
parents:
diff
changeset
|
304 |
2e97e8082d83
* Fix the symbol definition code which does not assume the id is the same as the mbname.
wycc
parents:
diff
changeset
|
305 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
|
306 menu_up(); |
2e97e8082d83
* Fix the symbol definition code which does not assume the id is the same as the mbname.
wycc
parents:
diff
changeset
|
307 break; |
2e97e8082d83
* Fix the symbol definition code which does not assume the id is the same as the mbname.
wycc
parents:
diff
changeset
|
308 |
2e97e8082d83
* Fix the symbol definition code which does not assume the id is the same as the mbname.
wycc
parents:
diff
changeset
|
309 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
|
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 0xff54: /* down */ |
2e97e8082d83
* Fix the symbol definition code which does not assume the id is the same as the mbname.
wycc
parents:
diff
changeset
|
313 menu_down(); |
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 0xff0d: /* enter */ |
2e97e8082d83
* Fix the symbol definition code which does not assume the id is the same as the mbname.
wycc
parents:
diff
changeset
|
317 menu_select(); |
2e97e8082d83
* Fix the symbol definition code which does not assume the id is the same as the mbname.
wycc
parents:
diff
changeset
|
318 break; |
2e97e8082d83
* Fix the symbol definition code which does not assume the id is the same as the mbname.
wycc
parents:
diff
changeset
|
319 default: |
2e97e8082d83
* Fix the symbol definition code which does not assume the id is the same as the mbname.
wycc
parents:
diff
changeset
|
320 return; |
2e97e8082d83
* Fix the symbol definition code which does not assume the id is the same as the mbname.
wycc
parents:
diff
changeset
|
321 } |
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 MyApp_InitContent() |
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 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
|
327 subject_t *key = MBAPP_keySubject(myApp); |
297 | 328 char name[255]; |
329 coord_t *l; | |
330 int i; | |
331 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
|
332 |
2e97e8082d83
* Fix the symbol definition code which does not assume the id is the same as the mbname.
wycc
parents:
diff
changeset
|
333 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
|
334 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
|
335 data->max = sizeof(menus)/sizeof(int)-1; |
297 | 336 for(i=0;i<9;i++) { |
337 items[i] = i+1; | |
338 snprintf(name,255,"item%d", i+1); | |
339 l = (coord_t *) MB_SPRITE_GET_OBJ(sprite,name); | |
340 menus_y[i] = coord_y(l); | |
341 } | |
296
2e97e8082d83
* Fix the symbol definition code which does not assume the id is the same as the mbname.
wycc
parents:
diff
changeset
|
342 |
2e97e8082d83
* Fix the symbol definition code which does not assume the id is the same as the mbname.
wycc
parents:
diff
changeset
|
343 fillMenuContent(); |
2e97e8082d83
* Fix the symbol definition code which does not assume the id is the same as the mbname.
wycc
parents:
diff
changeset
|
344 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
|
345 } |
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 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
|
348 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
|
349 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
|
350 MyAppData data; |
2e97e8082d83
* Fix the symbol definition code which does not assume the id is the same as the mbname.
wycc
parents:
diff
changeset
|
351 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
|
352 |
2e97e8082d83
* Fix the symbol definition code which does not assume the id is the same as the mbname.
wycc
parents:
diff
changeset
|
353 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
|
354 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
|
355 else |
2e97e8082d83
* Fix the symbol definition code which does not assume the id is the same as the mbname.
wycc
parents:
diff
changeset
|
356 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
|
357 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
|
358 MyApp_InitContent(); |
2e97e8082d83
* Fix the symbol definition code which does not assume the id is the same as the mbname.
wycc
parents:
diff
changeset
|
359 |
2e97e8082d83
* Fix the symbol definition code which does not assume the id is the same as the mbname.
wycc
parents:
diff
changeset
|
360 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
|
361 |
2e97e8082d83
* Fix the symbol definition code which does not assume the id is the same as the mbname.
wycc
parents:
diff
changeset
|
362 return 0; |
2e97e8082d83
* Fix the symbol definition code which does not assume the id is the same as the mbname.
wycc
parents:
diff
changeset
|
363 } |
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 /* vim: set ts=4 */ |