Mercurial > MadButterfly
annotate examples/dynamic/hello.c @ 1059:36aef79d68e4
Move macros privated used by redraw manager to redraw_man.c
author | Thinker K.F. Li <thinker@codemud.net> |
---|---|
date | Sun, 28 Nov 2010 12:07:37 +0800 |
parents | 26c302b47de1 |
children |
rev | line source |
---|---|
247 | 1 /*! \file |
2 * | |
3 * svg2code_ex is an example that show programmers how to create a | |
4 * menu with MadButterfly. | |
5 * | |
6 */ | |
7 #include <stdio.h> | |
8 #include <mb.h> | |
9 #include <string.h> | |
387
433fa83d16f9
Corrected build dependence - able to build in Ubuntu Intrepid
Ben Lau <xbenlau@gmail.com>
parents:
247
diff
changeset
|
10 //#include "menu.h" |
456
26c302b47de1
Change name of header files.
Thinker K.F. Li <thinker@branda.to>
parents:
454
diff
changeset
|
11 #include "mb_af.h" |
247 | 12 |
13 | |
454
9b8dda201ccb
Make naming convention consistent with MadButterfly.
Thinker K.F. Li <thinker@branda.to>
parents:
453
diff
changeset
|
14 mbaf_t *app; |
247 | 15 |
16 typedef struct { | |
17 shape_t *rect; | |
18 co_aix orx,ory; | |
19 int start_x,start_y; | |
20 observer_t *obs1,*obs2; | |
21 int currentscene; | |
454
9b8dda201ccb
Make naming convention consistent with MadButterfly.
Thinker K.F. Li <thinker@branda.to>
parents:
453
diff
changeset
|
22 }app_data_t; |
247 | 23 |
24 | |
25 void switch_scene(const mb_timeval_t *tmo, const mb_timeval_t *now,void *arg) | |
26 { | |
454
9b8dda201ccb
Make naming convention consistent with MadButterfly.
Thinker K.F. Li <thinker@branda.to>
parents:
453
diff
changeset
|
27 app_data_t *en = MBAF_DATA((mbaf_t *)arg,app_data_t ); |
247 | 28 mb_timeval_t timer,interval; |
29 | |
30 | |
31 get_now(&timer); | |
32 MB_TIMEVAL_SET(&interval, 1 ,0); | |
33 MB_TIMEVAL_ADD(&timer, &interval); | |
454
9b8dda201ccb
Make naming convention consistent with MadButterfly.
Thinker K.F. Li <thinker@branda.to>
parents:
453
diff
changeset
|
34 mb_tman_timeout( mbaf_get_timer(app), &timer, switch_scene, app); |
247 | 35 |
36 en->currentscene = (en->currentscene + 1) % 2; | |
37 printf("switch to scene %d\n", en->currentscene + 1); | |
454
9b8dda201ccb
Make naming convention consistent with MadButterfly.
Thinker K.F. Li <thinker@branda.to>
parents:
453
diff
changeset
|
38 MB_SPRITE_GOTO_SCENE(app->rootsprite,en->currentscene + 1); |
247 | 39 } |
40 | |
41 int main(int argc, char * const argv[]) { | |
42 subject_t *subject; | |
43 mb_button_t *b; | |
44 mb_obj_t *button; | |
454
9b8dda201ccb
Make naming convention consistent with MadButterfly.
Thinker K.F. Li <thinker@branda.to>
parents:
453
diff
changeset
|
45 app_data_t data; |
247 | 46 mb_timeval_t tmo,interval; |
47 | |
453
84ce2d4a8c3f
Change interface of sprite loader.
Thinker K.F. Li <thinker@branda.to>
parents:
399
diff
changeset
|
48 if (argc > 1) |
454
9b8dda201ccb
Make naming convention consistent with MadButterfly.
Thinker K.F. Li <thinker@branda.to>
parents:
453
diff
changeset
|
49 app = mbaf_init(argv[1], ""); |
247 | 50 else |
454
9b8dda201ccb
Make naming convention consistent with MadButterfly.
Thinker K.F. Li <thinker@branda.to>
parents:
453
diff
changeset
|
51 app = mbaf_init("scene", ".libs"); |
247 | 52 data.currentscene=0; |
454
9b8dda201ccb
Make naming convention consistent with MadButterfly.
Thinker K.F. Li <thinker@branda.to>
parents:
453
diff
changeset
|
53 mbaf_set_data(app,&data); |
9b8dda201ccb
Make naming convention consistent with MadButterfly.
Thinker K.F. Li <thinker@branda.to>
parents:
453
diff
changeset
|
54 //b = mb_button_new(app, app->rootsprite, "btn"); |
247 | 55 //mb_button_add_onClick(b, test,NULL); |
56 get_now(&tmo); | |
57 MB_TIMEVAL_SET(&interval, 1 ,0); | |
454
9b8dda201ccb
Make naming convention consistent with MadButterfly.
Thinker K.F. Li <thinker@branda.to>
parents:
453
diff
changeset
|
58 mb_tman_timeout( mbaf_get_timer(app), &tmo, switch_scene, app); |
247 | 59 |
60 | |
454
9b8dda201ccb
Make naming convention consistent with MadButterfly.
Thinker K.F. Li <thinker@branda.to>
parents:
453
diff
changeset
|
61 mbaf_loop(app); |
247 | 62 |
63 return 0; | |
64 } | |
65 | |
66 /* vim: set ts=4 */ |