comparison include/mb_redraw_man.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/redraw_man.h@c7e5b8779bb5
children 29e1b2bffe4c
comparison
equal deleted inserted replaced
185:c7e5b8779bb5 186:530bb7728546
1 #ifndef __REDRAW_MAN_H_
2 #define __REDRAW_MAN_H_
3
4 #include <cairo.h>
5 #include "mb_tools.h"
6 #include "mb_types.h"
7 #include "mb_observer.h"
8
9 typedef struct _redraw_man redraw_man_t;
10
11 typedef void (*free_func_t)(redraw_man_t *rdman, void *obj);
12 struct _free_obj {
13 void *obj;
14 free_func_t free_func;
15 };
16 typedef struct _free_obj free_obj_t;
17 struct _free_objs {
18 int num, max;
19 free_obj_t *objs;
20 };
21 typedef struct _free_objs free_objs_t;
22
23 DARRAY(coords, coord_t *);
24 DARRAY(geos, geo_t *);
25 DARRAY(areas, area_t *);
26
27 /*! \brief Manage redrawing of shapes (graphic elements).
28 *
29 * Every coord_t and geo_t object is assigned with a unique
30 * incremental order. The order is a unsigned integer.
31 * Every time a new coord_t or geo_t object is added, it is
32 * assigned with a order number that 1 bigger than last one
33 * until reaching maximum of unsigned integer.
34 * When a maximum is meet, all coord_t or geo_t objects
35 * are reasigned with a new order number from 1. It means
36 * order numbers that have been assigned and then removed
37 * later are recycled.
38 *
39 * Dirty flag is clear when the transformation matrix of a coord
40 * object been recomputed or when a geo_t objects been redrawed.
41 */
42 struct _redraw_man {
43 unsigned int next_coord_order;
44 int n_coords;
45 coord_t *root_coord;
46
47 elmpool_t *geo_pool;
48 elmpool_t *coord_pool;
49 elmpool_t *shnode_pool;
50 elmpool_t *observer_pool;
51 elmpool_t *subject_pool;
52 elmpool_t *paint_color_pool;
53
54 coords_t dirty_coords;
55 geos_t dirty_geos;
56 areas_t dirty_areas;
57
58 geos_t gen_geos;
59
60 STAILQ(shape_t) shapes; /*!< \brief All managed shapes. */
61 STAILQ(paint_t) paints; /*!< \brief All managed paints. */
62
63 free_objs_t free_objs;
64
65 cairo_t *cr;
66 cairo_t *backend;
67
68 ob_factory_t ob_factory;
69
70 subject_t *redraw; /*!< \brief Notified after redrawing. */
71 };
72
73 extern int redraw_man_init(redraw_man_t *rdman, cairo_t *cr,
74 cairo_t *backend);
75 extern void redraw_man_destroy(redraw_man_t *rdman);
76 extern int rdman_find_overlaid_shapes(redraw_man_t *rdman,
77 geo_t *geo,
78 geo_t ***overlays);
79 extern int rdman_add_shape(redraw_man_t *rdman,
80 shape_t *shape, coord_t *coord);
81 /*! \brief Make a shape been managed by a redraw manager. */
82 #define rdman_shape_man(rdman, shape) \
83 STAILQ_INS_TAIL(rdman->shapes, shape_t, sh_next, shape)
84 extern int rdman_shape_free(redraw_man_t *rdman, shape_t *shape);
85
86 #define rdman_paint_man(rdman, paint) \
87 STAILQ_INS_TAIL(rdman->paints, paint_t, pnt_next, shape)
88 extern int rdman_paint_free(redraw_man_t *rdman, paint_t *paint);
89
90 extern coord_t *rdman_coord_new(redraw_man_t *rdman, coord_t *parent);
91 extern int rdman_coord_free(redraw_man_t *rdman, coord_t *coord);
92 extern int rdman_coord_subtree_free(redraw_man_t *rdman, coord_t *subtree);
93 extern int rdman_coord_changed(redraw_man_t *rdman, coord_t *coord);
94 extern int rdman_shape_changed(redraw_man_t *rdman, shape_t *shape);
95 extern int rdman_redraw_changed(redraw_man_t *rdman);
96 extern int rdman_redraw_all(redraw_man_t *rdman);
97 extern int rdman_redraw_area(redraw_man_t *rdman, co_aix x, co_aix y,
98 co_aix w, co_aix h);
99 extern geo_t *rdman_geos(redraw_man_t *rdman, geo_t *last);
100 extern int rdman_force_clean(redraw_man_t *rdman);
101 extern shnode_t *shnode_new(redraw_man_t *rdman, shape_t *shape);
102 #define shnode_free(rdman, node) elmpool_elm_free((rdman)->shnode_pool, node)
103 #define shnode_list_free(rdman, q) \
104 do { \
105 shnode_t *__node, *__last; \
106 __last = STAILQ_HEAD(q); \
107 if(__last == NULL) break; \
108 for(__node = STAILQ_NEXT(shnode_t, next, __last); \
109 __node != NULL; \
110 __node = STAILQ_NEXT(shnode_t, next, __node)) { \
111 shnode_free(rdman, __last); \
112 __last = __node; \
113 } \
114 shnode_free(rdman, __last); \
115 } while(0)
116 #define _rdman_paint_child(rdman, paint, shape) \
117 do { \
118 shnode_t *__node; \
119 if((shape)->fill != (paint) && \
120 (shape)->stroke != (paint)) { \
121 __node = shnode_new(rdman, shape); \
122 STAILQ_INS_TAIL((paint)->members, \
123 shnode_t, next, __node); \
124 } \
125 } while(0)
126 extern void _rdman_paint_real_remove_child(redraw_man_t *rdman,
127 paint_t *paint,
128 shape_t *shape);
129 #define _rdman_paint_remove_child(rdman, paint, shape) \
130 do { \
131 if((shape)->fill == (shape)->stroke && \
132 (shape)->stroke == paint) \
133 break; \
134 _rdman_paint_real_remove_child(rdman, paint, shape); \
135 } while(0)
136 #define rdman_paint_fill(rdman, paint, shape) \
137 do { \
138 if((shape)->fill == paint) \
139 break; \
140 _rdman_paint_remove_child(rdman, paint, shape); \
141 _rdman_paint_child(rdman, paint, shape); \
142 (shape)->fill = paint; \
143 } while(0)
144 #define rdman_paint_stroke(rdman, paint, shape) \
145 do { \
146 if((shape)->stroke == paint) \
147 break; \
148 _rdman_paint_remove_child(rdman, paint, shape); \
149 _rdman_paint_child(rdman, paint, shape); \
150 (shape)->stroke = paint; \
151 } while(0)
152 extern int rdman_paint_changed(redraw_man_t *rdman, paint_t *paint);
153
154 extern shape_t *find_shape_at_pos(redraw_man_t *rdman,
155 co_aix x, co_aix y, int *in_stroke);
156 #define rdman_get_ob_factory(rdman) (&(rdman)->ob_factory)
157 #define rdman_get_redraw_subject(rdman) ((rdman)->redraw)
158
159
160 #endif /* __REDRAW_MAN_H_ */