Mercurial > MadButterfly
comparison include/mb_types.h @ 1067:7b4e80ab671a openvg
merge from default branch
author | Thinker K.F. Li <thinker@codemud.net> |
---|---|
date | Wed, 01 Dec 2010 12:25:56 +0800 |
parents | b42d69ab8857 09c1ef31884f |
children | d09f603438d8 |
comparison
equal
deleted
inserted
replaced
630:bd18951b51d5 | 1067:7b4e80ab671a |
---|---|
1 // -*- indent-tabs-mode: t; tab-width: 8; c-basic-offset: 4; -*- | |
2 // vim: sw=4:ts=8:sts=4 | |
1 #ifndef __MB_TYPES_H_ | 3 #ifndef __MB_TYPES_H_ |
2 #define __MB_TYPES_H_ | 4 #define __MB_TYPES_H_ |
3 | 5 |
4 #include "mb_graph_engine.h" | 6 #include "mb_graph_engine.h" |
5 #include "mb_tools.h" | 7 #include "mb_tools.h" |
6 #include "mb_observer.h" | 8 #include "mb_observer.h" |
7 #include "mb_prop.h" | 9 #include "mb_prop.h" |
8 | 10 |
9 typedef struct _shape shape_t; | 11 typedef struct _shape shape_t; |
10 typedef struct _geo geo_t; | 12 typedef struct _geo geo_t; |
13 typedef struct _area area_t; | |
11 typedef struct _shnode shnode_t; | 14 typedef struct _shnode shnode_t; |
12 typedef struct _paint paint_t; | 15 typedef struct _paint paint_t; |
13 typedef struct _mb_obj mb_obj_t; | 16 typedef struct _mb_obj mb_obj_t; |
14 typedef struct _mb_sprite mb_sprite_t; | 17 typedef struct _mb_sprite mb_sprite_t; |
15 /*! \todo Replace mbe_t with canvas_t. */ | 18 /*! \todo Replace mbe_t with canvas_t. */ |
28 * object to mb_obj_t and return obj_type. | 31 * object to mb_obj_t and return obj_type. |
29 * | 32 * |
30 * mb_obj_t should be initialized with mb_obj_init() and destroied with | 33 * mb_obj_t should be initialized with mb_obj_init() and destroied with |
31 * mb_obj_destroy(). | 34 * mb_obj_destroy(). |
32 * | 35 * |
33 * We have defined a set of convienent API which will wrap the coord_t or shape_t API accoridng to its type. | 36 * We have defined a set of convienent API which will wrap the coord_t |
34 * Please refer to http://www.assembla.com/wiki/show/dFrSMOtDer3BZUab7jnrAJ/MBAF_Object for the details. This | 37 * or shape_t API accoridng to its type. Please refer to |
35 * API is designed for regular programmers which can be used to change some common properties of objects without | 38 * http://www.assembla.com/wiki/show/dFrSMOtDer3BZUab7jnrAJ/MBAF_Object |
39 * for the details. This API is designed for regular programmers which | |
40 * can be used to change some common properties of objects without | |
36 * checking its type. | 41 * checking its type. |
37 */ | 42 */ |
38 struct _mb_obj { | 43 struct _mb_obj { |
39 int obj_type; /*!< \brief Type of a MadButterfly object. */ | 44 int obj_type; /*!< \brief Type of a MadButterfly object. */ |
40 mb_prop_store_t props; /*!< Initialized by rdman. */ | 45 mb_prop_store_t props; /*!< Initialized by rdman. */ |
77 * singleton for each paint type. | 82 * singleton for each paint type. |
78 */ | 83 */ |
79 struct _paint { | 84 struct _paint { |
80 int pnt_type; | 85 int pnt_type; |
81 int flags; | 86 int flags; |
82 void (*prepare)(paint_t *paint, mbe_t *cr); | 87 void (*prepare)(paint_t *paint, mbe_t *cr, shape_t *sh); |
83 void (*free)(struct _redraw_man *rdman, paint_t *paint); | 88 void (*free)(struct _redraw_man *rdman, paint_t *paint); |
84 STAILQ(shnode_t) members; | 89 STAILQ(shnode_t) members; |
85 paint_t *pnt_next; /*!< \brief Collect all paints of a rdman. */ | 90 paint_t *pnt_next; /*!< \brief Collect all paints of a rdman. */ |
86 }; | 91 }; |
87 enum { MBP_DUMMY, | 92 enum { MBP_DUMMY, |
94 #define PNTF_FREE 0x1 | 99 #define PNTF_FREE 0x1 |
95 | 100 |
96 struct _shnode { | 101 struct _shnode { |
97 shape_t *shape; | 102 shape_t *shape; |
98 shnode_t *next; | 103 shnode_t *next; |
104 }; | |
105 | |
106 struct _area { | |
107 co_aix x, y; | |
108 co_aix w, h; | |
99 }; | 109 }; |
100 | 110 |
101 /*! \brief Geometry data of a shape or a group of shape. | 111 /*! \brief Geometry data of a shape or a group of shape. |
102 */ | 112 */ |
103 struct _geo { | 113 struct _geo { |
116 #define GEF_DIRTY 0x1 | 126 #define GEF_DIRTY 0x1 |
117 #define GEF_HIDDEN 0x2 /*!< The geo is hidden. */ | 127 #define GEF_HIDDEN 0x2 /*!< The geo is hidden. */ |
118 #define GEF_FREE 0x4 | 128 #define GEF_FREE 0x4 |
119 #define GEF_OV_DRAW 0x8 /*!< To flag drawed for a overlay testing. */ | 129 #define GEF_OV_DRAW 0x8 /*!< To flag drawed for a overlay testing. */ |
120 #define GEF_SWAP 0x10 | 130 #define GEF_SWAP 0x10 |
131 #define GEF_NOT_SHOWED 0x20 /*!< This geo is not showed. | |
132 * | |
133 * A geo is not showed if it is hidden | |
134 * or one of its ancestors is hidden. | |
135 * Redraw manager uses this flag to | |
136 * determine who is not showed. | |
137 */ | |
121 | 138 |
122 extern int areas_are_overlay(area_t *r1, area_t *r2); | 139 extern int areas_are_overlay(area_t *r1, area_t *r2); |
123 extern void area_init(area_t *area, int n_pos, co_aix pos[][2]); | 140 extern void area_init(area_t *area, int n_pos, co_aix pos[][2]); |
124 #define _in_range(a, s, w) ((a) >= (s) && (a) < ((s) + (w))) | 141 #define _in_range(a, s, w) ((a) >= (s) && (a) < ((s) + (w))) |
125 #define area_pos_is_in(area, _x, _y) \ | 142 #define area_pos_is_in(area, _x, _y) \ |
158 area_t cached_dirty_area; /*!< Used to dirty an area in cached space. */ | 175 area_t cached_dirty_area; /*!< Used to dirty an area in cached space. */ |
159 area_t pcache_areas[2]; /*!< The area in the space of parent | 176 area_t pcache_areas[2]; /*!< The area in the space of parent |
160 * cached. */ | 177 * cached. */ |
161 area_t *pcache_cur_area; /*!< Current area for parent cached. */ | 178 area_t *pcache_cur_area; /*!< Current area for parent cached. */ |
162 area_t *pcache_last_area; /*!< Last area for parent cached. */ | 179 area_t *pcache_last_area; /*!< Last area for parent cached. */ |
180 co_aix cache_2_pdev[6]; /*!< Transfrom matrix from space of | |
181 * cached one to its parent. */ | |
182 co_aix cache_2_pdev_rev[6]; /*!< Reverse of cache_2_pdev. */ | |
183 co_aix aggr_2_pdev[6]; /*!< Aggregation of cache_2_pdev from root */ | |
184 co_aix aggr_2_pdev_rev[6]; /*!< Aggregation of cache_2_pdev_rev | |
185 * from root */ | |
163 } coord_canvas_info_t; | 186 } coord_canvas_info_t; |
164 | 187 |
165 /*! \brief A coordination system. | 188 /*! \brief A coordination system. |
166 * | 189 * |
167 * It have a transform function defined by matrix to transform | 190 * It have a transform function defined by matrix to transform |
212 * @{ | 235 * @{ |
213 */ | 236 */ |
214 #define COF_DIRTY 0x1 | 237 #define COF_DIRTY 0x1 |
215 #define COF_HIDDEN 0x2 /*!< A coord is hidden. */ | 238 #define COF_HIDDEN 0x2 /*!< A coord is hidden. */ |
216 #define COF_OWN_CANVAS 0x4 /*!< A coord owns a canvas or inherit it | 239 #define COF_OWN_CANVAS 0x4 /*!< A coord owns a canvas or inherit it |
217 * from an ancestor. | 240 * from an ancestor. |
218 */ | 241 */ |
219 #define COF_SKIP_TRIVAL 0x8 /*!< temporary skip descendants | 242 #define COF_SKIP_TRIVAL 0x8 /*!< temporary skip descendants |
220 * when trivaling. | 243 * when trivaling. |
221 */ | 244 */ |
222 #define COF_FREE 0x10 | 245 #define COF_FREE 0x10 |
236 * last clean. | 259 * last clean. |
237 * It is used by clean_rdman_dirties(). | 260 * It is used by clean_rdman_dirties(). |
238 */ | 261 */ |
239 #define COF_TEMP_MARK 0x400 /*!< \brief Temporary mark a coord. */ | 262 #define COF_TEMP_MARK 0x400 /*!< \brief Temporary mark a coord. */ |
240 #define COF_JUST_ZERO 0x800 /*!< \brief The coord is real peformed zeroing. | 263 #define COF_JUST_ZERO 0x800 /*!< \brief The coord is real peformed zeroing. |
241 * | 264 * |
242 * It's canvas is changed by zeroing. | 265 * It's canvas is changed by zeroing. |
243 */ | 266 */ |
244 #define COF_DIRTY_PCACHE_AREA 0x1000 /*!< \brief pcache_area shoud be | 267 /*! \brief pcache_area shoud be updated. |
245 * updated. | 268 * |
246 */ | 269 * A coord is marked with COF_DIRTY_PCACHE_AREA means its pcache_area |
270 * must be re-computed when zeroing. | |
271 */ | |
272 #define COF_DIRTY_PCACHE_AREA 0x1000 | |
247 #define COF_SKIP_ZERO 0x2000 /*!< \brief The coord just skip zeroing. | 273 #define COF_SKIP_ZERO 0x2000 /*!< \brief The coord just skip zeroing. |
248 * No real zeroing was performed. | 274 * No real zeroing was performed. |
249 */ | 275 */ |
276 #define COF_ALWAYS_CACHE 0x4000 /*!< \brief The coord always own a canvas */ | |
250 /* @} */ | 277 /* @} */ |
251 | 278 |
252 extern void matrix_mul(co_aix *m1, co_aix *m2, co_aix *dst); | 279 extern void matrix_mul(co_aix *m1, co_aix *m2, co_aix *dst); |
253 extern void matrix_trans_pos(co_aix *matrix, co_aix *x, co_aix *y); | 280 extern void matrix_trans_pos(co_aix *matrix, co_aix *x, co_aix *y); |
254 | 281 |
282 #define coord_nocache(co) \ | 309 #define coord_nocache(co) \ |
283 do { \ | 310 do { \ |
284 (co)->flags &= ~COF_CACHE_MASK; \ | 311 (co)->flags &= ~COF_CACHE_MASK; \ |
285 } while(0) | 312 } while(0) |
286 #define coord_is_root(co) ((co)->parent == NULL) | 313 #define coord_is_root(co) ((co)->parent == NULL) |
287 #define coord_is_cached(co) ((co)->flags & COF_OWN_CANVAS) | |
288 #define coord_is_fast_cached(co) ((co)->flags & COF_FAST_MASK) | |
289 #define coord_is_precise_cached(co) ((co)->flags & COF_PRECISE_MASK) | |
290 #define coord_is_zeroing(co) ((co)->flags & COF_MUST_ZEROING) | |
291 #define coord_set_zeroing(co) \ | |
292 do { (co)->flags |= COF_MUST_ZEROING; } while(0) | |
293 #define coord_clear_zeroing(co) \ | |
294 do { (co)->flags &= ~COF_MUST_ZEROING; } while(0) | |
295 #define coord_set_flags(co, _flags) \ | |
296 do { (co)->flags |= (_flags); } while(0) | |
297 #define coord_get_parent(co) ((co)->parent) | |
298 #define coord_get_flags(co, _flags) ((co)->flags & (_flags)) | |
299 #define coord_clear_flags(co, _flags) \ | |
300 do { (co)->flags &= ~(_flags); } while(0) | |
301 #define coord_get_mouse_event(coord) ((coord)->mouse_event) | 314 #define coord_get_mouse_event(coord) ((coord)->mouse_event) |
315 #define coord_get_opacity(coord) ((coord)->opacity) | |
316 #define coord_set_opacity(coord, v) do { (coord)->opacity = v; } while(0) | |
302 #define coord_get_aggr_matrix(coord) ((coord)->aggr_matrix) | 317 #define coord_get_aggr_matrix(coord) ((coord)->aggr_matrix) |
303 #define coord_get_matrix(coord) ((coord)->matrix) | 318 #define coord_get_matrix(coord) ((coord)->matrix) |
304 #define FOR_COORDS_POSTORDER(coord, cur) \ | 319 #define FOR_COORDS_POSTORDER(coord, cur) \ |
305 for((cur) = postorder_coord_subtree((coord), NULL); \ | 320 for((cur) = postorder_coord_subtree((coord), NULL); \ |
306 (cur) != NULL; \ | 321 (cur) != NULL; \ |
331 shape != NULL; \ | 346 shape != NULL; \ |
332 shape = geo_get_shape_safe(STAILQ_NEXT(geo_t, coord_next, \ | 347 shape = geo_get_shape_safe(STAILQ_NEXT(geo_t, coord_next, \ |
333 sh_get_geo(shape)))) | 348 sh_get_geo(shape)))) |
334 #define coord_get_area(coord) ((coord)->cur_area) | 349 #define coord_get_area(coord) ((coord)->cur_area) |
335 #define coord_get_last_area(coord) ((coord)->last_area) | 350 #define coord_get_last_area(coord) ((coord)->last_area) |
336 #define coord_get_pcache_area(coord) ((coord)->canvas_info->pcache_cur_area) | |
337 #define coord_get_pcache_last_area(coord) \ | |
338 ((coord)->canvas_info->pcache_last_area) | |
339 #define coord_get_cached(coord) ((coord)->canvas_info->owner) | |
340 #define _coord_get_canvas(coord) ((coord)->canvas_info->canvas) | |
341 #define _coord_set_canvas(coord, _canvas) \ | |
342 do { \ | |
343 (coord)->canvas_info->canvas = _canvas; \ | |
344 } while(0) | |
345 #define _coord_get_dirty_areas(coord) (&(coord)->canvas_info->dirty_areas) | |
346 #define _coord_get_aggr_dirty_areas(coord) \ | |
347 ((coord)->canvas_info->aggr_dirty_areas) | |
348 | 351 |
349 /* @} */ | 352 /* @} */ |
350 | 353 |
351 /*! \brief A grahpic shape. | 354 /*! \brief A grahpic shape. |
352 * | 355 * |
394 #define sh_get_fill(sh) ((sh)->fill) | 397 #define sh_get_fill(sh) ((sh)->fill) |
395 #define sh_get_stroke(sh) ((sh)->stroke) | 398 #define sh_get_stroke(sh) ((sh)->stroke) |
396 #define sh_set_stroke_width(sh, v) do { (sh)->stroke_width = (v); } while(0) | 399 #define sh_set_stroke_width(sh, v) do { (sh)->stroke_width = (v); } while(0) |
397 #define sh_get_stroke_width(sh) (sh)->stroke_width | 400 #define sh_get_stroke_width(sh) (sh)->stroke_width |
398 | 401 |
399 | |
400 /*! \brief A sprite is a set of graphics that being an object in animation. | |
401 * | |
402 * A sprite include graphics comprise an object. For example, a tank, in | |
403 * example tank, is comprised a set of graphics that is represented as a | |
404 * sprite. | |
405 */ | |
406 struct _mb_sprite { | |
407 void (*free)(mb_sprite_t *); | |
408 mb_obj_t *(*get_obj_with_name)(mb_sprite_t *sprite, const char *id); | |
409 /*! Return non-zero for error. */ | |
410 int (*goto_scene)(mb_sprite_t *sprite, int scene_no); | |
411 }; | |
412 | |
413 #define MB_SPRITE_FREE(sprite) ((mb_sprite_t *)(sprite))->free(sprite) | |
414 #define MB_SPRITE_GET_OBJ(sprite, name) \ | |
415 ((mb_sprite_t *)(sprite))->get_obj_with_name((mb_sprite_t *)(sprite), \ | |
416 (name)) | |
417 #define MB_SPRITE_GOTO_SCENE(sprite, scene_no) \ | |
418 ((mb_sprite_t *)(sprite))->goto_scene((mb_sprite_t *)(sprite), scene_no) | |
419 | |
420 | |
421 /*! \defgroup mb_sprite_lsym Sprite with linear symbol table. | |
422 * @{ | |
423 */ | |
424 struct _mb_sprite_lsym_entry { | |
425 const char *sym; | |
426 const int offset; | |
427 }; | |
428 typedef struct _mb_sprite_lsym_entry mb_sprite_lsym_entry_t; | |
429 | |
430 /*! \brief A sub-type of mb_sprite_t with linear symbol table. | |
431 * | |
432 * This type of sprite search symbols with linear/or binary searching. | |
433 */ | |
434 struct _mb_sprite_lsym { | |
435 mb_sprite_t sprite; | |
436 int num_entries; | |
437 mb_sprite_lsym_entry_t *entries; | |
438 }; | |
439 typedef struct _mb_sprite_lsym mb_sprite_lsym_t; | |
440 | |
441 /* @} */ | |
442 | |
443 #endif /* __MB_TYPES_H_ */ | 402 #endif /* __MB_TYPES_H_ */ |