Mercurial > MadButterfly
annotate examples/dynamic/text.c @ 456:26c302b47de1
Change name of header files.
author | Thinker K.F. Li <thinker@branda.to> |
---|---|
date | Thu, 06 Aug 2009 15:38:04 +0800 |
parents | 9b8dda201ccb |
children | ea09fdab333a |
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> | |
387
433fa83d16f9
Corrected build dependence - able to build in Ubuntu Intrepid
Ben Lau <xbenlau@gmail.com>
parents:
291
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 "m_af.h" |
286 | 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; |
286 | 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; |
286 | 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 ); |
286 | 28 mb_timeval_t timer,interval; |
454
9b8dda201ccb
Make naming convention consistent with MadButterfly.
Thinker K.F. Li <thinker@branda.to>
parents:
453
diff
changeset
|
29 shape_t *text = (shape_t *) MB_SPRITE_GET_OBJ(app->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); | |
454
9b8dda201ccb
Make naming convention consistent with MadButterfly.
Thinker K.F. Li <thinker@branda.to>
parents:
453
diff
changeset
|
38 mb_tman_timeout( mbaf_get_timer(app), &timer, switch_scene, app); |
286 | 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 } |
454
9b8dda201ccb
Make naming convention consistent with MadButterfly.
Thinker K.F. Li <thinker@branda.to>
parents:
453
diff
changeset
|
51 rdman_shape_changed(MBAF_RDMAN(app), 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 */ |
454
9b8dda201ccb
Make naming convention consistent with MadButterfly.
Thinker K.F. Li <thinker@branda.to>
parents:
453
diff
changeset
|
56 rdman_redraw_changed(MBAF_RDMAN(app)); |
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; | |
454
9b8dda201ccb
Make naming convention consistent with MadButterfly.
Thinker K.F. Li <thinker@branda.to>
parents:
453
diff
changeset
|
64 app_data_t data; |
286 | 65 mb_timeval_t tmo,interval; |
66 | |
67 if (argc > 1) | |
454
9b8dda201ccb
Make naming convention consistent with MadButterfly.
Thinker K.F. Li <thinker@branda.to>
parents:
453
diff
changeset
|
68 app = mbaf_init(argv[1], ""); |
286 | 69 else |
454
9b8dda201ccb
Make naming convention consistent with MadButterfly.
Thinker K.F. Li <thinker@branda.to>
parents:
453
diff
changeset
|
70 app = mbaf_init("mytext", ".libs"); |
286 | 71 data.currentscene=0; |
454
9b8dda201ccb
Make naming convention consistent with MadButterfly.
Thinker K.F. Li <thinker@branda.to>
parents:
453
diff
changeset
|
72 mbaf_set_data(app,&data); |
286 | 73 get_now(&tmo); |
74 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
|
75 mb_tman_timeout( mbaf_get_timer(app), &tmo, switch_scene, app); |
286 | 76 |
77 | |
454
9b8dda201ccb
Make naming convention consistent with MadButterfly.
Thinker K.F. Li <thinker@branda.to>
parents:
453
diff
changeset
|
78 mbaf_loop(app); |
286 | 79 |
80 return 0; | |
81 } | |
82 | |
83 /* vim: set ts=4 */ |