Mercurial > MadButterfly
annotate src/redraw_man.h @ 73:9ab15ebc9061
Observer for mouse events
author | Thinker K.F. Li <thinker@branda.to> |
---|---|
date | Mon, 18 Aug 2008 01:59:26 +0800 |
parents | 943acee7f346 |
children | 4c2d83721bcc |
rev | line source |
---|---|
12 | 1 #ifndef __REDRAW_MAN_H_ |
2 #define __REDRAW_MAN_H_ | |
3 | |
15
c2ce186a5c37
X_main uses rdman_redraw_all()
Thinker K.F. Li <thinker@branda.to>
parents:
14
diff
changeset
|
4 #include <cairo.h> |
12 | 5 #include "tools.h" |
6 #include "mb_types.h" | |
73
9ab15ebc9061
Observer for mouse events
Thinker K.F. Li <thinker@branda.to>
parents:
37
diff
changeset
|
7 #include "observer.h" |
12 | 8 |
13 | 9 /*! \brief Manage redrawing of shapes (graphic elements). |
10 * | |
11 * Every coord_t and geo_t object is assigned with a unique | |
12 * incremental order. The order is a unsigned integer. | |
13 * Every time a new coord_t or geo_t object is added, it is | |
14 * assigned with a order number that 1 bigger than last one | |
15 * until reaching maximum of unsigned integer. | |
16 * When a maximum is meet, all coord_t or geo_t objects | |
17 * are reasigned with a new order number from 1. It means | |
18 * order numbers that have been assigned and then removed | |
19 * later are recycled. | |
20 * | |
21 * Dirty flag is clear when the transformation matrix of a coord | |
22 * object been recomputed or when a geo_t objects been redrawed. | |
23 */ | |
12 | 24 typedef struct _redraw_man { |
16
e17e12b112c4
A simple animation using rdman_redraw_changed().
Thinker K.F. Li <thinker@branda.to>
parents:
15
diff
changeset
|
25 #ifdef GEO_ORDER |
13 | 26 unsigned int next_geo_order; |
16
e17e12b112c4
A simple animation using rdman_redraw_changed().
Thinker K.F. Li <thinker@branda.to>
parents:
15
diff
changeset
|
27 #endif |
12 | 28 int n_geos; |
29 STAILQ(geo_t) all_geos; | |
13 | 30 |
31 unsigned int next_coord_order; | |
32 int n_coords; | |
12 | 33 coord_t *root_coord; |
13 | 34 |
12 | 35 elmpool_t *geo_pool; |
36 elmpool_t *coord_pool; | |
18
0f3baa488a62
Support solid color paint for fill.
Thinker K.F. Li <thinker@branda.to>
parents:
16
diff
changeset
|
37 elmpool_t *shnode_pool; |
73
9ab15ebc9061
Observer for mouse events
Thinker K.F. Li <thinker@branda.to>
parents:
37
diff
changeset
|
38 elmpool_t *observer_pool; |
9ab15ebc9061
Observer for mouse events
Thinker K.F. Li <thinker@branda.to>
parents:
37
diff
changeset
|
39 elmpool_t *subject_pool; |
13 | 40 |
41 int max_dirty_coords; | |
42 int n_dirty_coords; | |
43 coord_t **dirty_coords; | |
44 | |
14 | 45 int max_dirty_geos; |
46 int n_dirty_geos; | |
47 geo_t **dirty_geos; | |
13 | 48 |
49 int max_dirty_areas; | |
50 int n_dirty_areas; | |
51 area_t **dirty_areas; | |
15
c2ce186a5c37
X_main uses rdman_redraw_all()
Thinker K.F. Li <thinker@branda.to>
parents:
14
diff
changeset
|
52 |
30
e06a4a667ce2
Accept mouse/pointer event and hint the shape that the pointer is over.
Thinker K.F. Li <thinker@branda.to>
parents:
24
diff
changeset
|
53 int max_gen_geos; |
e06a4a667ce2
Accept mouse/pointer event and hint the shape that the pointer is over.
Thinker K.F. Li <thinker@branda.to>
parents:
24
diff
changeset
|
54 int n_gen_geos; |
e06a4a667ce2
Accept mouse/pointer event and hint the shape that the pointer is over.
Thinker K.F. Li <thinker@branda.to>
parents:
24
diff
changeset
|
55 geo_t **gen_geos; /* general geo list */ |
e06a4a667ce2
Accept mouse/pointer event and hint the shape that the pointer is over.
Thinker K.F. Li <thinker@branda.to>
parents:
24
diff
changeset
|
56 |
15
c2ce186a5c37
X_main uses rdman_redraw_all()
Thinker K.F. Li <thinker@branda.to>
parents:
14
diff
changeset
|
57 cairo_t *cr; |
24
e598bc809c0f
No more flash when animation.
Thinker K.F. Li <thinker@branda.to>
parents:
22
diff
changeset
|
58 cairo_t *backend; |
73
9ab15ebc9061
Observer for mouse events
Thinker K.F. Li <thinker@branda.to>
parents:
37
diff
changeset
|
59 |
9ab15ebc9061
Observer for mouse events
Thinker K.F. Li <thinker@branda.to>
parents:
37
diff
changeset
|
60 ob_factory_t ob_factory; |
12 | 61 } redraw_man_t; |
62 | |
24
e598bc809c0f
No more flash when animation.
Thinker K.F. Li <thinker@branda.to>
parents:
22
diff
changeset
|
63 extern int redraw_man_init(redraw_man_t *rdman, cairo_t *cr, |
e598bc809c0f
No more flash when animation.
Thinker K.F. Li <thinker@branda.to>
parents:
22
diff
changeset
|
64 cairo_t *backend); |
12 | 65 extern void redraw_man_destroy(redraw_man_t *rdman); |
66 extern int rdman_find_overlaid_shapes(redraw_man_t *rdman, | |
67 geo_t *geo, | |
68 geo_t ***overlays); | |
69 extern int rdman_add_shape(redraw_man_t *rdman, | |
70 shape_t *shape, coord_t *coord); | |
71 extern int rdman_remove_shape(redraw_man_t *rdman, shape_t *shape); | |
72 extern coord_t *rdman_coord_new(redraw_man_t *rdman, coord_t *parent); | |
73 extern int rdman_coord_free(redraw_man_t *rdman, coord_t *coord); | |
15
c2ce186a5c37
X_main uses rdman_redraw_all()
Thinker K.F. Li <thinker@branda.to>
parents:
14
diff
changeset
|
74 extern int rdman_coord_changed(redraw_man_t *rdman, coord_t *coord); |
16
e17e12b112c4
A simple animation using rdman_redraw_changed().
Thinker K.F. Li <thinker@branda.to>
parents:
15
diff
changeset
|
75 extern int rdman_shape_changed(redraw_man_t *rdman, shape_t *shape); |
15
c2ce186a5c37
X_main uses rdman_redraw_all()
Thinker K.F. Li <thinker@branda.to>
parents:
14
diff
changeset
|
76 extern int rdman_redraw_changed(redraw_man_t *rdman); |
c2ce186a5c37
X_main uses rdman_redraw_all()
Thinker K.F. Li <thinker@branda.to>
parents:
14
diff
changeset
|
77 extern int rdman_redraw_all(redraw_man_t *rdman); |
37 | 78 extern int rdman_redraw_area(redraw_man_t *rdman, co_aix x, co_aix y, |
79 co_aix w, co_aix h); | |
30
e06a4a667ce2
Accept mouse/pointer event and hint the shape that the pointer is over.
Thinker K.F. Li <thinker@branda.to>
parents:
24
diff
changeset
|
80 extern int rdman_force_clean(redraw_man_t *rdman); |
18
0f3baa488a62
Support solid color paint for fill.
Thinker K.F. Li <thinker@branda.to>
parents:
16
diff
changeset
|
81 extern shnode_t *shnode_new(redraw_man_t *rdman, shape_t *shape); |
0f3baa488a62
Support solid color paint for fill.
Thinker K.F. Li <thinker@branda.to>
parents:
16
diff
changeset
|
82 #define shnode_free(rdman, node) elmpool_elm_free((rdman)->shnode_pool, node) |
0f3baa488a62
Support solid color paint for fill.
Thinker K.F. Li <thinker@branda.to>
parents:
16
diff
changeset
|
83 #define shnode_list_free(rdman, q) \ |
0f3baa488a62
Support solid color paint for fill.
Thinker K.F. Li <thinker@branda.to>
parents:
16
diff
changeset
|
84 do { \ |
0f3baa488a62
Support solid color paint for fill.
Thinker K.F. Li <thinker@branda.to>
parents:
16
diff
changeset
|
85 shnode_t *__node, *__last; \ |
0f3baa488a62
Support solid color paint for fill.
Thinker K.F. Li <thinker@branda.to>
parents:
16
diff
changeset
|
86 __last = STAILQ_HEAD(q); \ |
0f3baa488a62
Support solid color paint for fill.
Thinker K.F. Li <thinker@branda.to>
parents:
16
diff
changeset
|
87 if(__last == NULL) break; \ |
0f3baa488a62
Support solid color paint for fill.
Thinker K.F. Li <thinker@branda.to>
parents:
16
diff
changeset
|
88 for(__node = STAILQ_NEXT(shnode_t, next, __last); \ |
0f3baa488a62
Support solid color paint for fill.
Thinker K.F. Li <thinker@branda.to>
parents:
16
diff
changeset
|
89 __node != NULL; \ |
0f3baa488a62
Support solid color paint for fill.
Thinker K.F. Li <thinker@branda.to>
parents:
16
diff
changeset
|
90 __node = STAILQ_NEXT(shnode_t, next, __node)) { \ |
0f3baa488a62
Support solid color paint for fill.
Thinker K.F. Li <thinker@branda.to>
parents:
16
diff
changeset
|
91 shnode_free(rdman, __last); \ |
0f3baa488a62
Support solid color paint for fill.
Thinker K.F. Li <thinker@branda.to>
parents:
16
diff
changeset
|
92 __last = __node; \ |
0f3baa488a62
Support solid color paint for fill.
Thinker K.F. Li <thinker@branda.to>
parents:
16
diff
changeset
|
93 } \ |
0f3baa488a62
Support solid color paint for fill.
Thinker K.F. Li <thinker@branda.to>
parents:
16
diff
changeset
|
94 shnode_free(rdman, __last); \ |
0f3baa488a62
Support solid color paint for fill.
Thinker K.F. Li <thinker@branda.to>
parents:
16
diff
changeset
|
95 } while(0) |
22 | 96 #define _rdman_paint_child(rdman, paint, shape) \ |
18
0f3baa488a62
Support solid color paint for fill.
Thinker K.F. Li <thinker@branda.to>
parents:
16
diff
changeset
|
97 do { \ |
0f3baa488a62
Support solid color paint for fill.
Thinker K.F. Li <thinker@branda.to>
parents:
16
diff
changeset
|
98 shnode_t *__node; \ |
0f3baa488a62
Support solid color paint for fill.
Thinker K.F. Li <thinker@branda.to>
parents:
16
diff
changeset
|
99 if((shape)->fill != (paint) && \ |
0f3baa488a62
Support solid color paint for fill.
Thinker K.F. Li <thinker@branda.to>
parents:
16
diff
changeset
|
100 (shape)->stroke != (paint)) { \ |
0f3baa488a62
Support solid color paint for fill.
Thinker K.F. Li <thinker@branda.to>
parents:
16
diff
changeset
|
101 __node = shnode_new(rdman, shape); \ |
0f3baa488a62
Support solid color paint for fill.
Thinker K.F. Li <thinker@branda.to>
parents:
16
diff
changeset
|
102 STAILQ_INS_TAIL((paint)->members, \ |
0f3baa488a62
Support solid color paint for fill.
Thinker K.F. Li <thinker@branda.to>
parents:
16
diff
changeset
|
103 shnode_t, next, __node); \ |
0f3baa488a62
Support solid color paint for fill.
Thinker K.F. Li <thinker@branda.to>
parents:
16
diff
changeset
|
104 } \ |
22 | 105 } while(0) |
106 #define rdman_paint_fill(rdman, paint, shape) \ | |
107 do { \ | |
108 _rdman_paint_child(rdman, paint, shape); \ | |
18
0f3baa488a62
Support solid color paint for fill.
Thinker K.F. Li <thinker@branda.to>
parents:
16
diff
changeset
|
109 shape->fill = paint; \ |
0f3baa488a62
Support solid color paint for fill.
Thinker K.F. Li <thinker@branda.to>
parents:
16
diff
changeset
|
110 } while(0) |
22 | 111 #define rdman_paint_stroke(rdman, paint, shape) \ |
112 do { \ | |
113 _rdman_paint_child(rdman, paint, shape); \ | |
114 shape->stroke = paint; \ | |
115 } while(0) | |
18
0f3baa488a62
Support solid color paint for fill.
Thinker K.F. Li <thinker@branda.to>
parents:
16
diff
changeset
|
116 extern int rdman_paint_changed(redraw_man_t *rdman, paint_t *paint); |
12 | 117 |
30
e06a4a667ce2
Accept mouse/pointer event and hint the shape that the pointer is over.
Thinker K.F. Li <thinker@branda.to>
parents:
24
diff
changeset
|
118 extern shape_t *find_shape_at_pos(redraw_man_t *rdman, |
e06a4a667ce2
Accept mouse/pointer event and hint the shape that the pointer is over.
Thinker K.F. Li <thinker@branda.to>
parents:
24
diff
changeset
|
119 co_aix x, co_aix y, int *in_stroke); |
73
9ab15ebc9061
Observer for mouse events
Thinker K.F. Li <thinker@branda.to>
parents:
37
diff
changeset
|
120 #define rdman_get_ob_factory(rdman) (&(rdman)->ob_factory) |
30
e06a4a667ce2
Accept mouse/pointer event and hint the shape that the pointer is over.
Thinker K.F. Li <thinker@branda.to>
parents:
24
diff
changeset
|
121 |
12 | 122 |
123 #endif /* __REDRAW_MAN_H_ */ |