Mercurial > MadButterfly
annotate examples/dynamic/text.c @ 333:bdf36a26e420
Make generated code clean.
- Before changes, generated code include a lot of redundant empty lines.
- Add dnl after each command when svg2code.py generates code lines.
author | Thinker K.F. Li <thinker@branda.to> |
---|---|
date | Sat, 07 Mar 2009 10:55:42 +0800 |
parents | 137a73822d48 |
children | 433fa83d16f9 |
rev | line source |
---|---|
286 | 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> | |
10 #include "menu.h" | |
11 #include "mbapp.h" | |
12 | |
13 | |
14 MBApp *myApp; | |
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; | |
22 }MyAppData; | |
23 | |
24 | |
25 void switch_scene(const mb_timeval_t *tmo, const mb_timeval_t *now,void *arg) | |
26 { | |
27 MyAppData *en = MBAPP_DATA((MBApp *)arg,MyAppData ); | |
28 mb_timeval_t timer,interval; | |
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 | 33 |
34 | |
35 get_now(&timer); | |
36 MB_TIMEVAL_SET(&interval, 1 ,0); | |
37 MB_TIMEVAL_ADD(&timer, &interval); | |
38 mb_tman_timeout( MBApp_getTimer(myApp), &timer, switch_scene, myApp); | |
39 | |
40 en->currentscene = (en->currentscene + 1) % 2; | |
41 printf("xxx\n"); | |
42 if (en->currentscene == 0) { | |
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 | 46 } else { |
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 | 50 } |
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 | 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 | 58 } |
59 | |
60 int main(int argc, char * const argv[]) { | |
61 subject_t *subject; | |
62 mb_button_t *b; | |
63 mb_obj_t *button; | |
64 MyAppData data; | |
65 mb_timeval_t tmo,interval; | |
66 | |
67 if (argc > 1) | |
68 myApp = MBApp_Init(argv[1]); | |
69 else | |
70 myApp = MBApp_Init("mytext"); | |
71 data.currentscene=0; | |
72 MBApp_setData(myApp,&data); | |
73 get_now(&tmo); | |
74 MB_TIMEVAL_SET(&interval, 1 ,0); | |
75 mb_tman_timeout( MBApp_getTimer(myApp), &tmo, switch_scene, myApp); | |
76 | |
77 | |
78 MBApp_loop(myApp); | |
79 | |
80 return 0; | |
81 } | |
82 | |
83 /* vim: set ts=4 */ |