Mercurial > MadButterfly
comparison include/mb_types.h @ 186:530bb7728546 include_mb_test
Move header files to $(top_srcdir)/include/ and prefixed with 'mb_'.
This is the solution that I dicussed with FourDollars, last night.
author | Thinker K.F. Li <thinker@branda.to> |
---|---|
date | Wed, 05 Nov 2008 15:24:01 +0800 |
parents | include/mb/mb_types.h@c7e5b8779bb5 |
children | 257af0ed5852 |
comparison
equal
deleted
inserted
replaced
185:c7e5b8779bb5 | 186:530bb7728546 |
---|---|
1 #ifndef __MB_TYPES_H_ | |
2 #define __MB_TYPES_H_ | |
3 | |
4 #include <cairo.h> | |
5 #include "mb_tools.h" | |
6 #include "mb_observer.h" | |
7 | |
8 typedef float co_aix; | |
9 typedef struct _shape shape_t; | |
10 typedef struct _geo geo_t; | |
11 typedef struct _area area_t; | |
12 typedef struct _shnode shnode_t; | |
13 typedef struct _paint paint_t; | |
14 | |
15 struct _redraw_man; | |
16 | |
17 /*! \brief Base of paint types. | |
18 * | |
19 * Paints should be freed by users by calling rdman_paint_free() of | |
20 * the paint. | |
21 * | |
22 * \todo move member functions to a seperate structure and setup a | |
23 * singleton fro each paint type. | |
24 */ | |
25 struct _paint { | |
26 int flags; | |
27 void (*prepare)(paint_t *paint, cairo_t *cr); | |
28 void (*free)(struct _redraw_man *rdman, paint_t *paint); | |
29 STAILQ(shnode_t) members; | |
30 paint_t *pnt_next; /*!< \brief Collect all paints of a rdman. */ | |
31 }; | |
32 | |
33 #define PNTF_FREE 0x1 | |
34 | |
35 struct _shnode { | |
36 shape_t *shape; | |
37 shnode_t *next; | |
38 }; | |
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 { | |
48 #ifdef GEO_ORDER | |
49 unsigned int order; | |
50 #endif | |
51 unsigned int flags; | |
52 shape_t *shape; | |
53 geo_t *coord_next; /*!< \brief Link all member geos together. */ | |
54 | |
55 area_t *cur_area, *last_area; | |
56 area_t areas[2]; | |
57 | |
58 subject_t *mouse_event; | |
59 }; | |
60 #define GEF_DIRTY 0x1 | |
61 #define GEF_HIDDEN 0x2 /*!< The geo is hidden. */ | |
62 #define GEF_FREE 0x4 | |
63 | |
64 extern int is_overlay(area_t *r1, area_t *r2); | |
65 extern void area_init(area_t *area, int n_pos, co_aix pos[][2]); | |
66 extern void geo_init(geo_t *g); | |
67 extern void geo_from_positions(geo_t *g, int n_pos, co_aix pos[][2]); | |
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) | |
72 #define _geo_is_in(a, s, w) ((a) >= (s) && (a) < ((s) + (w))) | |
73 #define geo_pos_is_in(g, _x, _y) \ | |
74 (_geo_is_in(_x, (g)->cur_area->x, (g)->cur_area->w) && \ | |
75 _geo_is_in(_y, (g)->cur_area->y, (g)->cur_area->h)) | |
76 | |
77 | |
78 /*! \brief A coordination system. | |
79 * | |
80 * It have a transform function defined by matrix to transform | |
81 * coordination from source space to target space. | |
82 * Source space is where the contained is drawed, and target space | |
83 * is where the coordination of parent container of the element | |
84 * represented by this coord object. | |
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 | |
94 */ | |
95 typedef struct _coord { | |
96 unsigned int order; | |
97 unsigned int flags; | |
98 co_aix opacity; | |
99 /*! Own one or inherit from an ancestor. | |
100 * Setup it when clean coords. | |
101 * \sa | |
102 * - \ref COF_OWN_CANVAS | |
103 * - \ref redraw | |
104 */ | |
105 cairo_t *canvas; | |
106 area_t *cur_area, *last_area; | |
107 area_t areas[2]; | |
108 | |
109 co_aix matrix[6]; | |
110 co_aix aggr_matrix[6]; | |
111 | |
112 struct _coord *parent; | |
113 STAILQ(struct _coord) children; | |
114 struct _coord *sibling; | |
115 unsigned int before_pmem; /*!< \brief The coord is before nth member | |
116 * of parent. */ | |
117 | |
118 int num_members; | |
119 STAILQ(geo_t) members; /*!< \brief All geo_t members in this coord. */ | |
120 | |
121 STAILQ(shape_t) shapes; /*!< \brief All shapes managed by the rdman. */ | |
122 | |
123 subject_t *mouse_event; | |
124 } coord_t; | |
125 #define COF_DIRTY 0x1 | |
126 #define COF_HIDDEN 0x2 /*!< A coord is hidden. */ | |
127 #define COF_OWN_CANVAS 0x4 /*!< A coord owns a canvas or inherit it | |
128 * from an ancestor. | |
129 */ | |
130 #define COF_SKIP_TRIVAL 0x8 /*!< temporary skip descendants | |
131 * when trivaling. | |
132 */ | |
133 #define COF_FREE 0x10 | |
134 | |
135 extern void coord_init(coord_t *co, coord_t *parent); | |
136 extern void coord_trans_pos(coord_t *co, co_aix *x, co_aix *y); | |
137 extern co_aix coord_trans_size(coord_t *co, co_aix size); | |
138 extern void compute_aggr_of_coord(coord_t *coord); | |
139 extern void update_aggr_matrix(coord_t *start); | |
140 extern coord_t *preorder_coord_subtree(coord_t *root, coord_t *last); | |
141 extern coord_t *postorder_coord_subtree(coord_t *root, coord_t *last); | |
142 extern void preorder_coord_skip_subtree(coord_t *subroot); | |
143 #define preorder_coord_skip_subtree(sub) \ | |
144 do { (sub)->flags |= COF_SKIP_TRIVAL; } while(0) | |
145 #define coord_hide(co) \ | |
146 do { \ | |
147 (co)->flags |= COF_HIDDEN; \ | |
148 } while(0) | |
149 #define coord_show(co) do { co->flags &= ~COF_HIDDEN; } while(0) | |
150 #define coord_get_mouse_event(coord) ((coord)->mouse_event) | |
151 | |
152 | |
153 /*! \brief A grahpic shape. | |
154 * | |
155 * \dot | |
156 * digraph G { | |
157 * "shape" -> "coord"; | |
158 * "shape" -> "geo"; | |
159 * "geo" -> "shape"; | |
160 * "coord" -> "shape" [label="members"] | |
161 * "shape" -> "shape" [label="sibling"]; | |
162 * } | |
163 * \enddot | |
164 */ | |
165 struct _shape { | |
166 int sh_type; | |
167 geo_t *geo; | |
168 coord_t *coord; | |
169 paint_t *fill, *stroke; | |
170 co_aix stroke_width; | |
171 int stroke_linecap:2; | |
172 int stroke_linejoin:2; | |
173 struct _shape *sh_next; /*!< Link all shapes of a rdman together. */ | |
174 void (*free)(shape_t *shape); | |
175 }; | |
176 enum { SHT_UNKNOW, SHT_PATH, SHT_TEXT, SHT_RECT }; | |
177 | |
178 #define sh_get_mouse_event_subject(sh) ((sh)->geo->mouse_event) | |
179 #define sh_hide(sh) \ | |
180 do { \ | |
181 (sh)->geo->flags |= GEF_HIDDEN; \ | |
182 } while(0) | |
183 #define sh_show(sh) \ | |
184 do { \ | |
185 (sh)->geo->flags &= ~GEF_HIDDEN; \ | |
186 } while(0) | |
187 | |
188 | |
189 #endif /* __MB_TYPES_H_ */ |