Mercurial > MadButterfly
annotate examples/svg2code_ex/main.c @ 520:f106b57b8660 Android_Skia
Skip coords that is not cached when add coords into zeroing_coords list.
If we don't skip normal coords, non-cached, here, cached coords that
own one or more non-cached ancestors would be fail to add into
redraw_man_t::zeroing_coords list.
author | Thinker K.F. Li <thinker@branda.to> |
---|---|
date | Thu, 17 Dec 2009 16:13:35 +0800 |
parents | f9d507a3e1d9 |
children | 71489039406b |
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> |
186
530bb7728546
Move header files to $(top_srcdir)/include/ and prefixed with 'mb_'.
Thinker K.F. Li <thinker@branda.to>
parents:
130
diff
changeset
|
8 #include <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 | |
198
f9d507a3e1d9
Add event observer which listen to one event type only.
wycc@wycc-desktop
parents:
192
diff
changeset
|
17 #define COORD_SHOW(group) coord_show(group);rdman_coord_changed(X_MB_rdman(ex_rt->rt), group) |
f9d507a3e1d9
Add event observer which listen to one event type only.
wycc@wycc-desktop
parents:
192
diff
changeset
|
18 #define COORD_HIDE(group) coord_hide(group);rdman_coord_changed(X_MB_rdman(ex_rt->rt), group) |
f9d507a3e1d9
Add event observer which listen to one event type only.
wycc@wycc-desktop
parents:
192
diff
changeset
|
19 |
83 | 20 static void file_button_handler(event_t *evt, void *arg) { |
21 ex_rt_t *ex_rt = (ex_rt_t *)arg; | |
22 | |
198
f9d507a3e1d9
Add event observer which listen to one event type only.
wycc@wycc-desktop
parents:
192
diff
changeset
|
23 COORD_SHOW(ex_rt->code->file_menu); |
f9d507a3e1d9
Add event observer which listen to one event type only.
wycc@wycc-desktop
parents:
192
diff
changeset
|
24 /* Update changed part to UI. */ |
f9d507a3e1d9
Add event observer which listen to one event type only.
wycc@wycc-desktop
parents:
192
diff
changeset
|
25 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
|
26 } |
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 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
|
29 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
|
30 |
198
f9d507a3e1d9
Add event observer which listen to one event type only.
wycc@wycc-desktop
parents:
192
diff
changeset
|
31 COORD_HIDE(ex_rt->code->file_menu); |
f9d507a3e1d9
Add event observer which listen to one event type only.
wycc@wycc-desktop
parents:
192
diff
changeset
|
32 /* Update changed part to UI. */ |
f9d507a3e1d9
Add event observer which listen to one event type only.
wycc@wycc-desktop
parents:
192
diff
changeset
|
33 rdman_redraw_changed(X_MB_rdman(ex_rt->rt)); |
83 | 34 } |
35 | |
78 | 36 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
|
37 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
|
38 redraw_man_t *rdman; |
78 | 39 svg2code_ex_t *svg2code; |
83 | 40 subject_t *subject; |
41 ex_rt_t ex_rt; | |
78 | 42 |
108 | 43 /* |
44 * Initialize a runtime with XLib as backend. | |
45 */ | |
122
17e97e92b76e
Encapsulate X_MB_runtime_t and support X keyboard events.
Thinker K.F. Li <thinker@branda.to>
parents:
117
diff
changeset
|
46 rt = X_MB_new(":0.0", 800, 600); |
78 | 47 |
108 | 48 /* |
49 * Instantiate objects from a SVG file. | |
50 */ | |
122
17e97e92b76e
Encapsulate X_MB_runtime_t and support X keyboard events.
Thinker K.F. Li <thinker@branda.to>
parents:
117
diff
changeset
|
51 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
|
52 svg2code = svg2code_ex_new(rdman, rdman->root_coord); |
78 | 53 |
108 | 54 /* |
55 * Register observers to subjects of events for objects. | |
56 */ | |
83 | 57 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
|
58 ex_rt.rt = rt; |
83 | 59 ex_rt.code = svg2code; |
198
f9d507a3e1d9
Add event observer which listen to one event type only.
wycc@wycc-desktop
parents:
192
diff
changeset
|
60 subject_add_event_observer(subject, EVT_MOUSE_BUT_PRESS, 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
|
61 subject = coord_get_mouse_event(svg2code->file_menu); |
198
f9d507a3e1d9
Add event observer which listen to one event type only.
wycc@wycc-desktop
parents:
192
diff
changeset
|
62 subject_add_event_observer(subject, EVT_MOUSE_BUT_PRESS, file_menu_handler, &ex_rt); |
83 | 63 |
108 | 64 /* |
65 * Start handle connections, includes one to X server. | |
66 * User start to interact with the application. | |
67 */ | |
122
17e97e92b76e
Encapsulate X_MB_runtime_t and support X keyboard events.
Thinker K.F. Li <thinker@branda.to>
parents:
117
diff
changeset
|
68 X_MB_handle_connection(rt); |
83 | 69 |
108 | 70 /* |
71 * Clean | |
72 */ | |
83 | 73 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
|
74 X_MB_free(rt); |
78 | 75 |
76 return 0; | |
77 } |