Mercurial > MadButterfly
annotate examples/svg2code_ex/main.c @ 130:3a4d6179e6a9
change mb_c_source.m4 and mb_c_header.m4 to specify parent for SVG object
author | Thinker K.F. Li <thinker@branda.to> |
---|---|
date | Tue, 16 Sep 2008 21:23:34 +0800 |
parents | 17e97e92b76e |
children | 530bb7728546 |
rev | line source |
---|---|
117 | 1 /*! \file |
110 | 2 * |
3 * svg2code_ex is an example that show programmers how to create a | |
4 * menu with MadButterfly. | |
5 * | |
6 */ | |
78 | 7 #include <stdio.h> |
108 | 8 #include <mb/mb.h> |
78 | 9 #include "svg2code_ex.h" |
10 | |
83 | 11 typedef struct _ex_rt ex_rt_t; |
12 struct _ex_rt { | |
13 X_MB_runtime_t *rt; | |
14 svg2code_ex_t *code; | |
15 }; | |
16 | |
17 static void file_button_handler(event_t *evt, void *arg) { | |
18 ex_rt_t *ex_rt = (ex_rt_t *)arg; | |
19 | |
84
42698de1f653
Support translate() function for transform attribute of 'g' tag.
Thinker K.F. Li <thinker@branda.to>
parents:
83
diff
changeset
|
20 switch(evt->type) { |
42698de1f653
Support translate() function for transform attribute of 'g' tag.
Thinker K.F. Li <thinker@branda.to>
parents:
83
diff
changeset
|
21 case EVT_MOUSE_BUT_PRESS: |
42698de1f653
Support translate() function for transform attribute of 'g' tag.
Thinker K.F. Li <thinker@branda.to>
parents:
83
diff
changeset
|
22 coord_show(ex_rt->code->file_menu); |
108 | 23 /* Tell redraw manager that a coord (group) is chagned. */ |
122
17e97e92b76e
Encapsulate X_MB_runtime_t and support X keyboard events.
Thinker K.F. Li <thinker@branda.to>
parents:
117
diff
changeset
|
24 rdman_coord_changed(X_MB_rdman(ex_rt->rt), ex_rt->code->file_menu); |
108 | 25 /* Update changed part to UI. */ |
122
17e97e92b76e
Encapsulate X_MB_runtime_t and support X keyboard events.
Thinker K.F. Li <thinker@branda.to>
parents:
117
diff
changeset
|
26 rdman_redraw_changed(X_MB_rdman(ex_rt->rt)); |
84
42698de1f653
Support translate() function for transform attribute of 'g' tag.
Thinker K.F. Li <thinker@branda.to>
parents:
83
diff
changeset
|
27 break; |
42698de1f653
Support translate() function for transform attribute of 'g' tag.
Thinker K.F. Li <thinker@branda.to>
parents:
83
diff
changeset
|
28 } |
42698de1f653
Support translate() function for transform attribute of 'g' tag.
Thinker K.F. Li <thinker@branda.to>
parents:
83
diff
changeset
|
29 } |
42698de1f653
Support translate() function for transform attribute of 'g' tag.
Thinker K.F. Li <thinker@branda.to>
parents:
83
diff
changeset
|
30 |
42698de1f653
Support translate() function for transform attribute of 'g' tag.
Thinker K.F. Li <thinker@branda.to>
parents:
83
diff
changeset
|
31 static void file_menu_handler(event_t *evt, void *arg) { |
42698de1f653
Support translate() function for transform attribute of 'g' tag.
Thinker K.F. Li <thinker@branda.to>
parents:
83
diff
changeset
|
32 ex_rt_t *ex_rt = (ex_rt_t *)arg; |
122
17e97e92b76e
Encapsulate X_MB_runtime_t and support X keyboard events.
Thinker K.F. Li <thinker@branda.to>
parents:
117
diff
changeset
|
33 redraw_man_t *rdman; |
84
42698de1f653
Support translate() function for transform attribute of 'g' tag.
Thinker K.F. Li <thinker@branda.to>
parents:
83
diff
changeset
|
34 |
122
17e97e92b76e
Encapsulate X_MB_runtime_t and support X keyboard events.
Thinker K.F. Li <thinker@branda.to>
parents:
117
diff
changeset
|
35 rdman = X_MB_rdman(ex_rt->rt); |
84
42698de1f653
Support translate() function for transform attribute of 'g' tag.
Thinker K.F. Li <thinker@branda.to>
parents:
83
diff
changeset
|
36 switch(evt->type) { |
42698de1f653
Support translate() function for transform attribute of 'g' tag.
Thinker K.F. Li <thinker@branda.to>
parents:
83
diff
changeset
|
37 case EVT_MOUSE_BUT_PRESS: |
42698de1f653
Support translate() function for transform attribute of 'g' tag.
Thinker K.F. Li <thinker@branda.to>
parents:
83
diff
changeset
|
38 coord_hide(ex_rt->code->file_menu); |
108 | 39 /* Tell redraw manager that a coord (group) is chagned. */ |
122
17e97e92b76e
Encapsulate X_MB_runtime_t and support X keyboard events.
Thinker K.F. Li <thinker@branda.to>
parents:
117
diff
changeset
|
40 rdman_coord_changed(rdman, ex_rt->code->file_menu); |
108 | 41 /* Update changed part to UI. */ |
122
17e97e92b76e
Encapsulate X_MB_runtime_t and support X keyboard events.
Thinker K.F. Li <thinker@branda.to>
parents:
117
diff
changeset
|
42 rdman_redraw_changed(rdman); |
84
42698de1f653
Support translate() function for transform attribute of 'g' tag.
Thinker K.F. Li <thinker@branda.to>
parents:
83
diff
changeset
|
43 break; |
42698de1f653
Support translate() function for transform attribute of 'g' tag.
Thinker K.F. Li <thinker@branda.to>
parents:
83
diff
changeset
|
44 } |
83 | 45 } |
46 | |
78 | 47 int main(int argc, char * const argv[]) { |
122
17e97e92b76e
Encapsulate X_MB_runtime_t and support X keyboard events.
Thinker K.F. Li <thinker@branda.to>
parents:
117
diff
changeset
|
48 X_MB_runtime_t *rt; |
17e97e92b76e
Encapsulate X_MB_runtime_t and support X keyboard events.
Thinker K.F. Li <thinker@branda.to>
parents:
117
diff
changeset
|
49 redraw_man_t *rdman; |
78 | 50 svg2code_ex_t *svg2code; |
83 | 51 ob_factory_t *factory; |
52 subject_t *subject; | |
53 ex_rt_t ex_rt; | |
78 | 54 |
108 | 55 /* |
56 * Initialize a runtime with XLib as backend. | |
57 */ | |
122
17e97e92b76e
Encapsulate X_MB_runtime_t and support X keyboard events.
Thinker K.F. Li <thinker@branda.to>
parents:
117
diff
changeset
|
58 rt = X_MB_new(":0.0", 800, 600); |
78 | 59 |
108 | 60 /* |
61 * Instantiate objects from a SVG file. | |
62 */ | |
122
17e97e92b76e
Encapsulate X_MB_runtime_t and support X keyboard events.
Thinker K.F. Li <thinker@branda.to>
parents:
117
diff
changeset
|
63 rdman = X_MB_rdman(rt); |
130
3a4d6179e6a9
change mb_c_source.m4 and mb_c_header.m4 to specify parent for SVG object
Thinker K.F. Li <thinker@branda.to>
parents:
122
diff
changeset
|
64 svg2code = svg2code_ex_new(rdman, rdman->root_coord); |
78 | 65 |
108 | 66 /* |
67 * Get observer factory | |
68 */ | |
122
17e97e92b76e
Encapsulate X_MB_runtime_t and support X keyboard events.
Thinker K.F. Li <thinker@branda.to>
parents:
117
diff
changeset
|
69 factory = rdman_get_ob_factory(rdman); |
108 | 70 /* |
71 * Register observers to subjects of events for objects. | |
72 */ | |
83 | 73 subject = coord_get_mouse_event(svg2code->file_button); |
122
17e97e92b76e
Encapsulate X_MB_runtime_t and support X keyboard events.
Thinker K.F. Li <thinker@branda.to>
parents:
117
diff
changeset
|
74 ex_rt.rt = rt; |
83 | 75 ex_rt.code = svg2code; |
76 subject_add_observer(factory, subject, file_button_handler, &ex_rt); | |
84
42698de1f653
Support translate() function for transform attribute of 'g' tag.
Thinker K.F. Li <thinker@branda.to>
parents:
83
diff
changeset
|
77 subject = coord_get_mouse_event(svg2code->file_menu); |
42698de1f653
Support translate() function for transform attribute of 'g' tag.
Thinker K.F. Li <thinker@branda.to>
parents:
83
diff
changeset
|
78 subject_add_observer(factory, subject, file_menu_handler, &ex_rt); |
83 | 79 |
108 | 80 /* |
81 * Start handle connections, includes one to X server. | |
82 * User start to interact with the application. | |
83 */ | |
122
17e97e92b76e
Encapsulate X_MB_runtime_t and support X keyboard events.
Thinker K.F. Li <thinker@branda.to>
parents:
117
diff
changeset
|
84 X_MB_handle_connection(rt); |
83 | 85 |
108 | 86 /* |
87 * Clean | |
88 */ | |
83 | 89 svg2code_ex_free(svg2code); |
122
17e97e92b76e
Encapsulate X_MB_runtime_t and support X keyboard events.
Thinker K.F. Li <thinker@branda.to>
parents:
117
diff
changeset
|
90 X_MB_free(rt); |
78 | 91 |
92 return 0; | |
93 } |