annotate examples/dynamic/hello.c @ 303:f894b30676e9

Add MBAF object suport. This is still work in progress yet. However, it won't affect other features. Therefore, it is checked in before it become mature.
author wycc
date Sun, 15 Feb 2009 08:34:57 +0800
parents d9a78c859660
children 433fa83d16f9
rev   line source
247
d9a78c859660 Seperate the frameowrk codes from the main.c.
wycc
parents:
diff changeset
1 /*! \file
d9a78c859660 Seperate the frameowrk codes from the main.c.
wycc
parents:
diff changeset
2 *
d9a78c859660 Seperate the frameowrk codes from the main.c.
wycc
parents:
diff changeset
3 * svg2code_ex is an example that show programmers how to create a
d9a78c859660 Seperate the frameowrk codes from the main.c.
wycc
parents:
diff changeset
4 * menu with MadButterfly.
d9a78c859660 Seperate the frameowrk codes from the main.c.
wycc
parents:
diff changeset
5 *
d9a78c859660 Seperate the frameowrk codes from the main.c.
wycc
parents:
diff changeset
6 */
d9a78c859660 Seperate the frameowrk codes from the main.c.
wycc
parents:
diff changeset
7 #include <stdio.h>
d9a78c859660 Seperate the frameowrk codes from the main.c.
wycc
parents:
diff changeset
8 #include <mb.h>
d9a78c859660 Seperate the frameowrk codes from the main.c.
wycc
parents:
diff changeset
9 #include <string.h>
d9a78c859660 Seperate the frameowrk codes from the main.c.
wycc
parents:
diff changeset
10 #include "menu.h"
d9a78c859660 Seperate the frameowrk codes from the main.c.
wycc
parents:
diff changeset
11 #include "mbapp.h"
d9a78c859660 Seperate the frameowrk codes from the main.c.
wycc
parents:
diff changeset
12
d9a78c859660 Seperate the frameowrk codes from the main.c.
wycc
parents:
diff changeset
13
d9a78c859660 Seperate the frameowrk codes from the main.c.
wycc
parents:
diff changeset
14 MBApp *myApp;
d9a78c859660 Seperate the frameowrk codes from the main.c.
wycc
parents:
diff changeset
15
d9a78c859660 Seperate the frameowrk codes from the main.c.
wycc
parents:
diff changeset
16 typedef struct {
d9a78c859660 Seperate the frameowrk codes from the main.c.
wycc
parents:
diff changeset
17 shape_t *rect;
d9a78c859660 Seperate the frameowrk codes from the main.c.
wycc
parents:
diff changeset
18 co_aix orx,ory;
d9a78c859660 Seperate the frameowrk codes from the main.c.
wycc
parents:
diff changeset
19 int start_x,start_y;
d9a78c859660 Seperate the frameowrk codes from the main.c.
wycc
parents:
diff changeset
20 observer_t *obs1,*obs2;
d9a78c859660 Seperate the frameowrk codes from the main.c.
wycc
parents:
diff changeset
21 int currentscene;
d9a78c859660 Seperate the frameowrk codes from the main.c.
wycc
parents:
diff changeset
22 }MyAppData;
d9a78c859660 Seperate the frameowrk codes from the main.c.
wycc
parents:
diff changeset
23
d9a78c859660 Seperate the frameowrk codes from the main.c.
wycc
parents:
diff changeset
24
d9a78c859660 Seperate the frameowrk codes from the main.c.
wycc
parents:
diff changeset
25 void switch_scene(const mb_timeval_t *tmo, const mb_timeval_t *now,void *arg)
d9a78c859660 Seperate the frameowrk codes from the main.c.
wycc
parents:
diff changeset
26 {
d9a78c859660 Seperate the frameowrk codes from the main.c.
wycc
parents:
diff changeset
27 MyAppData *en = MBAPP_DATA((MBApp *)arg,MyAppData );
d9a78c859660 Seperate the frameowrk codes from the main.c.
wycc
parents:
diff changeset
28 mb_timeval_t timer,interval;
d9a78c859660 Seperate the frameowrk codes from the main.c.
wycc
parents:
diff changeset
29
d9a78c859660 Seperate the frameowrk codes from the main.c.
wycc
parents:
diff changeset
30
d9a78c859660 Seperate the frameowrk codes from the main.c.
wycc
parents:
diff changeset
31 get_now(&timer);
d9a78c859660 Seperate the frameowrk codes from the main.c.
wycc
parents:
diff changeset
32 MB_TIMEVAL_SET(&interval, 1 ,0);
d9a78c859660 Seperate the frameowrk codes from the main.c.
wycc
parents:
diff changeset
33 MB_TIMEVAL_ADD(&timer, &interval);
d9a78c859660 Seperate the frameowrk codes from the main.c.
wycc
parents:
diff changeset
34 mb_tman_timeout( MBApp_getTimer(myApp), &timer, switch_scene, myApp);
d9a78c859660 Seperate the frameowrk codes from the main.c.
wycc
parents:
diff changeset
35
d9a78c859660 Seperate the frameowrk codes from the main.c.
wycc
parents:
diff changeset
36 en->currentscene = (en->currentscene + 1) % 2;
d9a78c859660 Seperate the frameowrk codes from the main.c.
wycc
parents:
diff changeset
37 printf("switch to scene %d\n", en->currentscene + 1);
d9a78c859660 Seperate the frameowrk codes from the main.c.
wycc
parents:
diff changeset
38 MB_SPRITE_GOTO_SCENE(myApp->rootsprite,en->currentscene + 1);
d9a78c859660 Seperate the frameowrk codes from the main.c.
wycc
parents:
diff changeset
39 }
d9a78c859660 Seperate the frameowrk codes from the main.c.
wycc
parents:
diff changeset
40
d9a78c859660 Seperate the frameowrk codes from the main.c.
wycc
parents:
diff changeset
41 int main(int argc, char * const argv[]) {
d9a78c859660 Seperate the frameowrk codes from the main.c.
wycc
parents:
diff changeset
42 subject_t *subject;
d9a78c859660 Seperate the frameowrk codes from the main.c.
wycc
parents:
diff changeset
43 mb_button_t *b;
d9a78c859660 Seperate the frameowrk codes from the main.c.
wycc
parents:
diff changeset
44 mb_obj_t *button;
d9a78c859660 Seperate the frameowrk codes from the main.c.
wycc
parents:
diff changeset
45 MyAppData data;
d9a78c859660 Seperate the frameowrk codes from the main.c.
wycc
parents:
diff changeset
46 mb_timeval_t tmo,interval;
d9a78c859660 Seperate the frameowrk codes from the main.c.
wycc
parents:
diff changeset
47
d9a78c859660 Seperate the frameowrk codes from the main.c.
wycc
parents:
diff changeset
48 if (argc > 1)
d9a78c859660 Seperate the frameowrk codes from the main.c.
wycc
parents:
diff changeset
49 myApp = MBApp_Init(argv[1]);
d9a78c859660 Seperate the frameowrk codes from the main.c.
wycc
parents:
diff changeset
50 else
d9a78c859660 Seperate the frameowrk codes from the main.c.
wycc
parents:
diff changeset
51 myApp = MBApp_Init("scene");
d9a78c859660 Seperate the frameowrk codes from the main.c.
wycc
parents:
diff changeset
52 data.currentscene=0;
d9a78c859660 Seperate the frameowrk codes from the main.c.
wycc
parents:
diff changeset
53 MBApp_setData(myApp,&data);
d9a78c859660 Seperate the frameowrk codes from the main.c.
wycc
parents:
diff changeset
54 //b = mb_button_new(myApp, myApp->rootsprite, "btn");
d9a78c859660 Seperate the frameowrk codes from the main.c.
wycc
parents:
diff changeset
55 //mb_button_add_onClick(b, test,NULL);
d9a78c859660 Seperate the frameowrk codes from the main.c.
wycc
parents:
diff changeset
56 get_now(&tmo);
d9a78c859660 Seperate the frameowrk codes from the main.c.
wycc
parents:
diff changeset
57 MB_TIMEVAL_SET(&interval, 1 ,0);
d9a78c859660 Seperate the frameowrk codes from the main.c.
wycc
parents:
diff changeset
58 mb_tman_timeout( MBApp_getTimer(myApp), &tmo, switch_scene, myApp);
d9a78c859660 Seperate the frameowrk codes from the main.c.
wycc
parents:
diff changeset
59
d9a78c859660 Seperate the frameowrk codes from the main.c.
wycc
parents:
diff changeset
60
d9a78c859660 Seperate the frameowrk codes from the main.c.
wycc
parents:
diff changeset
61 MBApp_loop(myApp);
d9a78c859660 Seperate the frameowrk codes from the main.c.
wycc
parents:
diff changeset
62
d9a78c859660 Seperate the frameowrk codes from the main.c.
wycc
parents:
diff changeset
63 return 0;
d9a78c859660 Seperate the frameowrk codes from the main.c.
wycc
parents:
diff changeset
64 }
d9a78c859660 Seperate the frameowrk codes from the main.c.
wycc
parents:
diff changeset
65
d9a78c859660 Seperate the frameowrk codes from the main.c.
wycc
parents:
diff changeset
66 /* vim: set ts=4 */