annotate examples/svg2code_ex/main.c @ 83:ea758bb3bbe2

example
author Thinker K.F. Li <thinker@branda.to>
date Fri, 22 Aug 2008 00:12:04 +0800
parents 5bcb329a5157
children 42698de1f653
rev   line source
78
3645e29e4986 Add runtime for Xlib.
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
1 #include <stdio.h>
3645e29e4986 Add runtime for Xlib.
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
2 #include <mb_types.h>
3645e29e4986 Add runtime for Xlib.
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
3 #include <X_supp.h>
3645e29e4986 Add runtime for Xlib.
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
4 #include "svg2code_ex.h"
3645e29e4986 Add runtime for Xlib.
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
5
83
ea758bb3bbe2 example
Thinker K.F. Li <thinker@branda.to>
parents: 79
diff changeset
6 typedef struct _ex_rt ex_rt_t;
ea758bb3bbe2 example
Thinker K.F. Li <thinker@branda.to>
parents: 79
diff changeset
7 struct _ex_rt {
ea758bb3bbe2 example
Thinker K.F. Li <thinker@branda.to>
parents: 79
diff changeset
8 X_MB_runtime_t *rt;
ea758bb3bbe2 example
Thinker K.F. Li <thinker@branda.to>
parents: 79
diff changeset
9 svg2code_ex_t *code;
ea758bb3bbe2 example
Thinker K.F. Li <thinker@branda.to>
parents: 79
diff changeset
10 };
ea758bb3bbe2 example
Thinker K.F. Li <thinker@branda.to>
parents: 79
diff changeset
11
ea758bb3bbe2 example
Thinker K.F. Li <thinker@branda.to>
parents: 79
diff changeset
12 static void file_button_handler(event_t *evt, void *arg) {
ea758bb3bbe2 example
Thinker K.F. Li <thinker@branda.to>
parents: 79
diff changeset
13 ex_rt_t *ex_rt = (ex_rt_t *)arg;
ea758bb3bbe2 example
Thinker K.F. Li <thinker@branda.to>
parents: 79
diff changeset
14
ea758bb3bbe2 example
Thinker K.F. Li <thinker@branda.to>
parents: 79
diff changeset
15 coord_show(ex_rt->code->file_menu);
ea758bb3bbe2 example
Thinker K.F. Li <thinker@branda.to>
parents: 79
diff changeset
16 rdman_coord_changed(ex_rt->rt->rdman, ex_rt->code->file_menu);
ea758bb3bbe2 example
Thinker K.F. Li <thinker@branda.to>
parents: 79
diff changeset
17 rdman_redraw_changed(ex_rt->rt->rdman);
ea758bb3bbe2 example
Thinker K.F. Li <thinker@branda.to>
parents: 79
diff changeset
18 }
ea758bb3bbe2 example
Thinker K.F. Li <thinker@branda.to>
parents: 79
diff changeset
19
78
3645e29e4986 Add runtime for Xlib.
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
20 int main(int argc, char * const argv[]) {
3645e29e4986 Add runtime for Xlib.
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
21 X_MB_runtime_t rt;
3645e29e4986 Add runtime for Xlib.
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
22 svg2code_ex_t *svg2code;
83
ea758bb3bbe2 example
Thinker K.F. Li <thinker@branda.to>
parents: 79
diff changeset
23 ob_factory_t *factory;
ea758bb3bbe2 example
Thinker K.F. Li <thinker@branda.to>
parents: 79
diff changeset
24 subject_t *subject;
ea758bb3bbe2 example
Thinker K.F. Li <thinker@branda.to>
parents: 79
diff changeset
25 ex_rt_t ex_rt;
78
3645e29e4986 Add runtime for Xlib.
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
26 int r;
3645e29e4986 Add runtime for Xlib.
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
27
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
28 r = X_MB_init(":0.0", 800, 600, &rt);
78
3645e29e4986 Add runtime for Xlib.
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
29
3645e29e4986 Add runtime for Xlib.
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
30 svg2code = svg2code_ex_new(rt.rdman);
3645e29e4986 Add runtime for Xlib.
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
31
83
ea758bb3bbe2 example
Thinker K.F. Li <thinker@branda.to>
parents: 79
diff changeset
32 factory = rdman_get_ob_factory(rt.rdman);
ea758bb3bbe2 example
Thinker K.F. Li <thinker@branda.to>
parents: 79
diff changeset
33 subject = coord_get_mouse_event(svg2code->file_button);
ea758bb3bbe2 example
Thinker K.F. Li <thinker@branda.to>
parents: 79
diff changeset
34 ex_rt.rt = &rt;
ea758bb3bbe2 example
Thinker K.F. Li <thinker@branda.to>
parents: 79
diff changeset
35 ex_rt.code = svg2code;
ea758bb3bbe2 example
Thinker K.F. Li <thinker@branda.to>
parents: 79
diff changeset
36 subject_add_observer(factory, subject, file_button_handler, &ex_rt);
ea758bb3bbe2 example
Thinker K.F. Li <thinker@branda.to>
parents: 79
diff changeset
37
ea758bb3bbe2 example
Thinker K.F. Li <thinker@branda.to>
parents: 79
diff changeset
38 X_MB_handle_connection(&rt);
ea758bb3bbe2 example
Thinker K.F. Li <thinker@branda.to>
parents: 79
diff changeset
39
ea758bb3bbe2 example
Thinker K.F. Li <thinker@branda.to>
parents: 79
diff changeset
40 svg2code_ex_free(svg2code);
78
3645e29e4986 Add runtime for Xlib.
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
41 X_MB_destroy(&rt);
3645e29e4986 Add runtime for Xlib.
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
42
3645e29e4986 Add runtime for Xlib.
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
43 return 0;
3645e29e4986 Add runtime for Xlib.
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
44 }