Mercurial > MadButterfly
annotate examples/svg2code_ex/main.c @ 110:c14cb6d12030
-
author | Thinker K.F. Li <thinker@branda.to> |
---|---|
date | Fri, 12 Sep 2008 15:31:10 +0800 |
parents | 565b55508c8d |
children | e4e47d2cdbcd |
rev | line source |
---|---|
110 | 1 /*! \page svg2code_ex |
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. */ |
84
42698de1f653
Support translate() function for transform attribute of 'g' tag.
Thinker K.F. Li <thinker@branda.to>
parents:
83
diff
changeset
|
24 rdman_coord_changed(ex_rt->rt->rdman, ex_rt->code->file_menu); |
108 | 25 /* Update changed part to UI. */ |
84
42698de1f653
Support translate() function for transform attribute of 'g' tag.
Thinker K.F. Li <thinker@branda.to>
parents:
83
diff
changeset
|
26 rdman_redraw_changed(ex_rt->rt->rdman); |
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; |
42698de1f653
Support translate() function for transform attribute of 'g' tag.
Thinker K.F. Li <thinker@branda.to>
parents:
83
diff
changeset
|
33 |
42698de1f653
Support translate() function for transform attribute of 'g' tag.
Thinker K.F. Li <thinker@branda.to>
parents:
83
diff
changeset
|
34 switch(evt->type) { |
42698de1f653
Support translate() function for transform attribute of 'g' tag.
Thinker K.F. Li <thinker@branda.to>
parents:
83
diff
changeset
|
35 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
|
36 coord_hide(ex_rt->code->file_menu); |
108 | 37 /* Tell redraw manager that a coord (group) is chagned. */ |
84
42698de1f653
Support translate() function for transform attribute of 'g' tag.
Thinker K.F. Li <thinker@branda.to>
parents:
83
diff
changeset
|
38 rdman_coord_changed(ex_rt->rt->rdman, ex_rt->code->file_menu); |
108 | 39 /* Update changed part to UI. */ |
84
42698de1f653
Support translate() function for transform attribute of 'g' tag.
Thinker K.F. Li <thinker@branda.to>
parents:
83
diff
changeset
|
40 rdman_redraw_changed(ex_rt->rt->rdman); |
42698de1f653
Support translate() function for transform attribute of 'g' tag.
Thinker K.F. Li <thinker@branda.to>
parents:
83
diff
changeset
|
41 break; |
42698de1f653
Support translate() function for transform attribute of 'g' tag.
Thinker K.F. Li <thinker@branda.to>
parents:
83
diff
changeset
|
42 } |
83 | 43 } |
44 | |
78 | 45 int main(int argc, char * const argv[]) { |
46 X_MB_runtime_t rt; | |
47 svg2code_ex_t *svg2code; | |
83 | 48 ob_factory_t *factory; |
49 subject_t *subject; | |
50 ex_rt_t ex_rt; | |
78 | 51 int r; |
52 | |
108 | 53 /* |
54 * Initialize a runtime with XLib as backend. | |
55 */ | |
79
5bcb329a5157
Fix bug of core dump caused by forget to check if parent is NULL, root.
Thinker K.F. Li <thinker@branda.to>
parents:
78
diff
changeset
|
56 r = X_MB_init(":0.0", 800, 600, &rt); |
78 | 57 |
108 | 58 /* |
59 * Instantiate objects from a SVG file. | |
60 */ | |
78 | 61 svg2code = svg2code_ex_new(rt.rdman); |
62 | |
108 | 63 /* |
64 * Get observer factory | |
65 */ | |
83 | 66 factory = rdman_get_ob_factory(rt.rdman); |
108 | 67 /* |
68 * Register observers to subjects of events for objects. | |
69 */ | |
83 | 70 subject = coord_get_mouse_event(svg2code->file_button); |
71 ex_rt.rt = &rt; | |
72 ex_rt.code = svg2code; | |
73 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
|
74 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
|
75 subject_add_observer(factory, subject, file_menu_handler, &ex_rt); |
83 | 76 |
108 | 77 /* |
78 * Start handle connections, includes one to X server. | |
79 * User start to interact with the application. | |
80 */ | |
83 | 81 X_MB_handle_connection(&rt); |
82 | |
108 | 83 /* |
84 * Clean | |
85 */ | |
83 | 86 svg2code_ex_free(svg2code); |
78 | 87 X_MB_destroy(&rt); |
88 | |
89 return 0; | |
90 } |