annotate src/redraw_man.h @ 30:e06a4a667ce2

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