annotate examples/dynamic/text.c @ 387:433fa83d16f9

Corrected build dependence - able to build in Ubuntu Intrepid Removed '#include "menu.h"' from example code which is not needed
author Ben Lau <xbenlau@gmail.com>
date Fri, 10 Apr 2009 16:04:05 +0800
parents 137a73822d48
children 31b6633e3538
rev   line source
286
22d771e1b710 Add text program for text API
wycc
parents:
diff changeset
1 /*! \file
22d771e1b710 Add text program for text API
wycc
parents:
diff changeset
2 *
22d771e1b710 Add text program for text API
wycc
parents:
diff changeset
3 * svg2code_ex is an example that show programmers how to create a
22d771e1b710 Add text program for text API
wycc
parents:
diff changeset
4 * menu with MadButterfly.
22d771e1b710 Add text program for text API
wycc
parents:
diff changeset
5 *
22d771e1b710 Add text program for text API
wycc
parents:
diff changeset
6 */
22d771e1b710 Add text program for text API
wycc
parents:
diff changeset
7 #include <stdio.h>
22d771e1b710 Add text program for text API
wycc
parents:
diff changeset
8 #include <mb.h>
22d771e1b710 Add text program for text API
wycc
parents:
diff changeset
9 #include <string.h>
387
433fa83d16f9 Corrected build dependence - able to build in Ubuntu Intrepid
Ben Lau <xbenlau@gmail.com>
parents: 291
diff changeset
10 //#include "menu.h"
286
22d771e1b710 Add text program for text API
wycc
parents:
diff changeset
11 #include "mbapp.h"
22d771e1b710 Add text program for text API
wycc
parents:
diff changeset
12
22d771e1b710 Add text program for text API
wycc
parents:
diff changeset
13
22d771e1b710 Add text program for text API
wycc
parents:
diff changeset
14 MBApp *myApp;
22d771e1b710 Add text program for text API
wycc
parents:
diff changeset
15
22d771e1b710 Add text program for text API
wycc
parents:
diff changeset
16 typedef struct {
22d771e1b710 Add text program for text API
wycc
parents:
diff changeset
17 shape_t *rect;
22d771e1b710 Add text program for text API
wycc
parents:
diff changeset
18 co_aix orx,ory;
22d771e1b710 Add text program for text API
wycc
parents:
diff changeset
19 int start_x,start_y;
22d771e1b710 Add text program for text API
wycc
parents:
diff changeset
20 observer_t *obs1,*obs2;
22d771e1b710 Add text program for text API
wycc
parents:
diff changeset
21 int currentscene;
22d771e1b710 Add text program for text API
wycc
parents:
diff changeset
22 }MyAppData;
22d771e1b710 Add text program for text API
wycc
parents:
diff changeset
23
22d771e1b710 Add text program for text API
wycc
parents:
diff changeset
24
22d771e1b710 Add text program for text API
wycc
parents:
diff changeset
25 void switch_scene(const mb_timeval_t *tmo, const mb_timeval_t *now,void *arg)
22d771e1b710 Add text program for text API
wycc
parents:
diff changeset
26 {
22d771e1b710 Add text program for text API
wycc
parents:
diff changeset
27 MyAppData *en = MBAPP_DATA((MBApp *)arg,MyAppData );
22d771e1b710 Add text program for text API
wycc
parents:
diff changeset
28 mb_timeval_t timer,interval;
22d771e1b710 Add text program for text API
wycc
parents:
diff changeset
29 shape_t *text = (shape_t *) MB_SPRITE_GET_OBJ(myApp->rootsprite,"mytext");
291
137a73822d48 Add sh_text_set_style support to change the style of text element.
wycc
parents: 289
diff changeset
30 mb_textstyle_t style;
137a73822d48 Add sh_text_set_style support to change the style of text element.
wycc
parents: 289
diff changeset
31
137a73822d48 Add sh_text_set_style support to change the style of text element.
wycc
parents: 289
diff changeset
32 mb_textstyle_init(&style);
286
22d771e1b710 Add text program for text API
wycc
parents:
diff changeset
33
22d771e1b710 Add text program for text API
wycc
parents:
diff changeset
34
22d771e1b710 Add text program for text API
wycc
parents:
diff changeset
35 get_now(&timer);
22d771e1b710 Add text program for text API
wycc
parents:
diff changeset
36 MB_TIMEVAL_SET(&interval, 1 ,0);
22d771e1b710 Add text program for text API
wycc
parents:
diff changeset
37 MB_TIMEVAL_ADD(&timer, &interval);
22d771e1b710 Add text program for text API
wycc
parents:
diff changeset
38 mb_tman_timeout( MBApp_getTimer(myApp), &timer, switch_scene, myApp);
22d771e1b710 Add text program for text API
wycc
parents:
diff changeset
39
22d771e1b710 Add text program for text API
wycc
parents:
diff changeset
40 en->currentscene = (en->currentscene + 1) % 2;
22d771e1b710 Add text program for text API
wycc
parents:
diff changeset
41 printf("xxx\n");
22d771e1b710 Add text program for text API
wycc
parents:
diff changeset
42 if (en->currentscene == 0) {
22d771e1b710 Add text program for text API
wycc
parents:
diff changeset
43 sh_text_set_text(text,"This is 0");
291
137a73822d48 Add sh_text_set_style support to change the style of text element.
wycc
parents: 289
diff changeset
44 mb_textstyle_set_color(&style, TEXTCOLOR_RGB(255,0,0));
137a73822d48 Add sh_text_set_style support to change the style of text element.
wycc
parents: 289
diff changeset
45 sh_text_set_style(text,0,5,&style);
286
22d771e1b710 Add text program for text API
wycc
parents:
diff changeset
46 } else {
22d771e1b710 Add text program for text API
wycc
parents:
diff changeset
47 sh_text_set_text(text,"This is 1");
291
137a73822d48 Add sh_text_set_style support to change the style of text element.
wycc
parents: 289
diff changeset
48 mb_textstyle_set_color(&style, TEXTCOLOR_RGB(0,255,0));
137a73822d48 Add sh_text_set_style support to change the style of text element.
wycc
parents: 289
diff changeset
49 sh_text_set_style(text,0,5,&style);
286
22d771e1b710 Add text program for text API
wycc
parents:
diff changeset
50 }
22d771e1b710 Add text program for text API
wycc
parents:
diff changeset
51 rdman_shape_changed(MBAPP_RDMAN(myApp), text);
289
13ce87b6dbf5 Fix bug of sh_text_t that do not update it-self after changes.
Thinker K.F. Li <thinker@branda.to>
parents: 286
diff changeset
52 #if 0
13ce87b6dbf5 Fix bug of sh_text_t that do not update it-self after changes.
Thinker K.F. Li <thinker@branda.to>
parents: 286
diff changeset
53 /* Removed!
13ce87b6dbf5 Fix bug of sh_text_t that do not update it-self after changes.
Thinker K.F. Li <thinker@branda.to>
parents: 286
diff changeset
54 * X_MB_handle_connection() will invoke it automatically.
13ce87b6dbf5 Fix bug of sh_text_t that do not update it-self after changes.
Thinker K.F. Li <thinker@branda.to>
parents: 286
diff changeset
55 */
286
22d771e1b710 Add text program for text API
wycc
parents:
diff changeset
56 rdman_redraw_changed(MBAPP_RDMAN(myApp));
289
13ce87b6dbf5 Fix bug of sh_text_t that do not update it-self after changes.
Thinker K.F. Li <thinker@branda.to>
parents: 286
diff changeset
57 #endif
286
22d771e1b710 Add text program for text API
wycc
parents:
diff changeset
58 }
22d771e1b710 Add text program for text API
wycc
parents:
diff changeset
59
22d771e1b710 Add text program for text API
wycc
parents:
diff changeset
60 int main(int argc, char * const argv[]) {
22d771e1b710 Add text program for text API
wycc
parents:
diff changeset
61 subject_t *subject;
22d771e1b710 Add text program for text API
wycc
parents:
diff changeset
62 mb_button_t *b;
22d771e1b710 Add text program for text API
wycc
parents:
diff changeset
63 mb_obj_t *button;
22d771e1b710 Add text program for text API
wycc
parents:
diff changeset
64 MyAppData data;
22d771e1b710 Add text program for text API
wycc
parents:
diff changeset
65 mb_timeval_t tmo,interval;
22d771e1b710 Add text program for text API
wycc
parents:
diff changeset
66
22d771e1b710 Add text program for text API
wycc
parents:
diff changeset
67 if (argc > 1)
22d771e1b710 Add text program for text API
wycc
parents:
diff changeset
68 myApp = MBApp_Init(argv[1]);
22d771e1b710 Add text program for text API
wycc
parents:
diff changeset
69 else
22d771e1b710 Add text program for text API
wycc
parents:
diff changeset
70 myApp = MBApp_Init("mytext");
22d771e1b710 Add text program for text API
wycc
parents:
diff changeset
71 data.currentscene=0;
22d771e1b710 Add text program for text API
wycc
parents:
diff changeset
72 MBApp_setData(myApp,&data);
22d771e1b710 Add text program for text API
wycc
parents:
diff changeset
73 get_now(&tmo);
22d771e1b710 Add text program for text API
wycc
parents:
diff changeset
74 MB_TIMEVAL_SET(&interval, 1 ,0);
22d771e1b710 Add text program for text API
wycc
parents:
diff changeset
75 mb_tman_timeout( MBApp_getTimer(myApp), &tmo, switch_scene, myApp);
22d771e1b710 Add text program for text API
wycc
parents:
diff changeset
76
22d771e1b710 Add text program for text API
wycc
parents:
diff changeset
77
22d771e1b710 Add text program for text API
wycc
parents:
diff changeset
78 MBApp_loop(myApp);
22d771e1b710 Add text program for text API
wycc
parents:
diff changeset
79
22d771e1b710 Add text program for text API
wycc
parents:
diff changeset
80 return 0;
22d771e1b710 Add text program for text API
wycc
parents:
diff changeset
81 }
22d771e1b710 Add text program for text API
wycc
parents:
diff changeset
82
22d771e1b710 Add text program for text API
wycc
parents:
diff changeset
83 /* vim: set ts=4 */