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
e885dc875f30 Implement animation menu
wycc
parents: 296
diff changeset
4 * We need to have group item1-item9 in the SVG file. Initially, we will show
e885dc875f30 Implement animation menu
wycc
parents: 296
diff changeset
5 * item1-item8 only. When a up/down key is pressed, we will draw the next item in item9 and
e885dc875f30 Implement animation menu
wycc
parents: 296
diff changeset
6 * add two words to move item1-item9 smoothly. The first word move items to the 3/4 position
e885dc875f30 Implement animation menu
wycc
parents: 296
diff changeset
7 * fastly. The second will move it from 3/4 to the final position slowly to make retard effect.
e885dc875f30 Implement animation menu
wycc
parents: 296
diff changeset
8 *
e885dc875f30 Implement animation menu
wycc
parents: 296
diff changeset
9 * If we press another key before the second words finish, we will delete the word and replace
e885dc875f30 Implement animation menu
wycc
parents: 296
diff changeset
10 * it with a word to move it fastly to the final position and then we will repeat the procedure
e885dc875f30 Implement animation menu
wycc
parents: 296
diff changeset
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
e885dc875f30 Implement animation menu
wycc
parents: 296
diff changeset
40 int menus_y[10];
e885dc875f30 Implement animation menu
wycc
parents: 296
diff changeset
41 int items[10];
298
959c4ac544a1 Add SPPED marcro to adjust the speed
wycc
parents: 297
diff changeset
42 #define SPEED 600000
297
e885dc875f30 Implement animation menu
wycc
parents: 296
diff changeset
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
e885dc875f30 Implement animation menu
wycc
parents: 296
diff changeset
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
e885dc875f30 Implement animation menu
wycc
parents: 296
diff changeset
62 int tmp;
e885dc875f30 Implement animation menu
wycc
parents: 296
diff changeset
63 mb_timeval_t start, playing, now;
e885dc875f30 Implement animation menu
wycc
parents: 296
diff changeset
64 mb_progm_t *progm;
e885dc875f30 Implement animation menu
wycc
parents: 296
diff changeset
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
e885dc875f30 Implement animation menu
wycc
parents: 296
diff changeset
67
e885dc875f30 Implement animation menu
wycc
parents: 296
diff changeset
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
e885dc875f30 Implement animation menu
wycc
parents: 296
diff changeset
70 snprintf(name, sizeof(name),"item%dtext", items[i]);
e885dc875f30 Implement animation menu
wycc
parents: 296
diff changeset
71 text = (shape_t *) MB_SPRITE_GET_OBJ(sprite,name);
e885dc875f30 Implement animation menu
wycc
parents: 296
diff changeset
72 sh_text_set_text(text, menus[data->top+i]);
e885dc875f30 Implement animation menu
wycc
parents: 296
diff changeset
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
e885dc875f30 Implement animation menu
wycc
parents: 296
diff changeset
75
e885dc875f30 Implement animation menu
wycc
parents: 296
diff changeset
76
e885dc875f30 Implement animation menu
wycc
parents: 296
diff changeset
77 snprintf(name, sizeof(name),"item%d", items[i]);
e885dc875f30 Implement animation menu
wycc
parents: 296
diff changeset
78 textgroup = (coord_t *) MB_SPRITE_GET_OBJ(sprite,name);
e885dc875f30 Implement animation menu
wycc
parents: 296
diff changeset
79 coord_hide(textgroup);
e885dc875f30 Implement animation menu
wycc
parents: 296
diff changeset
80 rdman_coord_changed(MBAPP_RDMAN(myApp),textgroup);
e885dc875f30 Implement animation menu
wycc
parents: 296
diff changeset
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
e885dc875f30 Implement animation menu
wycc
parents: 296
diff changeset
87 rdman_redraw_changed(MBAPP_RDMAN(myApp));
e885dc875f30 Implement animation menu
wycc
parents: 296
diff changeset
88 }
e885dc875f30 Implement animation menu
wycc
parents: 296
diff changeset
89
e885dc875f30 Implement animation menu
wycc
parents: 296
diff changeset
90 static void fillMenuContentUp()
e885dc875f30 Implement animation menu
wycc
parents: 296
diff changeset
91 {
e885dc875f30 Implement animation menu
wycc
parents: 296
diff changeset
92 int i;
e885dc875f30 Implement animation menu
wycc
parents: 296
diff changeset
93 MyAppData *data = MBAPP_DATA(myApp,MyAppData);
e885dc875f30 Implement animation menu
wycc
parents: 296
diff changeset
94 mb_sprite_t *sprite=myApp->rootsprite;
e885dc875f30 Implement animation menu
wycc
parents: 296
diff changeset
95 coord_t *textgroup;
e885dc875f30 Implement animation menu
wycc
parents: 296
diff changeset
96 shape_t *text;
e885dc875f30 Implement animation menu
wycc
parents: 296
diff changeset
97 coord_t *group;
e885dc875f30 Implement animation menu
wycc
parents: 296
diff changeset
98 coord_t *lightbar;
e885dc875f30 Implement animation menu
wycc
parents: 296
diff changeset
99 char name[255];
e885dc875f30 Implement animation menu
wycc
parents: 296
diff changeset
100 int tmp;
e885dc875f30 Implement animation menu
wycc
parents: 296
diff changeset
101 mb_timeval_t start, playing, now;
e885dc875f30 Implement animation menu
wycc
parents: 296
diff changeset
102 mb_progm_t *progm;
e885dc875f30 Implement animation menu
wycc
parents: 296
diff changeset
103 mb_word_t *word;
e885dc875f30 Implement animation menu
wycc
parents: 296
diff changeset
104
e885dc875f30 Implement animation menu
wycc
parents: 296
diff changeset
105
e885dc875f30 Implement animation menu
wycc
parents: 296
diff changeset
106 // fill new item
e885dc875f30 Implement animation menu
wycc
parents: 296
diff changeset
107 snprintf(name, sizeof(name),"item%dtext", items[8]);
e885dc875f30 Implement animation menu
wycc
parents: 296
diff changeset
108 text = (shape_t *) MB_SPRITE_GET_OBJ(sprite,name);
e885dc875f30 Implement animation menu
wycc
parents: 296
diff changeset
109 sh_text_set_text(text, menus[data->top]);
e885dc875f30 Implement animation menu
wycc
parents: 296
diff changeset
110
e885dc875f30 Implement animation menu
wycc
parents: 296
diff changeset
111 progm = mb_progm_new(2, MBAPP_RDMAN(myApp));
e885dc875f30 Implement animation menu
wycc
parents: 296
diff changeset
112 MB_TIMEVAL_SET(&start, 0, 0);
298
959c4ac544a1 Add SPPED marcro to adjust the speed
wycc
parents: 297
diff changeset
113 MB_TIMEVAL_SET(&playing, 0, SPEED);
297
e885dc875f30 Implement animation menu
wycc
parents: 296
diff changeset
114 word = mb_progm_next_word(progm, &start, &playing);
e885dc875f30 Implement animation menu
wycc
parents: 296
diff changeset
115 get_now(&now);
e885dc875f30 Implement animation menu
wycc
parents: 296
diff changeset
116
e885dc875f30 Implement animation menu
wycc
parents: 296
diff changeset
117 for(i=0;i<7;i++) {
e885dc875f30 Implement animation menu
wycc
parents: 296
diff changeset
118 //shift to the next item
e885dc875f30 Implement animation menu
wycc
parents: 296
diff changeset
119 snprintf(name, sizeof(name),"item%d", items[i]);
e885dc875f30 Implement animation menu
wycc
parents: 296
diff changeset
120 textgroup = (coord_t *) MB_SPRITE_GET_OBJ(sprite,name);
e885dc875f30 Implement animation menu
wycc
parents: 296
diff changeset
121 mb_shift_new(0,menus_y[i+1]-coord_y(textgroup), textgroup,word);
e885dc875f30 Implement animation menu
wycc
parents: 296
diff changeset
122 }
e885dc875f30 Implement animation menu
wycc
parents: 296
diff changeset
123 // fade out the item[7]
e885dc875f30 Implement animation menu
wycc
parents: 296
diff changeset
124 snprintf(name, sizeof(name),"item%d", items[7]);
e885dc875f30 Implement animation menu
wycc
parents: 296
diff changeset
125 textgroup = (coord_t *) MB_SPRITE_GET_OBJ(sprite,name);
e885dc875f30 Implement animation menu
wycc
parents: 296
diff changeset
126 mb_shift_new(0,100, textgroup,word);
e885dc875f30 Implement animation menu
wycc
parents: 296
diff changeset
127
e885dc875f30 Implement animation menu
wycc
parents: 296
diff changeset
128 // fade in the item[8]
e885dc875f30 Implement animation menu
wycc
parents: 296
diff changeset
129 snprintf(name, sizeof(name),"item%d", items[8]);
e885dc875f30 Implement animation menu
wycc
parents: 296
diff changeset
130 textgroup = (coord_t *) MB_SPRITE_GET_OBJ(sprite,name);
e885dc875f30 Implement animation menu
wycc
parents: 296
diff changeset
131 snprintf(name,sizeof(name),"item%d", items[0]);
e885dc875f30 Implement animation menu
wycc
parents: 296
diff changeset
132 group = (coord_t *) MB_SPRITE_GET_OBJ(sprite,name);
e885dc875f30 Implement animation menu
wycc
parents: 296
diff changeset
133 coord_y(textgroup) = menus_y[0]-100;
e885dc875f30 Implement animation menu
wycc
parents: 296
diff changeset
134 coord_show(textgroup);
e885dc875f30 Implement animation menu
wycc
parents: 296
diff changeset
135 mb_shift_new(0,100, textgroup,word);
e885dc875f30 Implement animation menu
wycc
parents: 296
diff changeset
136
e885dc875f30 Implement animation menu
wycc
parents: 296
diff changeset
137 lightbar = (coord_t *) MB_SPRITE_GET_OBJ(sprite, "lightbar");
e885dc875f30 Implement animation menu
wycc
parents: 296
diff changeset
138 mb_shift_new(0,menus_y[data->cur]-coord_y(lightbar),lightbar,word);
e885dc875f30 Implement animation menu
wycc
parents: 296
diff changeset
139
298
959c4ac544a1 Add SPPED marcro to adjust the speed
wycc
parents: 297
diff changeset
140 MB_TIMEVAL_SET(&start, 0, SPEED);
297
e885dc875f30 Implement animation menu
wycc
parents: 296
diff changeset
141 MB_TIMEVAL_SET(&playing, 0, 0);
e885dc875f30 Implement animation menu
wycc
parents: 296
diff changeset
142 word = mb_progm_next_word(progm, &start, &playing);
299
5bf503270419 Fix the Fade out issue in scroll up.
wycc
parents: 298
diff changeset
143 snprintf(name, sizeof(name),"item%d", items[7]);
297
e885dc875f30 Implement animation menu
wycc
parents: 296
diff changeset
144 textgroup = (coord_t *) MB_SPRITE_GET_OBJ(sprite,name);
299
5bf503270419 Fix the Fade out issue in scroll up.
wycc
parents: 298
diff changeset
145 mb_visibility_new(VIS_HIDDEN, textgroup,word);
297
e885dc875f30 Implement animation menu
wycc
parents: 296
diff changeset
146
e885dc875f30 Implement animation menu
wycc
parents: 296
diff changeset
147 mb_progm_free_completed(progm);
e885dc875f30 Implement animation menu
wycc
parents: 296
diff changeset
148 mb_progm_start(progm, X_MB_tman(MBAPP_RDMAN(myApp)->rt), &now);
e885dc875f30 Implement animation menu
wycc
parents: 296
diff changeset
149 rdman_redraw_changed(MBAPP_RDMAN(myApp));
e885dc875f30 Implement animation menu
wycc
parents: 296
diff changeset
150 tmp = items[8];
e885dc875f30 Implement animation menu
wycc
parents: 296
diff changeset
151 for(i=8;i>0;i--) {
e885dc875f30 Implement animation menu
wycc
parents: 296
diff changeset
152 items[i] = items[i-1];
e885dc875f30 Implement animation menu
wycc
parents: 296
diff changeset
153 }
e885dc875f30 Implement animation menu
wycc
parents: 296
diff changeset
154 items[0] = tmp;
e885dc875f30 Implement animation menu
wycc
parents: 296
diff changeset
155 }
e885dc875f30 Implement animation menu
wycc
parents: 296
diff changeset
156 static void fillMenuContentDown()
e885dc875f30 Implement animation menu
wycc
parents: 296
diff changeset
157 {
e885dc875f30 Implement animation menu
wycc
parents: 296
diff changeset
158 int i;
e885dc875f30 Implement animation menu
wycc
parents: 296
diff changeset
159 MyAppData *data = MBAPP_DATA(myApp,MyAppData);
e885dc875f30 Implement animation menu
wycc
parents: 296
diff changeset
160 mb_sprite_t *sprite=myApp->rootsprite;
e885dc875f30 Implement animation menu
wycc
parents: 296
diff changeset
161 coord_t *textgroup;
e885dc875f30 Implement animation menu
wycc
parents: 296
diff changeset
162 shape_t *text;
e885dc875f30 Implement animation menu
wycc
parents: 296
diff changeset
163 coord_t *group;
e885dc875f30 Implement animation menu
wycc
parents: 296
diff changeset
164 coord_t *lightbar;
e885dc875f30 Implement animation menu
wycc
parents: 296
diff changeset
165 char name[255];
e885dc875f30 Implement animation menu
wycc
parents: 296
diff changeset
166 int tmp;
e885dc875f30 Implement animation menu
wycc
parents: 296
diff changeset
167 mb_timeval_t start, playing, now;
e885dc875f30 Implement animation menu
wycc
parents: 296
diff changeset
168 mb_progm_t *progm;
e885dc875f30 Implement animation menu
wycc
parents: 296
diff changeset
169 mb_word_t *word;
e885dc875f30 Implement animation menu
wycc
parents: 296
diff changeset
170
e885dc875f30 Implement animation menu
wycc
parents: 296
diff changeset
171
e885dc875f30 Implement animation menu
wycc
parents: 296
diff changeset
172 // fill new item
e885dc875f30 Implement animation menu
wycc
parents: 296
diff changeset
173 snprintf(name, sizeof(name),"item%dtext", items[8]);
e885dc875f30 Implement animation menu
wycc
parents: 296
diff changeset
174 text = (shape_t *) MB_SPRITE_GET_OBJ(sprite,name);
e885dc875f30 Implement animation menu
wycc
parents: 296
diff changeset
175 sh_text_set_text(text, menus[data->top+7]);
e885dc875f30 Implement animation menu
wycc
parents: 296
diff changeset
176
e885dc875f30 Implement animation menu
wycc
parents: 296
diff changeset
177 progm = mb_progm_new(2, MBAPP_RDMAN(myApp));
e885dc875f30 Implement animation menu
wycc
parents: 296
diff changeset
178 MB_TIMEVAL_SET(&start, 0, 0);
298
959c4ac544a1 Add SPPED marcro to adjust the speed
wycc
parents: 297
diff changeset
179 MB_TIMEVAL_SET(&playing, 0, SPEED);
297
e885dc875f30 Implement animation menu
wycc
parents: 296
diff changeset
180 word = mb_progm_next_word(progm, &start, &playing);
e885dc875f30 Implement animation menu
wycc
parents: 296
diff changeset
181 get_now(&now);
e885dc875f30 Implement animation menu
wycc
parents: 296
diff changeset
182
e885dc875f30 Implement animation menu
wycc
parents: 296
diff changeset
183 for(i=1;i<8;i++) {
e885dc875f30 Implement animation menu
wycc
parents: 296
diff changeset
184 //shift to the next item
e885dc875f30 Implement animation menu
wycc
parents: 296
diff changeset
185 snprintf(name, sizeof(name),"item%d", items[i]);
e885dc875f30 Implement animation menu
wycc
parents: 296
diff changeset
186 textgroup = (coord_t *) MB_SPRITE_GET_OBJ(sprite,name);
e885dc875f30 Implement animation menu
wycc
parents: 296
diff changeset
187 mb_shift_new(0,menus_y[i-1]-coord_y(textgroup), textgroup,word);
e885dc875f30 Implement animation menu
wycc
parents: 296
diff changeset
188 }
e885dc875f30 Implement animation menu
wycc
parents: 296
diff changeset
189 // fade out the item[0]
e885dc875f30 Implement animation menu
wycc
parents: 296
diff changeset
190 snprintf(name, sizeof(name),"item%d", items[0]);
e885dc875f30 Implement animation menu
wycc
parents: 296
diff changeset
191 textgroup = (coord_t *) MB_SPRITE_GET_OBJ(sprite,name);
e885dc875f30 Implement animation menu
wycc
parents: 296
diff changeset
192 mb_shift_new(0,-100, textgroup,word);
e885dc875f30 Implement animation menu
wycc
parents: 296
diff changeset
193
e885dc875f30 Implement animation menu
wycc
parents: 296
diff changeset
194 // fade in the item[8]
e885dc875f30 Implement animation menu
wycc
parents: 296
diff changeset
195 snprintf(name, sizeof(name),"item%d", items[8]);
e885dc875f30 Implement animation menu
wycc
parents: 296
diff changeset
196 textgroup = (coord_t *) MB_SPRITE_GET_OBJ(sprite,name);
e885dc875f30 Implement animation menu
wycc
parents: 296
diff changeset
197 coord_y(textgroup) = menus_y[7]+100;
e885dc875f30 Implement animation menu
wycc
parents: 296
diff changeset
198 coord_show(textgroup);
e885dc875f30 Implement animation menu
wycc
parents: 296
diff changeset
199 mb_shift_new(0,-100, textgroup,word);
e885dc875f30 Implement animation menu
wycc
parents: 296
diff changeset
200
e885dc875f30 Implement animation menu
wycc
parents: 296
diff changeset
201 lightbar = (coord_t *) MB_SPRITE_GET_OBJ(sprite, "lightbar");
e885dc875f30 Implement animation menu
wycc
parents: 296
diff changeset
202 mb_shift_new(0,menus_y[data->cur]-coord_y(lightbar),lightbar,word);
e885dc875f30 Implement animation menu
wycc
parents: 296
diff changeset
203
298
959c4ac544a1 Add SPPED marcro to adjust the speed
wycc
parents: 297
diff changeset
204 MB_TIMEVAL_SET(&start, 0, SPEED);
297
e885dc875f30 Implement animation menu
wycc
parents: 296
diff changeset
205 MB_TIMEVAL_SET(&playing, 0, 0);
e885dc875f30 Implement animation menu
wycc
parents: 296
diff changeset
206 word = mb_progm_next_word(progm, &start, &playing);
e885dc875f30 Implement animation menu
wycc
parents: 296
diff changeset
207 snprintf(name, sizeof(name),"item%d", items[0]);
e885dc875f30 Implement animation menu
wycc
parents: 296
diff changeset
208 textgroup = (coord_t *) MB_SPRITE_GET_OBJ(sprite,name);
e885dc875f30 Implement animation menu
wycc
parents: 296
diff changeset
209 mb_visibility_new(VIS_VISIBLE, textgroup,word);
e885dc875f30 Implement animation menu
wycc
parents: 296
diff changeset
210
e885dc875f30 Implement animation menu
wycc
parents: 296
diff changeset
211 mb_progm_free_completed(progm);
e885dc875f30 Implement animation menu
wycc
parents: 296
diff changeset
212 mb_progm_start(progm, X_MB_tman(MBAPP_RDMAN(myApp)->rt), &now);
e885dc875f30 Implement animation menu
wycc
parents: 296
diff changeset
213 rdman_redraw_changed(MBAPP_RDMAN(myApp));
e885dc875f30 Implement animation menu
wycc
parents: 296
diff changeset
214 tmp = items[0];
e885dc875f30 Implement animation menu
wycc
parents: 296
diff changeset
215 for(i=0;i<8;i++) {
e885dc875f30 Implement animation menu
wycc
parents: 296
diff changeset
216 items[i] = items[i+1];
e885dc875f30 Implement animation menu
wycc
parents: 296
diff changeset
217 }
e885dc875f30 Implement animation menu
wycc
parents: 296
diff changeset
218 items[8] = tmp;
e885dc875f30 Implement animation menu
wycc
parents: 296
diff changeset
219 }
e885dc875f30 Implement animation menu
wycc
parents: 296
diff changeset
220
e885dc875f30 Implement animation menu
wycc
parents: 296
diff changeset
221 MoveLightBar()
e885dc875f30 Implement animation menu
wycc
parents: 296
diff changeset
222 {
e885dc875f30 Implement animation menu
wycc
parents: 296
diff changeset
223 mb_sprite_t *sprite=myApp->rootsprite;
e885dc875f30 Implement animation menu
wycc
parents: 296
diff changeset
224 MyAppData *data = MBAPP_DATA(myApp,MyAppData);
e885dc875f30 Implement animation menu
wycc
parents: 296
diff changeset
225 mb_timeval_t start, playing, now;
e885dc875f30 Implement animation menu
wycc
parents: 296
diff changeset
226 mb_progm_t *progm;
e885dc875f30 Implement animation menu
wycc
parents: 296
diff changeset
227 mb_word_t *word;
e885dc875f30 Implement animation menu
wycc
parents: 296
diff changeset
228 coord_t *group;
e885dc875f30 Implement animation menu
wycc
parents: 296
diff changeset
229 coord_t *lightbar;
e885dc875f30 Implement animation menu
wycc
parents: 296
diff changeset
230 char name[255];
e885dc875f30 Implement animation menu
wycc
parents: 296
diff changeset
231
e885dc875f30 Implement animation menu
wycc
parents: 296
diff changeset
232 progm = mb_progm_new(1, MBAPP_RDMAN(myApp));
e885dc875f30 Implement animation menu
wycc
parents: 296
diff changeset
233 MB_TIMEVAL_SET(&start, 0, 0);
e885dc875f30 Implement animation menu
wycc
parents: 296
diff changeset
234 MB_TIMEVAL_SET(&playing, 0, 200000);
e885dc875f30 Implement animation menu
wycc
parents: 296
diff changeset
235 word = mb_progm_next_word(progm, &start, &playing);
e885dc875f30 Implement animation menu
wycc
parents: 296
diff changeset
236 get_now(&now);
e885dc875f30 Implement animation menu
wycc
parents: 296
diff changeset
237
e885dc875f30 Implement animation menu
wycc
parents: 296
diff changeset
238 lightbar = (coord_t *) MB_SPRITE_GET_OBJ(sprite, "lightbar");
e885dc875f30 Implement animation menu
wycc
parents: 296
diff changeset
239 snprintf(name,sizeof(name),"item%d", items[data->cur]);
e885dc875f30 Implement animation menu
wycc
parents: 296
diff changeset
240 group = (coord_t *) MB_SPRITE_GET_OBJ(sprite, name);
e885dc875f30 Implement animation menu
wycc
parents: 296
diff changeset
241 mb_shift_new(coord_x(group)-coord_x(lightbar),coord_y(group)-coord_y(lightbar),lightbar,word);
e885dc875f30 Implement animation menu
wycc
parents: 296
diff changeset
242 mb_progm_free_completed(progm);
e885dc875f30 Implement animation menu
wycc
parents: 296
diff changeset
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
e885dc875f30 Implement animation menu
wycc
parents: 296
diff changeset
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
e885dc875f30 Implement animation menu
wycc
parents: 296
diff changeset
253 MoveLightBar();
e885dc875f30 Implement animation menu
wycc
parents: 296
diff changeset
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
e885dc875f30 Implement animation menu
wycc
parents: 296
diff changeset
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
e885dc875f30 Implement animation menu
wycc
parents: 296
diff changeset
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
e885dc875f30 Implement animation menu
wycc
parents: 296
diff changeset
270 if (data->cur < 4) {
e885dc875f30 Implement animation menu
wycc
parents: 296
diff changeset
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
e885dc875f30 Implement animation menu
wycc
parents: 296
diff changeset
273 MoveLightBar();
e885dc875f30 Implement animation menu
wycc
parents: 296
diff changeset
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
e885dc875f30 Implement animation menu
wycc
parents: 296
diff changeset
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
e885dc875f30 Implement animation menu
wycc
parents: 296
diff changeset
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
e885dc875f30 Implement animation menu
wycc
parents: 296
diff changeset
282 MoveLightBar();
e885dc875f30 Implement animation menu
wycc
parents: 296
diff changeset
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
e885dc875f30 Implement animation menu
wycc
parents: 296
diff changeset
328 char name[255];
e885dc875f30 Implement animation menu
wycc
parents: 296
diff changeset
329 coord_t *l;
e885dc875f30 Implement animation menu
wycc
parents: 296
diff changeset
330 int i;
e885dc875f30 Implement animation menu
wycc
parents: 296
diff changeset
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
e885dc875f30 Implement animation menu
wycc
parents: 296
diff changeset
336 for(i=0;i<9;i++) {
e885dc875f30 Implement animation menu
wycc
parents: 296
diff changeset
337 items[i] = i+1;
e885dc875f30 Implement animation menu
wycc
parents: 296
diff changeset
338 snprintf(name,255,"item%d", i+1);
e885dc875f30 Implement animation menu
wycc
parents: 296
diff changeset
339 l = (coord_t *) MB_SPRITE_GET_OBJ(sprite,name);
e885dc875f30 Implement animation menu
wycc
parents: 296
diff changeset
340 menus_y[i] = coord_y(l);
e885dc875f30 Implement animation menu
wycc
parents: 296
diff changeset
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 */