annotate examples/dynamic/text.c @ 289:13ce87b6dbf5

Fix bug of sh_text_t that do not update it-self after changes. - It is wrong to compute bounding box. - location of left-top corner is (text->d_x, text->d_y) not (text->x, text->y).
author Thinker K.F. Li <thinker@branda.to>
date Sat, 31 Jan 2009 18:28:50 +0800
parents 22d771e1b710
children 137a73822d48
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>
22d771e1b710 Add text program for text API
wycc
parents:
diff changeset
10 #include "menu.h"
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");
22d771e1b710 Add text program for text API
wycc
parents:
diff changeset
30
22d771e1b710 Add text program for text API
wycc
parents:
diff changeset
31
22d771e1b710 Add text program for text API
wycc
parents:
diff changeset
32 get_now(&timer);
22d771e1b710 Add text program for text API
wycc
parents:
diff changeset
33 MB_TIMEVAL_SET(&interval, 1 ,0);
22d771e1b710 Add text program for text API
wycc
parents:
diff changeset
34 MB_TIMEVAL_ADD(&timer, &interval);
22d771e1b710 Add text program for text API
wycc
parents:
diff changeset
35 mb_tman_timeout( MBApp_getTimer(myApp), &timer, switch_scene, myApp);
22d771e1b710 Add text program for text API
wycc
parents:
diff changeset
36
22d771e1b710 Add text program for text API
wycc
parents:
diff changeset
37 en->currentscene = (en->currentscene + 1) % 2;
22d771e1b710 Add text program for text API
wycc
parents:
diff changeset
38 printf("xxx\n");
22d771e1b710 Add text program for text API
wycc
parents:
diff changeset
39 if (en->currentscene == 0) {
22d771e1b710 Add text program for text API
wycc
parents:
diff changeset
40 sh_text_set_text(text,"This is 0");
22d771e1b710 Add text program for text API
wycc
parents:
diff changeset
41 } else {
22d771e1b710 Add text program for text API
wycc
parents:
diff changeset
42 sh_text_set_text(text,"This is 1");
22d771e1b710 Add text program for text API
wycc
parents:
diff changeset
43 }
22d771e1b710 Add text program for text API
wycc
parents:
diff changeset
44 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
45 #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
46 /* 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
47 * 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
48 */
286
22d771e1b710 Add text program for text API
wycc
parents:
diff changeset
49 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
50 #endif
286
22d771e1b710 Add text program for text API
wycc
parents:
diff changeset
51 }
22d771e1b710 Add text program for text API
wycc
parents:
diff changeset
52
22d771e1b710 Add text program for text API
wycc
parents:
diff changeset
53 int main(int argc, char * const argv[]) {
22d771e1b710 Add text program for text API
wycc
parents:
diff changeset
54 subject_t *subject;
22d771e1b710 Add text program for text API
wycc
parents:
diff changeset
55 mb_button_t *b;
22d771e1b710 Add text program for text API
wycc
parents:
diff changeset
56 mb_obj_t *button;
22d771e1b710 Add text program for text API
wycc
parents:
diff changeset
57 MyAppData data;
22d771e1b710 Add text program for text API
wycc
parents:
diff changeset
58 mb_timeval_t tmo,interval;
22d771e1b710 Add text program for text API
wycc
parents:
diff changeset
59
22d771e1b710 Add text program for text API
wycc
parents:
diff changeset
60 if (argc > 1)
22d771e1b710 Add text program for text API
wycc
parents:
diff changeset
61 myApp = MBApp_Init(argv[1]);
22d771e1b710 Add text program for text API
wycc
parents:
diff changeset
62 else
22d771e1b710 Add text program for text API
wycc
parents:
diff changeset
63 myApp = MBApp_Init("mytext");
22d771e1b710 Add text program for text API
wycc
parents:
diff changeset
64 data.currentscene=0;
22d771e1b710 Add text program for text API
wycc
parents:
diff changeset
65 MBApp_setData(myApp,&data);
22d771e1b710 Add text program for text API
wycc
parents:
diff changeset
66 get_now(&tmo);
22d771e1b710 Add text program for text API
wycc
parents:
diff changeset
67 MB_TIMEVAL_SET(&interval, 1 ,0);
22d771e1b710 Add text program for text API
wycc
parents:
diff changeset
68 mb_tman_timeout( MBApp_getTimer(myApp), &tmo, switch_scene, myApp);
22d771e1b710 Add text program for text API
wycc
parents:
diff changeset
69
22d771e1b710 Add text program for text API
wycc
parents:
diff changeset
70
22d771e1b710 Add text program for text API
wycc
parents:
diff changeset
71 MBApp_loop(myApp);
22d771e1b710 Add text program for text API
wycc
parents:
diff changeset
72
22d771e1b710 Add text program for text API
wycc
parents:
diff changeset
73 return 0;
22d771e1b710 Add text program for text API
wycc
parents:
diff changeset
74 }
22d771e1b710 Add text program for text API
wycc
parents:
diff changeset
75
22d771e1b710 Add text program for text API
wycc
parents:
diff changeset
76 /* vim: set ts=4 */