Mercurial > MadButterfly
annotate include/mb_types.h @ 241:104d83378582
Add scene support in svg2code.py.
- Add mb_sprite_t::goto_scene()
- svg2code.py recoganize "scenes" tag in metadata of SVG file.
- tranform scenes into SCENE() macro.
- define SCENE macro in mb_c_*.m4
author | Thinker K.F. Li <thinker@branda.to> |
---|---|
date | Wed, 31 Dec 2008 02:08:40 +0800 |
parents | 65cabbdd5284 |
children | bd8ea44b421e |
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> |
186
530bb7728546
Move header files to $(top_srcdir)/include/ and prefixed with 'mb_'.
Thinker K.F. Li <thinker@branda.to>
parents:
185
diff
changeset
|
5 #include "mb_tools.h" |
530bb7728546
Move header files to $(top_srcdir)/include/ and prefixed with 'mb_'.
Thinker K.F. Li <thinker@branda.to>
parents:
185
diff
changeset
|
6 #include "mb_observer.h" |
224
29e1b2bffe4c
X backend only sent EVT_MOUSE_MOVE_RAW to MadButterfly.
Thinker K.F. Li <thinker@branda.to>
parents:
223
diff
changeset
|
7 #include "mb_prop.h" |
12 | 8 |
5
9c331ec9e210
SVG path is partially supported
Thinker K.F. Li <thinker@branda.to>
parents:
diff
changeset
|
9 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
|
10 typedef struct _shape shape_t; |
12 | 11 typedef struct _geo geo_t; |
13 | 12 typedef struct _area area_t; |
18
0f3baa488a62
Support solid color paint for fill.
Thinker K.F. Li <thinker@branda.to>
parents:
17
diff
changeset
|
13 typedef struct _shnode shnode_t; |
0f3baa488a62
Support solid color paint for fill.
Thinker K.F. Li <thinker@branda.to>
parents:
17
diff
changeset
|
14 typedef struct _paint paint_t; |
196
c234ee745ceb
Start moving to mb_obj_t
Thinker K.F. Li <thinker@branda.to>
parents:
189
diff
changeset
|
15 typedef struct _mb_obj mb_obj_t; |
208 | 16 typedef struct _mb_sprite mb_sprite_t; |
18
0f3baa488a62
Support solid color paint for fill.
Thinker K.F. Li <thinker@branda.to>
parents:
17
diff
changeset
|
17 |
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
|
18 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
|
19 |
224
29e1b2bffe4c
X backend only sent EVT_MOUSE_MOVE_RAW to MadButterfly.
Thinker K.F. Li <thinker@branda.to>
parents:
223
diff
changeset
|
20 /* \defgroup mb_obj_grp Object type |
29e1b2bffe4c
X backend only sent EVT_MOUSE_MOVE_RAW to MadButterfly.
Thinker K.F. Li <thinker@branda.to>
parents:
223
diff
changeset
|
21 * @{ |
29e1b2bffe4c
X backend only sent EVT_MOUSE_MOVE_RAW to MadButterfly.
Thinker K.F. Li <thinker@branda.to>
parents:
223
diff
changeset
|
22 */ |
204 | 23 /*! \brief MadButterfly object. |
24 * | |
25 * All objects (coord and shapes) should have mb_obj_t as first member | |
26 * variable. obj_type is used to identify type of an object. Please, | |
27 * use MBO_TYPE() to return this value. MBO_TYPE() will type-casting the | |
224
29e1b2bffe4c
X backend only sent EVT_MOUSE_MOVE_RAW to MadButterfly.
Thinker K.F. Li <thinker@branda.to>
parents:
223
diff
changeset
|
28 * object to mb_obj_t and return obj_type. |
29e1b2bffe4c
X backend only sent EVT_MOUSE_MOVE_RAW to MadButterfly.
Thinker K.F. Li <thinker@branda.to>
parents:
223
diff
changeset
|
29 * |
29e1b2bffe4c
X backend only sent EVT_MOUSE_MOVE_RAW to MadButterfly.
Thinker K.F. Li <thinker@branda.to>
parents:
223
diff
changeset
|
30 * mb_obj_t should be initialized with mb_obj_init() and destroied with |
29e1b2bffe4c
X backend only sent EVT_MOUSE_MOVE_RAW to MadButterfly.
Thinker K.F. Li <thinker@branda.to>
parents:
223
diff
changeset
|
31 * mb_obj_destroy(). |
204 | 32 */ |
196
c234ee745ceb
Start moving to mb_obj_t
Thinker K.F. Li <thinker@branda.to>
parents:
189
diff
changeset
|
33 struct _mb_obj { |
204 | 34 int obj_type; /*!< \brief Type of a MadButterfly object. */ |
224
29e1b2bffe4c
X backend only sent EVT_MOUSE_MOVE_RAW to MadButterfly.
Thinker K.F. Li <thinker@branda.to>
parents:
223
diff
changeset
|
35 mb_prop_store_t props; /*!< Initialized by rdman. */ |
196
c234ee745ceb
Start moving to mb_obj_t
Thinker K.F. Li <thinker@branda.to>
parents:
189
diff
changeset
|
36 }; |
c234ee745ceb
Start moving to mb_obj_t
Thinker K.F. Li <thinker@branda.to>
parents:
189
diff
changeset
|
37 |
c234ee745ceb
Start moving to mb_obj_t
Thinker K.F. Li <thinker@branda.to>
parents:
189
diff
changeset
|
38 enum { MBO_DUMMY, |
c234ee745ceb
Start moving to mb_obj_t
Thinker K.F. Li <thinker@branda.to>
parents:
189
diff
changeset
|
39 MBO_COORD, |
224
29e1b2bffe4c
X backend only sent EVT_MOUSE_MOVE_RAW to MadButterfly.
Thinker K.F. Li <thinker@branda.to>
parents:
223
diff
changeset
|
40 MBO_SHAPES=0x1000, /*! \note Don't touch this. */ |
196
c234ee745ceb
Start moving to mb_obj_t
Thinker K.F. Li <thinker@branda.to>
parents:
189
diff
changeset
|
41 MBO_PATH, |
c234ee745ceb
Start moving to mb_obj_t
Thinker K.F. Li <thinker@branda.to>
parents:
189
diff
changeset
|
42 MBO_TEXT, |
c234ee745ceb
Start moving to mb_obj_t
Thinker K.F. Li <thinker@branda.to>
parents:
189
diff
changeset
|
43 MBO_RECT |
c234ee745ceb
Start moving to mb_obj_t
Thinker K.F. Li <thinker@branda.to>
parents:
189
diff
changeset
|
44 }; |
c234ee745ceb
Start moving to mb_obj_t
Thinker K.F. Li <thinker@branda.to>
parents:
189
diff
changeset
|
45 #define MBO_CLASS_MASK 0xf000 |
c234ee745ceb
Start moving to mb_obj_t
Thinker K.F. Li <thinker@branda.to>
parents:
189
diff
changeset
|
46 #define MBO_CLASS(x) (((mb_obj_t *)(x))->obj_type & MBO_CLASS_MASK) |
204 | 47 /*! \brief Return type of a MadBufferly object. */ |
196
c234ee745ceb
Start moving to mb_obj_t
Thinker K.F. Li <thinker@branda.to>
parents:
189
diff
changeset
|
48 #define MBO_TYPE(x) (((mb_obj_t *)(x))->obj_type) |
c234ee745ceb
Start moving to mb_obj_t
Thinker K.F. Li <thinker@branda.to>
parents:
189
diff
changeset
|
49 #define IS_MBO_SHAPES(obj) (MBO_CLASS(obj) == MBO_SHAPES) |
224
29e1b2bffe4c
X backend only sent EVT_MOUSE_MOVE_RAW to MadButterfly.
Thinker K.F. Li <thinker@branda.to>
parents:
223
diff
changeset
|
50 #define IS_MBO_COORD(obj) (MBO_TYPE(obj) == MBO_COORD) |
29e1b2bffe4c
X backend only sent EVT_MOUSE_MOVE_RAW to MadButterfly.
Thinker K.F. Li <thinker@branda.to>
parents:
223
diff
changeset
|
51 #define mb_obj_init(obj, type) \ |
29e1b2bffe4c
X backend only sent EVT_MOUSE_MOVE_RAW to MadButterfly.
Thinker K.F. Li <thinker@branda.to>
parents:
223
diff
changeset
|
52 do { \ |
29e1b2bffe4c
X backend only sent EVT_MOUSE_MOVE_RAW to MadButterfly.
Thinker K.F. Li <thinker@branda.to>
parents:
223
diff
changeset
|
53 ((mb_obj_t *)(obj))->obj_type = type; \ |
29e1b2bffe4c
X backend only sent EVT_MOUSE_MOVE_RAW to MadButterfly.
Thinker K.F. Li <thinker@branda.to>
parents:
223
diff
changeset
|
54 } while(0) |
29e1b2bffe4c
X backend only sent EVT_MOUSE_MOVE_RAW to MadButterfly.
Thinker K.F. Li <thinker@branda.to>
parents:
223
diff
changeset
|
55 #define mb_obj_destroy(obj) |
29e1b2bffe4c
X backend only sent EVT_MOUSE_MOVE_RAW to MadButterfly.
Thinker K.F. Li <thinker@branda.to>
parents:
223
diff
changeset
|
56 #define mb_obj_prop_store(obj) (&(obj)->props) |
29e1b2bffe4c
X backend only sent EVT_MOUSE_MOVE_RAW to MadButterfly.
Thinker K.F. Li <thinker@branda.to>
parents:
223
diff
changeset
|
57 |
232
527894c2ad39
Add functions for collision test.
Thinker K.F. Li <thinker@branda.to>
parents:
224
diff
changeset
|
58 |
224
29e1b2bffe4c
X backend only sent EVT_MOUSE_MOVE_RAW to MadButterfly.
Thinker K.F. Li <thinker@branda.to>
parents:
223
diff
changeset
|
59 /* @} */ |
196
c234ee745ceb
Start moving to mb_obj_t
Thinker K.F. Li <thinker@branda.to>
parents:
189
diff
changeset
|
60 |
58 | 61 /*! \brief Base of paint types. |
62 * | |
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
|
63 * Paints should be freed by users by calling rdman_paint_free() of |
58 | 64 * the paint. |
65 * | |
66 * \todo move member functions to a seperate structure and setup a | |
189
257af0ed5852
When a bullet hits a tank or wall, it shows a bang animation.
Thinker K.F. Li <thinker@branda.to>
parents:
186
diff
changeset
|
67 * singleton for each paint type. |
58 | 68 */ |
18
0f3baa488a62
Support solid color paint for fill.
Thinker K.F. Li <thinker@branda.to>
parents:
17
diff
changeset
|
69 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
|
70 int flags; |
18
0f3baa488a62
Support solid color paint for fill.
Thinker K.F. Li <thinker@branda.to>
parents:
17
diff
changeset
|
71 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
|
72 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
|
73 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
|
74 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
|
75 }; |
0f3baa488a62
Support solid color paint for fill.
Thinker K.F. Li <thinker@branda.to>
parents:
17
diff
changeset
|
76 |
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
|
77 #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
|
78 |
18
0f3baa488a62
Support solid color paint for fill.
Thinker K.F. Li <thinker@branda.to>
parents:
17
diff
changeset
|
79 struct _shnode { |
0f3baa488a62
Support solid color paint for fill.
Thinker K.F. Li <thinker@branda.to>
parents:
17
diff
changeset
|
80 shape_t *shape; |
0f3baa488a62
Support solid color paint for fill.
Thinker K.F. Li <thinker@branda.to>
parents:
17
diff
changeset
|
81 shnode_t *next; |
0f3baa488a62
Support solid color paint for fill.
Thinker K.F. Li <thinker@branda.to>
parents:
17
diff
changeset
|
82 }; |
13 | 83 |
84 struct _area { | |
85 co_aix x, y; | |
86 co_aix w, h; | |
87 }; | |
88 | |
89 /*! \brief Geometry data of a shape or a group of shape. | |
90 */ | |
91 struct _geo { | |
16
e17e12b112c4
A simple animation using rdman_redraw_changed().
Thinker K.F. Li <thinker@branda.to>
parents:
15
diff
changeset
|
92 #ifdef GEO_ORDER |
13 | 93 unsigned int order; |
16
e17e12b112c4
A simple animation using rdman_redraw_changed().
Thinker K.F. Li <thinker@branda.to>
parents:
15
diff
changeset
|
94 #endif |
13 | 95 unsigned int flags; |
96 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
|
97 geo_t *coord_next; /*!< \brief Link all member geos together. */ |
13 | 98 |
99 area_t *cur_area, *last_area; | |
100 area_t areas[2]; | |
73
9ab15ebc9061
Observer for mouse events
Thinker K.F. Li <thinker@branda.to>
parents:
58
diff
changeset
|
101 |
9ab15ebc9061
Observer for mouse events
Thinker K.F. Li <thinker@branda.to>
parents:
58
diff
changeset
|
102 subject_t *mouse_event; |
13 | 103 }; |
104 #define GEF_DIRTY 0x1 | |
160
147c93163ef0
Fix bug of tank that bullet is not hidden when go out the map.
Thinker K.F. Li <thinker@branda.to>
parents:
159
diff
changeset
|
105 #define GEF_HIDDEN 0x2 /*!< The geo is hidden. */ |
158
c1cdd3fcd28f
Postponing rdman_coord_free() and rdman_remove_shape().
Thinker K.F. Li <thinker@branda.to>
parents:
151
diff
changeset
|
106 #define GEF_FREE 0x4 |
232
527894c2ad39
Add functions for collision test.
Thinker K.F. Li <thinker@branda.to>
parents:
224
diff
changeset
|
107 #define GEF_OV_DRAW 0x8 /*!< To flag drawed for a overlay testing. */ |
13 | 108 |
235 | 109 extern int areas_are_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
|
110 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
|
111 extern void geo_init(geo_t *g); |
41f0907b27ac
Unittest for rdman_redraw_changed().
Thinker K.F. Li <thinker@branda.to>
parents:
16
diff
changeset
|
112 extern void geo_from_positions(geo_t *g, int n_pos, co_aix pos[][2]); |
13 | 113 extern void geo_mark_overlay(geo_t *g, int n_others, geo_t **others, |
114 int *n_overlays, geo_t **overlays); | |
115 #define geo_get_shape(g) ((g)->shape) | |
235 | 116 #define geo_get_shape_safe(g) ((g)? (g)->shape: NULL) |
13 | 117 #define geo_set_shape(g, sh) do {(g)->shape = sh;} while(0) |
28 | 118 #define _geo_is_in(a, s, w) ((a) >= (s) && (a) < ((s) + (w))) |
119 #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
|
120 (_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
|
121 _geo_is_in(_y, (g)->cur_area->y, (g)->cur_area->h)) |
232
527894c2ad39
Add functions for collision test.
Thinker K.F. Li <thinker@branda.to>
parents:
224
diff
changeset
|
122 #define geo_get_area(g) ((g)->cur_area) |
235 | 123 #define geo_get_flags(g, mask) ((g)->flags & (mask)) |
124 #define geo_set_flags(g, mask) do {(g)->flags |= mask;} while(0) | |
125 #define geo_clear_flags(g, mask) do {(g)->flags &= ~(mask);} while(0) | |
13 | 126 |
5
9c331ec9e210
SVG path is partially supported
Thinker K.F. Li <thinker@branda.to>
parents:
diff
changeset
|
127 |
9c331ec9e210
SVG path is partially supported
Thinker K.F. Li <thinker@branda.to>
parents:
diff
changeset
|
128 /*! \brief A coordination system. |
9c331ec9e210
SVG path is partially supported
Thinker K.F. Li <thinker@branda.to>
parents:
diff
changeset
|
129 * |
9c331ec9e210
SVG path is partially supported
Thinker K.F. Li <thinker@branda.to>
parents:
diff
changeset
|
130 * 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
|
131 * coordination from source space to target space. |
9c331ec9e210
SVG path is partially supported
Thinker K.F. Li <thinker@branda.to>
parents:
diff
changeset
|
132 * 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
|
133 * 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
|
134 * represented by this coord object. |
12 | 135 * |
136 * \dot | |
137 * digraph G { | |
138 * graph [rankdir=LR]; | |
139 * root -> child00 -> child10 -> child20 [label="children" color="blue"]; | |
140 * child00 -> child01 -> child02 [label="sibling"]; | |
141 * child10 -> child11 [label="sibling"]; | |
142 * } | |
143 * \enddot | |
5
9c331ec9e210
SVG path is partially supported
Thinker K.F. Li <thinker@branda.to>
parents:
diff
changeset
|
144 */ |
9c331ec9e210
SVG path is partially supported
Thinker K.F. Li <thinker@branda.to>
parents:
diff
changeset
|
145 typedef struct _coord { |
196
c234ee745ceb
Start moving to mb_obj_t
Thinker K.F. Li <thinker@branda.to>
parents:
189
diff
changeset
|
146 mb_obj_t obj; |
13 | 147 unsigned int order; |
148 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
|
149 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
|
150 /*! 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
|
151 * 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
|
152 * \sa |
9f4fc9ecfd1f
Make shapes and coords drawed in post-order of tree.
Thinker K.F. Li <thinker@branda.to>
parents:
83
diff
changeset
|
153 * - \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
|
154 * - \ref redraw |
9f4fc9ecfd1f
Make shapes and coords drawed in post-order of tree.
Thinker K.F. Li <thinker@branda.to>
parents:
83
diff
changeset
|
155 */ |
9f4fc9ecfd1f
Make shapes and coords drawed in post-order of tree.
Thinker K.F. Li <thinker@branda.to>
parents:
83
diff
changeset
|
156 cairo_t *canvas; |
13 | 157 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
|
158 area_t areas[2]; |
13 | 159 |
5
9c331ec9e210
SVG path is partially supported
Thinker K.F. Li <thinker@branda.to>
parents:
diff
changeset
|
160 co_aix matrix[6]; |
9c331ec9e210
SVG path is partially supported
Thinker K.F. Li <thinker@branda.to>
parents:
diff
changeset
|
161 co_aix aggr_matrix[6]; |
13 | 162 |
5
9c331ec9e210
SVG path is partially supported
Thinker K.F. Li <thinker@branda.to>
parents:
diff
changeset
|
163 struct _coord *parent; |
12 | 164 STAILQ(struct _coord) children; |
165 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
|
166 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
|
167 * of parent. */ |
13 | 168 |
139
1695a4b02b14
Members of coords are geos instead of shapes, now.
Thinker K.F. Li <thinker@branda.to>
parents:
138
diff
changeset
|
169 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
|
170 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
|
171 |
73
9ab15ebc9061
Observer for mouse events
Thinker K.F. Li <thinker@branda.to>
parents:
58
diff
changeset
|
172 subject_t *mouse_event; |
5
9c331ec9e210
SVG path is partially supported
Thinker K.F. Li <thinker@branda.to>
parents:
diff
changeset
|
173 } coord_t; |
13 | 174 #define COF_DIRTY 0x1 |
160
147c93163ef0
Fix bug of tank that bullet is not hidden when go out the map.
Thinker K.F. Li <thinker@branda.to>
parents:
159
diff
changeset
|
175 #define COF_HIDDEN 0x2 /*!< A coord is hidden. */ |
138
9f4fc9ecfd1f
Make shapes and coords drawed in post-order of tree.
Thinker K.F. Li <thinker@branda.to>
parents:
83
diff
changeset
|
176 #define COF_OWN_CANVAS 0x4 /*!< A coord owns a canvas or inherit it |
160
147c93163ef0
Fix bug of tank that bullet is not hidden when go out the map.
Thinker K.F. Li <thinker@branda.to>
parents:
159
diff
changeset
|
177 * from an ancestor. |
138
9f4fc9ecfd1f
Make shapes and coords drawed in post-order of tree.
Thinker K.F. Li <thinker@branda.to>
parents:
83
diff
changeset
|
178 */ |
160
147c93163ef0
Fix bug of tank that bullet is not hidden when go out the map.
Thinker K.F. Li <thinker@branda.to>
parents:
159
diff
changeset
|
179 #define COF_SKIP_TRIVAL 0x8 /*!< temporary skip descendants |
151
d11aa8fc06c7
Fix bug of tanks do not show at right places.
Thinker K.F. Li <thinker@branda.to>
parents:
140
diff
changeset
|
180 * when trivaling. |
d11aa8fc06c7
Fix bug of tanks do not show at right places.
Thinker K.F. Li <thinker@branda.to>
parents:
140
diff
changeset
|
181 */ |
158
c1cdd3fcd28f
Postponing rdman_coord_free() and rdman_remove_shape().
Thinker K.F. Li <thinker@branda.to>
parents:
151
diff
changeset
|
182 #define COF_FREE 0x10 |
5
9c331ec9e210
SVG path is partially supported
Thinker K.F. Li <thinker@branda.to>
parents:
diff
changeset
|
183 |
9c331ec9e210
SVG path is partially supported
Thinker K.F. Li <thinker@branda.to>
parents:
diff
changeset
|
184 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
|
185 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
|
186 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
|
187 extern void compute_aggr_of_coord(coord_t *coord); |
10 | 188 extern void update_aggr_matrix(coord_t *start); |
13 | 189 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
|
190 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
|
191 #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
|
192 do { (sub)->flags |= COF_SKIP_TRIVAL; } while(0) |
160
147c93163ef0
Fix bug of tank that bullet is not hidden when go out the map.
Thinker K.F. Li <thinker@branda.to>
parents:
159
diff
changeset
|
193 #define coord_hide(co) \ |
147c93163ef0
Fix bug of tank that bullet is not hidden when go out the map.
Thinker K.F. Li <thinker@branda.to>
parents:
159
diff
changeset
|
194 do { \ |
147c93163ef0
Fix bug of tank that bullet is not hidden when go out the map.
Thinker K.F. Li <thinker@branda.to>
parents:
159
diff
changeset
|
195 (co)->flags |= COF_HIDDEN; \ |
147c93163ef0
Fix bug of tank that bullet is not hidden when go out the map.
Thinker K.F. Li <thinker@branda.to>
parents:
159
diff
changeset
|
196 } while(0) |
57
ab028c9f0930
Ability to hidden shapes and action of visibility.
Thinker K.F. Li <thinker@branda.to>
parents:
35
diff
changeset
|
197 #define coord_show(co) do { co->flags &= ~COF_HIDDEN; } while(0) |
83 | 198 #define coord_get_mouse_event(coord) ((coord)->mouse_event) |
232
527894c2ad39
Add functions for collision test.
Thinker K.F. Li <thinker@branda.to>
parents:
224
diff
changeset
|
199 #define FOR_COORDS_POSTORDER(coord, cur) \ |
527894c2ad39
Add functions for collision test.
Thinker K.F. Li <thinker@branda.to>
parents:
224
diff
changeset
|
200 for((cur) = postorder_coord_subtree((coord), NULL); \ |
527894c2ad39
Add functions for collision test.
Thinker K.F. Li <thinker@branda.to>
parents:
224
diff
changeset
|
201 (cur) != NULL; \ |
527894c2ad39
Add functions for collision test.
Thinker K.F. Li <thinker@branda.to>
parents:
224
diff
changeset
|
202 (cur) = postorder_coord_subtree((coord), (cur))) |
527894c2ad39
Add functions for collision test.
Thinker K.F. Li <thinker@branda.to>
parents:
224
diff
changeset
|
203 #define FOR_COORDS_PREORDER(coord, cur) \ |
527894c2ad39
Add functions for collision test.
Thinker K.F. Li <thinker@branda.to>
parents:
224
diff
changeset
|
204 for((cur) = (coord); \ |
527894c2ad39
Add functions for collision test.
Thinker K.F. Li <thinker@branda.to>
parents:
224
diff
changeset
|
205 (cur) != NULL; \ |
527894c2ad39
Add functions for collision test.
Thinker K.F. Li <thinker@branda.to>
parents:
224
diff
changeset
|
206 (cur) = preorder_coord_subtree((coord), (cur))) |
12 | 207 |
222
f7057177abbb
Add functions to move and scale the coord_t like the actionscript. Users should use these functions instead of the matrix directly.
wycc
parents:
211
diff
changeset
|
208 /*! \brief Coord operation function |
f7057177abbb
Add functions to move and scale the coord_t like the actionscript. Users should use these functions instead of the matrix directly.
wycc
parents:
211
diff
changeset
|
209 * These functions are used to move and scale the coord_t. Programmers should use these functions instead of using the matrix directly. |
f7057177abbb
Add functions to move and scale the coord_t like the actionscript. Users should use these functions instead of the matrix directly.
wycc
parents:
211
diff
changeset
|
210 * The x,y,sx,sy are all in co_aix type. |
f7057177abbb
Add functions to move and scale the coord_t like the actionscript. Users should use these functions instead of the matrix directly.
wycc
parents:
211
diff
changeset
|
211 * |
f7057177abbb
Add functions to move and scale the coord_t like the actionscript. Users should use these functions instead of the matrix directly.
wycc
parents:
211
diff
changeset
|
212 */ |
f7057177abbb
Add functions to move and scale the coord_t like the actionscript. Users should use these functions instead of the matrix directly.
wycc
parents:
211
diff
changeset
|
213 #define coord_move(co,x,y) do {(co)->matrix[2] = (x); (co)->matrix[5] = (y);} while(0) |
f7057177abbb
Add functions to move and scale the coord_t like the actionscript. Users should use these functions instead of the matrix directly.
wycc
parents:
211
diff
changeset
|
214 #define coord_set_scalex(ci,sx) do {(co)->matrix[0] = sx;} while(0) |
f7057177abbb
Add functions to move and scale the coord_t like the actionscript. Users should use these functions instead of the matrix directly.
wycc
parents:
211
diff
changeset
|
215 #define coord_set_scaley(ci,sy) do {(co)->matrux[3] = sy;} while(0) |
f7057177abbb
Add functions to move and scale the coord_t like the actionscript. Users should use these functions instead of the matrix directly.
wycc
parents:
211
diff
changeset
|
216 #define coord_scalex(ci) ((co)->matrix[0]) |
f7057177abbb
Add functions to move and scale the coord_t like the actionscript. Users should use these functions instead of the matrix directly.
wycc
parents:
211
diff
changeset
|
217 #define coord_scaley(ci) ((co)->matrix[3]) |
223 | 218 #define coord_x(ci) ((co)->matrix[2]) |
219 #define coord_y(ci) ((co)->matrix[5]) | |
232
527894c2ad39
Add functions for collision test.
Thinker K.F. Li <thinker@branda.to>
parents:
224
diff
changeset
|
220 #define FOR_COORD_MEMBERS(coord, geo) \ |
527894c2ad39
Add functions for collision test.
Thinker K.F. Li <thinker@branda.to>
parents:
224
diff
changeset
|
221 for(geo = STAILQ_HEAD((coord)->members); \ |
527894c2ad39
Add functions for collision test.
Thinker K.F. Li <thinker@branda.to>
parents:
224
diff
changeset
|
222 geo != NULL; \ |
527894c2ad39
Add functions for collision test.
Thinker K.F. Li <thinker@branda.to>
parents:
224
diff
changeset
|
223 geo = STAILQ_NEXT(geo_t, coord_next, geo)) |
235 | 224 #define FOR_COORD_SHAPES(coord, shape) \ |
225 for(shape = geo_get_shape_safe(STAILQ_HEAD((coord)->members)); \ | |
226 shape != NULL; \ | |
227 shape = geo_get_shape_safe(STAILQ_NEXT(geo_t, coord_next, \ | |
228 sh_get_geo(shape)))) | |
232
527894c2ad39
Add functions for collision test.
Thinker K.F. Li <thinker@branda.to>
parents:
224
diff
changeset
|
229 #define coord_get_area(coord) ((coord)->cur_area) |
12 | 230 |
231 /*! \brief A grahpic shape. | |
232 * | |
233 * \dot | |
234 * digraph G { | |
235 * "shape" -> "coord"; | |
236 * "shape" -> "geo"; | |
237 * "geo" -> "shape"; | |
238 * "coord" -> "shape" [label="members"] | |
239 * "shape" -> "shape" [label="sibling"]; | |
240 * } | |
241 * \enddot | |
242 */ | |
243 struct _shape { | |
196
c234ee745ceb
Start moving to mb_obj_t
Thinker K.F. Li <thinker@branda.to>
parents:
189
diff
changeset
|
244 mb_obj_t obj; |
12 | 245 geo_t *geo; |
246 coord_t *coord; | |
18
0f3baa488a62
Support solid color paint for fill.
Thinker K.F. Li <thinker@branda.to>
parents:
17
diff
changeset
|
247 paint_t *fill, *stroke; |
26
d50f33040de6
Set line width for path.
Thinker K.F. Li <thinker@branda.to>
parents:
18
diff
changeset
|
248 co_aix stroke_width; |
73
9ab15ebc9061
Observer for mouse events
Thinker K.F. Li <thinker@branda.to>
parents:
58
diff
changeset
|
249 int stroke_linecap:2; |
9ab15ebc9061
Observer for mouse events
Thinker K.F. Li <thinker@branda.to>
parents:
58
diff
changeset
|
250 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
|
251 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
|
252 void (*free)(shape_t *shape); |
12 | 253 }; |
196
c234ee745ceb
Start moving to mb_obj_t
Thinker K.F. Li <thinker@branda.to>
parents:
189
diff
changeset
|
254 /* enum { SHT_UNKNOW, SHT_PATH, SHT_TEXT, SHT_RECT }; */ |
12 | 255 |
77 | 256 #define sh_get_mouse_event_subject(sh) ((sh)->geo->mouse_event) |
160
147c93163ef0
Fix bug of tank that bullet is not hidden when go out the map.
Thinker K.F. Li <thinker@branda.to>
parents:
159
diff
changeset
|
257 #define sh_hide(sh) \ |
147c93163ef0
Fix bug of tank that bullet is not hidden when go out the map.
Thinker K.F. Li <thinker@branda.to>
parents:
159
diff
changeset
|
258 do { \ |
147c93163ef0
Fix bug of tank that bullet is not hidden when go out the map.
Thinker K.F. Li <thinker@branda.to>
parents:
159
diff
changeset
|
259 (sh)->geo->flags |= GEF_HIDDEN; \ |
147c93163ef0
Fix bug of tank that bullet is not hidden when go out the map.
Thinker K.F. Li <thinker@branda.to>
parents:
159
diff
changeset
|
260 } while(0) |
147c93163ef0
Fix bug of tank that bullet is not hidden when go out the map.
Thinker K.F. Li <thinker@branda.to>
parents:
159
diff
changeset
|
261 #define sh_show(sh) \ |
147c93163ef0
Fix bug of tank that bullet is not hidden when go out the map.
Thinker K.F. Li <thinker@branda.to>
parents:
159
diff
changeset
|
262 do { \ |
147c93163ef0
Fix bug of tank that bullet is not hidden when go out the map.
Thinker K.F. Li <thinker@branda.to>
parents:
159
diff
changeset
|
263 (sh)->geo->flags &= ~GEF_HIDDEN; \ |
147c93163ef0
Fix bug of tank that bullet is not hidden when go out the map.
Thinker K.F. Li <thinker@branda.to>
parents:
159
diff
changeset
|
264 } while(0) |
232
527894c2ad39
Add functions for collision test.
Thinker K.F. Li <thinker@branda.to>
parents:
224
diff
changeset
|
265 #define sh_get_geo(sh) ((sh)->geo) |
235 | 266 #define sh_get_geo_safe(sh) ((sh)? (sh)->geo: NULL) |
267 #define sh_get_flags(sh, mask) geo_get_flags(sh_get_geo(sh), mask) | |
268 #define sh_set_flags(sh, mask) geo_set_flags(sh_get_geo(sh), mask) | |
269 #define sh_clear_flags(sh, mask) geo_clear_flags(sh_get_geo(sh), mask) | |
270 #define sh_pos_is_in(sh, x, y) geo_pos_is_in(sh_get_geo(sh), x, y) | |
271 #define sh_get_area(sh) geo_get_area(sh_get_geo(sh)) | |
140
0de8fd11271e
Use macro to simplify the code.
Thinker K.F. Li <thinker@branda.to>
parents:
139
diff
changeset
|
272 |
12 | 273 |
208 | 274 /*! \brief A sprite is a set of graphics that being an object in animation. |
275 * | |
276 * A sprite include graphics comprise an object. For example, a tank, in | |
277 * example tank, is comprised a set of graphics that is represented as a | |
278 * sprite. | |
279 */ | |
280 struct _mb_sprite { | |
209
6f63aa67ed83
Define types for sprite shared object.
Thinker K.F. Li <thinker@branda.to>
parents:
208
diff
changeset
|
281 void (*free)(mb_sprite_t *); |
6f63aa67ed83
Define types for sprite shared object.
Thinker K.F. Li <thinker@branda.to>
parents:
208
diff
changeset
|
282 mb_obj_t *(*get_obj_with_name)(mb_sprite_t *sprite, const char *id); |
241
104d83378582
Add scene support in svg2code.py.
Thinker K.F. Li <thinker@branda.to>
parents:
235
diff
changeset
|
283 /*! Return non-zero for error. */ |
104d83378582
Add scene support in svg2code.py.
Thinker K.F. Li <thinker@branda.to>
parents:
235
diff
changeset
|
284 int (*goto_scene)(mb_sprite_t *sprite, int scene_no); |
208 | 285 }; |
286 | |
211
41eab0a10651
Define convenience macros for sprite.
Thinker K.F. Li <thinker@branda.to>
parents:
210
diff
changeset
|
287 #define MB_SPRITE_FREE(sprite) ((mb_sprite_t *)(sprite))->free(sprite) |
241
104d83378582
Add scene support in svg2code.py.
Thinker K.F. Li <thinker@branda.to>
parents:
235
diff
changeset
|
288 #define MB_SPRITE_GET_OBJ(sprite, name) \ |
104d83378582
Add scene support in svg2code.py.
Thinker K.F. Li <thinker@branda.to>
parents:
235
diff
changeset
|
289 ((mb_sprite_t *)(sprite))->get_obj_with_name((mb_sprite_t *)(sprite), \ |
104d83378582
Add scene support in svg2code.py.
Thinker K.F. Li <thinker@branda.to>
parents:
235
diff
changeset
|
290 (name)) |
104d83378582
Add scene support in svg2code.py.
Thinker K.F. Li <thinker@branda.to>
parents:
235
diff
changeset
|
291 #define MB_SPRITE_GOTO_SCENE(sprite, scene_no) \ |
104d83378582
Add scene support in svg2code.py.
Thinker K.F. Li <thinker@branda.to>
parents:
235
diff
changeset
|
292 ((mb_sprite_t *)(sprite))->goto_scene((mb_sprite_t *)(sprite), scene_no) |
211
41eab0a10651
Define convenience macros for sprite.
Thinker K.F. Li <thinker@branda.to>
parents:
210
diff
changeset
|
293 |
210
3fadd2f2742e
M4 macros to generate code for dynamic loading.
Thinker K.F. Li <thinker@branda.to>
parents:
209
diff
changeset
|
294 |
3fadd2f2742e
M4 macros to generate code for dynamic loading.
Thinker K.F. Li <thinker@branda.to>
parents:
209
diff
changeset
|
295 /*! \defgroup mb_sprite_lsym Sprite with linear symbol table. |
3fadd2f2742e
M4 macros to generate code for dynamic loading.
Thinker K.F. Li <thinker@branda.to>
parents:
209
diff
changeset
|
296 * @{ |
3fadd2f2742e
M4 macros to generate code for dynamic loading.
Thinker K.F. Li <thinker@branda.to>
parents:
209
diff
changeset
|
297 */ |
3fadd2f2742e
M4 macros to generate code for dynamic loading.
Thinker K.F. Li <thinker@branda.to>
parents:
209
diff
changeset
|
298 struct _mb_sprite_lsym_entry { |
3fadd2f2742e
M4 macros to generate code for dynamic loading.
Thinker K.F. Li <thinker@branda.to>
parents:
209
diff
changeset
|
299 const char *sym; |
3fadd2f2742e
M4 macros to generate code for dynamic loading.
Thinker K.F. Li <thinker@branda.to>
parents:
209
diff
changeset
|
300 const int offset; |
3fadd2f2742e
M4 macros to generate code for dynamic loading.
Thinker K.F. Li <thinker@branda.to>
parents:
209
diff
changeset
|
301 }; |
3fadd2f2742e
M4 macros to generate code for dynamic loading.
Thinker K.F. Li <thinker@branda.to>
parents:
209
diff
changeset
|
302 typedef struct _mb_sprite_lsym_entry mb_sprite_lsym_entry_t; |
3fadd2f2742e
M4 macros to generate code for dynamic loading.
Thinker K.F. Li <thinker@branda.to>
parents:
209
diff
changeset
|
303 |
3fadd2f2742e
M4 macros to generate code for dynamic loading.
Thinker K.F. Li <thinker@branda.to>
parents:
209
diff
changeset
|
304 /*! \brief A sub-type of mb_sprite_t with linear symbol table. |
3fadd2f2742e
M4 macros to generate code for dynamic loading.
Thinker K.F. Li <thinker@branda.to>
parents:
209
diff
changeset
|
305 * |
3fadd2f2742e
M4 macros to generate code for dynamic loading.
Thinker K.F. Li <thinker@branda.to>
parents:
209
diff
changeset
|
306 * This type of sprite search symbols with linear/or binary searching. |
3fadd2f2742e
M4 macros to generate code for dynamic loading.
Thinker K.F. Li <thinker@branda.to>
parents:
209
diff
changeset
|
307 */ |
3fadd2f2742e
M4 macros to generate code for dynamic loading.
Thinker K.F. Li <thinker@branda.to>
parents:
209
diff
changeset
|
308 struct _mb_sprite_lsym { |
3fadd2f2742e
M4 macros to generate code for dynamic loading.
Thinker K.F. Li <thinker@branda.to>
parents:
209
diff
changeset
|
309 mb_sprite_t sprite; |
3fadd2f2742e
M4 macros to generate code for dynamic loading.
Thinker K.F. Li <thinker@branda.to>
parents:
209
diff
changeset
|
310 int num_entries; |
3fadd2f2742e
M4 macros to generate code for dynamic loading.
Thinker K.F. Li <thinker@branda.to>
parents:
209
diff
changeset
|
311 mb_sprite_lsym_entry_t *entries; |
3fadd2f2742e
M4 macros to generate code for dynamic loading.
Thinker K.F. Li <thinker@branda.to>
parents:
209
diff
changeset
|
312 }; |
3fadd2f2742e
M4 macros to generate code for dynamic loading.
Thinker K.F. Li <thinker@branda.to>
parents:
209
diff
changeset
|
313 typedef struct _mb_sprite_lsym mb_sprite_lsym_t; |
3fadd2f2742e
M4 macros to generate code for dynamic loading.
Thinker K.F. Li <thinker@branda.to>
parents:
209
diff
changeset
|
314 |
3fadd2f2742e
M4 macros to generate code for dynamic loading.
Thinker K.F. Li <thinker@branda.to>
parents:
209
diff
changeset
|
315 /* @} */ |
3fadd2f2742e
M4 macros to generate code for dynamic loading.
Thinker K.F. Li <thinker@branda.to>
parents:
209
diff
changeset
|
316 |
5
9c331ec9e210
SVG path is partially supported
Thinker K.F. Li <thinker@branda.to>
parents:
diff
changeset
|
317 #endif /* __MB_TYPES_H_ */ |