annotate examples/menu/main.c @ 307:b6891068109f

Fix the boundary condition for scroll down
author wycc
date Sat, 21 Feb 2009 21:51:05 +0800
parents c981e561ac37
children 9e1d72eca57b
rev   line source
296
2e97e8082d83 * Fix the symbol definition code which does not assume the id is the same as the mbname.
wycc
parents:
diff changeset
1 /*! \file
2e97e8082d83 * Fix the symbol definition code which does not assume the id is the same as the mbname.
wycc
parents:
diff changeset
2 *
2e97e8082d83 * Fix the symbol definition code which does not assume the id is the same as the mbname.
wycc
parents:
diff changeset
3 * This is the demo program for the animated menu. We will use to test the MBAF API.
297
e885dc875f30 Implement animation menu
wycc
parents: 296
diff changeset
4 * We need to have group item1-item9 in the SVG file. Initially, we will show
e885dc875f30 Implement animation menu
wycc
parents: 296
diff changeset
5 * item1-item8 only. When a up/down key is pressed, we will draw the next item in item9 and
e885dc875f30 Implement animation menu
wycc
parents: 296
diff changeset
6 * add two words to move item1-item9 smoothly. The first word move items to the 3/4 position
e885dc875f30 Implement animation menu
wycc
parents: 296
diff changeset
7 * fastly. The second will move it from 3/4 to the final position slowly to make retard effect.
e885dc875f30 Implement animation menu
wycc
parents: 296
diff changeset
8 *
e885dc875f30 Implement animation menu
wycc
parents: 296
diff changeset
9 * If we press another key before the second words finish, we will delete the word and replace
e885dc875f30 Implement animation menu
wycc
parents: 296
diff changeset
10 * it with a word to move it fastly to the final position and then we will repeat the procedure
e885dc875f30 Implement animation menu
wycc
parents: 296
diff changeset
11 * to add another two words to move it to the next position.
296
2e97e8082d83 * Fix the symbol definition code which does not assume the id is the same as the mbname.
wycc
parents:
diff changeset
12 */
2e97e8082d83 * Fix the symbol definition code which does not assume the id is the same as the mbname.
wycc
parents:
diff changeset
13 #include <stdio.h>
2e97e8082d83 * Fix the symbol definition code which does not assume the id is the same as the mbname.
wycc
parents:
diff changeset
14 #include <mb.h>
2e97e8082d83 * Fix the symbol definition code which does not assume the id is the same as the mbname.
wycc
parents:
diff changeset
15 #include <string.h>
2e97e8082d83 * Fix the symbol definition code which does not assume the id is the same as the mbname.
wycc
parents:
diff changeset
16 #include "menu.h"
2e97e8082d83 * Fix the symbol definition code which does not assume the id is the same as the mbname.
wycc
parents:
diff changeset
17 #include "mbapp.h"
2e97e8082d83 * Fix the symbol definition code which does not assume the id is the same as the mbname.
wycc
parents:
diff changeset
18
302
8b45e7b374b8 Rewrite the menu as a widget style
wycc
parents: 299
diff changeset
19
306
c981e561ac37 * Keep the font name as the original case.
wycc
parents: 305
diff changeset
20 typedef struct _mb_animated_menu {
302
8b45e7b374b8 Rewrite the menu as a widget style
wycc
parents: 299
diff changeset
21 char **titles;
8b45e7b374b8 Rewrite the menu as a widget style
wycc
parents: 299
diff changeset
22 int *menus_y;
8b45e7b374b8 Rewrite the menu as a widget style
wycc
parents: 299
diff changeset
23 int *items;
8b45e7b374b8 Rewrite the menu as a widget style
wycc
parents: 299
diff changeset
24 int top;
8b45e7b374b8 Rewrite the menu as a widget style
wycc
parents: 299
diff changeset
25 int cur;
8b45e7b374b8 Rewrite the menu as a widget style
wycc
parents: 299
diff changeset
26 int max;
8b45e7b374b8 Rewrite the menu as a widget style
wycc
parents: 299
diff changeset
27 int ready;
306
c981e561ac37 * Keep the font name as the original case.
wycc
parents: 305
diff changeset
28 int speed;
302
8b45e7b374b8 Rewrite the menu as a widget style
wycc
parents: 299
diff changeset
29 MBApp *app;
8b45e7b374b8 Rewrite the menu as a widget style
wycc
parents: 299
diff changeset
30 mb_sprite_t *sprite;
8b45e7b374b8 Rewrite the menu as a widget style
wycc
parents: 299
diff changeset
31 mb_obj_t **objects;
8b45e7b374b8 Rewrite the menu as a widget style
wycc
parents: 299
diff changeset
32 mb_obj_t *lightbar;
306
c981e561ac37 * Keep the font name as the original case.
wycc
parents: 305
diff changeset
33 void (*callback)(struct _mb_animated_menu *m, int sel);
302
8b45e7b374b8 Rewrite the menu as a widget style
wycc
parents: 299
diff changeset
34 } mb_animated_menu_t;
8b45e7b374b8 Rewrite the menu as a widget style
wycc
parents: 299
diff changeset
35
296
2e97e8082d83 * Fix the symbol definition code which does not assume the id is the same as the mbname.
wycc
parents:
diff changeset
36 char *menus[] = {
2e97e8082d83 * Fix the symbol definition code which does not assume the id is the same as the mbname.
wycc
parents:
diff changeset
37 "Item 1",
2e97e8082d83 * Fix the symbol definition code which does not assume the id is the same as the mbname.
wycc
parents:
diff changeset
38 "Item 2",
2e97e8082d83 * Fix the symbol definition code which does not assume the id is the same as the mbname.
wycc
parents:
diff changeset
39 "Item 3",
2e97e8082d83 * Fix the symbol definition code which does not assume the id is the same as the mbname.
wycc
parents:
diff changeset
40 "Item 4",
2e97e8082d83 * Fix the symbol definition code which does not assume the id is the same as the mbname.
wycc
parents:
diff changeset
41 "Item 5",
2e97e8082d83 * Fix the symbol definition code which does not assume the id is the same as the mbname.
wycc
parents:
diff changeset
42 "Item 6",
2e97e8082d83 * Fix the symbol definition code which does not assume the id is the same as the mbname.
wycc
parents:
diff changeset
43 "Item 7",
2e97e8082d83 * Fix the symbol definition code which does not assume the id is the same as the mbname.
wycc
parents:
diff changeset
44 "Item 8",
2e97e8082d83 * Fix the symbol definition code which does not assume the id is the same as the mbname.
wycc
parents:
diff changeset
45 "Item 9",
2e97e8082d83 * Fix the symbol definition code which does not assume the id is the same as the mbname.
wycc
parents:
diff changeset
46 "Item 10",
2e97e8082d83 * Fix the symbol definition code which does not assume the id is the same as the mbname.
wycc
parents:
diff changeset
47 "Item 11",
2e97e8082d83 * Fix the symbol definition code which does not assume the id is the same as the mbname.
wycc
parents:
diff changeset
48 "Item 12",
2e97e8082d83 * Fix the symbol definition code which does not assume the id is the same as the mbname.
wycc
parents:
diff changeset
49 "Item 13",
2e97e8082d83 * Fix the symbol definition code which does not assume the id is the same as the mbname.
wycc
parents:
diff changeset
50 "Item 14",
2e97e8082d83 * Fix the symbol definition code which does not assume the id is the same as the mbname.
wycc
parents:
diff changeset
51 "Item 15",
2e97e8082d83 * Fix the symbol definition code which does not assume the id is the same as the mbname.
wycc
parents:
diff changeset
52 "Item 16",
2e97e8082d83 * Fix the symbol definition code which does not assume the id is the same as the mbname.
wycc
parents:
diff changeset
53 "Item 17",
2e97e8082d83 * Fix the symbol definition code which does not assume the id is the same as the mbname.
wycc
parents:
diff changeset
54 "Item 18",
2e97e8082d83 * Fix the symbol definition code which does not assume the id is the same as the mbname.
wycc
parents:
diff changeset
55 };
2e97e8082d83 * Fix the symbol definition code which does not assume the id is the same as the mbname.
wycc
parents:
diff changeset
56
2e97e8082d83 * Fix the symbol definition code which does not assume the id is the same as the mbname.
wycc
parents:
diff changeset
57 typedef struct {
302
8b45e7b374b8 Rewrite the menu as a widget style
wycc
parents: 299
diff changeset
58 mb_animated_menu_t *m;
296
2e97e8082d83 * Fix the symbol definition code which does not assume the id is the same as the mbname.
wycc
parents:
diff changeset
59 }MyAppData;
2e97e8082d83 * Fix the symbol definition code which does not assume the id is the same as the mbname.
wycc
parents:
diff changeset
60
2e97e8082d83 * Fix the symbol definition code which does not assume the id is the same as the mbname.
wycc
parents:
diff changeset
61 MBApp *myApp;
2e97e8082d83 * Fix the symbol definition code which does not assume the id is the same as the mbname.
wycc
parents:
diff changeset
62
302
8b45e7b374b8 Rewrite the menu as a widget style
wycc
parents: 299
diff changeset
63
8b45e7b374b8 Rewrite the menu as a widget style
wycc
parents: 299
diff changeset
64 static void set_text(coord_t *g, char *text)
8b45e7b374b8 Rewrite the menu as a widget style
wycc
parents: 299
diff changeset
65 {
8b45e7b374b8 Rewrite the menu as a widget style
wycc
parents: 299
diff changeset
66 geo_t *geo;
8b45e7b374b8 Rewrite the menu as a widget style
wycc
parents: 299
diff changeset
67 shape_t *shape;
8b45e7b374b8 Rewrite the menu as a widget style
wycc
parents: 299
diff changeset
68
8b45e7b374b8 Rewrite the menu as a widget style
wycc
parents: 299
diff changeset
69 FOR_COORD_MEMBERS(g, geo) {
8b45e7b374b8 Rewrite the menu as a widget style
wycc
parents: 299
diff changeset
70 shape = geo_get_shape(geo);
8b45e7b374b8 Rewrite the menu as a widget style
wycc
parents: 299
diff changeset
71 if(shape->obj.obj_type == MBO_TEXT) {
8b45e7b374b8 Rewrite the menu as a widget style
wycc
parents: 299
diff changeset
72 sh_text_set_text(shape, text);
8b45e7b374b8 Rewrite the menu as a widget style
wycc
parents: 299
diff changeset
73 }
8b45e7b374b8 Rewrite the menu as a widget style
wycc
parents: 299
diff changeset
74 }
8b45e7b374b8 Rewrite the menu as a widget style
wycc
parents: 299
diff changeset
75 }
8b45e7b374b8 Rewrite the menu as a widget style
wycc
parents: 299
diff changeset
76
8b45e7b374b8 Rewrite the menu as a widget style
wycc
parents: 299
diff changeset
77 static void mb_animated_menu_fillMenuContent(mb_animated_menu_t *m)
296
2e97e8082d83 * Fix the symbol definition code which does not assume the id is the same as the mbname.
wycc
parents:
diff changeset
78 {
2e97e8082d83 * Fix the symbol definition code which does not assume the id is the same as the mbname.
wycc
parents:
diff changeset
79 int i;
297
e885dc875f30 Implement animation menu
wycc
parents: 296
diff changeset
80 coord_t *textgroup;
296
2e97e8082d83 * Fix the symbol definition code which does not assume the id is the same as the mbname.
wycc
parents:
diff changeset
81 shape_t *text;
2e97e8082d83 * Fix the symbol definition code which does not assume the id is the same as the mbname.
wycc
parents:
diff changeset
82 coord_t *group;
2e97e8082d83 * Fix the symbol definition code which does not assume the id is the same as the mbname.
wycc
parents:
diff changeset
83 coord_t *lightbar;
297
e885dc875f30 Implement animation menu
wycc
parents: 296
diff changeset
84 int tmp;
e885dc875f30 Implement animation menu
wycc
parents: 296
diff changeset
85 mb_timeval_t start, playing, now;
e885dc875f30 Implement animation menu
wycc
parents: 296
diff changeset
86 mb_progm_t *progm;
e885dc875f30 Implement animation menu
wycc
parents: 296
diff changeset
87 mb_word_t *word;
296
2e97e8082d83 * Fix the symbol definition code which does not assume the id is the same as the mbname.
wycc
parents:
diff changeset
88
297
e885dc875f30 Implement animation menu
wycc
parents: 296
diff changeset
89
e885dc875f30 Implement animation menu
wycc
parents: 296
diff changeset
90 // fill new item
296
2e97e8082d83 * Fix the symbol definition code which does not assume the id is the same as the mbname.
wycc
parents:
diff changeset
91 for(i=0;i<8;i++) {
302
8b45e7b374b8 Rewrite the menu as a widget style
wycc
parents: 299
diff changeset
92 text = (shape_t *) m->objects[m->items[i]];
8b45e7b374b8 Rewrite the menu as a widget style
wycc
parents: 299
diff changeset
93 set_text(text, m->titles[m->top+i]);
8b45e7b374b8 Rewrite the menu as a widget style
wycc
parents: 299
diff changeset
94 //rdman_shape_changed(MBAPP_RDMAN(m->app),text);
296
2e97e8082d83 * Fix the symbol definition code which does not assume the id is the same as the mbname.
wycc
parents:
diff changeset
95 }
297
e885dc875f30 Implement animation menu
wycc
parents: 296
diff changeset
96
e885dc875f30 Implement animation menu
wycc
parents: 296
diff changeset
97
302
8b45e7b374b8 Rewrite the menu as a widget style
wycc
parents: 299
diff changeset
98 textgroup = (coord_t *) m->objects[m->items[i]];
297
e885dc875f30 Implement animation menu
wycc
parents: 296
diff changeset
99 coord_hide(textgroup);
302
8b45e7b374b8 Rewrite the menu as a widget style
wycc
parents: 299
diff changeset
100 rdman_coord_changed(MBAPP_RDMAN(m->app),textgroup);
297
e885dc875f30 Implement animation menu
wycc
parents: 296
diff changeset
101
302
8b45e7b374b8 Rewrite the menu as a widget style
wycc
parents: 299
diff changeset
102 lightbar = (coord_t *) m->lightbar;
304
c8f31eef947b Fix the initial drawn position issue. We will draw the lightbar in the right posityion.
wycc
parents: 302
diff changeset
103 group = (coord_t *) m->objects[m->cur];
296
2e97e8082d83 * Fix the symbol definition code which does not assume the id is the same as the mbname.
wycc
parents:
diff changeset
104 coord_x(lightbar) = coord_x(group);
2e97e8082d83 * Fix the symbol definition code which does not assume the id is the same as the mbname.
wycc
parents:
diff changeset
105 coord_y(lightbar) = coord_y(group);
302
8b45e7b374b8 Rewrite the menu as a widget style
wycc
parents: 299
diff changeset
106 rdman_redraw_changed(MBAPP_RDMAN(m->app));
297
e885dc875f30 Implement animation menu
wycc
parents: 296
diff changeset
107 }
e885dc875f30 Implement animation menu
wycc
parents: 296
diff changeset
108
305
0231b05552fe Wait for the last animation done before we send the next one.
wycc
parents: 304
diff changeset
109 static void mb_animated_menu_complete(event_t *ev,void *arg)
302
8b45e7b374b8 Rewrite the menu as a widget style
wycc
parents: 299
diff changeset
110 {
8b45e7b374b8 Rewrite the menu as a widget style
wycc
parents: 299
diff changeset
111 mb_animated_menu_t *m = (mb_animated_menu_t *) arg;
8b45e7b374b8 Rewrite the menu as a widget style
wycc
parents: 299
diff changeset
112
8b45e7b374b8 Rewrite the menu as a widget style
wycc
parents: 299
diff changeset
113 m->ready++;
305
0231b05552fe Wait for the last animation done before we send the next one.
wycc
parents: 304
diff changeset
114 printf("animated done ready=%d\n", m->ready);
302
8b45e7b374b8 Rewrite the menu as a widget style
wycc
parents: 299
diff changeset
115 }
8b45e7b374b8 Rewrite the menu as a widget style
wycc
parents: 299
diff changeset
116
8b45e7b374b8 Rewrite the menu as a widget style
wycc
parents: 299
diff changeset
117 static void mb_animated_menu_fillMenuContentUp(mb_animated_menu_t *m)
297
e885dc875f30 Implement animation menu
wycc
parents: 296
diff changeset
118 {
e885dc875f30 Implement animation menu
wycc
parents: 296
diff changeset
119 int i;
e885dc875f30 Implement animation menu
wycc
parents: 296
diff changeset
120 coord_t *textgroup;
e885dc875f30 Implement animation menu
wycc
parents: 296
diff changeset
121 shape_t *text;
e885dc875f30 Implement animation menu
wycc
parents: 296
diff changeset
122 coord_t *group;
e885dc875f30 Implement animation menu
wycc
parents: 296
diff changeset
123 coord_t *lightbar;
e885dc875f30 Implement animation menu
wycc
parents: 296
diff changeset
124 int tmp;
e885dc875f30 Implement animation menu
wycc
parents: 296
diff changeset
125 mb_timeval_t start, playing, now;
e885dc875f30 Implement animation menu
wycc
parents: 296
diff changeset
126 mb_progm_t *progm;
e885dc875f30 Implement animation menu
wycc
parents: 296
diff changeset
127 mb_word_t *word;
e885dc875f30 Implement animation menu
wycc
parents: 296
diff changeset
128
e885dc875f30 Implement animation menu
wycc
parents: 296
diff changeset
129
e885dc875f30 Implement animation menu
wycc
parents: 296
diff changeset
130 // fill new item
302
8b45e7b374b8 Rewrite the menu as a widget style
wycc
parents: 299
diff changeset
131 text = (shape_t *) m->objects[m->items[8]];
8b45e7b374b8 Rewrite the menu as a widget style
wycc
parents: 299
diff changeset
132 set_text(text, m->titles[m->top]);
297
e885dc875f30 Implement animation menu
wycc
parents: 296
diff changeset
133
302
8b45e7b374b8 Rewrite the menu as a widget style
wycc
parents: 299
diff changeset
134 progm = mb_progm_new(2, MBAPP_RDMAN(m->app));
297
e885dc875f30 Implement animation menu
wycc
parents: 296
diff changeset
135 MB_TIMEVAL_SET(&start, 0, 0);
306
c981e561ac37 * Keep the font name as the original case.
wycc
parents: 305
diff changeset
136 MB_TIMEVAL_SET(&playing, 0, m->speed);
297
e885dc875f30 Implement animation menu
wycc
parents: 296
diff changeset
137 word = mb_progm_next_word(progm, &start, &playing);
e885dc875f30 Implement animation menu
wycc
parents: 296
diff changeset
138 get_now(&now);
e885dc875f30 Implement animation menu
wycc
parents: 296
diff changeset
139
e885dc875f30 Implement animation menu
wycc
parents: 296
diff changeset
140 for(i=0;i<7;i++) {
e885dc875f30 Implement animation menu
wycc
parents: 296
diff changeset
141 //shift to the next item
302
8b45e7b374b8 Rewrite the menu as a widget style
wycc
parents: 299
diff changeset
142 textgroup = (coord_t *) m->objects[m->items[i]];
8b45e7b374b8 Rewrite the menu as a widget style
wycc
parents: 299
diff changeset
143 mb_shift_new(0,m->menus_y[i+1]-coord_y(textgroup), textgroup,word);
297
e885dc875f30 Implement animation menu
wycc
parents: 296
diff changeset
144 }
e885dc875f30 Implement animation menu
wycc
parents: 296
diff changeset
145 // fade out the item[7]
302
8b45e7b374b8 Rewrite the menu as a widget style
wycc
parents: 299
diff changeset
146 textgroup = (coord_t *) m->objects[m->items[7]];
297
e885dc875f30 Implement animation menu
wycc
parents: 296
diff changeset
147 mb_shift_new(0,100, textgroup,word);
e885dc875f30 Implement animation menu
wycc
parents: 296
diff changeset
148
e885dc875f30 Implement animation menu
wycc
parents: 296
diff changeset
149 // fade in the item[8]
302
8b45e7b374b8 Rewrite the menu as a widget style
wycc
parents: 299
diff changeset
150 textgroup = (coord_t *) m->objects[m->items[8]];
8b45e7b374b8 Rewrite the menu as a widget style
wycc
parents: 299
diff changeset
151 group = (coord_t *) m->objects[m->items[0]];
8b45e7b374b8 Rewrite the menu as a widget style
wycc
parents: 299
diff changeset
152 coord_y(textgroup) = m->menus_y[0]-100;
297
e885dc875f30 Implement animation menu
wycc
parents: 296
diff changeset
153 coord_show(textgroup);
e885dc875f30 Implement animation menu
wycc
parents: 296
diff changeset
154 mb_shift_new(0,100, textgroup,word);
e885dc875f30 Implement animation menu
wycc
parents: 296
diff changeset
155
302
8b45e7b374b8 Rewrite the menu as a widget style
wycc
parents: 299
diff changeset
156 lightbar = (coord_t *) m->lightbar;
8b45e7b374b8 Rewrite the menu as a widget style
wycc
parents: 299
diff changeset
157 mb_shift_new(0,m->menus_y[m->cur]-coord_y(lightbar),lightbar,word);
297
e885dc875f30 Implement animation menu
wycc
parents: 296
diff changeset
158
306
c981e561ac37 * Keep the font name as the original case.
wycc
parents: 305
diff changeset
159 MB_TIMEVAL_SET(&start, 0, m->speed);
297
e885dc875f30 Implement animation menu
wycc
parents: 296
diff changeset
160 MB_TIMEVAL_SET(&playing, 0, 0);
e885dc875f30 Implement animation menu
wycc
parents: 296
diff changeset
161 word = mb_progm_next_word(progm, &start, &playing);
302
8b45e7b374b8 Rewrite the menu as a widget style
wycc
parents: 299
diff changeset
162 textgroup = (coord_t *) m->objects[m->items[7]];
299
5bf503270419 Fix the Fade out issue in scroll up.
wycc
parents: 298
diff changeset
163 mb_visibility_new(VIS_HIDDEN, textgroup,word);
297
e885dc875f30 Implement animation menu
wycc
parents: 296
diff changeset
164
e885dc875f30 Implement animation menu
wycc
parents: 296
diff changeset
165 mb_progm_free_completed(progm);
302
8b45e7b374b8 Rewrite the menu as a widget style
wycc
parents: 299
diff changeset
166 m->ready--;
8b45e7b374b8 Rewrite the menu as a widget style
wycc
parents: 299
diff changeset
167 subject_add_observer(mb_progm_get_complete(progm), mb_animated_menu_complete,m);
8b45e7b374b8 Rewrite the menu as a widget style
wycc
parents: 299
diff changeset
168 mb_progm_start(progm, X_MB_tman(MBAPP_RDMAN(m->app)->rt), &now);
8b45e7b374b8 Rewrite the menu as a widget style
wycc
parents: 299
diff changeset
169 rdman_redraw_changed(MBAPP_RDMAN(m->app));
8b45e7b374b8 Rewrite the menu as a widget style
wycc
parents: 299
diff changeset
170 tmp = m->items[8];
297
e885dc875f30 Implement animation menu
wycc
parents: 296
diff changeset
171 for(i=8;i>0;i--) {
302
8b45e7b374b8 Rewrite the menu as a widget style
wycc
parents: 299
diff changeset
172 m->items[i] = m->items[i-1];
297
e885dc875f30 Implement animation menu
wycc
parents: 296
diff changeset
173 }
302
8b45e7b374b8 Rewrite the menu as a widget style
wycc
parents: 299
diff changeset
174 m->items[0] = tmp;
297
e885dc875f30 Implement animation menu
wycc
parents: 296
diff changeset
175 }
302
8b45e7b374b8 Rewrite the menu as a widget style
wycc
parents: 299
diff changeset
176
8b45e7b374b8 Rewrite the menu as a widget style
wycc
parents: 299
diff changeset
177
8b45e7b374b8 Rewrite the menu as a widget style
wycc
parents: 299
diff changeset
178 static void mb_animated_menu_fillMenuContentDown(mb_animated_menu_t *m)
297
e885dc875f30 Implement animation menu
wycc
parents: 296
diff changeset
179 {
e885dc875f30 Implement animation menu
wycc
parents: 296
diff changeset
180 int i;
e885dc875f30 Implement animation menu
wycc
parents: 296
diff changeset
181 coord_t *textgroup;
e885dc875f30 Implement animation menu
wycc
parents: 296
diff changeset
182 shape_t *text;
e885dc875f30 Implement animation menu
wycc
parents: 296
diff changeset
183 coord_t *group;
e885dc875f30 Implement animation menu
wycc
parents: 296
diff changeset
184 coord_t *lightbar;
e885dc875f30 Implement animation menu
wycc
parents: 296
diff changeset
185 char name[255];
e885dc875f30 Implement animation menu
wycc
parents: 296
diff changeset
186 int tmp;
e885dc875f30 Implement animation menu
wycc
parents: 296
diff changeset
187 mb_timeval_t start, playing, now;
e885dc875f30 Implement animation menu
wycc
parents: 296
diff changeset
188 mb_progm_t *progm;
e885dc875f30 Implement animation menu
wycc
parents: 296
diff changeset
189 mb_word_t *word;
e885dc875f30 Implement animation menu
wycc
parents: 296
diff changeset
190
e885dc875f30 Implement animation menu
wycc
parents: 296
diff changeset
191
e885dc875f30 Implement animation menu
wycc
parents: 296
diff changeset
192 // fill new item
302
8b45e7b374b8 Rewrite the menu as a widget style
wycc
parents: 299
diff changeset
193 set_text(m->objects[m->items[8]], m->titles[m->top+7]);
297
e885dc875f30 Implement animation menu
wycc
parents: 296
diff changeset
194
302
8b45e7b374b8 Rewrite the menu as a widget style
wycc
parents: 299
diff changeset
195 progm = mb_progm_new(2, MBAPP_RDMAN(m->app));
297
e885dc875f30 Implement animation menu
wycc
parents: 296
diff changeset
196 MB_TIMEVAL_SET(&start, 0, 0);
306
c981e561ac37 * Keep the font name as the original case.
wycc
parents: 305
diff changeset
197 MB_TIMEVAL_SET(&playing, 0, m->speed);
297
e885dc875f30 Implement animation menu
wycc
parents: 296
diff changeset
198 word = mb_progm_next_word(progm, &start, &playing);
e885dc875f30 Implement animation menu
wycc
parents: 296
diff changeset
199 get_now(&now);
e885dc875f30 Implement animation menu
wycc
parents: 296
diff changeset
200
e885dc875f30 Implement animation menu
wycc
parents: 296
diff changeset
201 for(i=1;i<8;i++) {
e885dc875f30 Implement animation menu
wycc
parents: 296
diff changeset
202 //shift to the next item
302
8b45e7b374b8 Rewrite the menu as a widget style
wycc
parents: 299
diff changeset
203 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);
297
e885dc875f30 Implement animation menu
wycc
parents: 296
diff changeset
204 }
e885dc875f30 Implement animation menu
wycc
parents: 296
diff changeset
205 // fade out the item[0]
302
8b45e7b374b8 Rewrite the menu as a widget style
wycc
parents: 299
diff changeset
206 mb_shift_new(0,-100, (coord_t *)m->objects[m->items[0]],word);
297
e885dc875f30 Implement animation menu
wycc
parents: 296
diff changeset
207
e885dc875f30 Implement animation menu
wycc
parents: 296
diff changeset
208 // fade in the item[8]
302
8b45e7b374b8 Rewrite the menu as a widget style
wycc
parents: 299
diff changeset
209 coord_y((coord_t *)m->objects[m->items[8]]) = m->menus_y[7]+100;
8b45e7b374b8 Rewrite the menu as a widget style
wycc
parents: 299
diff changeset
210 coord_show(((coord_t *)(m->objects[m->items[8]])));
8b45e7b374b8 Rewrite the menu as a widget style
wycc
parents: 299
diff changeset
211 mb_shift_new(0,-100, (coord_t *)m->objects[m->items[8]],word);
297
e885dc875f30 Implement animation menu
wycc
parents: 296
diff changeset
212
302
8b45e7b374b8 Rewrite the menu as a widget style
wycc
parents: 299
diff changeset
213 mb_shift_new(0,m->menus_y[m->cur]-coord_y((coord_t *)m->lightbar),((coord_t *)(m->lightbar)),word);
297
e885dc875f30 Implement animation menu
wycc
parents: 296
diff changeset
214
306
c981e561ac37 * Keep the font name as the original case.
wycc
parents: 305
diff changeset
215 MB_TIMEVAL_SET(&start, 0, m->speed);
297
e885dc875f30 Implement animation menu
wycc
parents: 296
diff changeset
216 MB_TIMEVAL_SET(&playing, 0, 0);
e885dc875f30 Implement animation menu
wycc
parents: 296
diff changeset
217 word = mb_progm_next_word(progm, &start, &playing);
302
8b45e7b374b8 Rewrite the menu as a widget style
wycc
parents: 299
diff changeset
218 mb_visibility_new(VIS_VISIBLE, (coord_t *) m->objects[m->items[0]],word);
297
e885dc875f30 Implement animation menu
wycc
parents: 296
diff changeset
219
e885dc875f30 Implement animation menu
wycc
parents: 296
diff changeset
220 mb_progm_free_completed(progm);
302
8b45e7b374b8 Rewrite the menu as a widget style
wycc
parents: 299
diff changeset
221 m->ready--;
8b45e7b374b8 Rewrite the menu as a widget style
wycc
parents: 299
diff changeset
222 subject_add_observer(mb_progm_get_complete(progm), mb_animated_menu_complete,m);
8b45e7b374b8 Rewrite the menu as a widget style
wycc
parents: 299
diff changeset
223 mb_progm_start(progm, X_MB_tman(MBAPP_RDMAN(m->app)->rt), &now);
8b45e7b374b8 Rewrite the menu as a widget style
wycc
parents: 299
diff changeset
224 rdman_redraw_changed(MBAPP_RDMAN(m->app));
8b45e7b374b8 Rewrite the menu as a widget style
wycc
parents: 299
diff changeset
225 tmp = m->items[0];
297
e885dc875f30 Implement animation menu
wycc
parents: 296
diff changeset
226 for(i=0;i<8;i++) {
302
8b45e7b374b8 Rewrite the menu as a widget style
wycc
parents: 299
diff changeset
227 m->items[i] = m->items[i+1];
297
e885dc875f30 Implement animation menu
wycc
parents: 296
diff changeset
228 }
302
8b45e7b374b8 Rewrite the menu as a widget style
wycc
parents: 299
diff changeset
229 m->items[8] = tmp;
297
e885dc875f30 Implement animation menu
wycc
parents: 296
diff changeset
230 }
e885dc875f30 Implement animation menu
wycc
parents: 296
diff changeset
231
302
8b45e7b374b8 Rewrite the menu as a widget style
wycc
parents: 299
diff changeset
232 void mb_animated_menu_moveLightBar(mb_animated_menu_t *m)
297
e885dc875f30 Implement animation menu
wycc
parents: 296
diff changeset
233 {
e885dc875f30 Implement animation menu
wycc
parents: 296
diff changeset
234 mb_timeval_t start, playing, now;
e885dc875f30 Implement animation menu
wycc
parents: 296
diff changeset
235 mb_progm_t *progm;
e885dc875f30 Implement animation menu
wycc
parents: 296
diff changeset
236 mb_word_t *word;
e885dc875f30 Implement animation menu
wycc
parents: 296
diff changeset
237 coord_t *group;
e885dc875f30 Implement animation menu
wycc
parents: 296
diff changeset
238 coord_t *lightbar;
e885dc875f30 Implement animation menu
wycc
parents: 296
diff changeset
239
302
8b45e7b374b8 Rewrite the menu as a widget style
wycc
parents: 299
diff changeset
240 progm = mb_progm_new(1, MBAPP_RDMAN(m->app));
297
e885dc875f30 Implement animation menu
wycc
parents: 296
diff changeset
241 MB_TIMEVAL_SET(&start, 0, 0);
306
c981e561ac37 * Keep the font name as the original case.
wycc
parents: 305
diff changeset
242 MB_TIMEVAL_SET(&playing, 0, m->speed);
297
e885dc875f30 Implement animation menu
wycc
parents: 296
diff changeset
243 word = mb_progm_next_word(progm, &start, &playing);
e885dc875f30 Implement animation menu
wycc
parents: 296
diff changeset
244 get_now(&now);
e885dc875f30 Implement animation menu
wycc
parents: 296
diff changeset
245
302
8b45e7b374b8 Rewrite the menu as a widget style
wycc
parents: 299
diff changeset
246 lightbar = (coord_t *) m->lightbar;
305
0231b05552fe Wait for the last animation done before we send the next one.
wycc
parents: 304
diff changeset
247 mb_shift_new(0,m->menus_y[m->cur]-coord_y(lightbar),lightbar,word);
297
e885dc875f30 Implement animation menu
wycc
parents: 296
diff changeset
248 mb_progm_free_completed(progm);
305
0231b05552fe Wait for the last animation done before we send the next one.
wycc
parents: 304
diff changeset
249 m->ready--;
0231b05552fe Wait for the last animation done before we send the next one.
wycc
parents: 304
diff changeset
250 subject_add_observer(mb_progm_get_complete(progm), mb_animated_menu_complete,m);
302
8b45e7b374b8 Rewrite the menu as a widget style
wycc
parents: 299
diff changeset
251 mb_progm_start(progm, X_MB_tman(MBAPP_RDMAN(m->app)->rt), &now);
8b45e7b374b8 Rewrite the menu as a widget style
wycc
parents: 299
diff changeset
252 rdman_redraw_changed(MBAPP_RDMAN(m->app));
296
2e97e8082d83 * Fix the symbol definition code which does not assume the id is the same as the mbname.
wycc
parents:
diff changeset
253 }
2e97e8082d83 * Fix the symbol definition code which does not assume the id is the same as the mbname.
wycc
parents:
diff changeset
254
302
8b45e7b374b8 Rewrite the menu as a widget style
wycc
parents: 299
diff changeset
255 void mb_animated_menu_up(mb_animated_menu_t *m)
296
2e97e8082d83 * Fix the symbol definition code which does not assume the id is the same as the mbname.
wycc
parents:
diff changeset
256 {
302
8b45e7b374b8 Rewrite the menu as a widget style
wycc
parents: 299
diff changeset
257 if (m->cur > 5) {
8b45e7b374b8 Rewrite the menu as a widget style
wycc
parents: 299
diff changeset
258 m->cur--;
8b45e7b374b8 Rewrite the menu as a widget style
wycc
parents: 299
diff changeset
259 mb_animated_menu_moveLightBar(m);
297
e885dc875f30 Implement animation menu
wycc
parents: 296
diff changeset
260 } else {
302
8b45e7b374b8 Rewrite the menu as a widget style
wycc
parents: 299
diff changeset
261 if (m->top > 0) {
8b45e7b374b8 Rewrite the menu as a widget style
wycc
parents: 299
diff changeset
262 m->top--;
8b45e7b374b8 Rewrite the menu as a widget style
wycc
parents: 299
diff changeset
263 mb_animated_menu_fillMenuContentUp(m);
296
2e97e8082d83 * Fix the symbol definition code which does not assume the id is the same as the mbname.
wycc
parents:
diff changeset
264 } else {
302
8b45e7b374b8 Rewrite the menu as a widget style
wycc
parents: 299
diff changeset
265 if (m->cur == 0)
296
2e97e8082d83 * Fix the symbol definition code which does not assume the id is the same as the mbname.
wycc
parents:
diff changeset
266 return;
302
8b45e7b374b8 Rewrite the menu as a widget style
wycc
parents: 299
diff changeset
267 m->cur--;
8b45e7b374b8 Rewrite the menu as a widget style
wycc
parents: 299
diff changeset
268 mb_animated_menu_moveLightBar(m);
296
2e97e8082d83 * Fix the symbol definition code which does not assume the id is the same as the mbname.
wycc
parents:
diff changeset
269 }
2e97e8082d83 * Fix the symbol definition code which does not assume the id is the same as the mbname.
wycc
parents:
diff changeset
270 }
2e97e8082d83 * Fix the symbol definition code which does not assume the id is the same as the mbname.
wycc
parents:
diff changeset
271 }
302
8b45e7b374b8 Rewrite the menu as a widget style
wycc
parents: 299
diff changeset
272 void mb_animated_menu_down(mb_animated_menu_t *m)
296
2e97e8082d83 * Fix the symbol definition code which does not assume the id is the same as the mbname.
wycc
parents:
diff changeset
273 {
2e97e8082d83 * Fix the symbol definition code which does not assume the id is the same as the mbname.
wycc
parents:
diff changeset
274
305
0231b05552fe Wait for the last animation done before we send the next one.
wycc
parents: 304
diff changeset
275 if (m->cur < 5) {
302
8b45e7b374b8 Rewrite the menu as a widget style
wycc
parents: 299
diff changeset
276 if (m->top+m->cur <= m->max) {
8b45e7b374b8 Rewrite the menu as a widget style
wycc
parents: 299
diff changeset
277 m->cur++;
8b45e7b374b8 Rewrite the menu as a widget style
wycc
parents: 299
diff changeset
278 mb_animated_menu_moveLightBar(m);
297
e885dc875f30 Implement animation menu
wycc
parents: 296
diff changeset
279 }
296
2e97e8082d83 * Fix the symbol definition code which does not assume the id is the same as the mbname.
wycc
parents:
diff changeset
280 } else {
307
b6891068109f Fix the boundary condition for scroll down
wycc
parents: 306
diff changeset
281 if ((m->top+8) < m->max-1) {
302
8b45e7b374b8 Rewrite the menu as a widget style
wycc
parents: 299
diff changeset
282 m->top++;
8b45e7b374b8 Rewrite the menu as a widget style
wycc
parents: 299
diff changeset
283 mb_animated_menu_fillMenuContentDown(m);
296
2e97e8082d83 * Fix the symbol definition code which does not assume the id is the same as the mbname.
wycc
parents:
diff changeset
284 } else {
307
b6891068109f Fix the boundary condition for scroll down
wycc
parents: 306
diff changeset
285 if (m->cur+m->top < m->max-2) {
302
8b45e7b374b8 Rewrite the menu as a widget style
wycc
parents: 299
diff changeset
286 m->cur++;
8b45e7b374b8 Rewrite the menu as a widget style
wycc
parents: 299
diff changeset
287 mb_animated_menu_moveLightBar(m);
297
e885dc875f30 Implement animation menu
wycc
parents: 296
diff changeset
288 } else
296
2e97e8082d83 * Fix the symbol definition code which does not assume the id is the same as the mbname.
wycc
parents:
diff changeset
289 return;
2e97e8082d83 * Fix the symbol definition code which does not assume the id is the same as the mbname.
wycc
parents:
diff changeset
290 }
2e97e8082d83 * Fix the symbol definition code which does not assume the id is the same as the mbname.
wycc
parents:
diff changeset
291 }
2e97e8082d83 * Fix the symbol definition code which does not assume the id is the same as the mbname.
wycc
parents:
diff changeset
292 }
306
c981e561ac37 * Keep the font name as the original case.
wycc
parents: 305
diff changeset
293
c981e561ac37 * Keep the font name as the original case.
wycc
parents: 305
diff changeset
294 void mb_animated_menu_set_callback(mb_animated_menu_t *m, void (*f)(mb_animated_menu_t *m, int sel))
c981e561ac37 * Keep the font name as the original case.
wycc
parents: 305
diff changeset
295 {
c981e561ac37 * Keep the font name as the original case.
wycc
parents: 305
diff changeset
296 m->callback = f;
c981e561ac37 * Keep the font name as the original case.
wycc
parents: 305
diff changeset
297 }
302
8b45e7b374b8 Rewrite the menu as a widget style
wycc
parents: 299
diff changeset
298 void mb_animated_menu_select(mb_animated_menu_t *m)
296
2e97e8082d83 * Fix the symbol definition code which does not assume the id is the same as the mbname.
wycc
parents:
diff changeset
299 {
306
c981e561ac37 * Keep the font name as the original case.
wycc
parents: 305
diff changeset
300 if (m->callback)
c981e561ac37 * Keep the font name as the original case.
wycc
parents: 305
diff changeset
301 m->callback(m,m->top+m->cur);
296
2e97e8082d83 * Fix the symbol definition code which does not assume the id is the same as the mbname.
wycc
parents:
diff changeset
302 }
2e97e8082d83 * Fix the symbol definition code which does not assume the id is the same as the mbname.
wycc
parents:
diff changeset
303
302
8b45e7b374b8 Rewrite the menu as a widget style
wycc
parents: 299
diff changeset
304 void mb_animated_menu_keyHandler(event_t *ev, void *arg)
296
2e97e8082d83 * Fix the symbol definition code which does not assume the id is the same as the mbname.
wycc
parents:
diff changeset
305 {
302
8b45e7b374b8 Rewrite the menu as a widget style
wycc
parents: 299
diff changeset
306 mb_animated_menu_t *m = (mb_animated_menu_t *) arg;
296
2e97e8082d83 * Fix the symbol definition code which does not assume the id is the same as the mbname.
wycc
parents:
diff changeset
307 X_kb_event_t *xkey = (X_kb_event_t *)ev;
2e97e8082d83 * Fix the symbol definition code which does not assume the id is the same as the mbname.
wycc
parents:
diff changeset
308 if(xkey->event.type != EVT_KB_PRESS) {
2e97e8082d83 * Fix the symbol definition code which does not assume the id is the same as the mbname.
wycc
parents:
diff changeset
309 return;
2e97e8082d83 * Fix the symbol definition code which does not assume the id is the same as the mbname.
wycc
parents:
diff changeset
310 }
305
0231b05552fe Wait for the last animation done before we send the next one.
wycc
parents: 304
diff changeset
311 printf("read=%d\n",m->ready);
0231b05552fe Wait for the last animation done before we send the next one.
wycc
parents: 304
diff changeset
312 if (m->ready<=0) return;
296
2e97e8082d83 * Fix the symbol definition code which does not assume the id is the same as the mbname.
wycc
parents:
diff changeset
313 switch(xkey->sym) {
2e97e8082d83 * Fix the symbol definition code which does not assume the id is the same as the mbname.
wycc
parents:
diff changeset
314 case 0xff51: /* left */
2e97e8082d83 * Fix the symbol definition code which does not assume the id is the same as the mbname.
wycc
parents:
diff changeset
315 break;
2e97e8082d83 * Fix the symbol definition code which does not assume the id is the same as the mbname.
wycc
parents:
diff changeset
316
2e97e8082d83 * Fix the symbol definition code which does not assume the id is the same as the mbname.
wycc
parents:
diff changeset
317 case 0xff52: /* up */
302
8b45e7b374b8 Rewrite the menu as a widget style
wycc
parents: 299
diff changeset
318 mb_animated_menu_up(m);
296
2e97e8082d83 * Fix the symbol definition code which does not assume the id is the same as the mbname.
wycc
parents:
diff changeset
319 break;
2e97e8082d83 * Fix the symbol definition code which does not assume the id is the same as the mbname.
wycc
parents:
diff changeset
320
2e97e8082d83 * Fix the symbol definition code which does not assume the id is the same as the mbname.
wycc
parents:
diff changeset
321 case 0xff53: /* right */
2e97e8082d83 * Fix the symbol definition code which does not assume the id is the same as the mbname.
wycc
parents:
diff changeset
322 break;
2e97e8082d83 * Fix the symbol definition code which does not assume the id is the same as the mbname.
wycc
parents:
diff changeset
323
2e97e8082d83 * Fix the symbol definition code which does not assume the id is the same as the mbname.
wycc
parents:
diff changeset
324 case 0xff54: /* down */
302
8b45e7b374b8 Rewrite the menu as a widget style
wycc
parents: 299
diff changeset
325 mb_animated_menu_down(m);
296
2e97e8082d83 * Fix the symbol definition code which does not assume the id is the same as the mbname.
wycc
parents:
diff changeset
326 break;
2e97e8082d83 * Fix the symbol definition code which does not assume the id is the same as the mbname.
wycc
parents:
diff changeset
327
2e97e8082d83 * Fix the symbol definition code which does not assume the id is the same as the mbname.
wycc
parents:
diff changeset
328 case 0xff0d: /* enter */
302
8b45e7b374b8 Rewrite the menu as a widget style
wycc
parents: 299
diff changeset
329 mb_animated_menu_select(m);
296
2e97e8082d83 * Fix the symbol definition code which does not assume the id is the same as the mbname.
wycc
parents:
diff changeset
330 break;
2e97e8082d83 * Fix the symbol definition code which does not assume the id is the same as the mbname.
wycc
parents:
diff changeset
331 default:
2e97e8082d83 * Fix the symbol definition code which does not assume the id is the same as the mbname.
wycc
parents:
diff changeset
332 return;
2e97e8082d83 * Fix the symbol definition code which does not assume the id is the same as the mbname.
wycc
parents:
diff changeset
333 }
2e97e8082d83 * Fix the symbol definition code which does not assume the id is the same as the mbname.
wycc
parents:
diff changeset
334 }
2e97e8082d83 * Fix the symbol definition code which does not assume the id is the same as the mbname.
wycc
parents:
diff changeset
335
302
8b45e7b374b8 Rewrite the menu as a widget style
wycc
parents: 299
diff changeset
336 /** \brief Create an instace of animated menu.
8b45e7b374b8 Rewrite the menu as a widget style
wycc
parents: 299
diff changeset
337 *
8b45e7b374b8 Rewrite the menu as a widget style
wycc
parents: 299
diff changeset
338 * The objectnames is used to extract symbols from the SVG file.
8b45e7b374b8 Rewrite the menu as a widget style
wycc
parents: 299
diff changeset
339 * ${objectnames}0 - ${objectnames}8 is the text object.
8b45e7b374b8 Rewrite the menu as a widget style
wycc
parents: 299
diff changeset
340 * ${objectnames}_lightbar is the lightbar.
8b45e7b374b8 Rewrite the menu as a widget style
wycc
parents: 299
diff changeset
341 *
8b45e7b374b8 Rewrite the menu as a widget style
wycc
parents: 299
diff changeset
342 */
8b45e7b374b8 Rewrite the menu as a widget style
wycc
parents: 299
diff changeset
343 mb_animated_menu_t *mb_animated_menu_new(MBApp *app,mb_sprite_t *sp,char *objnames,char *menus[])
8b45e7b374b8 Rewrite the menu as a widget style
wycc
parents: 299
diff changeset
344 {
8b45e7b374b8 Rewrite the menu as a widget style
wycc
parents: 299
diff changeset
345 mb_animated_menu_t *m;
8b45e7b374b8 Rewrite the menu as a widget style
wycc
parents: 299
diff changeset
346 int i,len;
8b45e7b374b8 Rewrite the menu as a widget style
wycc
parents: 299
diff changeset
347 char name[255];
8b45e7b374b8 Rewrite the menu as a widget style
wycc
parents: 299
diff changeset
348 mb_obj_t *l;
8b45e7b374b8 Rewrite the menu as a widget style
wycc
parents: 299
diff changeset
349
8b45e7b374b8 Rewrite the menu as a widget style
wycc
parents: 299
diff changeset
350 for(i=0;menus[i];i++);
8b45e7b374b8 Rewrite the menu as a widget style
wycc
parents: 299
diff changeset
351 len = i;
8b45e7b374b8 Rewrite the menu as a widget style
wycc
parents: 299
diff changeset
352
8b45e7b374b8 Rewrite the menu as a widget style
wycc
parents: 299
diff changeset
353 m = (mb_animated_menu_t *) malloc(sizeof(mb_animated_menu_t)+sizeof(int)*len*2+sizeof(mb_obj_t *)*len);
8b45e7b374b8 Rewrite the menu as a widget style
wycc
parents: 299
diff changeset
354 m->app = app;
8b45e7b374b8 Rewrite the menu as a widget style
wycc
parents: 299
diff changeset
355 m->sprite = sp;
8b45e7b374b8 Rewrite the menu as a widget style
wycc
parents: 299
diff changeset
356 m->top = 0;
8b45e7b374b8 Rewrite the menu as a widget style
wycc
parents: 299
diff changeset
357 m->cur = 0;
8b45e7b374b8 Rewrite the menu as a widget style
wycc
parents: 299
diff changeset
358 m->ready = 1;
8b45e7b374b8 Rewrite the menu as a widget style
wycc
parents: 299
diff changeset
359 m->max = len;
8b45e7b374b8 Rewrite the menu as a widget style
wycc
parents: 299
diff changeset
360 m->items = (int *) (m+1);
8b45e7b374b8 Rewrite the menu as a widget style
wycc
parents: 299
diff changeset
361 m->menus_y = (int *) (m->items+len);
8b45e7b374b8 Rewrite the menu as a widget style
wycc
parents: 299
diff changeset
362 m->objects = (mb_obj_t **) (m->menus_y+len);
306
c981e561ac37 * Keep the font name as the original case.
wycc
parents: 305
diff changeset
363 m->callback = NULL;
c981e561ac37 * Keep the font name as the original case.
wycc
parents: 305
diff changeset
364 m->speed = 300000;
302
8b45e7b374b8 Rewrite the menu as a widget style
wycc
parents: 299
diff changeset
365 for(i=0;i<9;i++) {
8b45e7b374b8 Rewrite the menu as a widget style
wycc
parents: 299
diff changeset
366 m->items[i] = i;
8b45e7b374b8 Rewrite the menu as a widget style
wycc
parents: 299
diff changeset
367 snprintf(name,sizeof(name),"%s%d", objnames, i+1);
8b45e7b374b8 Rewrite the menu as a widget style
wycc
parents: 299
diff changeset
368 l = MB_SPRITE_GET_OBJ(sp,name);
8b45e7b374b8 Rewrite the menu as a widget style
wycc
parents: 299
diff changeset
369 if (l == NULL) {
8b45e7b374b8 Rewrite the menu as a widget style
wycc
parents: 299
diff changeset
370 fprintf(stderr,"Can not find symbol %s\n",name);
8b45e7b374b8 Rewrite the menu as a widget style
wycc
parents: 299
diff changeset
371 }
8b45e7b374b8 Rewrite the menu as a widget style
wycc
parents: 299
diff changeset
372 m->objects[i] = (mb_obj_t *) l;
8b45e7b374b8 Rewrite the menu as a widget style
wycc
parents: 299
diff changeset
373 m->menus_y[i] = coord_y((coord_t*)l);
8b45e7b374b8 Rewrite the menu as a widget style
wycc
parents: 299
diff changeset
374 }
8b45e7b374b8 Rewrite the menu as a widget style
wycc
parents: 299
diff changeset
375 m->titles = menus;
8b45e7b374b8 Rewrite the menu as a widget style
wycc
parents: 299
diff changeset
376 snprintf(name,sizeof(name), "%s_lightbar", objnames);
8b45e7b374b8 Rewrite the menu as a widget style
wycc
parents: 299
diff changeset
377 m->lightbar = (mb_obj_t *) MB_SPRITE_GET_OBJ(sp,name);
305
0231b05552fe Wait for the last animation done before we send the next one.
wycc
parents: 304
diff changeset
378 if (m->lightbar==NULL)
302
8b45e7b374b8 Rewrite the menu as a widget style
wycc
parents: 299
diff changeset
379 fprintf(stderr,"Can not find object %s\n",name);
8b45e7b374b8 Rewrite the menu as a widget style
wycc
parents: 299
diff changeset
380 mb_animated_menu_fillMenuContent(m);
8b45e7b374b8 Rewrite the menu as a widget style
wycc
parents: 299
diff changeset
381 subject_add_observer(MBAPP_keySubject(myApp), mb_animated_menu_keyHandler,m);
8b45e7b374b8 Rewrite the menu as a widget style
wycc
parents: 299
diff changeset
382 return m;
8b45e7b374b8 Rewrite the menu as a widget style
wycc
parents: 299
diff changeset
383 }
8b45e7b374b8 Rewrite the menu as a widget style
wycc
parents: 299
diff changeset
384
306
c981e561ac37 * Keep the font name as the original case.
wycc
parents: 305
diff changeset
385
c981e561ac37 * Keep the font name as the original case.
wycc
parents: 305
diff changeset
386 void mb_animated_menu_set_speed(mb_animated_menu_t *m,int speed)
c981e561ac37 * Keep the font name as the original case.
wycc
parents: 305
diff changeset
387 {
c981e561ac37 * Keep the font name as the original case.
wycc
parents: 305
diff changeset
388 m->speed = speed*1000;
c981e561ac37 * Keep the font name as the original case.
wycc
parents: 305
diff changeset
389 }
c981e561ac37 * Keep the font name as the original case.
wycc
parents: 305
diff changeset
390
c981e561ac37 * Keep the font name as the original case.
wycc
parents: 305
diff changeset
391 int mb_animated_menu_get_speed(mb_animated_menu_t *m)
c981e561ac37 * Keep the font name as the original case.
wycc
parents: 305
diff changeset
392 {
c981e561ac37 * Keep the font name as the original case.
wycc
parents: 305
diff changeset
393 return m->speed/1000;
c981e561ac37 * Keep the font name as the original case.
wycc
parents: 305
diff changeset
394 }
c981e561ac37 * Keep the font name as the original case.
wycc
parents: 305
diff changeset
395
c981e561ac37 * Keep the font name as the original case.
wycc
parents: 305
diff changeset
396 void myselect(mb_animated_menu_t *m, int select)
c981e561ac37 * Keep the font name as the original case.
wycc
parents: 305
diff changeset
397 {
c981e561ac37 * Keep the font name as the original case.
wycc
parents: 305
diff changeset
398 printf("menu %d is selected\n", select);
c981e561ac37 * Keep the font name as the original case.
wycc
parents: 305
diff changeset
399 }
c981e561ac37 * Keep the font name as the original case.
wycc
parents: 305
diff changeset
400
c981e561ac37 * Keep the font name as the original case.
wycc
parents: 305
diff changeset
401
296
2e97e8082d83 * Fix the symbol definition code which does not assume the id is the same as the mbname.
wycc
parents:
diff changeset
402 MyApp_InitContent()
2e97e8082d83 * Fix the symbol definition code which does not assume the id is the same as the mbname.
wycc
parents:
diff changeset
403 {
2e97e8082d83 * Fix the symbol definition code which does not assume the id is the same as the mbname.
wycc
parents:
diff changeset
404 MyAppData *data = MBAPP_DATA(myApp,MyAppData);
2e97e8082d83 * Fix the symbol definition code which does not assume the id is the same as the mbname.
wycc
parents:
diff changeset
405 subject_t *key = MBAPP_keySubject(myApp);
297
e885dc875f30 Implement animation menu
wycc
parents: 296
diff changeset
406 char name[255];
e885dc875f30 Implement animation menu
wycc
parents: 296
diff changeset
407 coord_t *l;
e885dc875f30 Implement animation menu
wycc
parents: 296
diff changeset
408 int i;
e885dc875f30 Implement animation menu
wycc
parents: 296
diff changeset
409 mb_sprite_t *sprite=myApp->rootsprite;
296
2e97e8082d83 * Fix the symbol definition code which does not assume the id is the same as the mbname.
wycc
parents:
diff changeset
410
302
8b45e7b374b8 Rewrite the menu as a widget style
wycc
parents: 299
diff changeset
411 data->m = mb_animated_menu_new(myApp,myApp->rootsprite,"item",menus);
306
c981e561ac37 * Keep the font name as the original case.
wycc
parents: 305
diff changeset
412 mb_animated_menu_set_callback(data->m, myselect);
296
2e97e8082d83 * Fix the symbol definition code which does not assume the id is the same as the mbname.
wycc
parents:
diff changeset
413 }
2e97e8082d83 * Fix the symbol definition code which does not assume the id is the same as the mbname.
wycc
parents:
diff changeset
414
2e97e8082d83 * Fix the symbol definition code which does not assume the id is the same as the mbname.
wycc
parents:
diff changeset
415 int main(int argc, char * const argv[]) {
2e97e8082d83 * Fix the symbol definition code which does not assume the id is the same as the mbname.
wycc
parents:
diff changeset
416 subject_t *subject;
2e97e8082d83 * Fix the symbol definition code which does not assume the id is the same as the mbname.
wycc
parents:
diff changeset
417 mb_obj_t *button;
2e97e8082d83 * Fix the symbol definition code which does not assume the id is the same as the mbname.
wycc
parents:
diff changeset
418 MyAppData data;
2e97e8082d83 * Fix the symbol definition code which does not assume the id is the same as the mbname.
wycc
parents:
diff changeset
419 mb_timeval_t tmo,interval;
2e97e8082d83 * Fix the symbol definition code which does not assume the id is the same as the mbname.
wycc
parents:
diff changeset
420
2e97e8082d83 * Fix the symbol definition code which does not assume the id is the same as the mbname.
wycc
parents:
diff changeset
421 if (argc > 1)
2e97e8082d83 * Fix the symbol definition code which does not assume the id is the same as the mbname.
wycc
parents:
diff changeset
422 myApp = MBApp_Init(argv[1]);
2e97e8082d83 * Fix the symbol definition code which does not assume the id is the same as the mbname.
wycc
parents:
diff changeset
423 else
2e97e8082d83 * Fix the symbol definition code which does not assume the id is the same as the mbname.
wycc
parents:
diff changeset
424 myApp = MBApp_Init("list");
2e97e8082d83 * Fix the symbol definition code which does not assume the id is the same as the mbname.
wycc
parents:
diff changeset
425 MBApp_setData(myApp,&data);
2e97e8082d83 * Fix the symbol definition code which does not assume the id is the same as the mbname.
wycc
parents:
diff changeset
426 MyApp_InitContent();
2e97e8082d83 * Fix the symbol definition code which does not assume the id is the same as the mbname.
wycc
parents:
diff changeset
427
2e97e8082d83 * Fix the symbol definition code which does not assume the id is the same as the mbname.
wycc
parents:
diff changeset
428 MBApp_loop(myApp);
2e97e8082d83 * Fix the symbol definition code which does not assume the id is the same as the mbname.
wycc
parents:
diff changeset
429
2e97e8082d83 * Fix the symbol definition code which does not assume the id is the same as the mbname.
wycc
parents:
diff changeset
430 return 0;
2e97e8082d83 * Fix the symbol definition code which does not assume the id is the same as the mbname.
wycc
parents:
diff changeset
431 }
2e97e8082d83 * Fix the symbol definition code which does not assume the id is the same as the mbname.
wycc
parents:
diff changeset
432
2e97e8082d83 * Fix the symbol definition code which does not assume the id is the same as the mbname.
wycc
parents:
diff changeset
433 /* vim: set ts=4 */