annotate examples/menu/animated_menu.c @ 320:6e164a9dd46c

Fix the Makefile to generate files correctly. The filebrowser is not working yet.
author wycc
date Thu, 05 Mar 2009 08:19:43 +0800
parents 4b58e58c78da
children 44cc65e7e234
rev   line source
318
4b58e58c78da Add missing file
wycc
parents:
diff changeset
1 #include <stdio.h>
4b58e58c78da Add missing file
wycc
parents:
diff changeset
2 #include <mb.h>
4b58e58c78da Add missing file
wycc
parents:
diff changeset
3 #include <string.h>
4b58e58c78da Add missing file
wycc
parents:
diff changeset
4 #include "menu.h"
4b58e58c78da Add missing file
wycc
parents:
diff changeset
5 #include "mbapp.h"
4b58e58c78da Add missing file
wycc
parents:
diff changeset
6 #include <animated_menu.h>
4b58e58c78da Add missing file
wycc
parents:
diff changeset
7 static void set_text(coord_t *g, char *text)
4b58e58c78da Add missing file
wycc
parents:
diff changeset
8 {
4b58e58c78da Add missing file
wycc
parents:
diff changeset
9 geo_t *geo;
4b58e58c78da Add missing file
wycc
parents:
diff changeset
10 shape_t *shape;
4b58e58c78da Add missing file
wycc
parents:
diff changeset
11
4b58e58c78da Add missing file
wycc
parents:
diff changeset
12 FOR_COORD_MEMBERS(g, geo) {
4b58e58c78da Add missing file
wycc
parents:
diff changeset
13 shape = geo_get_shape(geo);
4b58e58c78da Add missing file
wycc
parents:
diff changeset
14 if(shape->obj.obj_type == MBO_TEXT) {
4b58e58c78da Add missing file
wycc
parents:
diff changeset
15 sh_text_set_text(shape, text);
4b58e58c78da Add missing file
wycc
parents:
diff changeset
16 }
4b58e58c78da Add missing file
wycc
parents:
diff changeset
17 }
4b58e58c78da Add missing file
wycc
parents:
diff changeset
18 }
4b58e58c78da Add missing file
wycc
parents:
diff changeset
19
4b58e58c78da Add missing file
wycc
parents:
diff changeset
20 static void mb_animated_menu_fillMenuContent(mb_animated_menu_t *m)
4b58e58c78da Add missing file
wycc
parents:
diff changeset
21 {
4b58e58c78da Add missing file
wycc
parents:
diff changeset
22 int i;
4b58e58c78da Add missing file
wycc
parents:
diff changeset
23 coord_t *textgroup;
4b58e58c78da Add missing file
wycc
parents:
diff changeset
24 shape_t *text;
4b58e58c78da Add missing file
wycc
parents:
diff changeset
25 coord_t *group;
4b58e58c78da Add missing file
wycc
parents:
diff changeset
26 coord_t *lightbar;
4b58e58c78da Add missing file
wycc
parents:
diff changeset
27 int tmp;
4b58e58c78da Add missing file
wycc
parents:
diff changeset
28 mb_timeval_t start, playing, now;
4b58e58c78da Add missing file
wycc
parents:
diff changeset
29 mb_progm_t *progm;
4b58e58c78da Add missing file
wycc
parents:
diff changeset
30 mb_word_t *word;
4b58e58c78da Add missing file
wycc
parents:
diff changeset
31
4b58e58c78da Add missing file
wycc
parents:
diff changeset
32 printf("max item is %d\n", m->max);
4b58e58c78da Add missing file
wycc
parents:
diff changeset
33 // fill new item
4b58e58c78da Add missing file
wycc
parents:
diff changeset
34 for(i=0;i<8;i++) {
4b58e58c78da Add missing file
wycc
parents:
diff changeset
35 group = (coord_t *) m->objects[m->items[i]];
4b58e58c78da Add missing file
wycc
parents:
diff changeset
36 if (i < m->max)
4b58e58c78da Add missing file
wycc
parents:
diff changeset
37 set_text(group, m->titles[m->top+i]);
4b58e58c78da Add missing file
wycc
parents:
diff changeset
38 else
4b58e58c78da Add missing file
wycc
parents:
diff changeset
39 set_text(group, "");
4b58e58c78da Add missing file
wycc
parents:
diff changeset
40 rdman_coord_changed(MBAPP_RDMAN(m->app),group);
4b58e58c78da Add missing file
wycc
parents:
diff changeset
41 }
4b58e58c78da Add missing file
wycc
parents:
diff changeset
42
4b58e58c78da Add missing file
wycc
parents:
diff changeset
43
4b58e58c78da Add missing file
wycc
parents:
diff changeset
44 textgroup = (coord_t *) m->objects[m->items[i]];
4b58e58c78da Add missing file
wycc
parents:
diff changeset
45 coord_hide(textgroup);
4b58e58c78da Add missing file
wycc
parents:
diff changeset
46 rdman_coord_changed(MBAPP_RDMAN(m->app),textgroup);
4b58e58c78da Add missing file
wycc
parents:
diff changeset
47
4b58e58c78da Add missing file
wycc
parents:
diff changeset
48 lightbar = (coord_t *) m->lightbar;
4b58e58c78da Add missing file
wycc
parents:
diff changeset
49 group = (coord_t *) m->objects[m->cur];
4b58e58c78da Add missing file
wycc
parents:
diff changeset
50 coord_x(lightbar) = coord_x(group);
4b58e58c78da Add missing file
wycc
parents:
diff changeset
51 coord_y(lightbar) = coord_y(group);
4b58e58c78da Add missing file
wycc
parents:
diff changeset
52 rdman_coord_changed(MBAPP_RDMAN(m->app),lightbar);
4b58e58c78da Add missing file
wycc
parents:
diff changeset
53 rdman_redraw_changed(MBAPP_RDMAN(m->app));
4b58e58c78da Add missing file
wycc
parents:
diff changeset
54 }
4b58e58c78da Add missing file
wycc
parents:
diff changeset
55
4b58e58c78da Add missing file
wycc
parents:
diff changeset
56 static void mb_animated_menu_complete(event_t *ev,void *arg)
4b58e58c78da Add missing file
wycc
parents:
diff changeset
57 {
4b58e58c78da Add missing file
wycc
parents:
diff changeset
58 mb_animated_menu_t *m = (mb_animated_menu_t *) arg;
4b58e58c78da Add missing file
wycc
parents:
diff changeset
59
4b58e58c78da Add missing file
wycc
parents:
diff changeset
60 m->ready++;
4b58e58c78da Add missing file
wycc
parents:
diff changeset
61 printf("animated done ready=%d\n", m->ready);
4b58e58c78da Add missing file
wycc
parents:
diff changeset
62 }
4b58e58c78da Add missing file
wycc
parents:
diff changeset
63
4b58e58c78da Add missing file
wycc
parents:
diff changeset
64 static void mb_animated_menu_fillMenuContentUp(mb_animated_menu_t *m)
4b58e58c78da Add missing file
wycc
parents:
diff changeset
65 {
4b58e58c78da Add missing file
wycc
parents:
diff changeset
66 int i;
4b58e58c78da Add missing file
wycc
parents:
diff changeset
67 coord_t *textgroup;
4b58e58c78da Add missing file
wycc
parents:
diff changeset
68 shape_t *text;
4b58e58c78da Add missing file
wycc
parents:
diff changeset
69 coord_t *group;
4b58e58c78da Add missing file
wycc
parents:
diff changeset
70 coord_t *lightbar;
4b58e58c78da Add missing file
wycc
parents:
diff changeset
71 int tmp;
4b58e58c78da Add missing file
wycc
parents:
diff changeset
72 mb_timeval_t start, playing, now;
4b58e58c78da Add missing file
wycc
parents:
diff changeset
73 mb_progm_t *progm;
4b58e58c78da Add missing file
wycc
parents:
diff changeset
74 mb_word_t *word;
4b58e58c78da Add missing file
wycc
parents:
diff changeset
75
4b58e58c78da Add missing file
wycc
parents:
diff changeset
76
4b58e58c78da Add missing file
wycc
parents:
diff changeset
77 // fill new item
4b58e58c78da Add missing file
wycc
parents:
diff changeset
78 group = (coord_t *) m->objects[m->items[8]];
4b58e58c78da Add missing file
wycc
parents:
diff changeset
79 set_text(group, m->titles[m->top]);
4b58e58c78da Add missing file
wycc
parents:
diff changeset
80
4b58e58c78da Add missing file
wycc
parents:
diff changeset
81 progm = mb_progm_new(2, MBAPP_RDMAN(m->app));
4b58e58c78da Add missing file
wycc
parents:
diff changeset
82 MB_TIMEVAL_SET(&start, 0, 0);
4b58e58c78da Add missing file
wycc
parents:
diff changeset
83 MB_TIMEVAL_SET(&playing, 0, m->speed);
4b58e58c78da Add missing file
wycc
parents:
diff changeset
84 word = mb_progm_next_word(progm, &start, &playing);
4b58e58c78da Add missing file
wycc
parents:
diff changeset
85 get_now(&now);
4b58e58c78da Add missing file
wycc
parents:
diff changeset
86
4b58e58c78da Add missing file
wycc
parents:
diff changeset
87 for(i=0;i<7;i++) {
4b58e58c78da Add missing file
wycc
parents:
diff changeset
88 //shift to the next item
4b58e58c78da Add missing file
wycc
parents:
diff changeset
89 textgroup = (coord_t *) m->objects[m->items[i]];
4b58e58c78da Add missing file
wycc
parents:
diff changeset
90 mb_shift_new(0,m->menus_y[i+1]-coord_y(textgroup), textgroup,word);
4b58e58c78da Add missing file
wycc
parents:
diff changeset
91 }
4b58e58c78da Add missing file
wycc
parents:
diff changeset
92 // fade out the item[7]
4b58e58c78da Add missing file
wycc
parents:
diff changeset
93 textgroup = (coord_t *) m->objects[m->items[7]];
4b58e58c78da Add missing file
wycc
parents:
diff changeset
94 mb_shift_new(0,100, textgroup,word);
4b58e58c78da Add missing file
wycc
parents:
diff changeset
95
4b58e58c78da Add missing file
wycc
parents:
diff changeset
96 // fade in the item[8]
4b58e58c78da Add missing file
wycc
parents:
diff changeset
97 textgroup = (coord_t *) m->objects[m->items[8]];
4b58e58c78da Add missing file
wycc
parents:
diff changeset
98 group = (coord_t *) m->objects[m->items[0]];
4b58e58c78da Add missing file
wycc
parents:
diff changeset
99 coord_y(textgroup) = m->menus_y[0]-100;
4b58e58c78da Add missing file
wycc
parents:
diff changeset
100 coord_show(textgroup);
4b58e58c78da Add missing file
wycc
parents:
diff changeset
101 mb_shift_new(0,100, textgroup,word);
4b58e58c78da Add missing file
wycc
parents:
diff changeset
102
4b58e58c78da Add missing file
wycc
parents:
diff changeset
103 lightbar = (coord_t *) m->lightbar;
4b58e58c78da Add missing file
wycc
parents:
diff changeset
104 mb_shift_new(0,m->menus_y[m->cur]-coord_y(lightbar),lightbar,word);
4b58e58c78da Add missing file
wycc
parents:
diff changeset
105
4b58e58c78da Add missing file
wycc
parents:
diff changeset
106 MB_TIMEVAL_SET(&start, 0, m->speed);
4b58e58c78da Add missing file
wycc
parents:
diff changeset
107 MB_TIMEVAL_SET(&playing, 0, 0);
4b58e58c78da Add missing file
wycc
parents:
diff changeset
108 word = mb_progm_next_word(progm, &start, &playing);
4b58e58c78da Add missing file
wycc
parents:
diff changeset
109 textgroup = (coord_t *) m->objects[m->items[7]];
4b58e58c78da Add missing file
wycc
parents:
diff changeset
110 mb_visibility_new(VIS_HIDDEN, textgroup,word);
4b58e58c78da Add missing file
wycc
parents:
diff changeset
111
4b58e58c78da Add missing file
wycc
parents:
diff changeset
112 mb_progm_free_completed(progm);
4b58e58c78da Add missing file
wycc
parents:
diff changeset
113 m->ready--;
4b58e58c78da Add missing file
wycc
parents:
diff changeset
114 subject_add_observer(mb_progm_get_complete(progm), mb_animated_menu_complete,m);
4b58e58c78da Add missing file
wycc
parents:
diff changeset
115 mb_progm_start(progm, X_MB_tman(MBAPP_RDMAN(m->app)->rt), &now);
4b58e58c78da Add missing file
wycc
parents:
diff changeset
116 rdman_redraw_changed(MBAPP_RDMAN(m->app));
4b58e58c78da Add missing file
wycc
parents:
diff changeset
117 tmp = m->items[8];
4b58e58c78da Add missing file
wycc
parents:
diff changeset
118 for(i=8;i>0;i--) {
4b58e58c78da Add missing file
wycc
parents:
diff changeset
119 m->items[i] = m->items[i-1];
4b58e58c78da Add missing file
wycc
parents:
diff changeset
120 }
4b58e58c78da Add missing file
wycc
parents:
diff changeset
121 m->items[0] = tmp;
4b58e58c78da Add missing file
wycc
parents:
diff changeset
122 }
4b58e58c78da Add missing file
wycc
parents:
diff changeset
123
4b58e58c78da Add missing file
wycc
parents:
diff changeset
124
4b58e58c78da Add missing file
wycc
parents:
diff changeset
125 static void mb_animated_menu_fillMenuContentDown(mb_animated_menu_t *m)
4b58e58c78da Add missing file
wycc
parents:
diff changeset
126 {
4b58e58c78da Add missing file
wycc
parents:
diff changeset
127 int i;
4b58e58c78da Add missing file
wycc
parents:
diff changeset
128 coord_t *textgroup;
4b58e58c78da Add missing file
wycc
parents:
diff changeset
129 shape_t *text;
4b58e58c78da Add missing file
wycc
parents:
diff changeset
130 coord_t *group;
4b58e58c78da Add missing file
wycc
parents:
diff changeset
131 coord_t *lightbar;
4b58e58c78da Add missing file
wycc
parents:
diff changeset
132 char name[255];
4b58e58c78da Add missing file
wycc
parents:
diff changeset
133 int tmp;
4b58e58c78da Add missing file
wycc
parents:
diff changeset
134 mb_timeval_t start, playing, now;
4b58e58c78da Add missing file
wycc
parents:
diff changeset
135 mb_progm_t *progm;
4b58e58c78da Add missing file
wycc
parents:
diff changeset
136 mb_word_t *word;
4b58e58c78da Add missing file
wycc
parents:
diff changeset
137
4b58e58c78da Add missing file
wycc
parents:
diff changeset
138
4b58e58c78da Add missing file
wycc
parents:
diff changeset
139 // fill new item
4b58e58c78da Add missing file
wycc
parents:
diff changeset
140 set_text((coord_t *)m->objects[m->items[8]], m->titles[m->top+7]);
4b58e58c78da Add missing file
wycc
parents:
diff changeset
141
4b58e58c78da Add missing file
wycc
parents:
diff changeset
142 progm = mb_progm_new(2, MBAPP_RDMAN(m->app));
4b58e58c78da Add missing file
wycc
parents:
diff changeset
143 MB_TIMEVAL_SET(&start, 0, 0);
4b58e58c78da Add missing file
wycc
parents:
diff changeset
144 MB_TIMEVAL_SET(&playing, 0, m->speed);
4b58e58c78da Add missing file
wycc
parents:
diff changeset
145 word = mb_progm_next_word(progm, &start, &playing);
4b58e58c78da Add missing file
wycc
parents:
diff changeset
146 get_now(&now);
4b58e58c78da Add missing file
wycc
parents:
diff changeset
147
4b58e58c78da Add missing file
wycc
parents:
diff changeset
148 for(i=1;i<8;i++) {
4b58e58c78da Add missing file
wycc
parents:
diff changeset
149 //shift to the next item
4b58e58c78da Add missing file
wycc
parents:
diff changeset
150 mb_shift_new(0,m->menus_y[i-1]-coord_y((coord_t *)m->objects[m->items[i]]), (coord_t *) m->objects[m->items[i]],word);
4b58e58c78da Add missing file
wycc
parents:
diff changeset
151 }
4b58e58c78da Add missing file
wycc
parents:
diff changeset
152 // fade out the item[0]
4b58e58c78da Add missing file
wycc
parents:
diff changeset
153 mb_shift_new(0,-100, (coord_t *)m->objects[m->items[0]],word);
4b58e58c78da Add missing file
wycc
parents:
diff changeset
154
4b58e58c78da Add missing file
wycc
parents:
diff changeset
155 // fade in the item[8]
4b58e58c78da Add missing file
wycc
parents:
diff changeset
156 coord_y((coord_t *)m->objects[m->items[8]]) = m->menus_y[7]+100;
4b58e58c78da Add missing file
wycc
parents:
diff changeset
157 coord_show(((coord_t *)(m->objects[m->items[8]])));
4b58e58c78da Add missing file
wycc
parents:
diff changeset
158 mb_shift_new(0,-100, (coord_t *)m->objects[m->items[8]],word);
4b58e58c78da Add missing file
wycc
parents:
diff changeset
159
4b58e58c78da Add missing file
wycc
parents:
diff changeset
160 mb_shift_new(0,m->menus_y[m->cur]-coord_y((coord_t *)m->lightbar),((coord_t *)(m->lightbar)),word);
4b58e58c78da Add missing file
wycc
parents:
diff changeset
161
4b58e58c78da Add missing file
wycc
parents:
diff changeset
162 MB_TIMEVAL_SET(&start, 0, m->speed);
4b58e58c78da Add missing file
wycc
parents:
diff changeset
163 MB_TIMEVAL_SET(&playing, 0, 0);
4b58e58c78da Add missing file
wycc
parents:
diff changeset
164 word = mb_progm_next_word(progm, &start, &playing);
4b58e58c78da Add missing file
wycc
parents:
diff changeset
165 mb_visibility_new(VIS_VISIBLE, (coord_t *) m->objects[m->items[0]],word);
4b58e58c78da Add missing file
wycc
parents:
diff changeset
166
4b58e58c78da Add missing file
wycc
parents:
diff changeset
167 mb_progm_free_completed(progm);
4b58e58c78da Add missing file
wycc
parents:
diff changeset
168 m->ready--;
4b58e58c78da Add missing file
wycc
parents:
diff changeset
169 subject_add_observer(mb_progm_get_complete(progm), mb_animated_menu_complete,m);
4b58e58c78da Add missing file
wycc
parents:
diff changeset
170 mb_progm_start(progm, X_MB_tman(MBAPP_RDMAN(m->app)->rt), &now);
4b58e58c78da Add missing file
wycc
parents:
diff changeset
171 rdman_redraw_changed(MBAPP_RDMAN(m->app));
4b58e58c78da Add missing file
wycc
parents:
diff changeset
172 tmp = m->items[0];
4b58e58c78da Add missing file
wycc
parents:
diff changeset
173 for(i=0;i<8;i++) {
4b58e58c78da Add missing file
wycc
parents:
diff changeset
174 m->items[i] = m->items[i+1];
4b58e58c78da Add missing file
wycc
parents:
diff changeset
175 }
4b58e58c78da Add missing file
wycc
parents:
diff changeset
176 m->items[8] = tmp;
4b58e58c78da Add missing file
wycc
parents:
diff changeset
177 }
4b58e58c78da Add missing file
wycc
parents:
diff changeset
178
4b58e58c78da Add missing file
wycc
parents:
diff changeset
179 void mb_animated_menu_moveLightBar(mb_animated_menu_t *m)
4b58e58c78da Add missing file
wycc
parents:
diff changeset
180 {
4b58e58c78da Add missing file
wycc
parents:
diff changeset
181 mb_timeval_t start, playing, now;
4b58e58c78da Add missing file
wycc
parents:
diff changeset
182 mb_progm_t *progm;
4b58e58c78da Add missing file
wycc
parents:
diff changeset
183 mb_word_t *word;
4b58e58c78da Add missing file
wycc
parents:
diff changeset
184 coord_t *group;
4b58e58c78da Add missing file
wycc
parents:
diff changeset
185 coord_t *lightbar;
4b58e58c78da Add missing file
wycc
parents:
diff changeset
186
4b58e58c78da Add missing file
wycc
parents:
diff changeset
187 progm = mb_progm_new(1, MBAPP_RDMAN(m->app));
4b58e58c78da Add missing file
wycc
parents:
diff changeset
188 MB_TIMEVAL_SET(&start, 0, 0);
4b58e58c78da Add missing file
wycc
parents:
diff changeset
189 MB_TIMEVAL_SET(&playing, 0, m->speed);
4b58e58c78da Add missing file
wycc
parents:
diff changeset
190 word = mb_progm_next_word(progm, &start, &playing);
4b58e58c78da Add missing file
wycc
parents:
diff changeset
191 get_now(&now);
4b58e58c78da Add missing file
wycc
parents:
diff changeset
192
4b58e58c78da Add missing file
wycc
parents:
diff changeset
193 lightbar = (coord_t *) m->lightbar;
4b58e58c78da Add missing file
wycc
parents:
diff changeset
194 mb_shift_new(0,m->menus_y[m->cur]-coord_y(lightbar),lightbar,word);
4b58e58c78da Add missing file
wycc
parents:
diff changeset
195 mb_progm_free_completed(progm);
4b58e58c78da Add missing file
wycc
parents:
diff changeset
196 m->ready--;
4b58e58c78da Add missing file
wycc
parents:
diff changeset
197 subject_add_observer(mb_progm_get_complete(progm), mb_animated_menu_complete,m);
4b58e58c78da Add missing file
wycc
parents:
diff changeset
198 mb_progm_start(progm, X_MB_tman(MBAPP_RDMAN(m->app)->rt), &now);
4b58e58c78da Add missing file
wycc
parents:
diff changeset
199 rdman_redraw_changed(MBAPP_RDMAN(m->app));
4b58e58c78da Add missing file
wycc
parents:
diff changeset
200 }
4b58e58c78da Add missing file
wycc
parents:
diff changeset
201
4b58e58c78da Add missing file
wycc
parents:
diff changeset
202 static void mb_animated_menu_up(mb_animated_menu_t *m)
4b58e58c78da Add missing file
wycc
parents:
diff changeset
203 {
4b58e58c78da Add missing file
wycc
parents:
diff changeset
204 if (m->cur > 5) {
4b58e58c78da Add missing file
wycc
parents:
diff changeset
205 m->cur--;
4b58e58c78da Add missing file
wycc
parents:
diff changeset
206 mb_animated_menu_moveLightBar(m);
4b58e58c78da Add missing file
wycc
parents:
diff changeset
207 } else {
4b58e58c78da Add missing file
wycc
parents:
diff changeset
208 if (m->top > 0) {
4b58e58c78da Add missing file
wycc
parents:
diff changeset
209 m->top--;
4b58e58c78da Add missing file
wycc
parents:
diff changeset
210 mb_animated_menu_fillMenuContentUp(m);
4b58e58c78da Add missing file
wycc
parents:
diff changeset
211 } else {
4b58e58c78da Add missing file
wycc
parents:
diff changeset
212 if (m->cur == 0)
4b58e58c78da Add missing file
wycc
parents:
diff changeset
213 return;
4b58e58c78da Add missing file
wycc
parents:
diff changeset
214 m->cur--;
4b58e58c78da Add missing file
wycc
parents:
diff changeset
215 mb_animated_menu_moveLightBar(m);
4b58e58c78da Add missing file
wycc
parents:
diff changeset
216 }
4b58e58c78da Add missing file
wycc
parents:
diff changeset
217 }
4b58e58c78da Add missing file
wycc
parents:
diff changeset
218 }
4b58e58c78da Add missing file
wycc
parents:
diff changeset
219 static void mb_animated_menu_down(mb_animated_menu_t *m)
4b58e58c78da Add missing file
wycc
parents:
diff changeset
220 {
4b58e58c78da Add missing file
wycc
parents:
diff changeset
221
4b58e58c78da Add missing file
wycc
parents:
diff changeset
222 if (m->cur < 5) {
4b58e58c78da Add missing file
wycc
parents:
diff changeset
223 if (m->top+m->cur <= m->max) {
4b58e58c78da Add missing file
wycc
parents:
diff changeset
224 m->cur++;
4b58e58c78da Add missing file
wycc
parents:
diff changeset
225 mb_animated_menu_moveLightBar(m);
4b58e58c78da Add missing file
wycc
parents:
diff changeset
226 }
4b58e58c78da Add missing file
wycc
parents:
diff changeset
227 } else {
4b58e58c78da Add missing file
wycc
parents:
diff changeset
228 if ((m->top+8) < m->max-1) {
4b58e58c78da Add missing file
wycc
parents:
diff changeset
229 m->top++;
4b58e58c78da Add missing file
wycc
parents:
diff changeset
230 mb_animated_menu_fillMenuContentDown(m);
4b58e58c78da Add missing file
wycc
parents:
diff changeset
231 } else {
4b58e58c78da Add missing file
wycc
parents:
diff changeset
232 if (m->cur+m->top < m->max-1) {
4b58e58c78da Add missing file
wycc
parents:
diff changeset
233 m->cur++;
4b58e58c78da Add missing file
wycc
parents:
diff changeset
234 mb_animated_menu_moveLightBar(m);
4b58e58c78da Add missing file
wycc
parents:
diff changeset
235 } else
4b58e58c78da Add missing file
wycc
parents:
diff changeset
236 return;
4b58e58c78da Add missing file
wycc
parents:
diff changeset
237 }
4b58e58c78da Add missing file
wycc
parents:
diff changeset
238 }
4b58e58c78da Add missing file
wycc
parents:
diff changeset
239 }
4b58e58c78da Add missing file
wycc
parents:
diff changeset
240
4b58e58c78da Add missing file
wycc
parents:
diff changeset
241 void mb_animated_menu_set_callback(mb_animated_menu_t *m, void (*f)(mb_animated_menu_t *m, int sel))
4b58e58c78da Add missing file
wycc
parents:
diff changeset
242 {
4b58e58c78da Add missing file
wycc
parents:
diff changeset
243 m->callback = f;
4b58e58c78da Add missing file
wycc
parents:
diff changeset
244 }
4b58e58c78da Add missing file
wycc
parents:
diff changeset
245 static void mb_animated_menu_select(mb_animated_menu_t *m)
4b58e58c78da Add missing file
wycc
parents:
diff changeset
246 {
4b58e58c78da Add missing file
wycc
parents:
diff changeset
247 if (m->callback)
4b58e58c78da Add missing file
wycc
parents:
diff changeset
248 m->callback(m,m->top+m->cur);
4b58e58c78da Add missing file
wycc
parents:
diff changeset
249 }
4b58e58c78da Add missing file
wycc
parents:
diff changeset
250
4b58e58c78da Add missing file
wycc
parents:
diff changeset
251 static void mb_animated_menu_keyHandler(event_t *ev, void *arg)
4b58e58c78da Add missing file
wycc
parents:
diff changeset
252 {
4b58e58c78da Add missing file
wycc
parents:
diff changeset
253 mb_animated_menu_t *m = (mb_animated_menu_t *) arg;
4b58e58c78da Add missing file
wycc
parents:
diff changeset
254 X_kb_event_t *xkey = (X_kb_event_t *)ev;
4b58e58c78da Add missing file
wycc
parents:
diff changeset
255 if(xkey->event.type != EVT_KB_PRESS) {
4b58e58c78da Add missing file
wycc
parents:
diff changeset
256 return;
4b58e58c78da Add missing file
wycc
parents:
diff changeset
257 }
4b58e58c78da Add missing file
wycc
parents:
diff changeset
258 printf("read=%d\n",m->ready);
4b58e58c78da Add missing file
wycc
parents:
diff changeset
259 if (m->ready<=0) return;
4b58e58c78da Add missing file
wycc
parents:
diff changeset
260 switch(xkey->sym) {
4b58e58c78da Add missing file
wycc
parents:
diff changeset
261 case 0xff51: /* left */
4b58e58c78da Add missing file
wycc
parents:
diff changeset
262 break;
4b58e58c78da Add missing file
wycc
parents:
diff changeset
263
4b58e58c78da Add missing file
wycc
parents:
diff changeset
264 case 0xff52: /* up */
4b58e58c78da Add missing file
wycc
parents:
diff changeset
265 mb_animated_menu_up(m);
4b58e58c78da Add missing file
wycc
parents:
diff changeset
266 break;
4b58e58c78da Add missing file
wycc
parents:
diff changeset
267
4b58e58c78da Add missing file
wycc
parents:
diff changeset
268 case 0xff53: /* right */
4b58e58c78da Add missing file
wycc
parents:
diff changeset
269 break;
4b58e58c78da Add missing file
wycc
parents:
diff changeset
270
4b58e58c78da Add missing file
wycc
parents:
diff changeset
271 case 0xff54: /* down */
4b58e58c78da Add missing file
wycc
parents:
diff changeset
272 mb_animated_menu_down(m);
4b58e58c78da Add missing file
wycc
parents:
diff changeset
273 break;
4b58e58c78da Add missing file
wycc
parents:
diff changeset
274
4b58e58c78da Add missing file
wycc
parents:
diff changeset
275 case 0xff0d: /* enter */
4b58e58c78da Add missing file
wycc
parents:
diff changeset
276 mb_animated_menu_select(m);
4b58e58c78da Add missing file
wycc
parents:
diff changeset
277 break;
4b58e58c78da Add missing file
wycc
parents:
diff changeset
278 default:
4b58e58c78da Add missing file
wycc
parents:
diff changeset
279 return;
4b58e58c78da Add missing file
wycc
parents:
diff changeset
280 }
4b58e58c78da Add missing file
wycc
parents:
diff changeset
281 }
4b58e58c78da Add missing file
wycc
parents:
diff changeset
282
4b58e58c78da Add missing file
wycc
parents:
diff changeset
283 /** \brief Create an instace of animated menu.
4b58e58c78da Add missing file
wycc
parents:
diff changeset
284 *
4b58e58c78da Add missing file
wycc
parents:
diff changeset
285 * The objectnames is used to extract symbols from the SVG file.
4b58e58c78da Add missing file
wycc
parents:
diff changeset
286 * ${objectnames}0 - ${objectnames}8 is the text object.
4b58e58c78da Add missing file
wycc
parents:
diff changeset
287 * ${objectnames}_lightbar is the lightbar.
4b58e58c78da Add missing file
wycc
parents:
diff changeset
288 *
4b58e58c78da Add missing file
wycc
parents:
diff changeset
289 */
4b58e58c78da Add missing file
wycc
parents:
diff changeset
290 mb_animated_menu_t *mb_animated_menu_new(MBApp *app,mb_sprite_t *sp,char *objnames,char *menus[])
4b58e58c78da Add missing file
wycc
parents:
diff changeset
291 {
4b58e58c78da Add missing file
wycc
parents:
diff changeset
292 mb_animated_menu_t *m;
4b58e58c78da Add missing file
wycc
parents:
diff changeset
293 int i,len;
4b58e58c78da Add missing file
wycc
parents:
diff changeset
294 char name[255];
4b58e58c78da Add missing file
wycc
parents:
diff changeset
295 mb_obj_t *l;
4b58e58c78da Add missing file
wycc
parents:
diff changeset
296 int ii;
4b58e58c78da Add missing file
wycc
parents:
diff changeset
297
4b58e58c78da Add missing file
wycc
parents:
diff changeset
298 if (menus == NULL)
4b58e58c78da Add missing file
wycc
parents:
diff changeset
299 i=0;
4b58e58c78da Add missing file
wycc
parents:
diff changeset
300 else
4b58e58c78da Add missing file
wycc
parents:
diff changeset
301 for(i=0;menus[i];i++);
4b58e58c78da Add missing file
wycc
parents:
diff changeset
302 ii=9;
4b58e58c78da Add missing file
wycc
parents:
diff changeset
303
4b58e58c78da Add missing file
wycc
parents:
diff changeset
304 m = (mb_animated_menu_t *) malloc(sizeof(mb_animated_menu_t));
4b58e58c78da Add missing file
wycc
parents:
diff changeset
305 m->items = (int *) malloc(sizeof(int)*ii*2+sizeof(mb_obj_t *)*ii);
4b58e58c78da Add missing file
wycc
parents:
diff changeset
306 m->app = app;
4b58e58c78da Add missing file
wycc
parents:
diff changeset
307 m->sprite = sp;
4b58e58c78da Add missing file
wycc
parents:
diff changeset
308 m->top = 0;
4b58e58c78da Add missing file
wycc
parents:
diff changeset
309 m->cur = 0;
4b58e58c78da Add missing file
wycc
parents:
diff changeset
310 m->ready = 1;
4b58e58c78da Add missing file
wycc
parents:
diff changeset
311 m->max = i;
4b58e58c78da Add missing file
wycc
parents:
diff changeset
312 m->menus_y = (int *) (m->items+ii);
4b58e58c78da Add missing file
wycc
parents:
diff changeset
313 m->objects = (mb_obj_t **) (m->menus_y+ii);
4b58e58c78da Add missing file
wycc
parents:
diff changeset
314 m->callback = NULL;
4b58e58c78da Add missing file
wycc
parents:
diff changeset
315 m->speed = 300000;
4b58e58c78da Add missing file
wycc
parents:
diff changeset
316 for(i=0;i<9;i++) {
4b58e58c78da Add missing file
wycc
parents:
diff changeset
317 m->items[i] = i;
4b58e58c78da Add missing file
wycc
parents:
diff changeset
318 snprintf(name,sizeof(name),"%s%d", objnames, i+1);
4b58e58c78da Add missing file
wycc
parents:
diff changeset
319 l = MB_SPRITE_GET_OBJ(sp,name);
4b58e58c78da Add missing file
wycc
parents:
diff changeset
320 if (l == NULL) {
4b58e58c78da Add missing file
wycc
parents:
diff changeset
321 fprintf(stderr,"Can not find symbol %s\n",name);
4b58e58c78da Add missing file
wycc
parents:
diff changeset
322 }
4b58e58c78da Add missing file
wycc
parents:
diff changeset
323 m->objects[i] = (mb_obj_t *) l;
4b58e58c78da Add missing file
wycc
parents:
diff changeset
324 m->menus_y[i] = coord_y((coord_t*)l);
4b58e58c78da Add missing file
wycc
parents:
diff changeset
325 }
4b58e58c78da Add missing file
wycc
parents:
diff changeset
326 m->titles = menus;
4b58e58c78da Add missing file
wycc
parents:
diff changeset
327 snprintf(name,sizeof(name), "%s_lightbar", objnames);
4b58e58c78da Add missing file
wycc
parents:
diff changeset
328 m->lightbar = (mb_obj_t *) MB_SPRITE_GET_OBJ(sp,name);
4b58e58c78da Add missing file
wycc
parents:
diff changeset
329 if (m->lightbar==NULL)
4b58e58c78da Add missing file
wycc
parents:
diff changeset
330 fprintf(stderr,"Can not find object %s\n",name);
4b58e58c78da Add missing file
wycc
parents:
diff changeset
331 mb_animated_menu_fillMenuContent(m);
4b58e58c78da Add missing file
wycc
parents:
diff changeset
332 subject_add_observer(MBAPP_keySubject(app), mb_animated_menu_keyHandler,m);
4b58e58c78da Add missing file
wycc
parents:
diff changeset
333 return m;
4b58e58c78da Add missing file
wycc
parents:
diff changeset
334 }
4b58e58c78da Add missing file
wycc
parents:
diff changeset
335
4b58e58c78da Add missing file
wycc
parents:
diff changeset
336 void mb_animated_menu_set_titles(mb_animated_menu_t *m, char *menus[])
4b58e58c78da Add missing file
wycc
parents:
diff changeset
337 {
4b58e58c78da Add missing file
wycc
parents:
diff changeset
338 int i;
4b58e58c78da Add missing file
wycc
parents:
diff changeset
339 for(i=0;menus[i];i++);
4b58e58c78da Add missing file
wycc
parents:
diff changeset
340
4b58e58c78da Add missing file
wycc
parents:
diff changeset
341 m->max = i;
4b58e58c78da Add missing file
wycc
parents:
diff changeset
342 m->top = 0;
4b58e58c78da Add missing file
wycc
parents:
diff changeset
343 m->cur = 0;
4b58e58c78da Add missing file
wycc
parents:
diff changeset
344 m->titles = menus;
4b58e58c78da Add missing file
wycc
parents:
diff changeset
345 mb_animated_menu_fillMenuContent(m);
4b58e58c78da Add missing file
wycc
parents:
diff changeset
346 }
4b58e58c78da Add missing file
wycc
parents:
diff changeset
347
4b58e58c78da Add missing file
wycc
parents:
diff changeset
348
4b58e58c78da Add missing file
wycc
parents:
diff changeset
349 void mb_animated_menu_set_speed(mb_animated_menu_t *m,int speed)
4b58e58c78da Add missing file
wycc
parents:
diff changeset
350 {
4b58e58c78da Add missing file
wycc
parents:
diff changeset
351 m->speed = speed*1000;
4b58e58c78da Add missing file
wycc
parents:
diff changeset
352 }
4b58e58c78da Add missing file
wycc
parents:
diff changeset
353
4b58e58c78da Add missing file
wycc
parents:
diff changeset
354 int mb_animated_menu_get_speed(mb_animated_menu_t *m)
4b58e58c78da Add missing file
wycc
parents:
diff changeset
355 {
4b58e58c78da Add missing file
wycc
parents:
diff changeset
356 return m->speed/1000;
4b58e58c78da Add missing file
wycc
parents:
diff changeset
357 }