annotate examples/dynamic/text.c @ 601:8863d23cea4b openvg

Load images with Imlib2. Image loader, now, use Imlib2 to load images into ARGB 32bits pixels. It can load png, jpg, bmp, tiff, ...., etc.
author Thinker K.F. Li <thinker@branda.to>
date Fri, 02 Jul 2010 11:59:17 +0800
parents ea09fdab333a
children
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"
457
ea09fdab333a Fix typo
Thinker K.F. Li <thinker@branda.to>
parents: 456
diff changeset
11 #include "mb_af.h"
286
22d771e1b710 Add text program for text API
wycc
parents:
diff changeset
12
22d771e1b710 Add text program for text API
wycc
parents:
diff changeset
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
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;
454
9b8dda201ccb Make naming convention consistent with MadButterfly.
Thinker K.F. Li <thinker@branda.to>
parents: 453
diff changeset
22 }app_data_t;
286
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 {
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
22d771e1b710 Add text program for text API
wycc
parents:
diff changeset
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
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);
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
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 }
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
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;
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
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)
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
22d771e1b710 Add text program for text API
wycc
parents:
diff changeset
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
22d771e1b710 Add text program for text API
wycc
parents:
diff changeset
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
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);
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
22d771e1b710 Add text program for text API
wycc
parents:
diff changeset
76
22d771e1b710 Add text program for text API
wycc
parents:
diff changeset
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
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 */