annotate src/mbaf/animated_menu.c @ 517:82c1ea2ba929 Android_Skia

Implement SurfaceHolder.Callback for waiting surface creature. SurfaceView should wait for surface being created. After that, user of SurfaceView can be used to draw graphics.
author Thinker K.F. Li <thinker@branda.to>
date Tue, 01 Dec 2009 22:55:27 +0800
parents 26c302b47de1
children f43224bf3524
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"
456
26c302b47de1 Change name of header files.
Thinker K.F. Li <thinker@branda.to>
parents: 455
diff changeset
5 #include "mb_af.h"
26c302b47de1 Change name of header files.
Thinker K.F. Li <thinker@branda.to>
parents: 455
diff changeset
6 #include "mb_ani_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 // 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, "");
454
9b8dda201ccb Make naming convention consistent with MadButterfly.
Thinker K.F. Li <thinker@branda.to>
parents: 368
diff changeset
40 rdman_coord_changed(MBAF_RDMAN(m->app),group);
318
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);
454
9b8dda201ccb Make naming convention consistent with MadButterfly.
Thinker K.F. Li <thinker@branda.to>
parents: 368
diff changeset
46 rdman_coord_changed(MBAF_RDMAN(m->app),textgroup);
318
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_y(lightbar) = coord_y(group);
454
9b8dda201ccb Make naming convention consistent with MadButterfly.
Thinker K.F. Li <thinker@branda.to>
parents: 368
diff changeset
51 rdman_coord_changed(MBAF_RDMAN(m->app),lightbar);
9b8dda201ccb Make naming convention consistent with MadButterfly.
Thinker K.F. Li <thinker@branda.to>
parents: 368
diff changeset
52 rdman_redraw_changed(MBAF_RDMAN(m->app));
318
4b58e58c78da Add missing file
wycc
parents:
diff changeset
53 }
4b58e58c78da Add missing file
wycc
parents:
diff changeset
54
4b58e58c78da Add missing file
wycc
parents:
diff changeset
55 static void mb_animated_menu_complete(event_t *ev,void *arg)
4b58e58c78da Add missing file
wycc
parents:
diff changeset
56 {
4b58e58c78da Add missing file
wycc
parents:
diff changeset
57 mb_animated_menu_t *m = (mb_animated_menu_t *) arg;
4b58e58c78da Add missing file
wycc
parents:
diff changeset
58
4b58e58c78da Add missing file
wycc
parents:
diff changeset
59 m->ready++;
4b58e58c78da Add missing file
wycc
parents:
diff changeset
60 }
4b58e58c78da Add missing file
wycc
parents:
diff changeset
61
4b58e58c78da Add missing file
wycc
parents:
diff changeset
62 static void mb_animated_menu_fillMenuContentUp(mb_animated_menu_t *m)
4b58e58c78da Add missing file
wycc
parents:
diff changeset
63 {
4b58e58c78da Add missing file
wycc
parents:
diff changeset
64 int i;
4b58e58c78da Add missing file
wycc
parents:
diff changeset
65 coord_t *textgroup;
4b58e58c78da Add missing file
wycc
parents:
diff changeset
66 shape_t *text;
4b58e58c78da Add missing file
wycc
parents:
diff changeset
67 coord_t *group;
4b58e58c78da Add missing file
wycc
parents:
diff changeset
68 coord_t *lightbar;
4b58e58c78da Add missing file
wycc
parents:
diff changeset
69 int tmp;
4b58e58c78da Add missing file
wycc
parents:
diff changeset
70 mb_timeval_t start, playing, now;
4b58e58c78da Add missing file
wycc
parents:
diff changeset
71 mb_progm_t *progm;
4b58e58c78da Add missing file
wycc
parents:
diff changeset
72 mb_word_t *word;
4b58e58c78da Add missing file
wycc
parents:
diff changeset
73
4b58e58c78da Add missing file
wycc
parents:
diff changeset
74
4b58e58c78da Add missing file
wycc
parents:
diff changeset
75 // fill new item
4b58e58c78da Add missing file
wycc
parents:
diff changeset
76 group = (coord_t *) m->objects[m->items[8]];
4b58e58c78da Add missing file
wycc
parents:
diff changeset
77 set_text(group, m->titles[m->top]);
4b58e58c78da Add missing file
wycc
parents:
diff changeset
78
454
9b8dda201ccb Make naming convention consistent with MadButterfly.
Thinker K.F. Li <thinker@branda.to>
parents: 368
diff changeset
79 m->progm = progm = mb_progm_new(2, MBAF_RDMAN(m->app));
318
4b58e58c78da Add missing file
wycc
parents:
diff changeset
80 MB_TIMEVAL_SET(&start, 0, 0);
4b58e58c78da Add missing file
wycc
parents:
diff changeset
81 MB_TIMEVAL_SET(&playing, 0, m->speed);
4b58e58c78da Add missing file
wycc
parents:
diff changeset
82 word = mb_progm_next_word(progm, &start, &playing);
4b58e58c78da Add missing file
wycc
parents:
diff changeset
83 get_now(&now);
4b58e58c78da Add missing file
wycc
parents:
diff changeset
84
4b58e58c78da Add missing file
wycc
parents:
diff changeset
85 for(i=0;i<7;i++) {
4b58e58c78da Add missing file
wycc
parents:
diff changeset
86 //shift to the next item
4b58e58c78da Add missing file
wycc
parents:
diff changeset
87 textgroup = (coord_t *) m->objects[m->items[i]];
4b58e58c78da Add missing file
wycc
parents:
diff changeset
88 mb_shift_new(0,m->menus_y[i+1]-coord_y(textgroup), textgroup,word);
4b58e58c78da Add missing file
wycc
parents:
diff changeset
89 }
4b58e58c78da Add missing file
wycc
parents:
diff changeset
90 // fade out the item[7]
4b58e58c78da Add missing file
wycc
parents:
diff changeset
91 textgroup = (coord_t *) m->objects[m->items[7]];
4b58e58c78da Add missing file
wycc
parents:
diff changeset
92 mb_shift_new(0,100, textgroup,word);
4b58e58c78da Add missing file
wycc
parents:
diff changeset
93
4b58e58c78da Add missing file
wycc
parents:
diff changeset
94 // fade in the item[8]
4b58e58c78da Add missing file
wycc
parents:
diff changeset
95 textgroup = (coord_t *) m->objects[m->items[8]];
4b58e58c78da Add missing file
wycc
parents:
diff changeset
96 group = (coord_t *) m->objects[m->items[0]];
4b58e58c78da Add missing file
wycc
parents:
diff changeset
97 coord_y(textgroup) = m->menus_y[0]-100;
4b58e58c78da Add missing file
wycc
parents:
diff changeset
98 coord_show(textgroup);
4b58e58c78da Add missing file
wycc
parents:
diff changeset
99 mb_shift_new(0,100, textgroup,word);
4b58e58c78da Add missing file
wycc
parents:
diff changeset
100
4b58e58c78da Add missing file
wycc
parents:
diff changeset
101 lightbar = (coord_t *) m->lightbar;
4b58e58c78da Add missing file
wycc
parents:
diff changeset
102 mb_shift_new(0,m->menus_y[m->cur]-coord_y(lightbar),lightbar,word);
4b58e58c78da Add missing file
wycc
parents:
diff changeset
103
4b58e58c78da Add missing file
wycc
parents:
diff changeset
104 MB_TIMEVAL_SET(&start, 0, m->speed);
4b58e58c78da Add missing file
wycc
parents:
diff changeset
105 MB_TIMEVAL_SET(&playing, 0, 0);
4b58e58c78da Add missing file
wycc
parents:
diff changeset
106 word = mb_progm_next_word(progm, &start, &playing);
4b58e58c78da Add missing file
wycc
parents:
diff changeset
107 textgroup = (coord_t *) m->objects[m->items[7]];
4b58e58c78da Add missing file
wycc
parents:
diff changeset
108 mb_visibility_new(VIS_HIDDEN, textgroup,word);
4b58e58c78da Add missing file
wycc
parents:
diff changeset
109
4b58e58c78da Add missing file
wycc
parents:
diff changeset
110 mb_progm_free_completed(progm);
4b58e58c78da Add missing file
wycc
parents:
diff changeset
111 m->ready--;
4b58e58c78da Add missing file
wycc
parents:
diff changeset
112 subject_add_observer(mb_progm_get_complete(progm), mb_animated_menu_complete,m);
454
9b8dda201ccb Make naming convention consistent with MadButterfly.
Thinker K.F. Li <thinker@branda.to>
parents: 368
diff changeset
113 mb_progm_start(progm, X_MB_tman(MBAF_RDMAN(m->app)->rt), &now);
9b8dda201ccb Make naming convention consistent with MadButterfly.
Thinker K.F. Li <thinker@branda.to>
parents: 368
diff changeset
114 rdman_redraw_changed(MBAF_RDMAN(m->app));
318
4b58e58c78da Add missing file
wycc
parents:
diff changeset
115 tmp = m->items[8];
4b58e58c78da Add missing file
wycc
parents:
diff changeset
116 for(i=8;i>0;i--) {
4b58e58c78da Add missing file
wycc
parents:
diff changeset
117 m->items[i] = m->items[i-1];
4b58e58c78da Add missing file
wycc
parents:
diff changeset
118 }
4b58e58c78da Add missing file
wycc
parents:
diff changeset
119 m->items[0] = tmp;
4b58e58c78da Add missing file
wycc
parents:
diff changeset
120 }
4b58e58c78da Add missing file
wycc
parents:
diff changeset
121
4b58e58c78da Add missing file
wycc
parents:
diff changeset
122
4b58e58c78da Add missing file
wycc
parents:
diff changeset
123 static void mb_animated_menu_fillMenuContentDown(mb_animated_menu_t *m)
4b58e58c78da Add missing file
wycc
parents:
diff changeset
124 {
4b58e58c78da Add missing file
wycc
parents:
diff changeset
125 int i;
4b58e58c78da Add missing file
wycc
parents:
diff changeset
126 coord_t *textgroup;
4b58e58c78da Add missing file
wycc
parents:
diff changeset
127 shape_t *text;
4b58e58c78da Add missing file
wycc
parents:
diff changeset
128 coord_t *group;
4b58e58c78da Add missing file
wycc
parents:
diff changeset
129 coord_t *lightbar;
4b58e58c78da Add missing file
wycc
parents:
diff changeset
130 char name[255];
4b58e58c78da Add missing file
wycc
parents:
diff changeset
131 int tmp;
4b58e58c78da Add missing file
wycc
parents:
diff changeset
132 mb_timeval_t start, playing, now;
4b58e58c78da Add missing file
wycc
parents:
diff changeset
133 mb_progm_t *progm;
4b58e58c78da Add missing file
wycc
parents:
diff changeset
134 mb_word_t *word;
4b58e58c78da Add missing file
wycc
parents:
diff changeset
135
4b58e58c78da Add missing file
wycc
parents:
diff changeset
136
4b58e58c78da Add missing file
wycc
parents:
diff changeset
137 // fill new item
4b58e58c78da Add missing file
wycc
parents:
diff changeset
138 set_text((coord_t *)m->objects[m->items[8]], m->titles[m->top+7]);
4b58e58c78da Add missing file
wycc
parents:
diff changeset
139
454
9b8dda201ccb Make naming convention consistent with MadButterfly.
Thinker K.F. Li <thinker@branda.to>
parents: 368
diff changeset
140 m->progm = progm = mb_progm_new(2, MBAF_RDMAN(m->app));
318
4b58e58c78da Add missing file
wycc
parents:
diff changeset
141 MB_TIMEVAL_SET(&start, 0, 0);
4b58e58c78da Add missing file
wycc
parents:
diff changeset
142 MB_TIMEVAL_SET(&playing, 0, m->speed);
4b58e58c78da Add missing file
wycc
parents:
diff changeset
143 word = mb_progm_next_word(progm, &start, &playing);
4b58e58c78da Add missing file
wycc
parents:
diff changeset
144 get_now(&now);
4b58e58c78da Add missing file
wycc
parents:
diff changeset
145
4b58e58c78da Add missing file
wycc
parents:
diff changeset
146 for(i=1;i<8;i++) {
4b58e58c78da Add missing file
wycc
parents:
diff changeset
147 //shift to the next item
4b58e58c78da Add missing file
wycc
parents:
diff changeset
148 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
149 }
4b58e58c78da Add missing file
wycc
parents:
diff changeset
150 // fade out the item[0]
4b58e58c78da Add missing file
wycc
parents:
diff changeset
151 mb_shift_new(0,-100, (coord_t *)m->objects[m->items[0]],word);
4b58e58c78da Add missing file
wycc
parents:
diff changeset
152
4b58e58c78da Add missing file
wycc
parents:
diff changeset
153 // fade in the item[8]
4b58e58c78da Add missing file
wycc
parents:
diff changeset
154 coord_y((coord_t *)m->objects[m->items[8]]) = m->menus_y[7]+100;
4b58e58c78da Add missing file
wycc
parents:
diff changeset
155 coord_show(((coord_t *)(m->objects[m->items[8]])));
4b58e58c78da Add missing file
wycc
parents:
diff changeset
156 mb_shift_new(0,-100, (coord_t *)m->objects[m->items[8]],word);
4b58e58c78da Add missing file
wycc
parents:
diff changeset
157
4b58e58c78da Add missing file
wycc
parents:
diff changeset
158 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
159
4b58e58c78da Add missing file
wycc
parents:
diff changeset
160 MB_TIMEVAL_SET(&start, 0, m->speed);
4b58e58c78da Add missing file
wycc
parents:
diff changeset
161 MB_TIMEVAL_SET(&playing, 0, 0);
4b58e58c78da Add missing file
wycc
parents:
diff changeset
162 word = mb_progm_next_word(progm, &start, &playing);
4b58e58c78da Add missing file
wycc
parents:
diff changeset
163 mb_visibility_new(VIS_VISIBLE, (coord_t *) m->objects[m->items[0]],word);
4b58e58c78da Add missing file
wycc
parents:
diff changeset
164
4b58e58c78da Add missing file
wycc
parents:
diff changeset
165 mb_progm_free_completed(progm);
4b58e58c78da Add missing file
wycc
parents:
diff changeset
166 m->ready--;
4b58e58c78da Add missing file
wycc
parents:
diff changeset
167 subject_add_observer(mb_progm_get_complete(progm), mb_animated_menu_complete,m);
454
9b8dda201ccb Make naming convention consistent with MadButterfly.
Thinker K.F. Li <thinker@branda.to>
parents: 368
diff changeset
168 mb_progm_start(progm, X_MB_tman(MBAF_RDMAN(m->app)->rt), &now);
9b8dda201ccb Make naming convention consistent with MadButterfly.
Thinker K.F. Li <thinker@branda.to>
parents: 368
diff changeset
169 rdman_redraw_changed(MBAF_RDMAN(m->app));
318
4b58e58c78da Add missing file
wycc
parents:
diff changeset
170 tmp = m->items[0];
4b58e58c78da Add missing file
wycc
parents:
diff changeset
171 for(i=0;i<8;i++) {
4b58e58c78da Add missing file
wycc
parents:
diff changeset
172 m->items[i] = m->items[i+1];
4b58e58c78da Add missing file
wycc
parents:
diff changeset
173 }
4b58e58c78da Add missing file
wycc
parents:
diff changeset
174 m->items[8] = tmp;
4b58e58c78da Add missing file
wycc
parents:
diff changeset
175 }
4b58e58c78da Add missing file
wycc
parents:
diff changeset
176
4b58e58c78da Add missing file
wycc
parents:
diff changeset
177 void mb_animated_menu_moveLightBar(mb_animated_menu_t *m)
4b58e58c78da Add missing file
wycc
parents:
diff changeset
178 {
4b58e58c78da Add missing file
wycc
parents:
diff changeset
179 mb_timeval_t start, playing, now;
4b58e58c78da Add missing file
wycc
parents:
diff changeset
180 mb_progm_t *progm;
4b58e58c78da Add missing file
wycc
parents:
diff changeset
181 mb_word_t *word;
4b58e58c78da Add missing file
wycc
parents:
diff changeset
182 coord_t *group;
4b58e58c78da Add missing file
wycc
parents:
diff changeset
183 coord_t *lightbar;
4b58e58c78da Add missing file
wycc
parents:
diff changeset
184
454
9b8dda201ccb Make naming convention consistent with MadButterfly.
Thinker K.F. Li <thinker@branda.to>
parents: 368
diff changeset
185 m->progm = progm = mb_progm_new(1, MBAF_RDMAN(m->app));
318
4b58e58c78da Add missing file
wycc
parents:
diff changeset
186 MB_TIMEVAL_SET(&start, 0, 0);
4b58e58c78da Add missing file
wycc
parents:
diff changeset
187 MB_TIMEVAL_SET(&playing, 0, m->speed);
4b58e58c78da Add missing file
wycc
parents:
diff changeset
188 word = mb_progm_next_word(progm, &start, &playing);
4b58e58c78da Add missing file
wycc
parents:
diff changeset
189 get_now(&now);
4b58e58c78da Add missing file
wycc
parents:
diff changeset
190
4b58e58c78da Add missing file
wycc
parents:
diff changeset
191 lightbar = (coord_t *) m->lightbar;
4b58e58c78da Add missing file
wycc
parents:
diff changeset
192 mb_shift_new(0,m->menus_y[m->cur]-coord_y(lightbar),lightbar,word);
4b58e58c78da Add missing file
wycc
parents:
diff changeset
193 mb_progm_free_completed(progm);
4b58e58c78da Add missing file
wycc
parents:
diff changeset
194 m->ready--;
4b58e58c78da Add missing file
wycc
parents:
diff changeset
195 subject_add_observer(mb_progm_get_complete(progm), mb_animated_menu_complete,m);
454
9b8dda201ccb Make naming convention consistent with MadButterfly.
Thinker K.F. Li <thinker@branda.to>
parents: 368
diff changeset
196 mb_progm_start(progm, X_MB_tman(MBAF_RDMAN(m->app)->rt), &now);
9b8dda201ccb Make naming convention consistent with MadButterfly.
Thinker K.F. Li <thinker@branda.to>
parents: 368
diff changeset
197 rdman_redraw_changed(MBAF_RDMAN(m->app));
318
4b58e58c78da Add missing file
wycc
parents:
diff changeset
198 }
4b58e58c78da Add missing file
wycc
parents:
diff changeset
199
4b58e58c78da Add missing file
wycc
parents:
diff changeset
200 static void mb_animated_menu_up(mb_animated_menu_t *m)
4b58e58c78da Add missing file
wycc
parents:
diff changeset
201 {
4b58e58c78da Add missing file
wycc
parents:
diff changeset
202 if (m->cur > 5) {
4b58e58c78da Add missing file
wycc
parents:
diff changeset
203 m->cur--;
4b58e58c78da Add missing file
wycc
parents:
diff changeset
204 mb_animated_menu_moveLightBar(m);
344
ab7f3c00fd05 Implement PMNG viewer
wycc
parents: 332
diff changeset
205 mb_animated_menu_update(m);
318
4b58e58c78da Add missing file
wycc
parents:
diff changeset
206 } else {
4b58e58c78da Add missing file
wycc
parents:
diff changeset
207 if (m->top > 0) {
4b58e58c78da Add missing file
wycc
parents:
diff changeset
208 m->top--;
4b58e58c78da Add missing file
wycc
parents:
diff changeset
209 mb_animated_menu_fillMenuContentUp(m);
344
ab7f3c00fd05 Implement PMNG viewer
wycc
parents: 332
diff changeset
210 mb_animated_menu_update(m);
318
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);
344
ab7f3c00fd05 Implement PMNG viewer
wycc
parents: 332
diff changeset
216 mb_animated_menu_update(m);
318
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 }
4b58e58c78da Add missing file
wycc
parents:
diff changeset
220 static void mb_animated_menu_down(mb_animated_menu_t *m)
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 if (m->cur < 5) {
4b58e58c78da Add missing file
wycc
parents:
diff changeset
224 if (m->top+m->cur <= m->max) {
4b58e58c78da Add missing file
wycc
parents:
diff changeset
225 m->cur++;
4b58e58c78da Add missing file
wycc
parents:
diff changeset
226 mb_animated_menu_moveLightBar(m);
344
ab7f3c00fd05 Implement PMNG viewer
wycc
parents: 332
diff changeset
227 mb_animated_menu_update(m);
318
4b58e58c78da Add missing file
wycc
parents:
diff changeset
228 }
4b58e58c78da Add missing file
wycc
parents:
diff changeset
229 } else {
4b58e58c78da Add missing file
wycc
parents:
diff changeset
230 if ((m->top+8) < m->max-1) {
4b58e58c78da Add missing file
wycc
parents:
diff changeset
231 m->top++;
4b58e58c78da Add missing file
wycc
parents:
diff changeset
232 mb_animated_menu_fillMenuContentDown(m);
344
ab7f3c00fd05 Implement PMNG viewer
wycc
parents: 332
diff changeset
233 mb_animated_menu_update(m);
318
4b58e58c78da Add missing file
wycc
parents:
diff changeset
234 } else {
4b58e58c78da Add missing file
wycc
parents:
diff changeset
235 if (m->cur+m->top < m->max-1) {
4b58e58c78da Add missing file
wycc
parents:
diff changeset
236 m->cur++;
4b58e58c78da Add missing file
wycc
parents:
diff changeset
237 mb_animated_menu_moveLightBar(m);
344
ab7f3c00fd05 Implement PMNG viewer
wycc
parents: 332
diff changeset
238 mb_animated_menu_update(m);
318
4b58e58c78da Add missing file
wycc
parents:
diff changeset
239 } else
4b58e58c78da Add missing file
wycc
parents:
diff changeset
240 return;
4b58e58c78da Add missing file
wycc
parents:
diff changeset
241 }
4b58e58c78da Add missing file
wycc
parents:
diff changeset
242 }
4b58e58c78da Add missing file
wycc
parents:
diff changeset
243 }
4b58e58c78da Add missing file
wycc
parents:
diff changeset
244
344
ab7f3c00fd05 Implement PMNG viewer
wycc
parents: 332
diff changeset
245 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
246 {
ab7f3c00fd05 Implement PMNG viewer
wycc
parents: 332
diff changeset
247 m->update_callback = f;
ab7f3c00fd05 Implement PMNG viewer
wycc
parents: 332
diff changeset
248 }
318
4b58e58c78da Add missing file
wycc
parents:
diff changeset
249 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
250 {
4b58e58c78da Add missing file
wycc
parents:
diff changeset
251 m->callback = f;
4b58e58c78da Add missing file
wycc
parents:
diff changeset
252 }
344
ab7f3c00fd05 Implement PMNG viewer
wycc
parents: 332
diff changeset
253 static void mb_animated_menu_update(mb_animated_menu_t *m)
ab7f3c00fd05 Implement PMNG viewer
wycc
parents: 332
diff changeset
254 {
ab7f3c00fd05 Implement PMNG viewer
wycc
parents: 332
diff changeset
255 if (m->update_callback)
ab7f3c00fd05 Implement PMNG viewer
wycc
parents: 332
diff changeset
256 m->update_callback(m,m->top+m->cur);
ab7f3c00fd05 Implement PMNG viewer
wycc
parents: 332
diff changeset
257
ab7f3c00fd05 Implement PMNG viewer
wycc
parents: 332
diff changeset
258 }
318
4b58e58c78da Add missing file
wycc
parents:
diff changeset
259 static void mb_animated_menu_select(mb_animated_menu_t *m)
4b58e58c78da Add missing file
wycc
parents:
diff changeset
260 {
4b58e58c78da Add missing file
wycc
parents:
diff changeset
261 if (m->callback)
4b58e58c78da Add missing file
wycc
parents:
diff changeset
262 m->callback(m,m->top+m->cur);
4b58e58c78da Add missing file
wycc
parents:
diff changeset
263 }
4b58e58c78da Add missing file
wycc
parents:
diff changeset
264
332
f90c60967a9c Add mb_progm_finish to terminate the current animation and put all objects in the final position.
wycc
parents: 329
diff changeset
265 // 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
266 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
267 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
268 {
f90c60967a9c Add mb_progm_finish to terminate the current animation and put all objects in the final position.
wycc
parents: 329
diff changeset
269 mb_animated_menu_t *m = (mb_animated_menu_t *) arg;
455
58b6337fb3b2 Fix bugs of pending keys of animated menu.
Thinker K.F. Li <thinker@branda.to>
parents: 454
diff changeset
270 X_kb_event_t *xkey;
58b6337fb3b2 Fix bugs of pending keys of animated menu.
Thinker K.F. Li <thinker@branda.to>
parents: 454
diff changeset
271
58b6337fb3b2 Fix bugs of pending keys of animated menu.
Thinker K.F. Li <thinker@branda.to>
parents: 454
diff changeset
272 xkey = &m->pending_keys[m->pending_pos];
58b6337fb3b2 Fix bugs of pending keys of animated menu.
Thinker K.F. Li <thinker@branda.to>
parents: 454
diff changeset
273 m->pending_pos = (m->pending_pos + 1) & 0xf;
58b6337fb3b2 Fix bugs of pending keys of animated menu.
Thinker K.F. Li <thinker@branda.to>
parents: 454
diff changeset
274 mb_animated_menu_keyHandler((event_t *) xkey, m);
332
f90c60967a9c Add mb_progm_finish to terminate the current animation and put all objects in the final position.
wycc
parents: 329
diff changeset
275 }
318
4b58e58c78da Add missing file
wycc
parents:
diff changeset
276 static void mb_animated_menu_keyHandler(event_t *ev, void *arg)
4b58e58c78da Add missing file
wycc
parents:
diff changeset
277 {
4b58e58c78da Add missing file
wycc
parents:
diff changeset
278 mb_animated_menu_t *m = (mb_animated_menu_t *) arg;
4b58e58c78da Add missing file
wycc
parents:
diff changeset
279 X_kb_event_t *xkey = (X_kb_event_t *)ev;
4b58e58c78da Add missing file
wycc
parents:
diff changeset
280 if(xkey->event.type != EVT_KB_PRESS) {
4b58e58c78da Add missing file
wycc
parents:
diff changeset
281 return;
4b58e58c78da Add missing file
wycc
parents:
diff changeset
282 }
332
f90c60967a9c Add mb_progm_finish to terminate the current animation and put all objects in the final position.
wycc
parents: 329
diff changeset
283 if (m->ready<=0) {
455
58b6337fb3b2 Fix bugs of pending keys of animated menu.
Thinker K.F. Li <thinker@branda.to>
parents: 454
diff changeset
284 m->pending_keys[m->pending_last++] = *xkey;
58b6337fb3b2 Fix bugs of pending keys of animated menu.
Thinker K.F. Li <thinker@branda.to>
parents: 454
diff changeset
285 m->pending_last &= 0xf;
58b6337fb3b2 Fix bugs of pending keys of animated menu.
Thinker K.F. Li <thinker@branda.to>
parents: 454
diff changeset
286 if(m->pending_last == m->pending_pos)
58b6337fb3b2 Fix bugs of pending keys of animated menu.
Thinker K.F. Li <thinker@branda.to>
parents: 454
diff changeset
287 m->pending_last = (m->pending_last - 1) & 0xf;
58b6337fb3b2 Fix bugs of pending keys of animated menu.
Thinker K.F. Li <thinker@branda.to>
parents: 454
diff changeset
288 else
58b6337fb3b2 Fix bugs of pending keys of animated menu.
Thinker K.F. Li <thinker@branda.to>
parents: 454
diff changeset
289 subject_add_observer(mb_progm_get_complete(m->progm),
58b6337fb3b2 Fix bugs of pending keys of animated menu.
Thinker K.F. Li <thinker@branda.to>
parents: 454
diff changeset
290 mb_animated_menu_send_pending_key,
58b6337fb3b2 Fix bugs of pending keys of animated menu.
Thinker K.F. Li <thinker@branda.to>
parents: 454
diff changeset
291 m);
332
f90c60967a9c Add mb_progm_finish to terminate the current animation and put all objects in the final position.
wycc
parents: 329
diff changeset
292 return;
f90c60967a9c Add mb_progm_finish to terminate the current animation and put all objects in the final position.
wycc
parents: 329
diff changeset
293 }
318
4b58e58c78da Add missing file
wycc
parents:
diff changeset
294 switch(xkey->sym) {
4b58e58c78da Add missing file
wycc
parents:
diff changeset
295 case 0xff51: /* left */
4b58e58c78da Add missing file
wycc
parents:
diff changeset
296 break;
4b58e58c78da Add missing file
wycc
parents:
diff changeset
297
4b58e58c78da Add missing file
wycc
parents:
diff changeset
298 case 0xff52: /* up */
4b58e58c78da Add missing file
wycc
parents:
diff changeset
299 mb_animated_menu_up(m);
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 0xff53: /* right */
4b58e58c78da Add missing file
wycc
parents:
diff changeset
303 break;
4b58e58c78da Add missing file
wycc
parents:
diff changeset
304
4b58e58c78da Add missing file
wycc
parents:
diff changeset
305 case 0xff54: /* down */
4b58e58c78da Add missing file
wycc
parents:
diff changeset
306 mb_animated_menu_down(m);
4b58e58c78da Add missing file
wycc
parents:
diff changeset
307 break;
4b58e58c78da Add missing file
wycc
parents:
diff changeset
308
4b58e58c78da Add missing file
wycc
parents:
diff changeset
309 case 0xff0d: /* enter */
4b58e58c78da Add missing file
wycc
parents:
diff changeset
310 mb_animated_menu_select(m);
4b58e58c78da Add missing file
wycc
parents:
diff changeset
311 break;
4b58e58c78da Add missing file
wycc
parents:
diff changeset
312 default:
4b58e58c78da Add missing file
wycc
parents:
diff changeset
313 return;
4b58e58c78da Add missing file
wycc
parents:
diff changeset
314 }
4b58e58c78da Add missing file
wycc
parents:
diff changeset
315 }
4b58e58c78da Add missing file
wycc
parents:
diff changeset
316
4b58e58c78da Add missing file
wycc
parents:
diff changeset
317 /** \brief Create an instace of animated menu.
4b58e58c78da Add missing file
wycc
parents:
diff changeset
318 *
4b58e58c78da Add missing file
wycc
parents:
diff changeset
319 * The objectnames is used to extract symbols from the SVG file.
4b58e58c78da Add missing file
wycc
parents:
diff changeset
320 * ${objectnames}0 - ${objectnames}8 is the text object.
4b58e58c78da Add missing file
wycc
parents:
diff changeset
321 * ${objectnames}_lightbar is the lightbar.
4b58e58c78da Add missing file
wycc
parents:
diff changeset
322 *
4b58e58c78da Add missing file
wycc
parents:
diff changeset
323 */
454
9b8dda201ccb Make naming convention consistent with MadButterfly.
Thinker K.F. Li <thinker@branda.to>
parents: 368
diff changeset
324 mb_animated_menu_t *mb_animated_menu_new(mbaf_t *app,mb_sprite_t *sp,char *objnames,char *menus[])
318
4b58e58c78da Add missing file
wycc
parents:
diff changeset
325 {
4b58e58c78da Add missing file
wycc
parents:
diff changeset
326 mb_animated_menu_t *m;
4b58e58c78da Add missing file
wycc
parents:
diff changeset
327 int i,len;
4b58e58c78da Add missing file
wycc
parents:
diff changeset
328 char name[255];
4b58e58c78da Add missing file
wycc
parents:
diff changeset
329 mb_obj_t *l;
4b58e58c78da Add missing file
wycc
parents:
diff changeset
330 int ii;
4b58e58c78da Add missing file
wycc
parents:
diff changeset
331
4b58e58c78da Add missing file
wycc
parents:
diff changeset
332 if (menus == NULL)
4b58e58c78da Add missing file
wycc
parents:
diff changeset
333 i=0;
4b58e58c78da Add missing file
wycc
parents:
diff changeset
334 else
4b58e58c78da Add missing file
wycc
parents:
diff changeset
335 for(i=0;menus[i];i++);
4b58e58c78da Add missing file
wycc
parents:
diff changeset
336 ii=9;
4b58e58c78da Add missing file
wycc
parents:
diff changeset
337
4b58e58c78da Add missing file
wycc
parents:
diff changeset
338 m = (mb_animated_menu_t *) malloc(sizeof(mb_animated_menu_t));
4b58e58c78da Add missing file
wycc
parents:
diff changeset
339 m->items = (int *) malloc(sizeof(int)*ii*2+sizeof(mb_obj_t *)*ii);
4b58e58c78da Add missing file
wycc
parents:
diff changeset
340 m->app = app;
4b58e58c78da Add missing file
wycc
parents:
diff changeset
341 m->sprite = sp;
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->ready = 1;
4b58e58c78da Add missing file
wycc
parents:
diff changeset
345 m->max = i;
4b58e58c78da Add missing file
wycc
parents:
diff changeset
346 m->menus_y = (int *) (m->items+ii);
4b58e58c78da Add missing file
wycc
parents:
diff changeset
347 m->objects = (mb_obj_t **) (m->menus_y+ii);
4b58e58c78da Add missing file
wycc
parents:
diff changeset
348 m->callback = NULL;
344
ab7f3c00fd05 Implement PMNG viewer
wycc
parents: 332
diff changeset
349 m->update_callback = NULL;
318
4b58e58c78da Add missing file
wycc
parents:
diff changeset
350 m->speed = 300000;
4b58e58c78da Add missing file
wycc
parents:
diff changeset
351 for(i=0;i<9;i++) {
4b58e58c78da Add missing file
wycc
parents:
diff changeset
352 m->items[i] = i;
4b58e58c78da Add missing file
wycc
parents:
diff changeset
353 snprintf(name,sizeof(name),"%s%d", objnames, i+1);
4b58e58c78da Add missing file
wycc
parents:
diff changeset
354 l = MB_SPRITE_GET_OBJ(sp,name);
4b58e58c78da Add missing file
wycc
parents:
diff changeset
355 if (l == NULL) {
4b58e58c78da Add missing file
wycc
parents:
diff changeset
356 fprintf(stderr,"Can not find symbol %s\n",name);
4b58e58c78da Add missing file
wycc
parents:
diff changeset
357 }
4b58e58c78da Add missing file
wycc
parents:
diff changeset
358 m->objects[i] = (mb_obj_t *) l;
4b58e58c78da Add missing file
wycc
parents:
diff changeset
359 m->menus_y[i] = coord_y((coord_t*)l);
4b58e58c78da Add missing file
wycc
parents:
diff changeset
360 }
4b58e58c78da Add missing file
wycc
parents:
diff changeset
361 m->titles = menus;
4b58e58c78da Add missing file
wycc
parents:
diff changeset
362 snprintf(name,sizeof(name), "%s_lightbar", objnames);
4b58e58c78da Add missing file
wycc
parents:
diff changeset
363 m->lightbar = (mb_obj_t *) MB_SPRITE_GET_OBJ(sp,name);
4b58e58c78da Add missing file
wycc
parents:
diff changeset
364 if (m->lightbar==NULL)
4b58e58c78da Add missing file
wycc
parents:
diff changeset
365 fprintf(stderr,"Can not find object %s\n",name);
455
58b6337fb3b2 Fix bugs of pending keys of animated menu.
Thinker K.F. Li <thinker@branda.to>
parents: 454
diff changeset
366 m->pending_pos = m->pending_last = 0;
318
4b58e58c78da Add missing file
wycc
parents:
diff changeset
367 mb_animated_menu_fillMenuContent(m);
454
9b8dda201ccb Make naming convention consistent with MadButterfly.
Thinker K.F. Li <thinker@branda.to>
parents: 368
diff changeset
368 subject_add_observer(MBAF_KB_SUBJECT(app), mb_animated_menu_keyHandler,m);
318
4b58e58c78da Add missing file
wycc
parents:
diff changeset
369 return m;
4b58e58c78da Add missing file
wycc
parents:
diff changeset
370 }
4b58e58c78da Add missing file
wycc
parents:
diff changeset
371
4b58e58c78da Add missing file
wycc
parents:
diff changeset
372 void mb_animated_menu_set_titles(mb_animated_menu_t *m, char *menus[])
4b58e58c78da Add missing file
wycc
parents:
diff changeset
373 {
4b58e58c78da Add missing file
wycc
parents:
diff changeset
374 int i;
4b58e58c78da Add missing file
wycc
parents:
diff changeset
375 for(i=0;menus[i];i++);
4b58e58c78da Add missing file
wycc
parents:
diff changeset
376
4b58e58c78da Add missing file
wycc
parents:
diff changeset
377 m->max = i;
4b58e58c78da Add missing file
wycc
parents:
diff changeset
378 m->top = 0;
4b58e58c78da Add missing file
wycc
parents:
diff changeset
379 m->cur = 0;
4b58e58c78da Add missing file
wycc
parents:
diff changeset
380 m->titles = menus;
4b58e58c78da Add missing file
wycc
parents:
diff changeset
381 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
382 mb_animated_menu_moveLightBar(m);
318
4b58e58c78da Add missing file
wycc
parents:
diff changeset
383 }
4b58e58c78da Add missing file
wycc
parents:
diff changeset
384
4b58e58c78da Add missing file
wycc
parents:
diff changeset
385
4b58e58c78da Add missing file
wycc
parents:
diff changeset
386 void mb_animated_menu_set_speed(mb_animated_menu_t *m,int speed)
4b58e58c78da Add missing file
wycc
parents:
diff changeset
387 {
4b58e58c78da Add missing file
wycc
parents:
diff changeset
388 m->speed = speed*1000;
4b58e58c78da Add missing file
wycc
parents:
diff changeset
389 }
4b58e58c78da Add missing file
wycc
parents:
diff changeset
390
4b58e58c78da Add missing file
wycc
parents:
diff changeset
391 int mb_animated_menu_get_speed(mb_animated_menu_t *m)
4b58e58c78da Add missing file
wycc
parents:
diff changeset
392 {
4b58e58c78da Add missing file
wycc
parents:
diff changeset
393 return m->speed/1000;
4b58e58c78da Add missing file
wycc
parents:
diff changeset
394 }