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
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];
e885dc875f30 Implement animation menu
wycc
parents: 296
diff changeset
42
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);
e885dc875f30 Implement animation menu
wycc
parents: 296
diff changeset
113 MB_TIMEVAL_SET(&playing, 0, 300000);
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 mb_visibility_new(VIS_HIDDEN, textgroup,word);
e885dc875f30 Implement animation menu
wycc
parents: 296
diff changeset
128
e885dc875f30 Implement animation menu
wycc
parents: 296
diff changeset
129 // fade in the item[8]
e885dc875f30 Implement animation menu
wycc
parents: 296
diff changeset
130 snprintf(name, sizeof(name),"item%d", items[8]);
e885dc875f30 Implement animation menu
wycc
parents: 296
diff changeset
131 textgroup = (coord_t *) MB_SPRITE_GET_OBJ(sprite,name);
e885dc875f30 Implement animation menu
wycc
parents: 296
diff changeset
132 snprintf(name,sizeof(name),"item%d", items[0]);
e885dc875f30 Implement animation menu
wycc
parents: 296
diff changeset
133 group = (coord_t *) MB_SPRITE_GET_OBJ(sprite,name);
e885dc875f30 Implement animation menu
wycc
parents: 296
diff changeset
134 coord_y(textgroup) = menus_y[0]-100;
e885dc875f30 Implement animation menu
wycc
parents: 296
diff changeset
135 coord_show(textgroup);
e885dc875f30 Implement animation menu
wycc
parents: 296
diff changeset
136 mb_shift_new(0,100, textgroup,word);
e885dc875f30 Implement animation menu
wycc
parents: 296
diff changeset
137
e885dc875f30 Implement animation menu
wycc
parents: 296
diff changeset
138 lightbar = (coord_t *) MB_SPRITE_GET_OBJ(sprite, "lightbar");
e885dc875f30 Implement animation menu
wycc
parents: 296
diff changeset
139 mb_shift_new(0,menus_y[data->cur]-coord_y(lightbar),lightbar,word);
e885dc875f30 Implement animation menu
wycc
parents: 296
diff changeset
140
e885dc875f30 Implement animation menu
wycc
parents: 296
diff changeset
141 MB_TIMEVAL_SET(&start, 0, 300000);
e885dc875f30 Implement animation menu
wycc
parents: 296
diff changeset
142 MB_TIMEVAL_SET(&playing, 0, 0);
e885dc875f30 Implement animation menu
wycc
parents: 296
diff changeset
143 word = mb_progm_next_word(progm, &start, &playing);
e885dc875f30 Implement animation menu
wycc
parents: 296
diff changeset
144 snprintf(name, sizeof(name),"item%d", items[8]);
e885dc875f30 Implement animation menu
wycc
parents: 296
diff changeset
145 textgroup = (coord_t *) MB_SPRITE_GET_OBJ(sprite,name);
e885dc875f30 Implement animation menu
wycc
parents: 296
diff changeset
146 mb_visibility_new(VIS_VISIBLE, textgroup,word);
e885dc875f30 Implement animation menu
wycc
parents: 296
diff changeset
147
e885dc875f30 Implement animation menu
wycc
parents: 296
diff changeset
148 mb_progm_free_completed(progm);
e885dc875f30 Implement animation menu
wycc
parents: 296
diff changeset
149 mb_progm_start(progm, X_MB_tman(MBAPP_RDMAN(myApp)->rt), &now);
e885dc875f30 Implement animation menu
wycc
parents: 296
diff changeset
150 rdman_redraw_changed(MBAPP_RDMAN(myApp));
e885dc875f30 Implement animation menu
wycc
parents: 296
diff changeset
151 tmp = items[8];
e885dc875f30 Implement animation menu
wycc
parents: 296
diff changeset
152 for(i=8;i>0;i--) {
e885dc875f30 Implement animation menu
wycc
parents: 296
diff changeset
153 items[i] = items[i-1];
e885dc875f30 Implement animation menu
wycc
parents: 296
diff changeset
154 }
e885dc875f30 Implement animation menu
wycc
parents: 296
diff changeset
155 items[0] = tmp;
e885dc875f30 Implement animation menu
wycc
parents: 296
diff changeset
156 }
e885dc875f30 Implement animation menu
wycc
parents: 296
diff changeset
157 static void fillMenuContentDown()
e885dc875f30 Implement animation menu
wycc
parents: 296
diff changeset
158 {
e885dc875f30 Implement animation menu
wycc
parents: 296
diff changeset
159 int i;
e885dc875f30 Implement animation menu
wycc
parents: 296
diff changeset
160 MyAppData *data = MBAPP_DATA(myApp,MyAppData);
e885dc875f30 Implement animation menu
wycc
parents: 296
diff changeset
161 mb_sprite_t *sprite=myApp->rootsprite;
e885dc875f30 Implement animation menu
wycc
parents: 296
diff changeset
162 coord_t *textgroup;
e885dc875f30 Implement animation menu
wycc
parents: 296
diff changeset
163 shape_t *text;
e885dc875f30 Implement animation menu
wycc
parents: 296
diff changeset
164 coord_t *group;
e885dc875f30 Implement animation menu
wycc
parents: 296
diff changeset
165 coord_t *lightbar;
e885dc875f30 Implement animation menu
wycc
parents: 296
diff changeset
166 char name[255];
e885dc875f30 Implement animation menu
wycc
parents: 296
diff changeset
167 int tmp;
e885dc875f30 Implement animation menu
wycc
parents: 296
diff changeset
168 mb_timeval_t start, playing, now;
e885dc875f30 Implement animation menu
wycc
parents: 296
diff changeset
169 mb_progm_t *progm;
e885dc875f30 Implement animation menu
wycc
parents: 296
diff changeset
170 mb_word_t *word;
e885dc875f30 Implement animation menu
wycc
parents: 296
diff changeset
171
e885dc875f30 Implement animation menu
wycc
parents: 296
diff changeset
172
e885dc875f30 Implement animation menu
wycc
parents: 296
diff changeset
173 // fill new item
e885dc875f30 Implement animation menu
wycc
parents: 296
diff changeset
174 snprintf(name, sizeof(name),"item%dtext", items[8]);
e885dc875f30 Implement animation menu
wycc
parents: 296
diff changeset
175 text = (shape_t *) MB_SPRITE_GET_OBJ(sprite,name);
e885dc875f30 Implement animation menu
wycc
parents: 296
diff changeset
176 sh_text_set_text(text, menus[data->top+7]);
e885dc875f30 Implement animation menu
wycc
parents: 296
diff changeset
177
e885dc875f30 Implement animation menu
wycc
parents: 296
diff changeset
178 progm = mb_progm_new(2, MBAPP_RDMAN(myApp));
e885dc875f30 Implement animation menu
wycc
parents: 296
diff changeset
179 MB_TIMEVAL_SET(&start, 0, 0);
e885dc875f30 Implement animation menu
wycc
parents: 296
diff changeset
180 MB_TIMEVAL_SET(&playing, 0, 300000);
e885dc875f30 Implement animation menu
wycc
parents: 296
diff changeset
181 word = mb_progm_next_word(progm, &start, &playing);
e885dc875f30 Implement animation menu
wycc
parents: 296
diff changeset
182 get_now(&now);
e885dc875f30 Implement animation menu
wycc
parents: 296
diff changeset
183
e885dc875f30 Implement animation menu
wycc
parents: 296
diff changeset
184 for(i=1;i<8;i++) {
e885dc875f30 Implement animation menu
wycc
parents: 296
diff changeset
185 //shift to the next item
e885dc875f30 Implement animation menu
wycc
parents: 296
diff changeset
186 snprintf(name, sizeof(name),"item%d", items[i]);
e885dc875f30 Implement animation menu
wycc
parents: 296
diff changeset
187 textgroup = (coord_t *) MB_SPRITE_GET_OBJ(sprite,name);
e885dc875f30 Implement animation menu
wycc
parents: 296
diff changeset
188 mb_shift_new(0,menus_y[i-1]-coord_y(textgroup), textgroup,word);
e885dc875f30 Implement animation menu
wycc
parents: 296
diff changeset
189 }
e885dc875f30 Implement animation menu
wycc
parents: 296
diff changeset
190 // fade out the item[0]
e885dc875f30 Implement animation menu
wycc
parents: 296
diff changeset
191 snprintf(name, sizeof(name),"item%d", items[0]);
e885dc875f30 Implement animation menu
wycc
parents: 296
diff changeset
192 textgroup = (coord_t *) MB_SPRITE_GET_OBJ(sprite,name);
e885dc875f30 Implement animation menu
wycc
parents: 296
diff changeset
193 mb_shift_new(0,-100, textgroup,word);
e885dc875f30 Implement animation menu
wycc
parents: 296
diff changeset
194
e885dc875f30 Implement animation menu
wycc
parents: 296
diff changeset
195 // fade in the item[8]
e885dc875f30 Implement animation menu
wycc
parents: 296
diff changeset
196 snprintf(name, sizeof(name),"item%d", items[8]);
e885dc875f30 Implement animation menu
wycc
parents: 296
diff changeset
197 textgroup = (coord_t *) MB_SPRITE_GET_OBJ(sprite,name);
e885dc875f30 Implement animation menu
wycc
parents: 296
diff changeset
198 coord_y(textgroup) = menus_y[7]+100;
e885dc875f30 Implement animation menu
wycc
parents: 296
diff changeset
199 coord_show(textgroup);
e885dc875f30 Implement animation menu
wycc
parents: 296
diff changeset
200 mb_shift_new(0,-100, textgroup,word);
e885dc875f30 Implement animation menu
wycc
parents: 296
diff changeset
201
e885dc875f30 Implement animation menu
wycc
parents: 296
diff changeset
202 lightbar = (coord_t *) MB_SPRITE_GET_OBJ(sprite, "lightbar");
e885dc875f30 Implement animation menu
wycc
parents: 296
diff changeset
203 mb_shift_new(0,menus_y[data->cur]-coord_y(lightbar),lightbar,word);
e885dc875f30 Implement animation menu
wycc
parents: 296
diff changeset
204
e885dc875f30 Implement animation menu
wycc
parents: 296
diff changeset
205 MB_TIMEVAL_SET(&start, 0, 300001);
e885dc875f30 Implement animation menu
wycc
parents: 296
diff changeset
206 MB_TIMEVAL_SET(&playing, 0, 0);
e885dc875f30 Implement animation menu
wycc
parents: 296
diff changeset
207 word = mb_progm_next_word(progm, &start, &playing);
e885dc875f30 Implement animation menu
wycc
parents: 296
diff changeset
208 snprintf(name, sizeof(name),"item%d", items[0]);
e885dc875f30 Implement animation menu
wycc
parents: 296
diff changeset
209 textgroup = (coord_t *) MB_SPRITE_GET_OBJ(sprite,name);
e885dc875f30 Implement animation menu
wycc
parents: 296
diff changeset
210 mb_visibility_new(VIS_VISIBLE, textgroup,word);
e885dc875f30 Implement animation menu
wycc
parents: 296
diff changeset
211
e885dc875f30 Implement animation menu
wycc
parents: 296
diff changeset
212 mb_progm_free_completed(progm);
e885dc875f30 Implement animation menu
wycc
parents: 296
diff changeset
213 mb_progm_start(progm, X_MB_tman(MBAPP_RDMAN(myApp)->rt), &now);
e885dc875f30 Implement animation menu
wycc
parents: 296
diff changeset
214 rdman_redraw_changed(MBAPP_RDMAN(myApp));
e885dc875f30 Implement animation menu
wycc
parents: 296
diff changeset
215 tmp = items[0];
e885dc875f30 Implement animation menu
wycc
parents: 296
diff changeset
216 for(i=0;i<8;i++) {
e885dc875f30 Implement animation menu
wycc
parents: 296
diff changeset
217 items[i] = items[i+1];
e885dc875f30 Implement animation menu
wycc
parents: 296
diff changeset
218 }
e885dc875f30 Implement animation menu
wycc
parents: 296
diff changeset
219 items[8] = tmp;
e885dc875f30 Implement animation menu
wycc
parents: 296
diff changeset
220 }
e885dc875f30 Implement animation menu
wycc
parents: 296
diff changeset
221
e885dc875f30 Implement animation menu
wycc
parents: 296
diff changeset
222 MoveLightBar()
e885dc875f30 Implement animation menu
wycc
parents: 296
diff changeset
223 {
e885dc875f30 Implement animation menu
wycc
parents: 296
diff changeset
224 mb_sprite_t *sprite=myApp->rootsprite;
e885dc875f30 Implement animation menu
wycc
parents: 296
diff changeset
225 MyAppData *data = MBAPP_DATA(myApp,MyAppData);
e885dc875f30 Implement animation menu
wycc
parents: 296
diff changeset
226 mb_timeval_t start, playing, now;
e885dc875f30 Implement animation menu
wycc
parents: 296
diff changeset
227 mb_progm_t *progm;
e885dc875f30 Implement animation menu
wycc
parents: 296
diff changeset
228 mb_word_t *word;
e885dc875f30 Implement animation menu
wycc
parents: 296
diff changeset
229 coord_t *group;
e885dc875f30 Implement animation menu
wycc
parents: 296
diff changeset
230 coord_t *lightbar;
e885dc875f30 Implement animation menu
wycc
parents: 296
diff changeset
231 char name[255];
e885dc875f30 Implement animation menu
wycc
parents: 296
diff changeset
232
e885dc875f30 Implement animation menu
wycc
parents: 296
diff changeset
233 progm = mb_progm_new(1, MBAPP_RDMAN(myApp));
e885dc875f30 Implement animation menu
wycc
parents: 296
diff changeset
234 MB_TIMEVAL_SET(&start, 0, 0);
e885dc875f30 Implement animation menu
wycc
parents: 296
diff changeset
235 MB_TIMEVAL_SET(&playing, 0, 200000);
e885dc875f30 Implement animation menu
wycc
parents: 296
diff changeset
236 word = mb_progm_next_word(progm, &start, &playing);
e885dc875f30 Implement animation menu
wycc
parents: 296
diff changeset
237 get_now(&now);
e885dc875f30 Implement animation menu
wycc
parents: 296
diff changeset
238
e885dc875f30 Implement animation menu
wycc
parents: 296
diff changeset
239 lightbar = (coord_t *) MB_SPRITE_GET_OBJ(sprite, "lightbar");
e885dc875f30 Implement animation menu
wycc
parents: 296
diff changeset
240 snprintf(name,sizeof(name),"item%d", items[data->cur]);
e885dc875f30 Implement animation menu
wycc
parents: 296
diff changeset
241 group = (coord_t *) MB_SPRITE_GET_OBJ(sprite, name);
e885dc875f30 Implement animation menu
wycc
parents: 296
diff changeset
242 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
243 mb_progm_free_completed(progm);
e885dc875f30 Implement animation menu
wycc
parents: 296
diff changeset
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
e885dc875f30 Implement animation menu
wycc
parents: 296
diff changeset
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
e885dc875f30 Implement animation menu
wycc
parents: 296
diff changeset
254 MoveLightBar();
e885dc875f30 Implement animation menu
wycc
parents: 296
diff changeset
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
e885dc875f30 Implement animation menu
wycc
parents: 296
diff changeset
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
e885dc875f30 Implement animation menu
wycc
parents: 296
diff changeset
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
e885dc875f30 Implement animation menu
wycc
parents: 296
diff changeset
271 if (data->cur < 4) {
e885dc875f30 Implement animation menu
wycc
parents: 296
diff changeset
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
e885dc875f30 Implement animation menu
wycc
parents: 296
diff changeset
274 MoveLightBar();
e885dc875f30 Implement animation menu
wycc
parents: 296
diff changeset
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
e885dc875f30 Implement animation menu
wycc
parents: 296
diff changeset
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
e885dc875f30 Implement animation menu
wycc
parents: 296
diff changeset
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
e885dc875f30 Implement animation menu
wycc
parents: 296
diff changeset
283 MoveLightBar();
e885dc875f30 Implement animation menu
wycc
parents: 296
diff changeset
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
e885dc875f30 Implement animation menu
wycc
parents: 296
diff changeset
329 char name[255];
e885dc875f30 Implement animation menu
wycc
parents: 296
diff changeset
330 coord_t *l;
e885dc875f30 Implement animation menu
wycc
parents: 296
diff changeset
331 int i;
e885dc875f30 Implement animation menu
wycc
parents: 296
diff changeset
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
e885dc875f30 Implement animation menu
wycc
parents: 296
diff changeset
337 for(i=0;i<9;i++) {
e885dc875f30 Implement animation menu
wycc
parents: 296
diff changeset
338 items[i] = i+1;
e885dc875f30 Implement animation menu
wycc
parents: 296
diff changeset
339 snprintf(name,255,"item%d", i+1);
e885dc875f30 Implement animation menu
wycc
parents: 296
diff changeset
340 l = (coord_t *) MB_SPRITE_GET_OBJ(sprite,name);
e885dc875f30 Implement animation menu
wycc
parents: 296
diff changeset
341 menus_y[i] = coord_y(l);
e885dc875f30 Implement animation menu
wycc
parents: 296
diff changeset
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 */