annotate examples/dynamic/main.c @ 242:d3fe0a0f3a8b

Implement MBApp API and modify the dynamic example to use this API.
author wycc
date Wed, 31 Dec 2008 22:37:21 +0800
parents d347a577a232
children d36abace2ce4
rev   line source
201
31933f9ee70e Chkec in demo for dynamic rectangle creation and button.
wycc@wycc-desktop
parents:
diff changeset
1 /*! \file
31933f9ee70e Chkec in demo for dynamic rectangle creation and button.
wycc@wycc-desktop
parents:
diff changeset
2 *
31933f9ee70e Chkec in demo for dynamic rectangle creation and button.
wycc@wycc-desktop
parents:
diff changeset
3 * svg2code_ex is an example that show programmers how to create a
31933f9ee70e Chkec in demo for dynamic rectangle creation and button.
wycc@wycc-desktop
parents:
diff changeset
4 * menu with MadButterfly.
31933f9ee70e Chkec in demo for dynamic rectangle creation and button.
wycc@wycc-desktop
parents:
diff changeset
5 *
31933f9ee70e Chkec in demo for dynamic rectangle creation and button.
wycc@wycc-desktop
parents:
diff changeset
6 */
31933f9ee70e Chkec in demo for dynamic rectangle creation and button.
wycc@wycc-desktop
parents:
diff changeset
7 #include <stdio.h>
31933f9ee70e Chkec in demo for dynamic rectangle creation and button.
wycc@wycc-desktop
parents:
diff changeset
8 #include <mb.h>
217
8d9d717c9300 Add sample code fro mb_button_t. If everything is OK, I will move it to the main src tree.
wycc@wycc-desktop
parents: 201
diff changeset
9 #include <string.h>
201
31933f9ee70e Chkec in demo for dynamic rectangle creation and button.
wycc@wycc-desktop
parents:
diff changeset
10 #include "menu.h"
31933f9ee70e Chkec in demo for dynamic rectangle creation and button.
wycc@wycc-desktop
parents:
diff changeset
11
31933f9ee70e Chkec in demo for dynamic rectangle creation and button.
wycc@wycc-desktop
parents:
diff changeset
12
240
d347a577a232 Rewrite the example by using the MBApp API.
wycc
parents: 230
diff changeset
13 typedef struct _mbapp MBApp;
d347a577a232 Rewrite the example by using the MBApp API.
wycc
parents: 230
diff changeset
14 struct _mbapp {
d347a577a232 Rewrite the example by using the MBApp API.
wycc
parents: 230
diff changeset
15 void *rt;
201
31933f9ee70e Chkec in demo for dynamic rectangle creation and button.
wycc@wycc-desktop
parents:
diff changeset
16 redraw_man_t *rdman;
240
d347a577a232 Rewrite the example by using the MBApp API.
wycc
parents: 230
diff changeset
17 mb_sprite_t *rootsprite;
d347a577a232 Rewrite the example by using the MBApp API.
wycc
parents: 230
diff changeset
18 mb_obj_t *root;
d347a577a232 Rewrite the example by using the MBApp API.
wycc
parents: 230
diff changeset
19 void *private;
d347a577a232 Rewrite the example by using the MBApp API.
wycc
parents: 230
diff changeset
20 };
d347a577a232 Rewrite the example by using the MBApp API.
wycc
parents: 230
diff changeset
21
d347a577a232 Rewrite the example by using the MBApp API.
wycc
parents: 230
diff changeset
22 typedef struct {
d347a577a232 Rewrite the example by using the MBApp API.
wycc
parents: 230
diff changeset
23 shape_t *rect;
201
31933f9ee70e Chkec in demo for dynamic rectangle creation and button.
wycc@wycc-desktop
parents:
diff changeset
24 co_aix orx,ory;
31933f9ee70e Chkec in demo for dynamic rectangle creation and button.
wycc@wycc-desktop
parents:
diff changeset
25 int start_x,start_y;
31933f9ee70e Chkec in demo for dynamic rectangle creation and button.
wycc@wycc-desktop
parents:
diff changeset
26 observer_t *obs1,*obs2;
242
d3fe0a0f3a8b Implement MBApp API and modify the dynamic example to use this API.
wycc
parents: 240
diff changeset
27 int currentscene;
240
d347a577a232 Rewrite the example by using the MBApp API.
wycc
parents: 230
diff changeset
28 }MyAppData;
d347a577a232 Rewrite the example by using the MBApp API.
wycc
parents: 230
diff changeset
29
d347a577a232 Rewrite the example by using the MBApp API.
wycc
parents: 230
diff changeset
30 #define MBAPP_DATA(app,type) ((type *) ((app)->private))
d347a577a232 Rewrite the example by using the MBApp API.
wycc
parents: 230
diff changeset
31 #define MBAPP_RDMAN(app) (((MBApp *) app)->rdman)
217
8d9d717c9300 Add sample code fro mb_button_t. If everything is OK, I will move it to the main src tree.
wycc@wycc-desktop
parents: 201
diff changeset
32
8d9d717c9300 Add sample code fro mb_button_t. If everything is OK, I will move it to the main src tree.
wycc@wycc-desktop
parents: 201
diff changeset
33
8d9d717c9300 Add sample code fro mb_button_t. If everything is OK, I will move it to the main src tree.
wycc@wycc-desktop
parents: 201
diff changeset
34 typedef struct _mb_button {
227
a6e559fb76d7 Add dynamic loading function for sprite
wycc
parents: 226
diff changeset
35 mb_obj_t obj;
240
d347a577a232 Rewrite the example by using the MBApp API.
wycc
parents: 230
diff changeset
36 MBApp *en;
d347a577a232 Rewrite the example by using the MBApp API.
wycc
parents: 230
diff changeset
37 int state;
217
8d9d717c9300 Add sample code fro mb_button_t. If everything is OK, I will move it to the main src tree.
wycc@wycc-desktop
parents: 201
diff changeset
38 coord_t *root;
8d9d717c9300 Add sample code fro mb_button_t. If everything is OK, I will move it to the main src tree.
wycc@wycc-desktop
parents: 201
diff changeset
39 coord_t *active;
8d9d717c9300 Add sample code fro mb_button_t. If everything is OK, I will move it to the main src tree.
wycc@wycc-desktop
parents: 201
diff changeset
40 coord_t *normal;
8d9d717c9300 Add sample code fro mb_button_t. If everything is OK, I will move it to the main src tree.
wycc@wycc-desktop
parents: 201
diff changeset
41 coord_t *click;
8d9d717c9300 Add sample code fro mb_button_t. If everything is OK, I will move it to the main src tree.
wycc@wycc-desktop
parents: 201
diff changeset
42 void (*press)();
8d9d717c9300 Add sample code fro mb_button_t. If everything is OK, I will move it to the main src tree.
wycc@wycc-desktop
parents: 201
diff changeset
43 void *arg;
221
ad4f8a956505 Implement a workaround for the button class. However, this won't solve all issues. We can use this as example to fix the mouse out event issue. When we move the curosr over the text inside the button. The upper layer group will receive MOUSE_OUT events. This is absolute incorrect.
wycc
parents: 217
diff changeset
44 observer_t *obs_move,*obs_out,*obs_press;
226
b24d7889cbda * Change the color of click frame
wycc@wycc-desktop
parents: 224
diff changeset
45 mb_progm_t *progm;
217
8d9d717c9300 Add sample code fro mb_button_t. If everything is OK, I will move it to the main src tree.
wycc@wycc-desktop
parents: 201
diff changeset
46 } mb_button_t;
8d9d717c9300 Add sample code fro mb_button_t. If everything is OK, I will move it to the main src tree.
wycc@wycc-desktop
parents: 201
diff changeset
47
8d9d717c9300 Add sample code fro mb_button_t. If everything is OK, I will move it to the main src tree.
wycc@wycc-desktop
parents: 201
diff changeset
48
8d9d717c9300 Add sample code fro mb_button_t. If everything is OK, I will move it to the main src tree.
wycc@wycc-desktop
parents: 201
diff changeset
49
8d9d717c9300 Add sample code fro mb_button_t. If everything is OK, I will move it to the main src tree.
wycc@wycc-desktop
parents: 201
diff changeset
50 #define CMOUSE(e) (coord_get_mouse_event(e))
8d9d717c9300 Add sample code fro mb_button_t. If everything is OK, I will move it to the main src tree.
wycc@wycc-desktop
parents: 201
diff changeset
51
8d9d717c9300 Add sample code fro mb_button_t. If everything is OK, I will move it to the main src tree.
wycc@wycc-desktop
parents: 201
diff changeset
52
221
ad4f8a956505 Implement a workaround for the button class. However, this won't solve all issues. We can use this as example to fix the mouse out event issue. When we move the curosr over the text inside the button. The upper layer group will receive MOUSE_OUT events. This is absolute incorrect.
wycc
parents: 217
diff changeset
53 static void mb_button_pressed(event_t *evt, void *arg);
ad4f8a956505 Implement a workaround for the button class. However, this won't solve all issues. We can use this as example to fix the mouse out event issue. When we move the curosr over the text inside the button. The upper layer group will receive MOUSE_OUT events. This is absolute incorrect.
wycc
parents: 217
diff changeset
54 static void mb_button_out(event_t *evt, void *arg);
217
8d9d717c9300 Add sample code fro mb_button_t. If everything is OK, I will move it to the main src tree.
wycc@wycc-desktop
parents: 201
diff changeset
55
240
d347a577a232 Rewrite the example by using the MBApp API.
wycc
parents: 230
diff changeset
56 void mb_button_refresh(mb_button_t *btn)
d347a577a232 Rewrite the example by using the MBApp API.
wycc
parents: 230
diff changeset
57 {
d347a577a232 Rewrite the example by using the MBApp API.
wycc
parents: 230
diff changeset
58 rdman_coord_changed(btn->en->rdman,btn->root);
d347a577a232 Rewrite the example by using the MBApp API.
wycc
parents: 230
diff changeset
59 rdman_redraw_changed(btn->en->rdman);
d347a577a232 Rewrite the example by using the MBApp API.
wycc
parents: 230
diff changeset
60 }
d347a577a232 Rewrite the example by using the MBApp API.
wycc
parents: 230
diff changeset
61
217
8d9d717c9300 Add sample code fro mb_button_t. If everything is OK, I will move it to the main src tree.
wycc@wycc-desktop
parents: 201
diff changeset
62 static void mb_button_move(event_t *evt, void *arg)
8d9d717c9300 Add sample code fro mb_button_t. If everything is OK, I will move it to the main src tree.
wycc@wycc-desktop
parents: 201
diff changeset
63 {
8d9d717c9300 Add sample code fro mb_button_t. If everything is OK, I will move it to the main src tree.
wycc@wycc-desktop
parents: 201
diff changeset
64 mb_button_t *btn = (mb_button_t *) arg;
240
d347a577a232 Rewrite the example by using the MBApp API.
wycc
parents: 230
diff changeset
65 MBApp *en = btn->en;
217
8d9d717c9300 Add sample code fro mb_button_t. If everything is OK, I will move it to the main src tree.
wycc@wycc-desktop
parents: 201
diff changeset
66
8d9d717c9300 Add sample code fro mb_button_t. If everything is OK, I will move it to the main src tree.
wycc@wycc-desktop
parents: 201
diff changeset
67
8d9d717c9300 Add sample code fro mb_button_t. If everything is OK, I will move it to the main src tree.
wycc@wycc-desktop
parents: 201
diff changeset
68 printf("Mouse move\n");
240
d347a577a232 Rewrite the example by using the MBApp API.
wycc
parents: 230
diff changeset
69 arg = (void *)en;
d347a577a232 Rewrite the example by using the MBApp API.
wycc
parents: 230
diff changeset
70 coord_show(btn->active);
d347a577a232 Rewrite the example by using the MBApp API.
wycc
parents: 230
diff changeset
71 mb_button_refresh(btn);
217
8d9d717c9300 Add sample code fro mb_button_t. If everything is OK, I will move it to the main src tree.
wycc@wycc-desktop
parents: 201
diff changeset
72 }
8d9d717c9300 Add sample code fro mb_button_t. If everything is OK, I will move it to the main src tree.
wycc@wycc-desktop
parents: 201
diff changeset
73 static void mb_button_out(event_t *evt, void *arg)
8d9d717c9300 Add sample code fro mb_button_t. If everything is OK, I will move it to the main src tree.
wycc@wycc-desktop
parents: 201
diff changeset
74 {
8d9d717c9300 Add sample code fro mb_button_t. If everything is OK, I will move it to the main src tree.
wycc@wycc-desktop
parents: 201
diff changeset
75 mb_button_t *btn = (mb_button_t *) arg;
240
d347a577a232 Rewrite the example by using the MBApp API.
wycc
parents: 230
diff changeset
76 MBApp *en = btn->en;
d347a577a232 Rewrite the example by using the MBApp API.
wycc
parents: 230
diff changeset
77 arg = (void *) en;
217
8d9d717c9300 Add sample code fro mb_button_t. If everything is OK, I will move it to the main src tree.
wycc@wycc-desktop
parents: 201
diff changeset
78
226
b24d7889cbda * Change the color of click frame
wycc@wycc-desktop
parents: 224
diff changeset
79 if (btn->progm) {
b24d7889cbda * Change the color of click frame
wycc@wycc-desktop
parents: 224
diff changeset
80 mb_progm_abort(btn->progm);
b24d7889cbda * Change the color of click frame
wycc@wycc-desktop
parents: 224
diff changeset
81 btn->progm = NULL;
b24d7889cbda * Change the color of click frame
wycc@wycc-desktop
parents: 224
diff changeset
82 }
217
8d9d717c9300 Add sample code fro mb_button_t. If everything is OK, I will move it to the main src tree.
wycc@wycc-desktop
parents: 201
diff changeset
83 printf("mouse out\n");
240
d347a577a232 Rewrite the example by using the MBApp API.
wycc
parents: 230
diff changeset
84 coord_hide(btn->click);
d347a577a232 Rewrite the example by using the MBApp API.
wycc
parents: 230
diff changeset
85 coord_hide(btn->active);
d347a577a232 Rewrite the example by using the MBApp API.
wycc
parents: 230
diff changeset
86 coord_show(btn->normal);
d347a577a232 Rewrite the example by using the MBApp API.
wycc
parents: 230
diff changeset
87 mb_button_refresh(btn);
217
8d9d717c9300 Add sample code fro mb_button_t. If everything is OK, I will move it to the main src tree.
wycc@wycc-desktop
parents: 201
diff changeset
88 }
8d9d717c9300 Add sample code fro mb_button_t. If everything is OK, I will move it to the main src tree.
wycc@wycc-desktop
parents: 201
diff changeset
89
221
ad4f8a956505 Implement a workaround for the button class. However, this won't solve all issues. We can use this as example to fix the mouse out event issue. When we move the curosr over the text inside the button. The upper layer group will receive MOUSE_OUT events. This is absolute incorrect.
wycc
parents: 217
diff changeset
90 void mb_button_show_active(event_t *evt, void *arg)
217
8d9d717c9300 Add sample code fro mb_button_t. If everything is OK, I will move it to the main src tree.
wycc@wycc-desktop
parents: 201
diff changeset
91 {
8d9d717c9300 Add sample code fro mb_button_t. If everything is OK, I will move it to the main src tree.
wycc@wycc-desktop
parents: 201
diff changeset
92 mb_button_t *btn = (mb_button_t *) arg;
240
d347a577a232 Rewrite the example by using the MBApp API.
wycc
parents: 230
diff changeset
93 MBApp *en = btn->en;
217
8d9d717c9300 Add sample code fro mb_button_t. If everything is OK, I will move it to the main src tree.
wycc@wycc-desktop
parents: 201
diff changeset
94
240
d347a577a232 Rewrite the example by using the MBApp API.
wycc
parents: 230
diff changeset
95 coord_show(btn->active);
d347a577a232 Rewrite the example by using the MBApp API.
wycc
parents: 230
diff changeset
96 mb_button_refresh(btn);
217
8d9d717c9300 Add sample code fro mb_button_t. If everything is OK, I will move it to the main src tree.
wycc@wycc-desktop
parents: 201
diff changeset
97 }
8d9d717c9300 Add sample code fro mb_button_t. If everything is OK, I will move it to the main src tree.
wycc@wycc-desktop
parents: 201
diff changeset
98
8d9d717c9300 Add sample code fro mb_button_t. If everything is OK, I will move it to the main src tree.
wycc@wycc-desktop
parents: 201
diff changeset
99 void mb_button_pressed(event_t *evt, void *arg)
8d9d717c9300 Add sample code fro mb_button_t. If everything is OK, I will move it to the main src tree.
wycc@wycc-desktop
parents: 201
diff changeset
100 {
8d9d717c9300 Add sample code fro mb_button_t. If everything is OK, I will move it to the main src tree.
wycc@wycc-desktop
parents: 201
diff changeset
101 mb_button_t *btn = (mb_button_t *) arg;
240
d347a577a232 Rewrite the example by using the MBApp API.
wycc
parents: 230
diff changeset
102 MBApp *en = btn->en;
224
29e1b2bffe4c X backend only sent EVT_MOUSE_MOVE_RAW to MadButterfly.
Thinker K.F. Li <thinker@branda.to>
parents: 221
diff changeset
103 mb_timeval_t start, playing, now;
29e1b2bffe4c X backend only sent EVT_MOUSE_MOVE_RAW to MadButterfly.
Thinker K.F. Li <thinker@branda.to>
parents: 221
diff changeset
104 mb_progm_t *progm;
29e1b2bffe4c X backend only sent EVT_MOUSE_MOVE_RAW to MadButterfly.
Thinker K.F. Li <thinker@branda.to>
parents: 221
diff changeset
105 mb_word_t *word;
240
d347a577a232 Rewrite the example by using the MBApp API.
wycc
parents: 230
diff changeset
106 arg = (void *) en;
217
8d9d717c9300 Add sample code fro mb_button_t. If everything is OK, I will move it to the main src tree.
wycc@wycc-desktop
parents: 201
diff changeset
107
8d9d717c9300 Add sample code fro mb_button_t. If everything is OK, I will move it to the main src tree.
wycc@wycc-desktop
parents: 201
diff changeset
108 printf("Pressed\n");
226
b24d7889cbda * Change the color of click frame
wycc@wycc-desktop
parents: 224
diff changeset
109 if (btn->progm) {
b24d7889cbda * Change the color of click frame
wycc@wycc-desktop
parents: 224
diff changeset
110 mb_progm_abort(btn->progm);
b24d7889cbda * Change the color of click frame
wycc@wycc-desktop
parents: 224
diff changeset
111 btn->progm = NULL;
b24d7889cbda * Change the color of click frame
wycc@wycc-desktop
parents: 224
diff changeset
112 }
240
d347a577a232 Rewrite the example by using the MBApp API.
wycc
parents: 230
diff changeset
113 coord_show(btn->click);
d347a577a232 Rewrite the example by using the MBApp API.
wycc
parents: 230
diff changeset
114 coord_hide(btn->active);
d347a577a232 Rewrite the example by using the MBApp API.
wycc
parents: 230
diff changeset
115 rdman_coord_changed(MBAPP_RDMAN(arg),btn->root);
d347a577a232 Rewrite the example by using the MBApp API.
wycc
parents: 230
diff changeset
116 rdman_redraw_changed(MBAPP_RDMAN(arg));
224
29e1b2bffe4c X backend only sent EVT_MOUSE_MOVE_RAW to MadButterfly.
Thinker K.F. Li <thinker@branda.to>
parents: 221
diff changeset
117
240
d347a577a232 Rewrite the example by using the MBApp API.
wycc
parents: 230
diff changeset
118 btn->progm = progm = mb_progm_new(1, MBAPP_RDMAN(arg));
224
29e1b2bffe4c X backend only sent EVT_MOUSE_MOVE_RAW to MadButterfly.
Thinker K.F. Li <thinker@branda.to>
parents: 221
diff changeset
119 MB_TIMEVAL_SET(&start, 0, 500000);
29e1b2bffe4c X backend only sent EVT_MOUSE_MOVE_RAW to MadButterfly.
Thinker K.F. Li <thinker@branda.to>
parents: 221
diff changeset
120 MB_TIMEVAL_SET(&playing, 0, 0);
29e1b2bffe4c X backend only sent EVT_MOUSE_MOVE_RAW to MadButterfly.
Thinker K.F. Li <thinker@branda.to>
parents: 221
diff changeset
121 word = mb_progm_next_word(progm, &start, &playing);
29e1b2bffe4c X backend only sent EVT_MOUSE_MOVE_RAW to MadButterfly.
Thinker K.F. Li <thinker@branda.to>
parents: 221
diff changeset
122 mb_visibility_new(VIS_HIDDEN, btn->click, word);
29e1b2bffe4c X backend only sent EVT_MOUSE_MOVE_RAW to MadButterfly.
Thinker K.F. Li <thinker@branda.to>
parents: 221
diff changeset
123 mb_visibility_new(VIS_VISIBLE, btn->active, word);
29e1b2bffe4c X backend only sent EVT_MOUSE_MOVE_RAW to MadButterfly.
Thinker K.F. Li <thinker@branda.to>
parents: 221
diff changeset
124 mb_progm_free_completed(progm);
217
8d9d717c9300 Add sample code fro mb_button_t. If everything is OK, I will move it to the main src tree.
wycc@wycc-desktop
parents: 201
diff changeset
125 get_now(&now);
224
29e1b2bffe4c X backend only sent EVT_MOUSE_MOVE_RAW to MadButterfly.
Thinker K.F. Li <thinker@branda.to>
parents: 221
diff changeset
126 mb_progm_start(progm, X_MB_tman(en->rt), &now);
230
3e6da6f6a226 Call the button callback when the button is clicked
wycc
parents: 229
diff changeset
127 if (btn->press)
3e6da6f6a226 Call the button callback when the button is clicked
wycc
parents: 229
diff changeset
128 btn->press(btn->arg);
217
8d9d717c9300 Add sample code fro mb_button_t. If everything is OK, I will move it to the main src tree.
wycc@wycc-desktop
parents: 201
diff changeset
129 }
240
d347a577a232 Rewrite the example by using the MBApp API.
wycc
parents: 230
diff changeset
130 mb_button_t *mb_button_new(MBApp *app,mb_sprite_t *sp, char *name)
217
8d9d717c9300 Add sample code fro mb_button_t. If everything is OK, I will move it to the main src tree.
wycc@wycc-desktop
parents: 201
diff changeset
131 {
8d9d717c9300 Add sample code fro mb_button_t. If everything is OK, I will move it to the main src tree.
wycc@wycc-desktop
parents: 201
diff changeset
132 mb_button_t *btn = (mb_button_t *) malloc(sizeof(mb_button_t));
8d9d717c9300 Add sample code fro mb_button_t. If everything is OK, I will move it to the main src tree.
wycc@wycc-desktop
parents: 201
diff changeset
133 char *buf = (char *) malloc(strlen(name)+5);
240
d347a577a232 Rewrite the example by using the MBApp API.
wycc
parents: 230
diff changeset
134 MBApp *arg = app;
217
8d9d717c9300 Add sample code fro mb_button_t. If everything is OK, I will move it to the main src tree.
wycc@wycc-desktop
parents: 201
diff changeset
135
8d9d717c9300 Add sample code fro mb_button_t. If everything is OK, I will move it to the main src tree.
wycc@wycc-desktop
parents: 201
diff changeset
136 btn->root = (coord_t *) MB_SPRITE_GET_OBJ(sp, name);
8d9d717c9300 Add sample code fro mb_button_t. If everything is OK, I will move it to the main src tree.
wycc@wycc-desktop
parents: 201
diff changeset
137 sprintf(buf, "%s_normal", name);
8d9d717c9300 Add sample code fro mb_button_t. If everything is OK, I will move it to the main src tree.
wycc@wycc-desktop
parents: 201
diff changeset
138 btn->normal = (coord_t *) MB_SPRITE_GET_OBJ(sp, buf);
8d9d717c9300 Add sample code fro mb_button_t. If everything is OK, I will move it to the main src tree.
wycc@wycc-desktop
parents: 201
diff changeset
139 if (btn->normal == NULL) {
8d9d717c9300 Add sample code fro mb_button_t. If everything is OK, I will move it to the main src tree.
wycc@wycc-desktop
parents: 201
diff changeset
140 printf("Missing normal button, this is not a correct button\n");
8d9d717c9300 Add sample code fro mb_button_t. If everything is OK, I will move it to the main src tree.
wycc@wycc-desktop
parents: 201
diff changeset
141 }
8d9d717c9300 Add sample code fro mb_button_t. If everything is OK, I will move it to the main src tree.
wycc@wycc-desktop
parents: 201
diff changeset
142 sprintf(buf, "%s_active", name);
8d9d717c9300 Add sample code fro mb_button_t. If everything is OK, I will move it to the main src tree.
wycc@wycc-desktop
parents: 201
diff changeset
143 btn->active = (coord_t *) MB_SPRITE_GET_OBJ(sp, buf);
8d9d717c9300 Add sample code fro mb_button_t. If everything is OK, I will move it to the main src tree.
wycc@wycc-desktop
parents: 201
diff changeset
144 if (btn->active == NULL) {
240
d347a577a232 Rewrite the example by using the MBApp API.
wycc
parents: 230
diff changeset
145 printf("Missing click button, this is not a correct button\n");
217
8d9d717c9300 Add sample code fro mb_button_t. If everything is OK, I will move it to the main src tree.
wycc@wycc-desktop
parents: 201
diff changeset
146 }
8d9d717c9300 Add sample code fro mb_button_t. If everything is OK, I will move it to the main src tree.
wycc@wycc-desktop
parents: 201
diff changeset
147 sprintf(buf, "%s_click", name);
8d9d717c9300 Add sample code fro mb_button_t. If everything is OK, I will move it to the main src tree.
wycc@wycc-desktop
parents: 201
diff changeset
148 btn->click = (coord_t *) MB_SPRITE_GET_OBJ(sp, buf);
240
d347a577a232 Rewrite the example by using the MBApp API.
wycc
parents: 230
diff changeset
149 if (btn->active == NULL) {
217
8d9d717c9300 Add sample code fro mb_button_t. If everything is OK, I will move it to the main src tree.
wycc@wycc-desktop
parents: 201
diff changeset
150 printf("Missing click button, this is not a correct button\n");
8d9d717c9300 Add sample code fro mb_button_t. If everything is OK, I will move it to the main src tree.
wycc@wycc-desktop
parents: 201
diff changeset
151 }
8d9d717c9300 Add sample code fro mb_button_t. If everything is OK, I will move it to the main src tree.
wycc@wycc-desktop
parents: 201
diff changeset
152 btn->press = NULL;
8d9d717c9300 Add sample code fro mb_button_t. If everything is OK, I will move it to the main src tree.
wycc@wycc-desktop
parents: 201
diff changeset
153 // Show only the normal button
240
d347a577a232 Rewrite the example by using the MBApp API.
wycc
parents: 230
diff changeset
154 coord_hide(btn->active);
d347a577a232 Rewrite the example by using the MBApp API.
wycc
parents: 230
diff changeset
155 coord_hide(btn->click);
d347a577a232 Rewrite the example by using the MBApp API.
wycc
parents: 230
diff changeset
156 coord_show(btn->normal);
217
8d9d717c9300 Add sample code fro mb_button_t. If everything is OK, I will move it to the main src tree.
wycc@wycc-desktop
parents: 201
diff changeset
157 // Move to the same position
8d9d717c9300 Add sample code fro mb_button_t. If everything is OK, I will move it to the main src tree.
wycc@wycc-desktop
parents: 201
diff changeset
158 btn->active->matrix[2] = 200;
8d9d717c9300 Add sample code fro mb_button_t. If everything is OK, I will move it to the main src tree.
wycc@wycc-desktop
parents: 201
diff changeset
159 btn->active->matrix[5] = 200;
8d9d717c9300 Add sample code fro mb_button_t. If everything is OK, I will move it to the main src tree.
wycc@wycc-desktop
parents: 201
diff changeset
160 btn->normal->matrix[2] = 200;
8d9d717c9300 Add sample code fro mb_button_t. If everything is OK, I will move it to the main src tree.
wycc@wycc-desktop
parents: 201
diff changeset
161 btn->normal->matrix[5] = 200;
8d9d717c9300 Add sample code fro mb_button_t. If everything is OK, I will move it to the main src tree.
wycc@wycc-desktop
parents: 201
diff changeset
162 btn->click->matrix[2] = 200;
8d9d717c9300 Add sample code fro mb_button_t. If everything is OK, I will move it to the main src tree.
wycc@wycc-desktop
parents: 201
diff changeset
163 btn->click->matrix[5] = 200;
240
d347a577a232 Rewrite the example by using the MBApp API.
wycc
parents: 230
diff changeset
164 btn->en = app;
224
29e1b2bffe4c X backend only sent EVT_MOUSE_MOVE_RAW to MadButterfly.
Thinker K.F. Li <thinker@branda.to>
parents: 221
diff changeset
165 btn->obs_move = subject_add_event_observer(CMOUSE(btn->root), EVT_MOUSE_MOVE, mb_button_move,btn);
29e1b2bffe4c X backend only sent EVT_MOUSE_MOVE_RAW to MadButterfly.
Thinker K.F. Li <thinker@branda.to>
parents: 221
diff changeset
166 btn->obs_press = subject_add_event_observer(CMOUSE(btn->root), EVT_MOUSE_BUT_PRESS, mb_button_pressed,btn);
29e1b2bffe4c X backend only sent EVT_MOUSE_MOVE_RAW to MadButterfly.
Thinker K.F. Li <thinker@branda.to>
parents: 221
diff changeset
167 btn->obs_out = subject_add_event_observer(CMOUSE(btn->root), EVT_MOUSE_OUT, mb_button_out,btn);
226
b24d7889cbda * Change the color of click frame
wycc@wycc-desktop
parents: 224
diff changeset
168 btn->progm = NULL;
240
d347a577a232 Rewrite the example by using the MBApp API.
wycc
parents: 230
diff changeset
169 rdman_redraw_changed(MBAPP_RDMAN(arg));
217
8d9d717c9300 Add sample code fro mb_button_t. If everything is OK, I will move it to the main src tree.
wycc@wycc-desktop
parents: 201
diff changeset
170 return btn;
8d9d717c9300 Add sample code fro mb_button_t. If everything is OK, I will move it to the main src tree.
wycc@wycc-desktop
parents: 201
diff changeset
171 }
8d9d717c9300 Add sample code fro mb_button_t. If everything is OK, I will move it to the main src tree.
wycc@wycc-desktop
parents: 201
diff changeset
172
8d9d717c9300 Add sample code fro mb_button_t. If everything is OK, I will move it to the main src tree.
wycc@wycc-desktop
parents: 201
diff changeset
173
8d9d717c9300 Add sample code fro mb_button_t. If everything is OK, I will move it to the main src tree.
wycc@wycc-desktop
parents: 201
diff changeset
174 void mb_button_add_onClick(mb_button_t *b, void (*h)(void *arg), void *arg)
8d9d717c9300 Add sample code fro mb_button_t. If everything is OK, I will move it to the main src tree.
wycc@wycc-desktop
parents: 201
diff changeset
175 {
8d9d717c9300 Add sample code fro mb_button_t. If everything is OK, I will move it to the main src tree.
wycc@wycc-desktop
parents: 201
diff changeset
176 b->press = h;
8d9d717c9300 Add sample code fro mb_button_t. If everything is OK, I will move it to the main src tree.
wycc@wycc-desktop
parents: 201
diff changeset
177 b->arg = arg;
8d9d717c9300 Add sample code fro mb_button_t. If everything is OK, I will move it to the main src tree.
wycc@wycc-desktop
parents: 201
diff changeset
178 }
8d9d717c9300 Add sample code fro mb_button_t. If everything is OK, I will move it to the main src tree.
wycc@wycc-desktop
parents: 201
diff changeset
179
240
d347a577a232 Rewrite the example by using the MBApp API.
wycc
parents: 230
diff changeset
180 MBApp *MBApp_Init(char *module)
201
31933f9ee70e Chkec in demo for dynamic rectangle creation and button.
wycc@wycc-desktop
parents:
diff changeset
181 {
240
d347a577a232 Rewrite the example by using the MBApp API.
wycc
parents: 230
diff changeset
182 MBApp *app = (MBApp *) malloc(sizeof(MBApp));
d347a577a232 Rewrite the example by using the MBApp API.
wycc
parents: 230
diff changeset
183 X_MB_runtime_t *rt;
201
31933f9ee70e Chkec in demo for dynamic rectangle creation and button.
wycc@wycc-desktop
parents:
diff changeset
184
31933f9ee70e Chkec in demo for dynamic rectangle creation and button.
wycc@wycc-desktop
parents:
diff changeset
185 rt = X_MB_new(":0.0", 800, 600);
31933f9ee70e Chkec in demo for dynamic rectangle creation and button.
wycc@wycc-desktop
parents:
diff changeset
186
240
d347a577a232 Rewrite the example by using the MBApp API.
wycc
parents: 230
diff changeset
187 app->rt = rt;
d347a577a232 Rewrite the example by using the MBApp API.
wycc
parents: 230
diff changeset
188 app->rdman = X_MB_rdman(rt);
242
d3fe0a0f3a8b Implement MBApp API and modify the dynamic example to use this API.
wycc
parents: 240
diff changeset
189 app->rootsprite= sprite_load(module,app->rdman, app->rdman->root_coord);
240
d347a577a232 Rewrite the example by using the MBApp API.
wycc
parents: 230
diff changeset
190 return app;
201
31933f9ee70e Chkec in demo for dynamic rectangle creation and button.
wycc@wycc-desktop
parents:
diff changeset
191 }
31933f9ee70e Chkec in demo for dynamic rectangle creation and button.
wycc@wycc-desktop
parents:
diff changeset
192
240
d347a577a232 Rewrite the example by using the MBApp API.
wycc
parents: 230
diff changeset
193 void MBApp_setData(MBApp *app,void *data)
d347a577a232 Rewrite the example by using the MBApp API.
wycc
parents: 230
diff changeset
194 {
d347a577a232 Rewrite the example by using the MBApp API.
wycc
parents: 230
diff changeset
195 app->private = (void *) data;
d347a577a232 Rewrite the example by using the MBApp API.
wycc
parents: 230
diff changeset
196 }
d347a577a232 Rewrite the example by using the MBApp API.
wycc
parents: 230
diff changeset
197
242
d3fe0a0f3a8b Implement MBApp API and modify the dynamic example to use this API.
wycc
parents: 240
diff changeset
198 mb_tman_t *MBApp_getTimer(MBApp *app)
d3fe0a0f3a8b Implement MBApp API and modify the dynamic example to use this API.
wycc
parents: 240
diff changeset
199 {
d3fe0a0f3a8b Implement MBApp API and modify the dynamic example to use this API.
wycc
parents: 240
diff changeset
200 return X_MB_tman(app->rt);
d3fe0a0f3a8b Implement MBApp API and modify the dynamic example to use this API.
wycc
parents: 240
diff changeset
201 }
d3fe0a0f3a8b Implement MBApp API and modify the dynamic example to use this API.
wycc
parents: 240
diff changeset
202
240
d347a577a232 Rewrite the example by using the MBApp API.
wycc
parents: 230
diff changeset
203 void MBApp_loop(MBApp *en)
201
31933f9ee70e Chkec in demo for dynamic rectangle creation and button.
wycc@wycc-desktop
parents:
diff changeset
204 {
31933f9ee70e Chkec in demo for dynamic rectangle creation and button.
wycc@wycc-desktop
parents:
diff changeset
205 /*
31933f9ee70e Chkec in demo for dynamic rectangle creation and button.
wycc@wycc-desktop
parents:
diff changeset
206 * Start handle connections, includes one to X server.
31933f9ee70e Chkec in demo for dynamic rectangle creation and button.
wycc@wycc-desktop
parents:
diff changeset
207 * User start to interact with the application.
31933f9ee70e Chkec in demo for dynamic rectangle creation and button.
wycc@wycc-desktop
parents:
diff changeset
208 */
31933f9ee70e Chkec in demo for dynamic rectangle creation and button.
wycc@wycc-desktop
parents:
diff changeset
209 X_MB_handle_connection(en->rt);
31933f9ee70e Chkec in demo for dynamic rectangle creation and button.
wycc@wycc-desktop
parents:
diff changeset
210
31933f9ee70e Chkec in demo for dynamic rectangle creation and button.
wycc@wycc-desktop
parents:
diff changeset
211 /*
31933f9ee70e Chkec in demo for dynamic rectangle creation and button.
wycc@wycc-desktop
parents:
diff changeset
212 * Clean
31933f9ee70e Chkec in demo for dynamic rectangle creation and button.
wycc@wycc-desktop
parents:
diff changeset
213 */
31933f9ee70e Chkec in demo for dynamic rectangle creation and button.
wycc@wycc-desktop
parents:
diff changeset
214 X_MB_free(en->rt);
31933f9ee70e Chkec in demo for dynamic rectangle creation and button.
wycc@wycc-desktop
parents:
diff changeset
215 free(en);
31933f9ee70e Chkec in demo for dynamic rectangle creation and button.
wycc@wycc-desktop
parents:
diff changeset
216 }
31933f9ee70e Chkec in demo for dynamic rectangle creation and button.
wycc@wycc-desktop
parents:
diff changeset
217
31933f9ee70e Chkec in demo for dynamic rectangle creation and button.
wycc@wycc-desktop
parents:
diff changeset
218
31933f9ee70e Chkec in demo for dynamic rectangle creation and button.
wycc@wycc-desktop
parents:
diff changeset
219 static void add_rect_move(event_t *evt, void *arg)
31933f9ee70e Chkec in demo for dynamic rectangle creation and button.
wycc@wycc-desktop
parents:
diff changeset
220 {
240
d347a577a232 Rewrite the example by using the MBApp API.
wycc
parents: 230
diff changeset
221 MyAppData *en = MBAPP_DATA((MBApp *)arg,MyAppData );
201
31933f9ee70e Chkec in demo for dynamic rectangle creation and button.
wycc@wycc-desktop
parents:
diff changeset
222 mouse_event_t *mev = (mouse_event_t *) evt;
31933f9ee70e Chkec in demo for dynamic rectangle creation and button.
wycc@wycc-desktop
parents:
diff changeset
223
31933f9ee70e Chkec in demo for dynamic rectangle creation and button.
wycc@wycc-desktop
parents:
diff changeset
224 printf("resize rectangle\n");
240
d347a577a232 Rewrite the example by using the MBApp API.
wycc
parents: 230
diff changeset
225 sh_rect_set(en->rect, en->start_x, en->start_y, mev->x - en->start_x, mev->y-en->start_y,0,0);
d347a577a232 Rewrite the example by using the MBApp API.
wycc
parents: 230
diff changeset
226 rdman_shape_changed(MBAPP_RDMAN(arg),en->rect);
d347a577a232 Rewrite the example by using the MBApp API.
wycc
parents: 230
diff changeset
227 rdman_redraw_changed(MBAPP_RDMAN(arg));
201
31933f9ee70e Chkec in demo for dynamic rectangle creation and button.
wycc@wycc-desktop
parents:
diff changeset
228 }
31933f9ee70e Chkec in demo for dynamic rectangle creation and button.
wycc@wycc-desktop
parents:
diff changeset
229
31933f9ee70e Chkec in demo for dynamic rectangle creation and button.
wycc@wycc-desktop
parents:
diff changeset
230 static void add_rect_release(event_t *evt, void *arg)
31933f9ee70e Chkec in demo for dynamic rectangle creation and button.
wycc@wycc-desktop
parents:
diff changeset
231 {
240
d347a577a232 Rewrite the example by using the MBApp API.
wycc
parents: 230
diff changeset
232 MyAppData *en = MBAPP_DATA((MBApp *)arg,MyAppData );
201
31933f9ee70e Chkec in demo for dynamic rectangle creation and button.
wycc@wycc-desktop
parents:
diff changeset
233 mouse_event_t *mev = (mouse_event_t *) evt;
31933f9ee70e Chkec in demo for dynamic rectangle creation and button.
wycc@wycc-desktop
parents:
diff changeset
234
31933f9ee70e Chkec in demo for dynamic rectangle creation and button.
wycc@wycc-desktop
parents:
diff changeset
235 printf("rectangle done\n");
240
d347a577a232 Rewrite the example by using the MBApp API.
wycc
parents: 230
diff changeset
236 subject_remove_observer(CMOUSE(MBAPP_RDMAN(arg)->root_coord), en->obs1);
d347a577a232 Rewrite the example by using the MBApp API.
wycc
parents: 230
diff changeset
237 subject_remove_observer(CMOUSE(MBAPP_RDMAN(arg)->root_coord), en->obs2);
201
31933f9ee70e Chkec in demo for dynamic rectangle creation and button.
wycc@wycc-desktop
parents:
diff changeset
238 }
31933f9ee70e Chkec in demo for dynamic rectangle creation and button.
wycc@wycc-desktop
parents:
diff changeset
239
31933f9ee70e Chkec in demo for dynamic rectangle creation and button.
wycc@wycc-desktop
parents:
diff changeset
240 static void add_rect_2(event_t *evt, void *arg)
31933f9ee70e Chkec in demo for dynamic rectangle creation and button.
wycc@wycc-desktop
parents:
diff changeset
241 {
240
d347a577a232 Rewrite the example by using the MBApp API.
wycc
parents: 230
diff changeset
242 MyAppData *en = MBAPP_DATA((MBApp *)arg,MyAppData );
201
31933f9ee70e Chkec in demo for dynamic rectangle creation and button.
wycc@wycc-desktop
parents:
diff changeset
243 mouse_event_t *mev = (mouse_event_t *) evt;
31933f9ee70e Chkec in demo for dynamic rectangle creation and button.
wycc@wycc-desktop
parents:
diff changeset
244 paint_t *color;
31933f9ee70e Chkec in demo for dynamic rectangle creation and button.
wycc@wycc-desktop
parents:
diff changeset
245
31933f9ee70e Chkec in demo for dynamic rectangle creation and button.
wycc@wycc-desktop
parents:
diff changeset
246 printf("select first point\n");
31933f9ee70e Chkec in demo for dynamic rectangle creation and button.
wycc@wycc-desktop
parents:
diff changeset
247 // Add an rect path
31933f9ee70e Chkec in demo for dynamic rectangle creation and button.
wycc@wycc-desktop
parents:
diff changeset
248
31933f9ee70e Chkec in demo for dynamic rectangle creation and button.
wycc@wycc-desktop
parents:
diff changeset
249 en->start_x = mev->x;
31933f9ee70e Chkec in demo for dynamic rectangle creation and button.
wycc@wycc-desktop
parents:
diff changeset
250 en->start_y = mev->y;
240
d347a577a232 Rewrite the example by using the MBApp API.
wycc
parents: 230
diff changeset
251 subject_remove_observer(CMOUSE(MBAPP_RDMAN(arg)->root_coord), en->obs1);
d347a577a232 Rewrite the example by using the MBApp API.
wycc
parents: 230
diff changeset
252 subject_remove_observer(CMOUSE(MBAPP_RDMAN(arg)->root_coord), en->obs2);
d347a577a232 Rewrite the example by using the MBApp API.
wycc
parents: 230
diff changeset
253 en->obs1 = subject_add_event_observer(CMOUSE(MBAPP_RDMAN(arg)->root_coord), EVT_MOUSE_MOVE, add_rect_move, en);
d347a577a232 Rewrite the example by using the MBApp API.
wycc
parents: 230
diff changeset
254 en->obs2 = subject_add_event_observer(CMOUSE(MBAPP_RDMAN(arg)->root_coord), EVT_MOUSE_BUT_RELEASE, add_rect_release, en);
201
31933f9ee70e Chkec in demo for dynamic rectangle creation and button.
wycc@wycc-desktop
parents:
diff changeset
255 }
31933f9ee70e Chkec in demo for dynamic rectangle creation and button.
wycc@wycc-desktop
parents:
diff changeset
256
31933f9ee70e Chkec in demo for dynamic rectangle creation and button.
wycc@wycc-desktop
parents:
diff changeset
257 static void add_rect_2_move(event_t *evt, void *arg)
31933f9ee70e Chkec in demo for dynamic rectangle creation and button.
wycc@wycc-desktop
parents:
diff changeset
258 {
240
d347a577a232 Rewrite the example by using the MBApp API.
wycc
parents: 230
diff changeset
259 MyAppData *en = MBAPP_DATA((MBApp *)arg,MyAppData );
201
31933f9ee70e Chkec in demo for dynamic rectangle creation and button.
wycc@wycc-desktop
parents:
diff changeset
260 mouse_event_t *mev = (mouse_event_t *) evt;
31933f9ee70e Chkec in demo for dynamic rectangle creation and button.
wycc@wycc-desktop
parents:
diff changeset
261
240
d347a577a232 Rewrite the example by using the MBApp API.
wycc
parents: 230
diff changeset
262 sh_rect_set(en->rect, mev->x, mev->y, 50,50,0,0);
d347a577a232 Rewrite the example by using the MBApp API.
wycc
parents: 230
diff changeset
263 rdman_shape_changed(MBAPP_RDMAN(arg),en->rect);
d347a577a232 Rewrite the example by using the MBApp API.
wycc
parents: 230
diff changeset
264 rdman_redraw_changed(MBAPP_RDMAN(arg));
201
31933f9ee70e Chkec in demo for dynamic rectangle creation and button.
wycc@wycc-desktop
parents:
diff changeset
265 }
31933f9ee70e Chkec in demo for dynamic rectangle creation and button.
wycc@wycc-desktop
parents:
diff changeset
266
31933f9ee70e Chkec in demo for dynamic rectangle creation and button.
wycc@wycc-desktop
parents:
diff changeset
267 static void add_rect(event_t *evt, void *arg)
31933f9ee70e Chkec in demo for dynamic rectangle creation and button.
wycc@wycc-desktop
parents:
diff changeset
268 {
240
d347a577a232 Rewrite the example by using the MBApp API.
wycc
parents: 230
diff changeset
269 MyAppData *en = MBAPP_DATA((MBApp *)arg,MyAppData );
201
31933f9ee70e Chkec in demo for dynamic rectangle creation and button.
wycc@wycc-desktop
parents:
diff changeset
270 mouse_event_t *mev = (mouse_event_t *) evt;
31933f9ee70e Chkec in demo for dynamic rectangle creation and button.
wycc@wycc-desktop
parents:
diff changeset
271 paint_t *color;
31933f9ee70e Chkec in demo for dynamic rectangle creation and button.
wycc@wycc-desktop
parents:
diff changeset
272
31933f9ee70e Chkec in demo for dynamic rectangle creation and button.
wycc@wycc-desktop
parents:
diff changeset
273 printf("menut selected\n");
240
d347a577a232 Rewrite the example by using the MBApp API.
wycc
parents: 230
diff changeset
274 en->obs1 = subject_add_event_observer(CMOUSE(MBAPP_RDMAN(arg)->root_coord), EVT_MOUSE_BUT_PRESS, add_rect_2, en);
d347a577a232 Rewrite the example by using the MBApp API.
wycc
parents: 230
diff changeset
275 en->obs2 = subject_add_event_observer(CMOUSE(MBAPP_RDMAN(arg)->root_coord), EVT_MOUSE_MOVE, add_rect_2_move, en);
d347a577a232 Rewrite the example by using the MBApp API.
wycc
parents: 230
diff changeset
276 en->rect = rdman_shape_rect_new(MBAPP_RDMAN(arg), mev->x, mev->y, 50 , 50, 0,0);
201
31933f9ee70e Chkec in demo for dynamic rectangle creation and button.
wycc@wycc-desktop
parents:
diff changeset
277 // Paint it with color
240
d347a577a232 Rewrite the example by using the MBApp API.
wycc
parents: 230
diff changeset
278 en->obs1 = subject_add_event_observer(CMOUSE(MBAPP_RDMAN(arg)->root_coord), EVT_MOUSE_BUT_PRESS, add_rect_2, en);
d347a577a232 Rewrite the example by using the MBApp API.
wycc
parents: 230
diff changeset
279 en->obs2 = subject_add_event_observer(CMOUSE(MBAPP_RDMAN(arg)->root_coord), EVT_MOUSE_MOVE, add_rect_2_move, en);
d347a577a232 Rewrite the example by using the MBApp API.
wycc
parents: 230
diff changeset
280 en->rect = rdman_shape_rect_new(MBAPP_RDMAN(arg), mev->x, mev->y, 50 , 50, 0,0);
d347a577a232 Rewrite the example by using the MBApp API.
wycc
parents: 230
diff changeset
281 // Paint it with color
d347a577a232 Rewrite the example by using the MBApp API.
wycc
parents: 230
diff changeset
282 color = rdman_paint_color_new(MBAPP_RDMAN(arg), 0.800000, 0.800000, 0.400000, 1.000000);
d347a577a232 Rewrite the example by using the MBApp API.
wycc
parents: 230
diff changeset
283 rdman_paint_fill(MBAPP_RDMAN(arg), color, en->rect);
201
31933f9ee70e Chkec in demo for dynamic rectangle creation and button.
wycc@wycc-desktop
parents:
diff changeset
284 // Add to the stage
240
d347a577a232 Rewrite the example by using the MBApp API.
wycc
parents: 230
diff changeset
285 //rdman_add_shape(MBAPP_RDMAN(arg), en->rect, en->menu->root_coord);
201
31933f9ee70e Chkec in demo for dynamic rectangle creation and button.
wycc@wycc-desktop
parents:
diff changeset
286 }
31933f9ee70e Chkec in demo for dynamic rectangle creation and button.
wycc@wycc-desktop
parents:
diff changeset
287
31933f9ee70e Chkec in demo for dynamic rectangle creation and button.
wycc@wycc-desktop
parents:
diff changeset
288
217
8d9d717c9300 Add sample code fro mb_button_t. If everything is OK, I will move it to the main src tree.
wycc@wycc-desktop
parents: 201
diff changeset
289 void test(void *a)
8d9d717c9300 Add sample code fro mb_button_t. If everything is OK, I will move it to the main src tree.
wycc@wycc-desktop
parents: 201
diff changeset
290 {
8d9d717c9300 Add sample code fro mb_button_t. If everything is OK, I will move it to the main src tree.
wycc@wycc-desktop
parents: 201
diff changeset
291 printf("Button is pressed.....\n");
8d9d717c9300 Add sample code fro mb_button_t. If everything is OK, I will move it to the main src tree.
wycc@wycc-desktop
parents: 201
diff changeset
292 }
201
31933f9ee70e Chkec in demo for dynamic rectangle creation and button.
wycc@wycc-desktop
parents:
diff changeset
293
240
d347a577a232 Rewrite the example by using the MBApp API.
wycc
parents: 230
diff changeset
294 MBApp *myApp;
201
31933f9ee70e Chkec in demo for dynamic rectangle creation and button.
wycc@wycc-desktop
parents:
diff changeset
295
242
d3fe0a0f3a8b Implement MBApp API and modify the dynamic example to use this API.
wycc
parents: 240
diff changeset
296 void switch_scene(const mb_timeval_t *tmo, const mb_timeval_t *now,void *arg)
d3fe0a0f3a8b Implement MBApp API and modify the dynamic example to use this API.
wycc
parents: 240
diff changeset
297 {
d3fe0a0f3a8b Implement MBApp API and modify the dynamic example to use this API.
wycc
parents: 240
diff changeset
298 MyAppData *en = MBAPP_DATA((MBApp *)arg,MyAppData );
d3fe0a0f3a8b Implement MBApp API and modify the dynamic example to use this API.
wycc
parents: 240
diff changeset
299 mb_timeval_t timer,interval;
d3fe0a0f3a8b Implement MBApp API and modify the dynamic example to use this API.
wycc
parents: 240
diff changeset
300
d3fe0a0f3a8b Implement MBApp API and modify the dynamic example to use this API.
wycc
parents: 240
diff changeset
301
d3fe0a0f3a8b Implement MBApp API and modify the dynamic example to use this API.
wycc
parents: 240
diff changeset
302 get_now(&timer);
d3fe0a0f3a8b Implement MBApp API and modify the dynamic example to use this API.
wycc
parents: 240
diff changeset
303 MB_TIMEVAL_SET(&interval, 1 ,0);
d3fe0a0f3a8b Implement MBApp API and modify the dynamic example to use this API.
wycc
parents: 240
diff changeset
304 MB_TIMEVAL_ADD(&timer, &interval);
d3fe0a0f3a8b Implement MBApp API and modify the dynamic example to use this API.
wycc
parents: 240
diff changeset
305 mb_tman_timeout( MBApp_getTimer(myApp), &timer, switch_scene, myApp);
d3fe0a0f3a8b Implement MBApp API and modify the dynamic example to use this API.
wycc
parents: 240
diff changeset
306
d3fe0a0f3a8b Implement MBApp API and modify the dynamic example to use this API.
wycc
parents: 240
diff changeset
307 en->currentscene = (en->currentscene+1) %2;
d3fe0a0f3a8b Implement MBApp API and modify the dynamic example to use this API.
wycc
parents: 240
diff changeset
308 printf("switch to scene %d\n", en->currentscene);
d3fe0a0f3a8b Implement MBApp API and modify the dynamic example to use this API.
wycc
parents: 240
diff changeset
309 MB_SPRITE_GOTO_SCENE(myApp->rootsprite,en->currentscene);
d3fe0a0f3a8b Implement MBApp API and modify the dynamic example to use this API.
wycc
parents: 240
diff changeset
310 }
d3fe0a0f3a8b Implement MBApp API and modify the dynamic example to use this API.
wycc
parents: 240
diff changeset
311
201
31933f9ee70e Chkec in demo for dynamic rectangle creation and button.
wycc@wycc-desktop
parents:
diff changeset
312 int main(int argc, char * const argv[]) {
31933f9ee70e Chkec in demo for dynamic rectangle creation and button.
wycc@wycc-desktop
parents:
diff changeset
313 subject_t *subject;
217
8d9d717c9300 Add sample code fro mb_button_t. If everything is OK, I will move it to the main src tree.
wycc@wycc-desktop
parents: 201
diff changeset
314 mb_button_t *b;
240
d347a577a232 Rewrite the example by using the MBApp API.
wycc
parents: 230
diff changeset
315 mb_obj_t *button;
d347a577a232 Rewrite the example by using the MBApp API.
wycc
parents: 230
diff changeset
316 MyAppData data;
242
d3fe0a0f3a8b Implement MBApp API and modify the dynamic example to use this API.
wycc
parents: 240
diff changeset
317 mb_timeval_t tmo,interval;
201
31933f9ee70e Chkec in demo for dynamic rectangle creation and button.
wycc@wycc-desktop
parents:
diff changeset
318
242
d3fe0a0f3a8b Implement MBApp API and modify the dynamic example to use this API.
wycc
parents: 240
diff changeset
319 if (argc > 1)
d3fe0a0f3a8b Implement MBApp API and modify the dynamic example to use this API.
wycc
parents: 240
diff changeset
320 myApp = MBApp_Init(argv[1]);
d3fe0a0f3a8b Implement MBApp API and modify the dynamic example to use this API.
wycc
parents: 240
diff changeset
321 else
d3fe0a0f3a8b Implement MBApp API and modify the dynamic example to use this API.
wycc
parents: 240
diff changeset
322 myApp = MBApp_Init("scene");
d3fe0a0f3a8b Implement MBApp API and modify the dynamic example to use this API.
wycc
parents: 240
diff changeset
323 data.currentscene=0;
240
d347a577a232 Rewrite the example by using the MBApp API.
wycc
parents: 230
diff changeset
324 MBApp_setData(myApp,&data);
242
d3fe0a0f3a8b Implement MBApp API and modify the dynamic example to use this API.
wycc
parents: 240
diff changeset
325 //b = mb_button_new(myApp, myApp->rootsprite, "btn");
d3fe0a0f3a8b Implement MBApp API and modify the dynamic example to use this API.
wycc
parents: 240
diff changeset
326 //mb_button_add_onClick(b, test,NULL);
d3fe0a0f3a8b Implement MBApp API and modify the dynamic example to use this API.
wycc
parents: 240
diff changeset
327 get_now(&tmo);
d3fe0a0f3a8b Implement MBApp API and modify the dynamic example to use this API.
wycc
parents: 240
diff changeset
328 MB_TIMEVAL_SET(&interval, 1 ,0);
d3fe0a0f3a8b Implement MBApp API and modify the dynamic example to use this API.
wycc
parents: 240
diff changeset
329 mb_tman_timeout( MBApp_getTimer(myApp), &tmo, switch_scene, myApp);
d3fe0a0f3a8b Implement MBApp API and modify the dynamic example to use this API.
wycc
parents: 240
diff changeset
330
201
31933f9ee70e Chkec in demo for dynamic rectangle creation and button.
wycc@wycc-desktop
parents:
diff changeset
331
240
d347a577a232 Rewrite the example by using the MBApp API.
wycc
parents: 230
diff changeset
332 MBApp_loop(myApp);
201
31933f9ee70e Chkec in demo for dynamic rectangle creation and button.
wycc@wycc-desktop
parents:
diff changeset
333
31933f9ee70e Chkec in demo for dynamic rectangle creation and button.
wycc@wycc-desktop
parents:
diff changeset
334 return 0;
31933f9ee70e Chkec in demo for dynamic rectangle creation and button.
wycc@wycc-desktop
parents:
diff changeset
335 }
31933f9ee70e Chkec in demo for dynamic rectangle creation and button.
wycc@wycc-desktop
parents:
diff changeset
336
31933f9ee70e Chkec in demo for dynamic rectangle creation and button.
wycc@wycc-desktop
parents:
diff changeset
337 /* vim: set ts=4 */