Mercurial > MadButterfly
annotate examples/svg2code_ex/main.c @ 108:565b55508c8d
More dox
author | Thinker K.F. Li <thinker@branda.to> |
---|---|
date | Fri, 12 Sep 2008 13:58:30 +0800 |
parents | 42698de1f653 |
children | c14cb6d12030 |
rev | line source |
---|---|
78 | 1 #include <stdio.h> |
108 | 2 #include <mb/mb.h> |
78 | 3 #include "svg2code_ex.h" |
4 | |
83 | 5 typedef struct _ex_rt ex_rt_t; |
6 struct _ex_rt { | |
7 X_MB_runtime_t *rt; | |
8 svg2code_ex_t *code; | |
9 }; | |
10 | |
11 static void file_button_handler(event_t *evt, void *arg) { | |
12 ex_rt_t *ex_rt = (ex_rt_t *)arg; | |
13 | |
84
42698de1f653
Support translate() function for transform attribute of 'g' tag.
Thinker K.F. Li <thinker@branda.to>
parents:
83
diff
changeset
|
14 switch(evt->type) { |
42698de1f653
Support translate() function for transform attribute of 'g' tag.
Thinker K.F. Li <thinker@branda.to>
parents:
83
diff
changeset
|
15 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
|
16 coord_show(ex_rt->code->file_menu); |
108 | 17 /* 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
|
18 rdman_coord_changed(ex_rt->rt->rdman, ex_rt->code->file_menu); |
108 | 19 /* 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
|
20 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
|
21 break; |
42698de1f653
Support translate() function for transform attribute of 'g' tag.
Thinker K.F. Li <thinker@branda.to>
parents:
83
diff
changeset
|
22 } |
42698de1f653
Support translate() function for transform attribute of 'g' tag.
Thinker K.F. Li <thinker@branda.to>
parents:
83
diff
changeset
|
23 } |
42698de1f653
Support translate() function for transform attribute of 'g' tag.
Thinker K.F. Li <thinker@branda.to>
parents:
83
diff
changeset
|
24 |
42698de1f653
Support translate() function for transform attribute of 'g' tag.
Thinker K.F. Li <thinker@branda.to>
parents:
83
diff
changeset
|
25 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
|
26 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
|
27 |
42698de1f653
Support translate() function for transform attribute of 'g' tag.
Thinker K.F. Li <thinker@branda.to>
parents:
83
diff
changeset
|
28 switch(evt->type) { |
42698de1f653
Support translate() function for transform attribute of 'g' tag.
Thinker K.F. Li <thinker@branda.to>
parents:
83
diff
changeset
|
29 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
|
30 coord_hide(ex_rt->code->file_menu); |
108 | 31 /* 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
|
32 rdman_coord_changed(ex_rt->rt->rdman, ex_rt->code->file_menu); |
108 | 33 /* 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
|
34 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
|
35 break; |
42698de1f653
Support translate() function for transform attribute of 'g' tag.
Thinker K.F. Li <thinker@branda.to>
parents:
83
diff
changeset
|
36 } |
83 | 37 } |
38 | |
78 | 39 int main(int argc, char * const argv[]) { |
40 X_MB_runtime_t rt; | |
41 svg2code_ex_t *svg2code; | |
83 | 42 ob_factory_t *factory; |
43 subject_t *subject; | |
44 ex_rt_t ex_rt; | |
78 | 45 int r; |
46 | |
108 | 47 /* |
48 * Initialize a runtime with XLib as backend. | |
49 */ | |
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
|
50 r = X_MB_init(":0.0", 800, 600, &rt); |
78 | 51 |
108 | 52 /* |
53 * Instantiate objects from a SVG file. | |
54 */ | |
78 | 55 svg2code = svg2code_ex_new(rt.rdman); |
56 | |
108 | 57 /* |
58 * Get observer factory | |
59 */ | |
83 | 60 factory = rdman_get_ob_factory(rt.rdman); |
108 | 61 /* |
62 * Register observers to subjects of events for objects. | |
63 */ | |
83 | 64 subject = coord_get_mouse_event(svg2code->file_button); |
65 ex_rt.rt = &rt; | |
66 ex_rt.code = svg2code; | |
67 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
|
68 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
|
69 subject_add_observer(factory, subject, file_menu_handler, &ex_rt); |
83 | 70 |
108 | 71 /* |
72 * Start handle connections, includes one to X server. | |
73 * User start to interact with the application. | |
74 */ | |
83 | 75 X_MB_handle_connection(&rt); |
76 | |
108 | 77 /* |
78 * Clean | |
79 */ | |
83 | 80 svg2code_ex_free(svg2code); |
78 | 81 X_MB_destroy(&rt); |
82 | |
83 return 0; | |
84 } |