Mercurial > MadButterfly
annotate src/mb_types.h @ 139:1695a4b02b14
Members of coords are geos instead of shapes, now.
author | Thinker K.F. Li <thinker@branda.to> |
---|---|
date | Mon, 22 Sep 2008 19:22:57 +0800 |
parents | 9f4fc9ecfd1f |
children | 0de8fd11271e |
rev | line source |
---|---|
5
9c331ec9e210
SVG path is partially supported
Thinker K.F. Li <thinker@branda.to>
parents:
diff
changeset
|
1 #ifndef __MB_TYPES_H_ |
9c331ec9e210
SVG path is partially supported
Thinker K.F. Li <thinker@branda.to>
parents:
diff
changeset
|
2 #define __MB_TYPES_H_ |
9c331ec9e210
SVG path is partially supported
Thinker K.F. Li <thinker@branda.to>
parents:
diff
changeset
|
3 |
18
0f3baa488a62
Support solid color paint for fill.
Thinker K.F. Li <thinker@branda.to>
parents:
17
diff
changeset
|
4 #include <cairo.h> |
12 | 5 #include "tools.h" |
73
9ab15ebc9061
Observer for mouse events
Thinker K.F. Li <thinker@branda.to>
parents:
58
diff
changeset
|
6 #include "observer.h" |
12 | 7 |
5
9c331ec9e210
SVG path is partially supported
Thinker K.F. Li <thinker@branda.to>
parents:
diff
changeset
|
8 typedef float co_aix; |
11
128af06c876c
Fix the bug that data of a path end with white spaces would make system down
Thinker K.F. Li <thinker@branda.to>
parents:
10
diff
changeset
|
9 typedef struct _shape shape_t; |
12 | 10 typedef struct _geo geo_t; |
13 | 11 typedef struct _area area_t; |
18
0f3baa488a62
Support solid color paint for fill.
Thinker K.F. Li <thinker@branda.to>
parents:
17
diff
changeset
|
12 typedef struct _shnode shnode_t; |
0f3baa488a62
Support solid color paint for fill.
Thinker K.F. Li <thinker@branda.to>
parents:
17
diff
changeset
|
13 typedef struct _paint paint_t; |
0f3baa488a62
Support solid color paint for fill.
Thinker K.F. Li <thinker@branda.to>
parents:
17
diff
changeset
|
14 |
58 | 15 /*! \brief Base of paint types. |
16 * | |
17 * Paints should be freed by users by calling paint_t::free() of | |
18 * the paint. | |
19 * | |
20 * \todo move member functions to a seperate structure and setup a | |
21 * singleton fro each paint type. | |
22 */ | |
18
0f3baa488a62
Support solid color paint for fill.
Thinker K.F. Li <thinker@branda.to>
parents:
17
diff
changeset
|
23 struct _paint { |
0f3baa488a62
Support solid color paint for fill.
Thinker K.F. Li <thinker@branda.to>
parents:
17
diff
changeset
|
24 void (*prepare)(paint_t *paint, cairo_t *cr); |
0f3baa488a62
Support solid color paint for fill.
Thinker K.F. Li <thinker@branda.to>
parents:
17
diff
changeset
|
25 void (*free)(paint_t *paint); |
0f3baa488a62
Support solid color paint for fill.
Thinker K.F. Li <thinker@branda.to>
parents:
17
diff
changeset
|
26 STAILQ(shnode_t) members; |
0f3baa488a62
Support solid color paint for fill.
Thinker K.F. Li <thinker@branda.to>
parents:
17
diff
changeset
|
27 }; |
0f3baa488a62
Support solid color paint for fill.
Thinker K.F. Li <thinker@branda.to>
parents:
17
diff
changeset
|
28 |
0f3baa488a62
Support solid color paint for fill.
Thinker K.F. Li <thinker@branda.to>
parents:
17
diff
changeset
|
29 struct _shnode { |
0f3baa488a62
Support solid color paint for fill.
Thinker K.F. Li <thinker@branda.to>
parents:
17
diff
changeset
|
30 shape_t *shape; |
0f3baa488a62
Support solid color paint for fill.
Thinker K.F. Li <thinker@branda.to>
parents:
17
diff
changeset
|
31 shnode_t *next; |
0f3baa488a62
Support solid color paint for fill.
Thinker K.F. Li <thinker@branda.to>
parents:
17
diff
changeset
|
32 }; |
13 | 33 |
34 struct _area { | |
35 co_aix x, y; | |
36 co_aix w, h; | |
37 }; | |
38 | |
39 /*! \brief Geometry data of a shape or a group of shape. | |
40 */ | |
41 struct _geo { | |
16
e17e12b112c4
A simple animation using rdman_redraw_changed().
Thinker K.F. Li <thinker@branda.to>
parents:
15
diff
changeset
|
42 #ifdef GEO_ORDER |
13 | 43 unsigned int order; |
16
e17e12b112c4
A simple animation using rdman_redraw_changed().
Thinker K.F. Li <thinker@branda.to>
parents:
15
diff
changeset
|
44 #endif |
13 | 45 unsigned int flags; |
46 shape_t *shape; | |
139
1695a4b02b14
Members of coords are geos instead of shapes, now.
Thinker K.F. Li <thinker@branda.to>
parents:
138
diff
changeset
|
47 geo_t *coord_next; /*!< \brief Link all member geos together. */ |
13 | 48 |
49 area_t *cur_area, *last_area; | |
50 area_t areas[2]; | |
73
9ab15ebc9061
Observer for mouse events
Thinker K.F. Li <thinker@branda.to>
parents:
58
diff
changeset
|
51 |
9ab15ebc9061
Observer for mouse events
Thinker K.F. Li <thinker@branda.to>
parents:
58
diff
changeset
|
52 subject_t *mouse_event; |
13 | 53 }; |
54 #define GEF_DIRTY 0x1 | |
57
ab028c9f0930
Ability to hidden shapes and action of visibility.
Thinker K.F. Li <thinker@branda.to>
parents:
35
diff
changeset
|
55 #define GEF_HIDDEN 0x2 |
13 | 56 |
57 extern int is_overlay(area_t *r1, area_t *r2); | |
15
c2ce186a5c37
X_main uses rdman_redraw_all()
Thinker K.F. Li <thinker@branda.to>
parents:
14
diff
changeset
|
58 extern void area_init(area_t *area, int n_pos, co_aix pos[][2]); |
17
41f0907b27ac
Unittest for rdman_redraw_changed().
Thinker K.F. Li <thinker@branda.to>
parents:
16
diff
changeset
|
59 extern void geo_init(geo_t *g); |
41f0907b27ac
Unittest for rdman_redraw_changed().
Thinker K.F. Li <thinker@branda.to>
parents:
16
diff
changeset
|
60 extern void geo_from_positions(geo_t *g, int n_pos, co_aix pos[][2]); |
13 | 61 extern void geo_mark_overlay(geo_t *g, int n_others, geo_t **others, |
62 int *n_overlays, geo_t **overlays); | |
63 #define geo_get_shape(g) ((g)->shape) | |
64 #define geo_set_shape(g, sh) do {(g)->shape = sh;} while(0) | |
28 | 65 #define _geo_is_in(a, s, w) ((a) >= (s) && (a) < ((s) + (w))) |
66 #define geo_pos_is_in(g, _x, _y) \ | |
30
e06a4a667ce2
Accept mouse/pointer event and hint the shape that the pointer is over.
Thinker K.F. Li <thinker@branda.to>
parents:
28
diff
changeset
|
67 (_geo_is_in(_x, (g)->cur_area->x, (g)->cur_area->w) && \ |
e06a4a667ce2
Accept mouse/pointer event and hint the shape that the pointer is over.
Thinker K.F. Li <thinker@branda.to>
parents:
28
diff
changeset
|
68 _geo_is_in(_y, (g)->cur_area->y, (g)->cur_area->h)) |
13 | 69 |
5
9c331ec9e210
SVG path is partially supported
Thinker K.F. Li <thinker@branda.to>
parents:
diff
changeset
|
70 |
9c331ec9e210
SVG path is partially supported
Thinker K.F. Li <thinker@branda.to>
parents:
diff
changeset
|
71 /*! \brief A coordination system. |
9c331ec9e210
SVG path is partially supported
Thinker K.F. Li <thinker@branda.to>
parents:
diff
changeset
|
72 * |
9c331ec9e210
SVG path is partially supported
Thinker K.F. Li <thinker@branda.to>
parents:
diff
changeset
|
73 * It have a transform function defined by matrix to transform |
9c331ec9e210
SVG path is partially supported
Thinker K.F. Li <thinker@branda.to>
parents:
diff
changeset
|
74 * coordination from source space to target space. |
9c331ec9e210
SVG path is partially supported
Thinker K.F. Li <thinker@branda.to>
parents:
diff
changeset
|
75 * Source space is where the contained is drawed, and target space |
9c331ec9e210
SVG path is partially supported
Thinker K.F. Li <thinker@branda.to>
parents:
diff
changeset
|
76 * is where the coordination of parent container of the element |
9c331ec9e210
SVG path is partially supported
Thinker K.F. Li <thinker@branda.to>
parents:
diff
changeset
|
77 * represented by this coord object. |
12 | 78 * |
79 * \dot | |
80 * digraph G { | |
81 * graph [rankdir=LR]; | |
82 * root -> child00 -> child10 -> child20 [label="children" color="blue"]; | |
83 * child00 -> child01 -> child02 [label="sibling"]; | |
84 * child10 -> child11 [label="sibling"]; | |
85 * } | |
86 * \enddot | |
5
9c331ec9e210
SVG path is partially supported
Thinker K.F. Li <thinker@branda.to>
parents:
diff
changeset
|
87 */ |
9c331ec9e210
SVG path is partially supported
Thinker K.F. Li <thinker@branda.to>
parents:
diff
changeset
|
88 typedef struct _coord { |
13 | 89 unsigned int order; |
90 unsigned int flags; | |
138
9f4fc9ecfd1f
Make shapes and coords drawed in post-order of tree.
Thinker K.F. Li <thinker@branda.to>
parents:
83
diff
changeset
|
91 co_aix opacity; |
9f4fc9ecfd1f
Make shapes and coords drawed in post-order of tree.
Thinker K.F. Li <thinker@branda.to>
parents:
83
diff
changeset
|
92 /*! Own one or inherit from an ancestor. |
9f4fc9ecfd1f
Make shapes and coords drawed in post-order of tree.
Thinker K.F. Li <thinker@branda.to>
parents:
83
diff
changeset
|
93 * Setup it when clean coords. |
9f4fc9ecfd1f
Make shapes and coords drawed in post-order of tree.
Thinker K.F. Li <thinker@branda.to>
parents:
83
diff
changeset
|
94 * \sa |
9f4fc9ecfd1f
Make shapes and coords drawed in post-order of tree.
Thinker K.F. Li <thinker@branda.to>
parents:
83
diff
changeset
|
95 * - \ref COF_OWN_CANVAS |
9f4fc9ecfd1f
Make shapes and coords drawed in post-order of tree.
Thinker K.F. Li <thinker@branda.to>
parents:
83
diff
changeset
|
96 * - \ref redraw |
9f4fc9ecfd1f
Make shapes and coords drawed in post-order of tree.
Thinker K.F. Li <thinker@branda.to>
parents:
83
diff
changeset
|
97 */ |
9f4fc9ecfd1f
Make shapes and coords drawed in post-order of tree.
Thinker K.F. Li <thinker@branda.to>
parents:
83
diff
changeset
|
98 cairo_t *canvas; |
13 | 99 area_t *cur_area, *last_area; |
15
c2ce186a5c37
X_main uses rdman_redraw_all()
Thinker K.F. Li <thinker@branda.to>
parents:
14
diff
changeset
|
100 area_t areas[2]; |
13 | 101 |
5
9c331ec9e210
SVG path is partially supported
Thinker K.F. Li <thinker@branda.to>
parents:
diff
changeset
|
102 co_aix matrix[6]; |
9c331ec9e210
SVG path is partially supported
Thinker K.F. Li <thinker@branda.to>
parents:
diff
changeset
|
103 co_aix aggr_matrix[6]; |
13 | 104 |
5
9c331ec9e210
SVG path is partially supported
Thinker K.F. Li <thinker@branda.to>
parents:
diff
changeset
|
105 struct _coord *parent; |
12 | 106 STAILQ(struct _coord) children; |
107 struct _coord *sibling; | |
138
9f4fc9ecfd1f
Make shapes and coords drawed in post-order of tree.
Thinker K.F. Li <thinker@branda.to>
parents:
83
diff
changeset
|
108 unsigned int before_pmem; /*!< \brief The coord is before nth member |
9f4fc9ecfd1f
Make shapes and coords drawed in post-order of tree.
Thinker K.F. Li <thinker@branda.to>
parents:
83
diff
changeset
|
109 * of parent. */ |
13 | 110 |
139
1695a4b02b14
Members of coords are geos instead of shapes, now.
Thinker K.F. Li <thinker@branda.to>
parents:
138
diff
changeset
|
111 int num_members; |
1695a4b02b14
Members of coords are geos instead of shapes, now.
Thinker K.F. Li <thinker@branda.to>
parents:
138
diff
changeset
|
112 STAILQ(geo_t) members; /*!< All geo_t members in this coord. */ |
73
9ab15ebc9061
Observer for mouse events
Thinker K.F. Li <thinker@branda.to>
parents:
58
diff
changeset
|
113 subject_t *mouse_event; |
5
9c331ec9e210
SVG path is partially supported
Thinker K.F. Li <thinker@branda.to>
parents:
diff
changeset
|
114 } coord_t; |
13 | 115 #define COF_DIRTY 0x1 |
57
ab028c9f0930
Ability to hidden shapes and action of visibility.
Thinker K.F. Li <thinker@branda.to>
parents:
35
diff
changeset
|
116 #define COF_HIDDEN 0x2 |
138
9f4fc9ecfd1f
Make shapes and coords drawed in post-order of tree.
Thinker K.F. Li <thinker@branda.to>
parents:
83
diff
changeset
|
117 #define COF_OWN_CANVAS 0x4 /*!< A coord owns a canvas or inherit it |
9f4fc9ecfd1f
Make shapes and coords drawed in post-order of tree.
Thinker K.F. Li <thinker@branda.to>
parents:
83
diff
changeset
|
118 * from an ancestor. |
9f4fc9ecfd1f
Make shapes and coords drawed in post-order of tree.
Thinker K.F. Li <thinker@branda.to>
parents:
83
diff
changeset
|
119 */ |
5
9c331ec9e210
SVG path is partially supported
Thinker K.F. Li <thinker@branda.to>
parents:
diff
changeset
|
120 |
9c331ec9e210
SVG path is partially supported
Thinker K.F. Li <thinker@branda.to>
parents:
diff
changeset
|
121 extern void coord_init(coord_t *co, coord_t *parent); |
9c331ec9e210
SVG path is partially supported
Thinker K.F. Li <thinker@branda.to>
parents:
diff
changeset
|
122 extern void coord_trans_pos(coord_t *co, co_aix *x, co_aix *y); |
31
da770188a44d
resize font size for changige of coord.
Thinker K.F. Li <thinker@branda.to>
parents:
30
diff
changeset
|
123 extern co_aix coord_trans_size(coord_t *co, co_aix size); |
16
e17e12b112c4
A simple animation using rdman_redraw_changed().
Thinker K.F. Li <thinker@branda.to>
parents:
15
diff
changeset
|
124 extern void compute_aggr_of_coord(coord_t *coord); |
10 | 125 extern void update_aggr_matrix(coord_t *start); |
13 | 126 extern coord_t *preorder_coord_subtree(coord_t *root, coord_t *last); |
138
9f4fc9ecfd1f
Make shapes and coords drawed in post-order of tree.
Thinker K.F. Li <thinker@branda.to>
parents:
83
diff
changeset
|
127 extern coord_t *postorder_coord_subtree(coord_t *root, coord_t *last); |
57
ab028c9f0930
Ability to hidden shapes and action of visibility.
Thinker K.F. Li <thinker@branda.to>
parents:
35
diff
changeset
|
128 #define coord_hide(co) do { co->flags |= COF_HIDDEN; } while(0) |
ab028c9f0930
Ability to hidden shapes and action of visibility.
Thinker K.F. Li <thinker@branda.to>
parents:
35
diff
changeset
|
129 #define coord_show(co) do { co->flags &= ~COF_HIDDEN; } while(0) |
83 | 130 #define coord_get_mouse_event(coord) ((coord)->mouse_event) |
12 | 131 |
132 | |
133 /*! \brief A grahpic shape. | |
134 * | |
135 * \dot | |
136 * digraph G { | |
137 * "shape" -> "coord"; | |
138 * "shape" -> "geo"; | |
139 * "geo" -> "shape"; | |
140 * "coord" -> "shape" [label="members"] | |
141 * "shape" -> "shape" [label="sibling"]; | |
142 * } | |
143 * \enddot | |
144 */ | |
145 struct _shape { | |
146 int sh_type; | |
147 geo_t *geo; | |
148 coord_t *coord; | |
18
0f3baa488a62
Support solid color paint for fill.
Thinker K.F. Li <thinker@branda.to>
parents:
17
diff
changeset
|
149 paint_t *fill, *stroke; |
26
d50f33040de6
Set line width for path.
Thinker K.F. Li <thinker@branda.to>
parents:
18
diff
changeset
|
150 co_aix stroke_width; |
73
9ab15ebc9061
Observer for mouse events
Thinker K.F. Li <thinker@branda.to>
parents:
58
diff
changeset
|
151 int stroke_linecap:2; |
9ab15ebc9061
Observer for mouse events
Thinker K.F. Li <thinker@branda.to>
parents:
58
diff
changeset
|
152 int stroke_linejoin:2; |
9ab15ebc9061
Observer for mouse events
Thinker K.F. Li <thinker@branda.to>
parents:
58
diff
changeset
|
153 void (*free)(shape_t *shape); |
12 | 154 }; |
35
581a03196093
Support rectangle tag of SVG.
Thinker K.F. Li <thinker@branda.to>
parents:
31
diff
changeset
|
155 enum { SHT_UNKNOW, SHT_PATH, SHT_TEXT, SHT_RECT }; |
12 | 156 |
157 #define sh_attach_geo(sh, g) \ | |
158 do { \ | |
159 (sh)->geo = g; \ | |
160 (g)->shape = (shape_t *)(sh); \ | |
161 } while(0) | |
162 #define sh_detach_geo(sh) \ | |
163 do { \ | |
164 (sh)->geo->shape = NULL; \ | |
165 (sh)->geo = NULL; \ | |
166 } while(0) | |
77 | 167 #define sh_get_geo(sh) ((sh)->geo) |
168 #define sh_get_mouse_event_subject(sh) ((sh)->geo->mouse_event) | |
81 | 169 #define sh_hide(sh) do { (sh)->geo->flags |= GEF_HIDDEN; } while(0) |
170 #define sh_show(sh) do { (sh)->geo->flags &= ~GEF_HIDDEN; } while(0) | |
12 | 171 extern void sh_attach_coord(shape_t *sh, coord_t *coord); |
172 extern void sh_detach_coord(shape_t *sh); | |
173 | |
5
9c331ec9e210
SVG path is partially supported
Thinker K.F. Li <thinker@branda.to>
parents:
diff
changeset
|
174 #endif /* __MB_TYPES_H_ */ |