Mercurial > MadButterfly
annotate examples/svg2code_ex/main.c @ 1535:9aff42a7e2b9 tip
Fix issue of add/remove a frame at a scene before all key frames of a layer.
When you added or removed a frame at a scene before all key frames of
a layer, frameline was not updated correctly. It seems nothing
happened, but domview is updated. This changeset fix this issue by
correcting logic for boundary case.
author | Thinker K.F. Li <thinker@codemud.net> |
---|---|
date | Fri, 30 Sep 2011 22:07:28 +0800 |
parents | 71489039406b |
children |
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 { | |
1029
71489039406b
Migrate examples/svg2code_ex to new definition of backend
Thinker K.F. Li <thinker@codemud.net>
parents:
198
diff
changeset
|
13 mb_rt_t *rt; |
83 | 14 svg2code_ex_t *code; |
15 }; | |
16 | |
1029
71489039406b
Migrate examples/svg2code_ex to new definition of backend
Thinker K.F. Li <thinker@codemud.net>
parents:
198
diff
changeset
|
17 #define COORD_SHOW(group) do { \ |
71489039406b
Migrate examples/svg2code_ex to new definition of backend
Thinker K.F. Li <thinker@codemud.net>
parents:
198
diff
changeset
|
18 coord_show(group); \ |
71489039406b
Migrate examples/svg2code_ex to new definition of backend
Thinker K.F. Li <thinker@codemud.net>
parents:
198
diff
changeset
|
19 rdman_coord_changed(mb_runtime_rdman(ex_rt->rt), group); \ |
71489039406b
Migrate examples/svg2code_ex to new definition of backend
Thinker K.F. Li <thinker@codemud.net>
parents:
198
diff
changeset
|
20 } while(0) |
71489039406b
Migrate examples/svg2code_ex to new definition of backend
Thinker K.F. Li <thinker@codemud.net>
parents:
198
diff
changeset
|
21 #define COORD_HIDE(group) do { \ |
71489039406b
Migrate examples/svg2code_ex to new definition of backend
Thinker K.F. Li <thinker@codemud.net>
parents:
198
diff
changeset
|
22 coord_hide(group); \ |
71489039406b
Migrate examples/svg2code_ex to new definition of backend
Thinker K.F. Li <thinker@codemud.net>
parents:
198
diff
changeset
|
23 rdman_coord_changed(mb_runtime_rdman(ex_rt->rt), group); \ |
71489039406b
Migrate examples/svg2code_ex to new definition of backend
Thinker K.F. Li <thinker@codemud.net>
parents:
198
diff
changeset
|
24 } while(0) |
198
f9d507a3e1d9
Add event observer which listen to one event type only.
wycc@wycc-desktop
parents:
192
diff
changeset
|
25 |
83 | 26 static void file_button_handler(event_t *evt, void *arg) { |
27 ex_rt_t *ex_rt = (ex_rt_t *)arg; | |
1029
71489039406b
Migrate examples/svg2code_ex to new definition of backend
Thinker K.F. Li <thinker@codemud.net>
parents:
198
diff
changeset
|
28 redraw_man_t *rdman; |
83 | 29 |
198
f9d507a3e1d9
Add event observer which listen to one event type only.
wycc@wycc-desktop
parents:
192
diff
changeset
|
30 COORD_SHOW(ex_rt->code->file_menu); |
1029
71489039406b
Migrate examples/svg2code_ex to new definition of backend
Thinker K.F. Li <thinker@codemud.net>
parents:
198
diff
changeset
|
31 rdman = mb_runtime_rdman(ex_rt->rt); |
198
f9d507a3e1d9
Add event observer which listen to one event type only.
wycc@wycc-desktop
parents:
192
diff
changeset
|
32 /* Update changed part to UI. */ |
1029
71489039406b
Migrate examples/svg2code_ex to new definition of backend
Thinker K.F. Li <thinker@codemud.net>
parents:
198
diff
changeset
|
33 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
|
34 } |
42698de1f653
Support translate() function for transform attribute of 'g' tag.
Thinker K.F. Li <thinker@branda.to>
parents:
83
diff
changeset
|
35 |
42698de1f653
Support translate() function for transform attribute of 'g' tag.
Thinker K.F. Li <thinker@branda.to>
parents:
83
diff
changeset
|
36 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
|
37 ex_rt_t *ex_rt = (ex_rt_t *)arg; |
1029
71489039406b
Migrate examples/svg2code_ex to new definition of backend
Thinker K.F. Li <thinker@codemud.net>
parents:
198
diff
changeset
|
38 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
|
39 |
198
f9d507a3e1d9
Add event observer which listen to one event type only.
wycc@wycc-desktop
parents:
192
diff
changeset
|
40 COORD_HIDE(ex_rt->code->file_menu); |
1029
71489039406b
Migrate examples/svg2code_ex to new definition of backend
Thinker K.F. Li <thinker@codemud.net>
parents:
198
diff
changeset
|
41 rdman = mb_runtime_rdman(ex_rt->rt); |
198
f9d507a3e1d9
Add event observer which listen to one event type only.
wycc@wycc-desktop
parents:
192
diff
changeset
|
42 /* Update changed part to UI. */ |
1029
71489039406b
Migrate examples/svg2code_ex to new definition of backend
Thinker K.F. Li <thinker@codemud.net>
parents:
198
diff
changeset
|
43 rdman_redraw_changed(rdman); |
83 | 44 } |
45 | |
78 | 46 int main(int argc, char * const argv[]) { |
1029
71489039406b
Migrate examples/svg2code_ex to new definition of backend
Thinker K.F. Li <thinker@codemud.net>
parents:
198
diff
changeset
|
47 mb_rt_t *rt; |
122
17e97e92b76e
Encapsulate X_MB_runtime_t and support X keyboard events.
Thinker K.F. Li <thinker@branda.to>
parents:
117
diff
changeset
|
48 redraw_man_t *rdman; |
78 | 49 svg2code_ex_t *svg2code; |
83 | 50 subject_t *subject; |
51 ex_rt_t ex_rt; | |
78 | 52 |
108 | 53 /* |
54 * Initialize a runtime with XLib as backend. | |
55 */ | |
1029
71489039406b
Migrate examples/svg2code_ex to new definition of backend
Thinker K.F. Li <thinker@codemud.net>
parents:
198
diff
changeset
|
56 rt = mb_runtime_new(":0.0", 800, 600); |
78 | 57 |
108 | 58 /* |
59 * Instantiate objects from a SVG file. | |
60 */ | |
1029
71489039406b
Migrate examples/svg2code_ex to new definition of backend
Thinker K.F. Li <thinker@codemud.net>
parents:
198
diff
changeset
|
61 rdman = mb_runtime_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
|
62 svg2code = svg2code_ex_new(rdman, rdman->root_coord); |
78 | 63 |
108 | 64 /* |
65 * Register observers to subjects of events for objects. | |
66 */ | |
83 | 67 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
|
68 ex_rt.rt = rt; |
83 | 69 ex_rt.code = svg2code; |
198
f9d507a3e1d9
Add event observer which listen to one event type only.
wycc@wycc-desktop
parents:
192
diff
changeset
|
70 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
|
71 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
|
72 subject_add_event_observer(subject, EVT_MOUSE_BUT_PRESS, file_menu_handler, &ex_rt); |
83 | 73 |
108 | 74 /* |
75 * Start handle connections, includes one to X server. | |
76 * User start to interact with the application. | |
77 */ | |
1029
71489039406b
Migrate examples/svg2code_ex to new definition of backend
Thinker K.F. Li <thinker@codemud.net>
parents:
198
diff
changeset
|
78 mb_runtime_event_loop(rt); |
83 | 79 |
108 | 80 /* |
81 * Clean | |
82 */ | |
83 | 83 svg2code_ex_free(svg2code); |
1029
71489039406b
Migrate examples/svg2code_ex to new definition of backend
Thinker K.F. Li <thinker@codemud.net>
parents:
198
diff
changeset
|
84 mb_runtime_free(rt); |
78 | 85 |
86 return 0; | |
87 } |