Mercurial > MadButterfly
annotate src/mb_types.h @ 58:1ca417f741f1
-
author | Thinker K.F. Li <thinker@branda.to> |
---|---|
date | Sun, 10 Aug 2008 21:32:42 +0800 |
parents | ab028c9f0930 |
children | 9ab15ebc9061 |
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" |
6 | |
5
9c331ec9e210
SVG path is partially supported
Thinker K.F. Li <thinker@branda.to>
parents:
diff
changeset
|
7 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
|
8 typedef struct _shape shape_t; |
12 | 9 typedef struct _geo geo_t; |
13 | 10 typedef struct _area area_t; |
18
0f3baa488a62
Support solid color paint for fill.
Thinker K.F. Li <thinker@branda.to>
parents:
17
diff
changeset
|
11 typedef struct _shnode shnode_t; |
0f3baa488a62
Support solid color paint for fill.
Thinker K.F. Li <thinker@branda.to>
parents:
17
diff
changeset
|
12 typedef struct _paint paint_t; |
0f3baa488a62
Support solid color paint for fill.
Thinker K.F. Li <thinker@branda.to>
parents:
17
diff
changeset
|
13 |
58 | 14 /*! \brief Base of paint types. |
15 * | |
16 * Paints should be freed by users by calling paint_t::free() of | |
17 * the paint. | |
18 * | |
19 * \todo move member functions to a seperate structure and setup a | |
20 * singleton fro each paint type. | |
21 */ | |
18
0f3baa488a62
Support solid color paint for fill.
Thinker K.F. Li <thinker@branda.to>
parents:
17
diff
changeset
|
22 struct _paint { |
0f3baa488a62
Support solid color paint for fill.
Thinker K.F. Li <thinker@branda.to>
parents:
17
diff
changeset
|
23 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
|
24 void (*free)(paint_t *paint); |
0f3baa488a62
Support solid color paint for fill.
Thinker K.F. Li <thinker@branda.to>
parents:
17
diff
changeset
|
25 STAILQ(shnode_t) members; |
0f3baa488a62
Support solid color paint for fill.
Thinker K.F. Li <thinker@branda.to>
parents:
17
diff
changeset
|
26 }; |
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 struct _shnode { |
0f3baa488a62
Support solid color paint for fill.
Thinker K.F. Li <thinker@branda.to>
parents:
17
diff
changeset
|
29 shape_t *shape; |
0f3baa488a62
Support solid color paint for fill.
Thinker K.F. Li <thinker@branda.to>
parents:
17
diff
changeset
|
30 shnode_t *next; |
0f3baa488a62
Support solid color paint for fill.
Thinker K.F. Li <thinker@branda.to>
parents:
17
diff
changeset
|
31 }; |
13 | 32 |
33 struct _area { | |
34 co_aix x, y; | |
35 co_aix w, h; | |
36 }; | |
37 | |
38 /*! \brief Geometry data of a shape or a group of shape. | |
39 */ | |
40 struct _geo { | |
16
e17e12b112c4
A simple animation using rdman_redraw_changed().
Thinker K.F. Li <thinker@branda.to>
parents:
15
diff
changeset
|
41 #ifdef GEO_ORDER |
13 | 42 unsigned int order; |
16
e17e12b112c4
A simple animation using rdman_redraw_changed().
Thinker K.F. Li <thinker@branda.to>
parents:
15
diff
changeset
|
43 #endif |
13 | 44 unsigned int flags; |
45 shape_t *shape; | |
46 geo_t *next; /*!< \brief Link all geo objects. */ | |
47 | |
48 area_t *cur_area, *last_area; | |
49 area_t areas[2]; | |
50 }; | |
51 #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
|
52 #define GEF_HIDDEN 0x2 |
13 | 53 |
54 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
|
55 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
|
56 extern void geo_init(geo_t *g); |
41f0907b27ac
Unittest for rdman_redraw_changed().
Thinker K.F. Li <thinker@branda.to>
parents:
16
diff
changeset
|
57 extern void geo_from_positions(geo_t *g, int n_pos, co_aix pos[][2]); |
13 | 58 extern void geo_mark_overlay(geo_t *g, int n_others, geo_t **others, |
59 int *n_overlays, geo_t **overlays); | |
60 #define geo_get_shape(g) ((g)->shape) | |
61 #define geo_set_shape(g, sh) do {(g)->shape = sh;} while(0) | |
28 | 62 #define _geo_is_in(a, s, w) ((a) >= (s) && (a) < ((s) + (w))) |
63 #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
|
64 (_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
|
65 _geo_is_in(_y, (g)->cur_area->y, (g)->cur_area->h)) |
13 | 66 |
5
9c331ec9e210
SVG path is partially supported
Thinker K.F. Li <thinker@branda.to>
parents:
diff
changeset
|
67 |
9c331ec9e210
SVG path is partially supported
Thinker K.F. Li <thinker@branda.to>
parents:
diff
changeset
|
68 /*! \brief A coordination system. |
9c331ec9e210
SVG path is partially supported
Thinker K.F. Li <thinker@branda.to>
parents:
diff
changeset
|
69 * |
9c331ec9e210
SVG path is partially supported
Thinker K.F. Li <thinker@branda.to>
parents:
diff
changeset
|
70 * 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
|
71 * coordination from source space to target space. |
9c331ec9e210
SVG path is partially supported
Thinker K.F. Li <thinker@branda.to>
parents:
diff
changeset
|
72 * 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
|
73 * 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
|
74 * represented by this coord object. |
12 | 75 * |
76 * \dot | |
77 * digraph G { | |
78 * graph [rankdir=LR]; | |
79 * root -> child00 -> child10 -> child20 [label="children" color="blue"]; | |
80 * child00 -> child01 -> child02 [label="sibling"]; | |
81 * child10 -> child11 [label="sibling"]; | |
82 * } | |
83 * \enddot | |
5
9c331ec9e210
SVG path is partially supported
Thinker K.F. Li <thinker@branda.to>
parents:
diff
changeset
|
84 */ |
9c331ec9e210
SVG path is partially supported
Thinker K.F. Li <thinker@branda.to>
parents:
diff
changeset
|
85 typedef struct _coord { |
13 | 86 unsigned int order; |
87 unsigned int flags; | |
88 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
|
89 area_t areas[2]; |
13 | 90 |
5
9c331ec9e210
SVG path is partially supported
Thinker K.F. Li <thinker@branda.to>
parents:
diff
changeset
|
91 co_aix matrix[6]; |
9c331ec9e210
SVG path is partially supported
Thinker K.F. Li <thinker@branda.to>
parents:
diff
changeset
|
92 co_aix aggr_matrix[6]; |
13 | 93 |
5
9c331ec9e210
SVG path is partially supported
Thinker K.F. Li <thinker@branda.to>
parents:
diff
changeset
|
94 struct _coord *parent; |
12 | 95 STAILQ(struct _coord) children; |
96 struct _coord *sibling; | |
13 | 97 |
98 STAILQ(shape_t) members; /*!< All shape_t objects in this coord. */ | |
5
9c331ec9e210
SVG path is partially supported
Thinker K.F. Li <thinker@branda.to>
parents:
diff
changeset
|
99 } coord_t; |
13 | 100 #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
|
101 #define COF_HIDDEN 0x2 |
5
9c331ec9e210
SVG path is partially supported
Thinker K.F. Li <thinker@branda.to>
parents:
diff
changeset
|
102 |
9c331ec9e210
SVG path is partially supported
Thinker K.F. Li <thinker@branda.to>
parents:
diff
changeset
|
103 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
|
104 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
|
105 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
|
106 extern void compute_aggr_of_coord(coord_t *coord); |
10 | 107 extern void update_aggr_matrix(coord_t *start); |
13 | 108 extern coord_t *preorder_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
|
109 #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
|
110 #define coord_show(co) do { co->flags &= ~COF_HIDDEN; } while(0) |
12 | 111 |
112 | |
113 /*! \brief A grahpic shape. | |
114 * | |
115 * \dot | |
116 * digraph G { | |
117 * "shape" -> "coord"; | |
118 * "shape" -> "geo"; | |
119 * "geo" -> "shape"; | |
120 * "coord" -> "shape" [label="members"] | |
121 * "shape" -> "shape" [label="sibling"]; | |
122 * } | |
123 * \enddot | |
124 */ | |
125 struct _shape { | |
126 int sh_type; | |
127 geo_t *geo; | |
128 coord_t *coord; | |
129 shape_t *coord_mem_next; | |
18
0f3baa488a62
Support solid color paint for fill.
Thinker K.F. Li <thinker@branda.to>
parents:
17
diff
changeset
|
130 paint_t *fill, *stroke; |
26
d50f33040de6
Set line width for path.
Thinker K.F. Li <thinker@branda.to>
parents:
18
diff
changeset
|
131 co_aix stroke_width; |
d50f33040de6
Set line width for path.
Thinker K.F. Li <thinker@branda.to>
parents:
18
diff
changeset
|
132 int stroke_linecap; |
d50f33040de6
Set line width for path.
Thinker K.F. Li <thinker@branda.to>
parents:
18
diff
changeset
|
133 int stroke_linejoin; |
12 | 134 }; |
35
581a03196093
Support rectangle tag of SVG.
Thinker K.F. Li <thinker@branda.to>
parents:
31
diff
changeset
|
135 enum { SHT_UNKNOW, SHT_PATH, SHT_TEXT, SHT_RECT }; |
12 | 136 |
137 #define sh_attach_geo(sh, g) \ | |
138 do { \ | |
139 (sh)->geo = g; \ | |
140 (g)->shape = (shape_t *)(sh); \ | |
141 } while(0) | |
142 #define sh_detach_geo(sh) \ | |
143 do { \ | |
144 (sh)->geo->shape = NULL; \ | |
145 (sh)->geo = NULL; \ | |
146 } while(0) | |
147 extern void sh_attach_coord(shape_t *sh, coord_t *coord); | |
148 extern void sh_detach_coord(shape_t *sh); | |
149 | |
5
9c331ec9e210
SVG path is partially supported
Thinker K.F. Li <thinker@branda.to>
parents:
diff
changeset
|
150 #endif /* __MB_TYPES_H_ */ |