Mercurial > MadButterfly
changeset 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 | 104d83378582 |
children | 6c6b62d342ee |
files | examples/dynamic/Makefile.am examples/dynamic/main.c inkscape/MB_Frame.py |
diffstat | 3 files changed, 50 insertions(+), 5 deletions(-) [+] |
line wrap: on
line diff
--- a/examples/dynamic/Makefile.am Wed Dec 31 02:08:40 2008 +0800 +++ b/examples/dynamic/Makefile.am Wed Dec 31 22:37:21 2008 +0800 @@ -20,7 +20,7 @@ menu.c: menu.mb m4 -I $(top_srcdir)/tools mb_c_source.m4 $< > $@ -button.so: button.o +button.so: button.o button.h gcc -shared -o button.so button.o button.mb: $(srcdir)/button.svg @@ -31,3 +31,15 @@ button.c: button.mb m4 -I $(top_srcdir)/tools mb_c_source.m4 $< > $@ + +scene.so: scene.o scene.h + gcc -shared -o scene.so scene.o + +scene.mb: $(srcdir)/scene.svg + $(top_srcdir)/tools/svg2code.py $? $@ + +scene.h: scene.mb + m4 -I $(top_srcdir)/tools mb_c_header.m4 $< > $@ + +scene.c: scene.mb + m4 -I $(top_srcdir)/tools mb_c_source.m4 $< > $@
--- a/examples/dynamic/main.c Wed Dec 31 02:08:40 2008 +0800 +++ b/examples/dynamic/main.c Wed Dec 31 22:37:21 2008 +0800 @@ -24,6 +24,7 @@ co_aix orx,ory; int start_x,start_y; observer_t *obs1,*obs2; + int currentscene; }MyAppData; #define MBAPP_DATA(app,type) ((type *) ((app)->private)) @@ -185,7 +186,7 @@ app->rt = rt; app->rdman = X_MB_rdman(rt); - app->rootsprite= sprite_load("button",app->rdman, app->rdman->root_coord); + app->rootsprite= sprite_load(module,app->rdman, app->rdman->root_coord); return app; } @@ -194,6 +195,11 @@ app->private = (void *) data; } +mb_tman_t *MBApp_getTimer(MBApp *app) +{ + return X_MB_tman(app->rt); +} + void MBApp_loop(MBApp *en) { /* @@ -287,16 +293,41 @@ MBApp *myApp; +void switch_scene(const mb_timeval_t *tmo, const mb_timeval_t *now,void *arg) +{ + MyAppData *en = MBAPP_DATA((MBApp *)arg,MyAppData ); + mb_timeval_t timer,interval; + + + get_now(&timer); + MB_TIMEVAL_SET(&interval, 1 ,0); + MB_TIMEVAL_ADD(&timer, &interval); + mb_tman_timeout( MBApp_getTimer(myApp), &timer, switch_scene, myApp); + + en->currentscene = (en->currentscene+1) %2; + printf("switch to scene %d\n", en->currentscene); + MB_SPRITE_GOTO_SCENE(myApp->rootsprite,en->currentscene); +} + int main(int argc, char * const argv[]) { subject_t *subject; mb_button_t *b; mb_obj_t *button; MyAppData data; + mb_timeval_t tmo,interval; - myApp = MBApp_Init("button"); + if (argc > 1) + myApp = MBApp_Init(argv[1]); + else + myApp = MBApp_Init("scene"); + data.currentscene=0; MBApp_setData(myApp,&data); - b = mb_button_new(myApp, myApp->rootsprite, "btn"); - mb_button_add_onClick(b, test,NULL); + //b = mb_button_new(myApp, myApp->rootsprite, "btn"); + //mb_button_add_onClick(b, test,NULL); + get_now(&tmo); + MB_TIMEVAL_SET(&interval, 1 ,0); + mb_tman_timeout( MBApp_getTimer(myApp), &tmo, switch_scene, myApp); + MBApp_loop(myApp);