comparison 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
comparison
equal deleted inserted replaced
241:104d83378582 242:d3fe0a0f3a8b
22 typedef struct { 22 typedef struct {
23 shape_t *rect; 23 shape_t *rect;
24 co_aix orx,ory; 24 co_aix orx,ory;
25 int start_x,start_y; 25 int start_x,start_y;
26 observer_t *obs1,*obs2; 26 observer_t *obs1,*obs2;
27 int currentscene;
27 }MyAppData; 28 }MyAppData;
28 29
29 #define MBAPP_DATA(app,type) ((type *) ((app)->private)) 30 #define MBAPP_DATA(app,type) ((type *) ((app)->private))
30 #define MBAPP_RDMAN(app) (((MBApp *) app)->rdman) 31 #define MBAPP_RDMAN(app) (((MBApp *) app)->rdman)
31 32
183 184
184 rt = X_MB_new(":0.0", 800, 600); 185 rt = X_MB_new(":0.0", 800, 600);
185 186
186 app->rt = rt; 187 app->rt = rt;
187 app->rdman = X_MB_rdman(rt); 188 app->rdman = X_MB_rdman(rt);
188 app->rootsprite= sprite_load("button",app->rdman, app->rdman->root_coord); 189 app->rootsprite= sprite_load(module,app->rdman, app->rdman->root_coord);
189 return app; 190 return app;
190 } 191 }
191 192
192 void MBApp_setData(MBApp *app,void *data) 193 void MBApp_setData(MBApp *app,void *data)
193 { 194 {
194 app->private = (void *) data; 195 app->private = (void *) data;
196 }
197
198 mb_tman_t *MBApp_getTimer(MBApp *app)
199 {
200 return X_MB_tman(app->rt);
195 } 201 }
196 202
197 void MBApp_loop(MBApp *en) 203 void MBApp_loop(MBApp *en)
198 { 204 {
199 /* 205 /*
285 printf("Button is pressed.....\n"); 291 printf("Button is pressed.....\n");
286 } 292 }
287 293
288 MBApp *myApp; 294 MBApp *myApp;
289 295
296 void switch_scene(const mb_timeval_t *tmo, const mb_timeval_t *now,void *arg)
297 {
298 MyAppData *en = MBAPP_DATA((MBApp *)arg,MyAppData );
299 mb_timeval_t timer,interval;
300
301
302 get_now(&timer);
303 MB_TIMEVAL_SET(&interval, 1 ,0);
304 MB_TIMEVAL_ADD(&timer, &interval);
305 mb_tman_timeout( MBApp_getTimer(myApp), &timer, switch_scene, myApp);
306
307 en->currentscene = (en->currentscene+1) %2;
308 printf("switch to scene %d\n", en->currentscene);
309 MB_SPRITE_GOTO_SCENE(myApp->rootsprite,en->currentscene);
310 }
311
290 int main(int argc, char * const argv[]) { 312 int main(int argc, char * const argv[]) {
291 subject_t *subject; 313 subject_t *subject;
292 mb_button_t *b; 314 mb_button_t *b;
293 mb_obj_t *button; 315 mb_obj_t *button;
294 MyAppData data; 316 MyAppData data;
295 317 mb_timeval_t tmo,interval;
296 myApp = MBApp_Init("button"); 318
319 if (argc > 1)
320 myApp = MBApp_Init(argv[1]);
321 else
322 myApp = MBApp_Init("scene");
323 data.currentscene=0;
297 MBApp_setData(myApp,&data); 324 MBApp_setData(myApp,&data);
298 b = mb_button_new(myApp, myApp->rootsprite, "btn"); 325 //b = mb_button_new(myApp, myApp->rootsprite, "btn");
299 mb_button_add_onClick(b, test,NULL); 326 //mb_button_add_onClick(b, test,NULL);
327 get_now(&tmo);
328 MB_TIMEVAL_SET(&interval, 1 ,0);
329 mb_tman_timeout( MBApp_getTimer(myApp), &tmo, switch_scene, myApp);
330
300 331
301 MBApp_loop(myApp); 332 MBApp_loop(myApp);
302 333
303 return 0; 334 return 0;
304 } 335 }