Mercurial > MadButterfly
annotate src/mb_types.h @ 159:b90abd31a281
Postponse free of coords, shapes, and paints when the rdman is dirty.
- Life-cycle of shapes and paints are managed by rdman.
- Add redraw_man_t::free_objs to collect objects their freeing are
postonsed.
Know Issue:
- Bullet of tank are not removed from screen when it is go out the range
of the map.
author | Thinker K.F. Li <thinker@branda.to> |
---|---|
date | Sun, 05 Oct 2008 23:32:58 +0800 |
parents | c1cdd3fcd28f |
children | 147c93163ef0 |
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 |
159
b90abd31a281
Postponse free of coords, shapes, and paints when the rdman is dirty.
Thinker K.F. Li <thinker@branda.to>
parents:
158
diff
changeset
|
15 struct _redraw_man; |
b90abd31a281
Postponse free of coords, shapes, and paints when the rdman is dirty.
Thinker K.F. Li <thinker@branda.to>
parents:
158
diff
changeset
|
16 |
58 | 17 /*! \brief Base of paint types. |
18 * | |
159
b90abd31a281
Postponse free of coords, shapes, and paints when the rdman is dirty.
Thinker K.F. Li <thinker@branda.to>
parents:
158
diff
changeset
|
19 * Paints should be freed by users by calling rdman_paint_free() of |
58 | 20 * the paint. |
21 * | |
22 * \todo move member functions to a seperate structure and setup a | |
23 * singleton fro each paint type. | |
24 */ | |
18
0f3baa488a62
Support solid color paint for fill.
Thinker K.F. Li <thinker@branda.to>
parents:
17
diff
changeset
|
25 struct _paint { |
159
b90abd31a281
Postponse free of coords, shapes, and paints when the rdman is dirty.
Thinker K.F. Li <thinker@branda.to>
parents:
158
diff
changeset
|
26 int flags; |
18
0f3baa488a62
Support solid color paint for fill.
Thinker K.F. Li <thinker@branda.to>
parents:
17
diff
changeset
|
27 void (*prepare)(paint_t *paint, cairo_t *cr); |
159
b90abd31a281
Postponse free of coords, shapes, and paints when the rdman is dirty.
Thinker K.F. Li <thinker@branda.to>
parents:
158
diff
changeset
|
28 void (*free)(struct _redraw_man *rdman, paint_t *paint); |
18
0f3baa488a62
Support solid color paint for fill.
Thinker K.F. Li <thinker@branda.to>
parents:
17
diff
changeset
|
29 STAILQ(shnode_t) members; |
159
b90abd31a281
Postponse free of coords, shapes, and paints when the rdman is dirty.
Thinker K.F. Li <thinker@branda.to>
parents:
158
diff
changeset
|
30 paint_t *pnt_next; /*!< \brief Collect all paints of a rdman. */ |
18
0f3baa488a62
Support solid color paint for fill.
Thinker K.F. Li <thinker@branda.to>
parents:
17
diff
changeset
|
31 }; |
0f3baa488a62
Support solid color paint for fill.
Thinker K.F. Li <thinker@branda.to>
parents:
17
diff
changeset
|
32 |
159
b90abd31a281
Postponse free of coords, shapes, and paints when the rdman is dirty.
Thinker K.F. Li <thinker@branda.to>
parents:
158
diff
changeset
|
33 #define PNTF_FREE 0x1 |
b90abd31a281
Postponse free of coords, shapes, and paints when the rdman is dirty.
Thinker K.F. Li <thinker@branda.to>
parents:
158
diff
changeset
|
34 |
18
0f3baa488a62
Support solid color paint for fill.
Thinker K.F. Li <thinker@branda.to>
parents:
17
diff
changeset
|
35 struct _shnode { |
0f3baa488a62
Support solid color paint for fill.
Thinker K.F. Li <thinker@branda.to>
parents:
17
diff
changeset
|
36 shape_t *shape; |
0f3baa488a62
Support solid color paint for fill.
Thinker K.F. Li <thinker@branda.to>
parents:
17
diff
changeset
|
37 shnode_t *next; |
0f3baa488a62
Support solid color paint for fill.
Thinker K.F. Li <thinker@branda.to>
parents:
17
diff
changeset
|
38 }; |
13 | 39 |
40 struct _area { | |
41 co_aix x, y; | |
42 co_aix w, h; | |
43 }; | |
44 | |
45 /*! \brief Geometry data of a shape or a group of shape. | |
46 */ | |
47 struct _geo { | |
16
e17e12b112c4
A simple animation using rdman_redraw_changed().
Thinker K.F. Li <thinker@branda.to>
parents:
15
diff
changeset
|
48 #ifdef GEO_ORDER |
13 | 49 unsigned int order; |
16
e17e12b112c4
A simple animation using rdman_redraw_changed().
Thinker K.F. Li <thinker@branda.to>
parents:
15
diff
changeset
|
50 #endif |
13 | 51 unsigned int flags; |
52 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
|
53 geo_t *coord_next; /*!< \brief Link all member geos together. */ |
13 | 54 |
55 area_t *cur_area, *last_area; | |
56 area_t areas[2]; | |
73
9ab15ebc9061
Observer for mouse events
Thinker K.F. Li <thinker@branda.to>
parents:
58
diff
changeset
|
57 |
9ab15ebc9061
Observer for mouse events
Thinker K.F. Li <thinker@branda.to>
parents:
58
diff
changeset
|
58 subject_t *mouse_event; |
13 | 59 }; |
60 #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
|
61 #define GEF_HIDDEN 0x2 |
158
c1cdd3fcd28f
Postponing rdman_coord_free() and rdman_remove_shape().
Thinker K.F. Li <thinker@branda.to>
parents:
151
diff
changeset
|
62 #define GEF_FREE 0x4 |
13 | 63 |
64 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
|
65 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
|
66 extern void geo_init(geo_t *g); |
41f0907b27ac
Unittest for rdman_redraw_changed().
Thinker K.F. Li <thinker@branda.to>
parents:
16
diff
changeset
|
67 extern void geo_from_positions(geo_t *g, int n_pos, co_aix pos[][2]); |
13 | 68 extern void geo_mark_overlay(geo_t *g, int n_others, geo_t **others, |
69 int *n_overlays, geo_t **overlays); | |
70 #define geo_get_shape(g) ((g)->shape) | |
71 #define geo_set_shape(g, sh) do {(g)->shape = sh;} while(0) | |
28 | 72 #define _geo_is_in(a, s, w) ((a) >= (s) && (a) < ((s) + (w))) |
73 #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
|
74 (_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
|
75 _geo_is_in(_y, (g)->cur_area->y, (g)->cur_area->h)) |
13 | 76 |
5
9c331ec9e210
SVG path is partially supported
Thinker K.F. Li <thinker@branda.to>
parents:
diff
changeset
|
77 |
9c331ec9e210
SVG path is partially supported
Thinker K.F. Li <thinker@branda.to>
parents:
diff
changeset
|
78 /*! \brief A coordination system. |
9c331ec9e210
SVG path is partially supported
Thinker K.F. Li <thinker@branda.to>
parents:
diff
changeset
|
79 * |
9c331ec9e210
SVG path is partially supported
Thinker K.F. Li <thinker@branda.to>
parents:
diff
changeset
|
80 * 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
|
81 * coordination from source space to target space. |
9c331ec9e210
SVG path is partially supported
Thinker K.F. Li <thinker@branda.to>
parents:
diff
changeset
|
82 * 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
|
83 * 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
|
84 * represented by this coord object. |
12 | 85 * |
86 * \dot | |
87 * digraph G { | |
88 * graph [rankdir=LR]; | |
89 * root -> child00 -> child10 -> child20 [label="children" color="blue"]; | |
90 * child00 -> child01 -> child02 [label="sibling"]; | |
91 * child10 -> child11 [label="sibling"]; | |
92 * } | |
93 * \enddot | |
5
9c331ec9e210
SVG path is partially supported
Thinker K.F. Li <thinker@branda.to>
parents:
diff
changeset
|
94 */ |
9c331ec9e210
SVG path is partially supported
Thinker K.F. Li <thinker@branda.to>
parents:
diff
changeset
|
95 typedef struct _coord { |
13 | 96 unsigned int order; |
97 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
|
98 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
|
99 /*! 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
|
100 * 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
|
101 * \sa |
9f4fc9ecfd1f
Make shapes and coords drawed in post-order of tree.
Thinker K.F. Li <thinker@branda.to>
parents:
83
diff
changeset
|
102 * - \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
|
103 * - \ref redraw |
9f4fc9ecfd1f
Make shapes and coords drawed in post-order of tree.
Thinker K.F. Li <thinker@branda.to>
parents:
83
diff
changeset
|
104 */ |
9f4fc9ecfd1f
Make shapes and coords drawed in post-order of tree.
Thinker K.F. Li <thinker@branda.to>
parents:
83
diff
changeset
|
105 cairo_t *canvas; |
13 | 106 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
|
107 area_t areas[2]; |
13 | 108 |
5
9c331ec9e210
SVG path is partially supported
Thinker K.F. Li <thinker@branda.to>
parents:
diff
changeset
|
109 co_aix matrix[6]; |
9c331ec9e210
SVG path is partially supported
Thinker K.F. Li <thinker@branda.to>
parents:
diff
changeset
|
110 co_aix aggr_matrix[6]; |
13 | 111 |
5
9c331ec9e210
SVG path is partially supported
Thinker K.F. Li <thinker@branda.to>
parents:
diff
changeset
|
112 struct _coord *parent; |
12 | 113 STAILQ(struct _coord) children; |
114 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
|
115 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
|
116 * of parent. */ |
13 | 117 |
139
1695a4b02b14
Members of coords are geos instead of shapes, now.
Thinker K.F. Li <thinker@branda.to>
parents:
138
diff
changeset
|
118 int num_members; |
159
b90abd31a281
Postponse free of coords, shapes, and paints when the rdman is dirty.
Thinker K.F. Li <thinker@branda.to>
parents:
158
diff
changeset
|
119 STAILQ(geo_t) members; /*!< \brief All geo_t members in this coord. */ |
b90abd31a281
Postponse free of coords, shapes, and paints when the rdman is dirty.
Thinker K.F. Li <thinker@branda.to>
parents:
158
diff
changeset
|
120 |
b90abd31a281
Postponse free of coords, shapes, and paints when the rdman is dirty.
Thinker K.F. Li <thinker@branda.to>
parents:
158
diff
changeset
|
121 STAILQ(shape_t) shapes; /*!< \brief All shapes managed by the rdman. */ |
b90abd31a281
Postponse free of coords, shapes, and paints when the rdman is dirty.
Thinker K.F. Li <thinker@branda.to>
parents:
158
diff
changeset
|
122 |
73
9ab15ebc9061
Observer for mouse events
Thinker K.F. Li <thinker@branda.to>
parents:
58
diff
changeset
|
123 subject_t *mouse_event; |
5
9c331ec9e210
SVG path is partially supported
Thinker K.F. Li <thinker@branda.to>
parents:
diff
changeset
|
124 } coord_t; |
13 | 125 #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
|
126 #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
|
127 #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
|
128 * 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
|
129 */ |
151
d11aa8fc06c7
Fix bug of tanks do not show at right places.
Thinker K.F. Li <thinker@branda.to>
parents:
140
diff
changeset
|
130 #define COF_SKIP_TRIVAL 0x8 /*!< Temporary skip descendants |
d11aa8fc06c7
Fix bug of tanks do not show at right places.
Thinker K.F. Li <thinker@branda.to>
parents:
140
diff
changeset
|
131 * when trivaling. |
d11aa8fc06c7
Fix bug of tanks do not show at right places.
Thinker K.F. Li <thinker@branda.to>
parents:
140
diff
changeset
|
132 */ |
158
c1cdd3fcd28f
Postponing rdman_coord_free() and rdman_remove_shape().
Thinker K.F. Li <thinker@branda.to>
parents:
151
diff
changeset
|
133 #define COF_FREE 0x10 |
5
9c331ec9e210
SVG path is partially supported
Thinker K.F. Li <thinker@branda.to>
parents:
diff
changeset
|
134 |
9c331ec9e210
SVG path is partially supported
Thinker K.F. Li <thinker@branda.to>
parents:
diff
changeset
|
135 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
|
136 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
|
137 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
|
138 extern void compute_aggr_of_coord(coord_t *coord); |
10 | 139 extern void update_aggr_matrix(coord_t *start); |
13 | 140 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
|
141 extern coord_t *postorder_coord_subtree(coord_t *root, coord_t *last); |
151
d11aa8fc06c7
Fix bug of tanks do not show at right places.
Thinker K.F. Li <thinker@branda.to>
parents:
140
diff
changeset
|
142 extern void preorder_coord_skip_subtree(coord_t *subroot); |
d11aa8fc06c7
Fix bug of tanks do not show at right places.
Thinker K.F. Li <thinker@branda.to>
parents:
140
diff
changeset
|
143 #define preorder_coord_skip_subtree(sub) \ |
d11aa8fc06c7
Fix bug of tanks do not show at right places.
Thinker K.F. Li <thinker@branda.to>
parents:
140
diff
changeset
|
144 do { (sub)->flags |= COF_SKIP_TRIVAL; } while(0) |
57
ab028c9f0930
Ability to hidden shapes and action of visibility.
Thinker K.F. Li <thinker@branda.to>
parents:
35
diff
changeset
|
145 #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
|
146 #define coord_show(co) do { co->flags &= ~COF_HIDDEN; } while(0) |
83 | 147 #define coord_get_mouse_event(coord) ((coord)->mouse_event) |
12 | 148 |
149 | |
150 /*! \brief A grahpic shape. | |
151 * | |
152 * \dot | |
153 * digraph G { | |
154 * "shape" -> "coord"; | |
155 * "shape" -> "geo"; | |
156 * "geo" -> "shape"; | |
157 * "coord" -> "shape" [label="members"] | |
158 * "shape" -> "shape" [label="sibling"]; | |
159 * } | |
160 * \enddot | |
161 */ | |
162 struct _shape { | |
163 int sh_type; | |
164 geo_t *geo; | |
165 coord_t *coord; | |
18
0f3baa488a62
Support solid color paint for fill.
Thinker K.F. Li <thinker@branda.to>
parents:
17
diff
changeset
|
166 paint_t *fill, *stroke; |
26
d50f33040de6
Set line width for path.
Thinker K.F. Li <thinker@branda.to>
parents:
18
diff
changeset
|
167 co_aix stroke_width; |
73
9ab15ebc9061
Observer for mouse events
Thinker K.F. Li <thinker@branda.to>
parents:
58
diff
changeset
|
168 int stroke_linecap:2; |
9ab15ebc9061
Observer for mouse events
Thinker K.F. Li <thinker@branda.to>
parents:
58
diff
changeset
|
169 int stroke_linejoin:2; |
159
b90abd31a281
Postponse free of coords, shapes, and paints when the rdman is dirty.
Thinker K.F. Li <thinker@branda.to>
parents:
158
diff
changeset
|
170 struct _shape *sh_next; /*!< Link all shapes of a rdman together. */ |
73
9ab15ebc9061
Observer for mouse events
Thinker K.F. Li <thinker@branda.to>
parents:
58
diff
changeset
|
171 void (*free)(shape_t *shape); |
12 | 172 }; |
35
581a03196093
Support rectangle tag of SVG.
Thinker K.F. Li <thinker@branda.to>
parents:
31
diff
changeset
|
173 enum { SHT_UNKNOW, SHT_PATH, SHT_TEXT, SHT_RECT }; |
12 | 174 |
77 | 175 #define sh_get_mouse_event_subject(sh) ((sh)->geo->mouse_event) |
81 | 176 #define sh_hide(sh) do { (sh)->geo->flags |= GEF_HIDDEN; } while(0) |
177 #define sh_show(sh) do { (sh)->geo->flags &= ~GEF_HIDDEN; } while(0) | |
140
0de8fd11271e
Use macro to simplify the code.
Thinker K.F. Li <thinker@branda.to>
parents:
139
diff
changeset
|
178 |
12 | 179 |
5
9c331ec9e210
SVG path is partially supported
Thinker K.F. Li <thinker@branda.to>
parents:
diff
changeset
|
180 #endif /* __MB_TYPES_H_ */ |