annotate src/mbaf/animated_menu.c @ 368:080aca2b7c47

Move the animated menu to the MBAF layer
author wycc
date Mon, 16 Mar 2009 08:45:54 +0800
parents examples/menu/animated_menu.c@ab7f3c00fd05
children 9b8dda201ccb
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>
325
4453ea44a83d Remove the menu.h
root@localhost.localdomain
parents: 321
diff changeset
4 //#include "menu.h"
318
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>
344
ab7f3c00fd05 Implement PMNG viewer
wycc
parents: 332
diff changeset
7 static void mb_animated_menu_update(mb_animated_menu_t *m);
318
4b58e58c78da Add missing file
wycc
parents:
diff changeset
8 static void set_text(coord_t *g, char *text)
4b58e58c78da Add missing file
wycc
parents:
diff changeset
9 {
4b58e58c78da Add missing file
wycc
parents:
diff changeset
10 geo_t *geo;
4b58e58c78da Add missing file
wycc
parents:
diff changeset
11 shape_t *shape;
4b58e58c78da Add missing file
wycc
parents:
diff changeset
12
4b58e58c78da Add missing file
wycc
parents:
diff changeset
13 FOR_COORD_MEMBERS(g, geo) {
4b58e58c78da Add missing file
wycc
parents:
diff changeset
14 shape = geo_get_shape(geo);
4b58e58c78da Add missing file
wycc
parents:
diff changeset
15 if(shape->obj.obj_type == MBO_TEXT) {
4b58e58c78da Add missing file
wycc
parents:
diff changeset
16 sh_text_set_text(shape, text);
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
4b58e58c78da Add missing file
wycc
parents:
diff changeset
21 static void mb_animated_menu_fillMenuContent(mb_animated_menu_t *m)
4b58e58c78da Add missing file
wycc
parents:
diff changeset
22 {
4b58e58c78da Add missing file
wycc
parents:
diff changeset
23 int i;
4b58e58c78da Add missing file
wycc
parents:
diff changeset
24 coord_t *textgroup;
4b58e58c78da Add missing file
wycc
parents:
diff changeset
25 shape_t *text;
4b58e58c78da Add missing file
wycc
parents:
diff changeset
26 coord_t *group;
4b58e58c78da Add missing file
wycc
parents:
diff changeset
27 coord_t *lightbar;
4b58e58c78da Add missing file
wycc
parents:
diff changeset
28 int tmp;
4b58e58c78da Add missing file
wycc
parents:
diff changeset
29 mb_timeval_t start, playing, now;
4b58e58c78da Add missing file
wycc
parents:
diff changeset
30 mb_progm_t *progm;
4b58e58c78da Add missing file
wycc
parents:
diff changeset
31 mb_word_t *word;
4b58e58c78da Add missing file
wycc
parents:
diff changeset
32
4b58e58c78da Add missing file
wycc
parents:
diff changeset
33 printf("max item is %d\n", m->max);
4b58e58c78da Add missing file
wycc
parents:
diff changeset
34 // fill new item
4b58e58c78da Add missing file
wycc
parents:
diff changeset
35 for(i=0;i<8;i++) {
4b58e58c78da Add missing file
wycc
parents:
diff changeset
36 group = (coord_t *) m->objects[m->items[i]];
4b58e58c78da Add missing file
wycc
parents:
diff changeset
37 if (i < m->max)
4b58e58c78da Add missing file
wycc
parents:
diff changeset
38 set_text(group, m->titles[m->top+i]);
4b58e58c78da Add missing file
wycc
parents:
diff changeset
39 else
4b58e58c78da Add missing file
wycc
parents:
diff changeset
40 set_text(group, "");
4b58e58c78da Add missing file
wycc
parents:
diff changeset
41 rdman_coord_changed(MBAPP_RDMAN(m->app),group);
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
4b58e58c78da Add missing file
wycc
parents:
diff changeset
45 textgroup = (coord_t *) m->objects[m->items[i]];
4b58e58c78da Add missing file
wycc
parents:
diff changeset
46 coord_hide(textgroup);
4b58e58c78da Add missing file
wycc
parents:
diff changeset
47 rdman_coord_changed(MBAPP_RDMAN(m->app),textgroup);
4b58e58c78da Add missing file
wycc
parents:
diff changeset
48
4b58e58c78da Add missing file
wycc
parents:
diff changeset
49 lightbar = (coord_t *) m->lightbar;
4b58e58c78da Add missing file
wycc
parents:
diff changeset
50 group = (coord_t *) m->objects[m->cur];
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
332
f90c60967a9c Add mb_progm_finish to terminate the current animation and put all objects in the final position.
wycc
parents: 329
diff changeset
81 m->progm = progm = mb_progm_new(2, MBAPP_RDMAN(m->app));
318
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;
321
44cc65e7e234 Use relative path in the SVG file
wycc
parents: 318
diff changeset
122 printf("fill menu\n");
318
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
4b58e58c78da Add missing file
wycc
parents:
diff changeset
126 static void mb_animated_menu_fillMenuContentDown(mb_animated_menu_t *m)
4b58e58c78da Add missing file
wycc
parents:
diff changeset
127 {
4b58e58c78da Add missing file
wycc
parents:
diff changeset
128 int i;
4b58e58c78da Add missing file
wycc
parents:
diff changeset
129 coord_t *textgroup;
4b58e58c78da Add missing file
wycc
parents:
diff changeset
130 shape_t *text;
4b58e58c78da Add missing file
wycc
parents:
diff changeset
131 coord_t *group;
4b58e58c78da Add missing file
wycc
parents:
diff changeset
132 coord_t *lightbar;
4b58e58c78da Add missing file
wycc
parents:
diff changeset
133 char name[255];
4b58e58c78da Add missing file
wycc
parents:
diff changeset
134 int tmp;
4b58e58c78da Add missing file
wycc
parents:
diff changeset
135 mb_timeval_t start, playing, now;
4b58e58c78da Add missing file
wycc
parents:
diff changeset
136 mb_progm_t *progm;
4b58e58c78da Add missing file
wycc
parents:
diff changeset
137 mb_word_t *word;
4b58e58c78da Add missing file
wycc
parents:
diff changeset
138
4b58e58c78da Add missing file
wycc
parents:
diff changeset
139
4b58e58c78da Add missing file
wycc
parents:
diff changeset
140 // fill new item
4b58e58c78da Add missing file
wycc
parents:
diff changeset
141 set_text((coord_t *)m->objects[m->items[8]], m->titles[m->top+7]);
4b58e58c78da Add missing file
wycc
parents:
diff changeset
142
332
f90c60967a9c Add mb_progm_finish to terminate the current animation and put all objects in the final position.
wycc
parents: 329
diff changeset
143 m->progm = progm = mb_progm_new(2, MBAPP_RDMAN(m->app));
318
4b58e58c78da Add missing file
wycc
parents:
diff changeset
144 MB_TIMEVAL_SET(&start, 0, 0);
4b58e58c78da Add missing file
wycc
parents:
diff changeset
145 MB_TIMEVAL_SET(&playing, 0, m->speed);
4b58e58c78da Add missing file
wycc
parents:
diff changeset
146 word = mb_progm_next_word(progm, &start, &playing);
4b58e58c78da Add missing file
wycc
parents:
diff changeset
147 get_now(&now);
4b58e58c78da Add missing file
wycc
parents:
diff changeset
148
4b58e58c78da Add missing file
wycc
parents:
diff changeset
149 for(i=1;i<8;i++) {
4b58e58c78da Add missing file
wycc
parents:
diff changeset
150 //shift to the next item
4b58e58c78da Add missing file
wycc
parents:
diff changeset
151 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
152 }
4b58e58c78da Add missing file
wycc
parents:
diff changeset
153 // fade out the item[0]
4b58e58c78da Add missing file
wycc
parents:
diff changeset
154 mb_shift_new(0,-100, (coord_t *)m->objects[m->items[0]],word);
4b58e58c78da Add missing file
wycc
parents:
diff changeset
155
4b58e58c78da Add missing file
wycc
parents:
diff changeset
156 // fade in the item[8]
4b58e58c78da Add missing file
wycc
parents:
diff changeset
157 coord_y((coord_t *)m->objects[m->items[8]]) = m->menus_y[7]+100;
4b58e58c78da Add missing file
wycc
parents:
diff changeset
158 coord_show(((coord_t *)(m->objects[m->items[8]])));
4b58e58c78da Add missing file
wycc
parents:
diff changeset
159 mb_shift_new(0,-100, (coord_t *)m->objects[m->items[8]],word);
4b58e58c78da Add missing file
wycc
parents:
diff changeset
160
4b58e58c78da Add missing file
wycc
parents:
diff changeset
161 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
162
4b58e58c78da Add missing file
wycc
parents:
diff changeset
163 MB_TIMEVAL_SET(&start, 0, m->speed);
4b58e58c78da Add missing file
wycc
parents:
diff changeset
164 MB_TIMEVAL_SET(&playing, 0, 0);
4b58e58c78da Add missing file
wycc
parents:
diff changeset
165 word = mb_progm_next_word(progm, &start, &playing);
4b58e58c78da Add missing file
wycc
parents:
diff changeset
166 mb_visibility_new(VIS_VISIBLE, (coord_t *) m->objects[m->items[0]],word);
4b58e58c78da Add missing file
wycc
parents:
diff changeset
167
4b58e58c78da Add missing file
wycc
parents:
diff changeset
168 mb_progm_free_completed(progm);
4b58e58c78da Add missing file
wycc
parents:
diff changeset
169 m->ready--;
4b58e58c78da Add missing file
wycc
parents:
diff changeset
170 subject_add_observer(mb_progm_get_complete(progm), mb_animated_menu_complete,m);
4b58e58c78da Add missing file
wycc
parents:
diff changeset
171 mb_progm_start(progm, X_MB_tman(MBAPP_RDMAN(m->app)->rt), &now);
4b58e58c78da Add missing file
wycc
parents:
diff changeset
172 rdman_redraw_changed(MBAPP_RDMAN(m->app));
4b58e58c78da Add missing file
wycc
parents:
diff changeset
173 tmp = m->items[0];
4b58e58c78da Add missing file
wycc
parents:
diff changeset
174 for(i=0;i<8;i++) {
4b58e58c78da Add missing file
wycc
parents:
diff changeset
175 m->items[i] = m->items[i+1];
4b58e58c78da Add missing file
wycc
parents:
diff changeset
176 }
4b58e58c78da Add missing file
wycc
parents:
diff changeset
177 m->items[8] = tmp;
4b58e58c78da Add missing file
wycc
parents:
diff changeset
178 }
4b58e58c78da Add missing file
wycc
parents:
diff changeset
179
4b58e58c78da Add missing file
wycc
parents:
diff changeset
180 void mb_animated_menu_moveLightBar(mb_animated_menu_t *m)
4b58e58c78da Add missing file
wycc
parents:
diff changeset
181 {
4b58e58c78da Add missing file
wycc
parents:
diff changeset
182 mb_timeval_t start, playing, now;
4b58e58c78da Add missing file
wycc
parents:
diff changeset
183 mb_progm_t *progm;
4b58e58c78da Add missing file
wycc
parents:
diff changeset
184 mb_word_t *word;
4b58e58c78da Add missing file
wycc
parents:
diff changeset
185 coord_t *group;
4b58e58c78da Add missing file
wycc
parents:
diff changeset
186 coord_t *lightbar;
4b58e58c78da Add missing file
wycc
parents:
diff changeset
187
332
f90c60967a9c Add mb_progm_finish to terminate the current animation and put all objects in the final position.
wycc
parents: 329
diff changeset
188 m->progm = progm = mb_progm_new(1, MBAPP_RDMAN(m->app));
318
4b58e58c78da Add missing file
wycc
parents:
diff changeset
189 MB_TIMEVAL_SET(&start, 0, 0);
4b58e58c78da Add missing file
wycc
parents:
diff changeset
190 MB_TIMEVAL_SET(&playing, 0, m->speed);
4b58e58c78da Add missing file
wycc
parents:
diff changeset
191 word = mb_progm_next_word(progm, &start, &playing);
4b58e58c78da Add missing file
wycc
parents:
diff changeset
192 get_now(&now);
4b58e58c78da Add missing file
wycc
parents:
diff changeset
193
4b58e58c78da Add missing file
wycc
parents:
diff changeset
194 lightbar = (coord_t *) m->lightbar;
4b58e58c78da Add missing file
wycc
parents:
diff changeset
195 mb_shift_new(0,m->menus_y[m->cur]-coord_y(lightbar),lightbar,word);
4b58e58c78da Add missing file
wycc
parents:
diff changeset
196 mb_progm_free_completed(progm);
4b58e58c78da Add missing file
wycc
parents:
diff changeset
197 m->ready--;
4b58e58c78da Add missing file
wycc
parents:
diff changeset
198 subject_add_observer(mb_progm_get_complete(progm), mb_animated_menu_complete,m);
4b58e58c78da Add missing file
wycc
parents:
diff changeset
199 mb_progm_start(progm, X_MB_tman(MBAPP_RDMAN(m->app)->rt), &now);
4b58e58c78da Add missing file
wycc
parents:
diff changeset
200 rdman_redraw_changed(MBAPP_RDMAN(m->app));
4b58e58c78da Add missing file
wycc
parents:
diff changeset
201 }
4b58e58c78da Add missing file
wycc
parents:
diff changeset
202
4b58e58c78da Add missing file
wycc
parents:
diff changeset
203 static void mb_animated_menu_up(mb_animated_menu_t *m)
4b58e58c78da Add missing file
wycc
parents:
diff changeset
204 {
4b58e58c78da Add missing file
wycc
parents:
diff changeset
205 if (m->cur > 5) {
4b58e58c78da Add missing file
wycc
parents:
diff changeset
206 m->cur--;
4b58e58c78da Add missing file
wycc
parents:
diff changeset
207 mb_animated_menu_moveLightBar(m);
344
ab7f3c00fd05 Implement PMNG viewer
wycc
parents: 332
diff changeset
208 mb_animated_menu_update(m);
318
4b58e58c78da Add missing file
wycc
parents:
diff changeset
209 } else {
4b58e58c78da Add missing file
wycc
parents:
diff changeset
210 if (m->top > 0) {
4b58e58c78da Add missing file
wycc
parents:
diff changeset
211 m->top--;
4b58e58c78da Add missing file
wycc
parents:
diff changeset
212 mb_animated_menu_fillMenuContentUp(m);
344
ab7f3c00fd05 Implement PMNG viewer
wycc
parents: 332
diff changeset
213 mb_animated_menu_update(m);
318
4b58e58c78da Add missing file
wycc
parents:
diff changeset
214 } else {
4b58e58c78da Add missing file
wycc
parents:
diff changeset
215 if (m->cur == 0)
4b58e58c78da Add missing file
wycc
parents:
diff changeset
216 return;
4b58e58c78da Add missing file
wycc
parents:
diff changeset
217 m->cur--;
4b58e58c78da Add missing file
wycc
parents:
diff changeset
218 mb_animated_menu_moveLightBar(m);
344
ab7f3c00fd05 Implement PMNG viewer
wycc
parents: 332
diff changeset
219 mb_animated_menu_update(m);
318
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 }
4b58e58c78da Add missing file
wycc
parents:
diff changeset
223 static void mb_animated_menu_down(mb_animated_menu_t *m)
4b58e58c78da Add missing file
wycc
parents:
diff changeset
224 {
4b58e58c78da Add missing file
wycc
parents:
diff changeset
225
4b58e58c78da Add missing file
wycc
parents:
diff changeset
226 if (m->cur < 5) {
4b58e58c78da Add missing file
wycc
parents:
diff changeset
227 if (m->top+m->cur <= m->max) {
4b58e58c78da Add missing file
wycc
parents:
diff changeset
228 m->cur++;
4b58e58c78da Add missing file
wycc
parents:
diff changeset
229 mb_animated_menu_moveLightBar(m);
344
ab7f3c00fd05 Implement PMNG viewer
wycc
parents: 332
diff changeset
230 mb_animated_menu_update(m);
318
4b58e58c78da Add missing file
wycc
parents:
diff changeset
231 }
4b58e58c78da Add missing file
wycc
parents:
diff changeset
232 } else {
4b58e58c78da Add missing file
wycc
parents:
diff changeset
233 if ((m->top+8) < m->max-1) {
4b58e58c78da Add missing file
wycc
parents:
diff changeset
234 m->top++;
4b58e58c78da Add missing file
wycc
parents:
diff changeset
235 mb_animated_menu_fillMenuContentDown(m);
344
ab7f3c00fd05 Implement PMNG viewer
wycc
parents: 332
diff changeset
236 mb_animated_menu_update(m);
318
4b58e58c78da Add missing file
wycc
parents:
diff changeset
237 } else {
4b58e58c78da Add missing file
wycc
parents:
diff changeset
238 if (m->cur+m->top < m->max-1) {
4b58e58c78da Add missing file
wycc
parents:
diff changeset
239 m->cur++;
4b58e58c78da Add missing file
wycc
parents:
diff changeset
240 mb_animated_menu_moveLightBar(m);
344
ab7f3c00fd05 Implement PMNG viewer
wycc
parents: 332
diff changeset
241 mb_animated_menu_update(m);
318
4b58e58c78da Add missing file
wycc
parents:
diff changeset
242 } else
4b58e58c78da Add missing file
wycc
parents:
diff changeset
243 return;
4b58e58c78da Add missing file
wycc
parents:
diff changeset
244 }
4b58e58c78da Add missing file
wycc
parents:
diff changeset
245 }
4b58e58c78da Add missing file
wycc
parents:
diff changeset
246 }
4b58e58c78da Add missing file
wycc
parents:
diff changeset
247
344
ab7f3c00fd05 Implement PMNG viewer
wycc
parents: 332
diff changeset
248 void mb_animated_menu_set_update_callback(mb_animated_menu_t *m, void (*f)(mb_animated_menu_t *m, int sel))
ab7f3c00fd05 Implement PMNG viewer
wycc
parents: 332
diff changeset
249 {
ab7f3c00fd05 Implement PMNG viewer
wycc
parents: 332
diff changeset
250 m->update_callback = f;
ab7f3c00fd05 Implement PMNG viewer
wycc
parents: 332
diff changeset
251 }
318
4b58e58c78da Add missing file
wycc
parents:
diff changeset
252 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
253 {
4b58e58c78da Add missing file
wycc
parents:
diff changeset
254 m->callback = f;
4b58e58c78da Add missing file
wycc
parents:
diff changeset
255 }
344
ab7f3c00fd05 Implement PMNG viewer
wycc
parents: 332
diff changeset
256 static void mb_animated_menu_update(mb_animated_menu_t *m)
ab7f3c00fd05 Implement PMNG viewer
wycc
parents: 332
diff changeset
257 {
ab7f3c00fd05 Implement PMNG viewer
wycc
parents: 332
diff changeset
258 if (m->update_callback)
ab7f3c00fd05 Implement PMNG viewer
wycc
parents: 332
diff changeset
259 m->update_callback(m,m->top+m->cur);
ab7f3c00fd05 Implement PMNG viewer
wycc
parents: 332
diff changeset
260
ab7f3c00fd05 Implement PMNG viewer
wycc
parents: 332
diff changeset
261 }
318
4b58e58c78da Add missing file
wycc
parents:
diff changeset
262 static void mb_animated_menu_select(mb_animated_menu_t *m)
4b58e58c78da Add missing file
wycc
parents:
diff changeset
263 {
4b58e58c78da Add missing file
wycc
parents:
diff changeset
264 if (m->callback)
4b58e58c78da Add missing file
wycc
parents:
diff changeset
265 m->callback(m,m->top+m->cur);
4b58e58c78da Add missing file
wycc
parents:
diff changeset
266 }
4b58e58c78da Add missing file
wycc
parents:
diff changeset
267
332
f90c60967a9c Add mb_progm_finish to terminate the current animation and put all objects in the final position.
wycc
parents: 329
diff changeset
268 // Send the pending key in the animation progm complete callback
f90c60967a9c Add mb_progm_finish to terminate the current animation and put all objects in the final position.
wycc
parents: 329
diff changeset
269 static void mb_animated_menu_keyHandler(event_t *ev, void *arg);
f90c60967a9c Add mb_progm_finish to terminate the current animation and put all objects in the final position.
wycc
parents: 329
diff changeset
270 static void mb_animated_menu_send_pending_key(event_t *ev,void *arg)
f90c60967a9c Add mb_progm_finish to terminate the current animation and put all objects in the final position.
wycc
parents: 329
diff changeset
271 {
f90c60967a9c Add mb_progm_finish to terminate the current animation and put all objects in the final position.
wycc
parents: 329
diff changeset
272 mb_animated_menu_t *m = (mb_animated_menu_t *) arg;
f90c60967a9c Add mb_progm_finish to terminate the current animation and put all objects in the final position.
wycc
parents: 329
diff changeset
273
f90c60967a9c Add mb_progm_finish to terminate the current animation and put all objects in the final position.
wycc
parents: 329
diff changeset
274 if (m->ready<=0)
f90c60967a9c Add mb_progm_finish to terminate the current animation and put all objects in the final position.
wycc
parents: 329
diff changeset
275 mb_animated_menu_keyHandler((event_t *) &m->pending_key,m);
f90c60967a9c Add mb_progm_finish to terminate the current animation and put all objects in the final position.
wycc
parents: 329
diff changeset
276 }
318
4b58e58c78da Add missing file
wycc
parents:
diff changeset
277 static void mb_animated_menu_keyHandler(event_t *ev, void *arg)
4b58e58c78da Add missing file
wycc
parents:
diff changeset
278 {
4b58e58c78da Add missing file
wycc
parents:
diff changeset
279 mb_animated_menu_t *m = (mb_animated_menu_t *) arg;
4b58e58c78da Add missing file
wycc
parents:
diff changeset
280 X_kb_event_t *xkey = (X_kb_event_t *)ev;
4b58e58c78da Add missing file
wycc
parents:
diff changeset
281 if(xkey->event.type != EVT_KB_PRESS) {
4b58e58c78da Add missing file
wycc
parents:
diff changeset
282 return;
4b58e58c78da Add missing file
wycc
parents:
diff changeset
283 }
4b58e58c78da Add missing file
wycc
parents:
diff changeset
284 printf("read=%d\n",m->ready);
332
f90c60967a9c Add mb_progm_finish to terminate the current animation and put all objects in the final position.
wycc
parents: 329
diff changeset
285 if (m->ready<=0) {
f90c60967a9c Add mb_progm_finish to terminate the current animation and put all objects in the final position.
wycc
parents: 329
diff changeset
286 subject_add_observer(mb_progm_get_complete(m->progm), mb_animated_menu_send_pending_key,m);
f90c60967a9c Add mb_progm_finish to terminate the current animation and put all objects in the final position.
wycc
parents: 329
diff changeset
287 mb_progm_finish(m->progm);
f90c60967a9c Add mb_progm_finish to terminate the current animation and put all objects in the final position.
wycc
parents: 329
diff changeset
288 m->pending_key = *xkey;
f90c60967a9c Add mb_progm_finish to terminate the current animation and put all objects in the final position.
wycc
parents: 329
diff changeset
289 return;
f90c60967a9c Add mb_progm_finish to terminate the current animation and put all objects in the final position.
wycc
parents: 329
diff changeset
290 }
318
4b58e58c78da Add missing file
wycc
parents:
diff changeset
291 switch(xkey->sym) {
4b58e58c78da Add missing file
wycc
parents:
diff changeset
292 case 0xff51: /* left */
4b58e58c78da Add missing file
wycc
parents:
diff changeset
293 break;
4b58e58c78da Add missing file
wycc
parents:
diff changeset
294
4b58e58c78da Add missing file
wycc
parents:
diff changeset
295 case 0xff52: /* up */
4b58e58c78da Add missing file
wycc
parents:
diff changeset
296 mb_animated_menu_up(m);
4b58e58c78da Add missing file
wycc
parents:
diff changeset
297 break;
4b58e58c78da Add missing file
wycc
parents:
diff changeset
298
4b58e58c78da Add missing file
wycc
parents:
diff changeset
299 case 0xff53: /* right */
4b58e58c78da Add missing file
wycc
parents:
diff changeset
300 break;
4b58e58c78da Add missing file
wycc
parents:
diff changeset
301
4b58e58c78da Add missing file
wycc
parents:
diff changeset
302 case 0xff54: /* down */
4b58e58c78da Add missing file
wycc
parents:
diff changeset
303 mb_animated_menu_down(m);
4b58e58c78da Add missing file
wycc
parents:
diff changeset
304 break;
4b58e58c78da Add missing file
wycc
parents:
diff changeset
305
4b58e58c78da Add missing file
wycc
parents:
diff changeset
306 case 0xff0d: /* enter */
4b58e58c78da Add missing file
wycc
parents:
diff changeset
307 mb_animated_menu_select(m);
4b58e58c78da Add missing file
wycc
parents:
diff changeset
308 break;
4b58e58c78da Add missing file
wycc
parents:
diff changeset
309 default:
4b58e58c78da Add missing file
wycc
parents:
diff changeset
310 return;
4b58e58c78da Add missing file
wycc
parents:
diff changeset
311 }
4b58e58c78da Add missing file
wycc
parents:
diff changeset
312 }
4b58e58c78da Add missing file
wycc
parents:
diff changeset
313
4b58e58c78da Add missing file
wycc
parents:
diff changeset
314 /** \brief Create an instace of animated menu.
4b58e58c78da Add missing file
wycc
parents:
diff changeset
315 *
4b58e58c78da Add missing file
wycc
parents:
diff changeset
316 * The objectnames is used to extract symbols from the SVG file.
4b58e58c78da Add missing file
wycc
parents:
diff changeset
317 * ${objectnames}0 - ${objectnames}8 is the text object.
4b58e58c78da Add missing file
wycc
parents:
diff changeset
318 * ${objectnames}_lightbar is the lightbar.
4b58e58c78da Add missing file
wycc
parents:
diff changeset
319 *
4b58e58c78da Add missing file
wycc
parents:
diff changeset
320 */
4b58e58c78da Add missing file
wycc
parents:
diff changeset
321 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
322 {
4b58e58c78da Add missing file
wycc
parents:
diff changeset
323 mb_animated_menu_t *m;
4b58e58c78da Add missing file
wycc
parents:
diff changeset
324 int i,len;
4b58e58c78da Add missing file
wycc
parents:
diff changeset
325 char name[255];
4b58e58c78da Add missing file
wycc
parents:
diff changeset
326 mb_obj_t *l;
4b58e58c78da Add missing file
wycc
parents:
diff changeset
327 int ii;
4b58e58c78da Add missing file
wycc
parents:
diff changeset
328
4b58e58c78da Add missing file
wycc
parents:
diff changeset
329 if (menus == NULL)
4b58e58c78da Add missing file
wycc
parents:
diff changeset
330 i=0;
4b58e58c78da Add missing file
wycc
parents:
diff changeset
331 else
4b58e58c78da Add missing file
wycc
parents:
diff changeset
332 for(i=0;menus[i];i++);
4b58e58c78da Add missing file
wycc
parents:
diff changeset
333 ii=9;
4b58e58c78da Add missing file
wycc
parents:
diff changeset
334
4b58e58c78da Add missing file
wycc
parents:
diff changeset
335 m = (mb_animated_menu_t *) malloc(sizeof(mb_animated_menu_t));
4b58e58c78da Add missing file
wycc
parents:
diff changeset
336 m->items = (int *) malloc(sizeof(int)*ii*2+sizeof(mb_obj_t *)*ii);
4b58e58c78da Add missing file
wycc
parents:
diff changeset
337 m->app = app;
4b58e58c78da Add missing file
wycc
parents:
diff changeset
338 m->sprite = sp;
4b58e58c78da Add missing file
wycc
parents:
diff changeset
339 m->top = 0;
4b58e58c78da Add missing file
wycc
parents:
diff changeset
340 m->cur = 0;
4b58e58c78da Add missing file
wycc
parents:
diff changeset
341 m->ready = 1;
4b58e58c78da Add missing file
wycc
parents:
diff changeset
342 m->max = i;
4b58e58c78da Add missing file
wycc
parents:
diff changeset
343 m->menus_y = (int *) (m->items+ii);
4b58e58c78da Add missing file
wycc
parents:
diff changeset
344 m->objects = (mb_obj_t **) (m->menus_y+ii);
4b58e58c78da Add missing file
wycc
parents:
diff changeset
345 m->callback = NULL;
344
ab7f3c00fd05 Implement PMNG viewer
wycc
parents: 332
diff changeset
346 m->update_callback = NULL;
318
4b58e58c78da Add missing file
wycc
parents:
diff changeset
347 m->speed = 300000;
4b58e58c78da Add missing file
wycc
parents:
diff changeset
348 for(i=0;i<9;i++) {
4b58e58c78da Add missing file
wycc
parents:
diff changeset
349 m->items[i] = i;
4b58e58c78da Add missing file
wycc
parents:
diff changeset
350 snprintf(name,sizeof(name),"%s%d", objnames, i+1);
4b58e58c78da Add missing file
wycc
parents:
diff changeset
351 l = MB_SPRITE_GET_OBJ(sp,name);
4b58e58c78da Add missing file
wycc
parents:
diff changeset
352 if (l == NULL) {
4b58e58c78da Add missing file
wycc
parents:
diff changeset
353 fprintf(stderr,"Can not find symbol %s\n",name);
4b58e58c78da Add missing file
wycc
parents:
diff changeset
354 }
4b58e58c78da Add missing file
wycc
parents:
diff changeset
355 m->objects[i] = (mb_obj_t *) l;
4b58e58c78da Add missing file
wycc
parents:
diff changeset
356 m->menus_y[i] = coord_y((coord_t*)l);
4b58e58c78da Add missing file
wycc
parents:
diff changeset
357 }
4b58e58c78da Add missing file
wycc
parents:
diff changeset
358 m->titles = menus;
4b58e58c78da Add missing file
wycc
parents:
diff changeset
359 snprintf(name,sizeof(name), "%s_lightbar", objnames);
4b58e58c78da Add missing file
wycc
parents:
diff changeset
360 m->lightbar = (mb_obj_t *) MB_SPRITE_GET_OBJ(sp,name);
4b58e58c78da Add missing file
wycc
parents:
diff changeset
361 if (m->lightbar==NULL)
4b58e58c78da Add missing file
wycc
parents:
diff changeset
362 fprintf(stderr,"Can not find object %s\n",name);
4b58e58c78da Add missing file
wycc
parents:
diff changeset
363 mb_animated_menu_fillMenuContent(m);
4b58e58c78da Add missing file
wycc
parents:
diff changeset
364 subject_add_observer(MBAPP_keySubject(app), mb_animated_menu_keyHandler,m);
4b58e58c78da Add missing file
wycc
parents:
diff changeset
365 return m;
4b58e58c78da Add missing file
wycc
parents:
diff changeset
366 }
4b58e58c78da Add missing file
wycc
parents:
diff changeset
367
4b58e58c78da Add missing file
wycc
parents:
diff changeset
368 void mb_animated_menu_set_titles(mb_animated_menu_t *m, char *menus[])
4b58e58c78da Add missing file
wycc
parents:
diff changeset
369 {
4b58e58c78da Add missing file
wycc
parents:
diff changeset
370 int i;
4b58e58c78da Add missing file
wycc
parents:
diff changeset
371 for(i=0;menus[i];i++);
4b58e58c78da Add missing file
wycc
parents:
diff changeset
372
4b58e58c78da Add missing file
wycc
parents:
diff changeset
373 m->max = i;
4b58e58c78da Add missing file
wycc
parents:
diff changeset
374 m->top = 0;
4b58e58c78da Add missing file
wycc
parents:
diff changeset
375 m->cur = 0;
4b58e58c78da Add missing file
wycc
parents:
diff changeset
376 m->titles = menus;
4b58e58c78da Add missing file
wycc
parents:
diff changeset
377 mb_animated_menu_fillMenuContent(m);
329
740844ee48c4 Update position of light-bar after update menu item
Thinker K.F. Li <thinker@branda.to>
parents: 328
diff changeset
378 mb_animated_menu_moveLightBar(m);
318
4b58e58c78da Add missing file
wycc
parents:
diff changeset
379 }
4b58e58c78da Add missing file
wycc
parents:
diff changeset
380
4b58e58c78da Add missing file
wycc
parents:
diff changeset
381
4b58e58c78da Add missing file
wycc
parents:
diff changeset
382 void mb_animated_menu_set_speed(mb_animated_menu_t *m,int speed)
4b58e58c78da Add missing file
wycc
parents:
diff changeset
383 {
4b58e58c78da Add missing file
wycc
parents:
diff changeset
384 m->speed = speed*1000;
4b58e58c78da Add missing file
wycc
parents:
diff changeset
385 }
4b58e58c78da Add missing file
wycc
parents:
diff changeset
386
4b58e58c78da Add missing file
wycc
parents:
diff changeset
387 int mb_animated_menu_get_speed(mb_animated_menu_t *m)
4b58e58c78da Add missing file
wycc
parents:
diff changeset
388 {
4b58e58c78da Add missing file
wycc
parents:
diff changeset
389 return m->speed/1000;
4b58e58c78da Add missing file
wycc
parents:
diff changeset
390 }