Mercurial > MadButterfly
annotate src/redraw_man.c @ 257:50d253d0fcba
Simple image loader and image shape.
- img_ldr.c is a simple image loader that rooted on a directory
specified when a loader instance been created.
- sh_image_t is corresponding shape of image tag in SVG.
- This changeset is still buggy. It need more testing.
- svg2code.py is not ready for image tag.
author | Thinker K.F. Li <thinker@branda.to> |
---|---|
date | Thu, 15 Jan 2009 16:46:47 +0800 |
parents | f08b3ba9c1d8 |
children | 29acbd8a0dd0 |
rev | line source |
---|---|
12 | 1 #include <stdio.h> |
2 #include <stdlib.h> | |
3 #include <string.h> | |
15
c2ce186a5c37
X_main uses rdman_redraw_all()
Thinker K.F. Li <thinker@branda.to>
parents:
14
diff
changeset
|
4 #include <cairo.h> |
186
530bb7728546
Move header files to $(top_srcdir)/include/ and prefixed with 'mb_'.
Thinker K.F. Li <thinker@branda.to>
parents:
185
diff
changeset
|
5 #include "mb_types.h" |
530bb7728546
Move header files to $(top_srcdir)/include/ and prefixed with 'mb_'.
Thinker K.F. Li <thinker@branda.to>
parents:
185
diff
changeset
|
6 #include "mb_shapes.h" |
530bb7728546
Move header files to $(top_srcdir)/include/ and prefixed with 'mb_'.
Thinker K.F. Li <thinker@branda.to>
parents:
185
diff
changeset
|
7 #include "mb_tools.h" |
530bb7728546
Move header files to $(top_srcdir)/include/ and prefixed with 'mb_'.
Thinker K.F. Li <thinker@branda.to>
parents:
185
diff
changeset
|
8 #include "mb_redraw_man.h" |
530bb7728546
Move header files to $(top_srcdir)/include/ and prefixed with 'mb_'.
Thinker K.F. Li <thinker@branda.to>
parents:
185
diff
changeset
|
9 #include "mb_observer.h" |
224
29e1b2bffe4c
X backend only sent EVT_MOUSE_MOVE_RAW to MadButterfly.
Thinker K.F. Li <thinker@branda.to>
parents:
196
diff
changeset
|
10 #include "mb_prop.h" |
73
9ab15ebc9061
Observer for mouse events
Thinker K.F. Li <thinker@branda.to>
parents:
58
diff
changeset
|
11 |
224
29e1b2bffe4c
X backend only sent EVT_MOUSE_MOVE_RAW to MadButterfly.
Thinker K.F. Li <thinker@branda.to>
parents:
196
diff
changeset
|
12 #ifndef ASSERT |
29e1b2bffe4c
X backend only sent EVT_MOUSE_MOVE_RAW to MadButterfly.
Thinker K.F. Li <thinker@branda.to>
parents:
196
diff
changeset
|
13 #define ASSERT(x) |
29e1b2bffe4c
X backend only sent EVT_MOUSE_MOVE_RAW to MadButterfly.
Thinker K.F. Li <thinker@branda.to>
parents:
196
diff
changeset
|
14 #endif |
12 | 15 |
26
d50f33040de6
Set line width for path.
Thinker K.F. Li <thinker@branda.to>
parents:
25
diff
changeset
|
16 /* NOTE: bounding box should also consider width of stroke. |
d50f33040de6
Set line width for path.
Thinker K.F. Li <thinker@branda.to>
parents:
25
diff
changeset
|
17 */ |
d50f33040de6
Set line width for path.
Thinker K.F. Li <thinker@branda.to>
parents:
25
diff
changeset
|
18 |
158
c1cdd3fcd28f
Postponing rdman_coord_free() and rdman_remove_shape().
Thinker K.F. Li <thinker@branda.to>
parents:
154
diff
changeset
|
19 #define sh_attach_geo(sh, g) \ |
c1cdd3fcd28f
Postponing rdman_coord_free() and rdman_remove_shape().
Thinker K.F. Li <thinker@branda.to>
parents:
154
diff
changeset
|
20 do { \ |
c1cdd3fcd28f
Postponing rdman_coord_free() and rdman_remove_shape().
Thinker K.F. Li <thinker@branda.to>
parents:
154
diff
changeset
|
21 (sh)->geo = g; \ |
c1cdd3fcd28f
Postponing rdman_coord_free() and rdman_remove_shape().
Thinker K.F. Li <thinker@branda.to>
parents:
154
diff
changeset
|
22 (g)->shape = (shape_t *)(sh); \ |
c1cdd3fcd28f
Postponing rdman_coord_free() and rdman_remove_shape().
Thinker K.F. Li <thinker@branda.to>
parents:
154
diff
changeset
|
23 } while(0) |
c1cdd3fcd28f
Postponing rdman_coord_free() and rdman_remove_shape().
Thinker K.F. Li <thinker@branda.to>
parents:
154
diff
changeset
|
24 #define sh_detach_geo(sh) \ |
c1cdd3fcd28f
Postponing rdman_coord_free() and rdman_remove_shape().
Thinker K.F. Li <thinker@branda.to>
parents:
154
diff
changeset
|
25 do { \ |
c1cdd3fcd28f
Postponing rdman_coord_free() and rdman_remove_shape().
Thinker K.F. Li <thinker@branda.to>
parents:
154
diff
changeset
|
26 (sh)->geo->shape = NULL; \ |
c1cdd3fcd28f
Postponing rdman_coord_free() and rdman_remove_shape().
Thinker K.F. Li <thinker@branda.to>
parents:
154
diff
changeset
|
27 (sh)->geo = NULL; \ |
c1cdd3fcd28f
Postponing rdman_coord_free() and rdman_remove_shape().
Thinker K.F. Li <thinker@branda.to>
parents:
154
diff
changeset
|
28 } while(0) |
c1cdd3fcd28f
Postponing rdman_coord_free() and rdman_remove_shape().
Thinker K.F. Li <thinker@branda.to>
parents:
154
diff
changeset
|
29 #define sh_get_geo(sh) ((sh)->geo) |
c1cdd3fcd28f
Postponing rdman_coord_free() and rdman_remove_shape().
Thinker K.F. Li <thinker@branda.to>
parents:
154
diff
changeset
|
30 #define sh_attach_coord(sh, coord) do { (sh)->coord = coord; } while(0) |
c1cdd3fcd28f
Postponing rdman_coord_free() and rdman_remove_shape().
Thinker K.F. Li <thinker@branda.to>
parents:
154
diff
changeset
|
31 #define sh_detach_coord(sh) do { (sh)->coord = NULL; } while(0) |
c1cdd3fcd28f
Postponing rdman_coord_free() and rdman_remove_shape().
Thinker K.F. Li <thinker@branda.to>
parents:
154
diff
changeset
|
32 #define rdman_is_dirty(rdman) \ |
c1cdd3fcd28f
Postponing rdman_coord_free() and rdman_remove_shape().
Thinker K.F. Li <thinker@branda.to>
parents:
154
diff
changeset
|
33 ((rdman)->dirty_coords.num != 0 || \ |
c1cdd3fcd28f
Postponing rdman_coord_free() and rdman_remove_shape().
Thinker K.F. Li <thinker@branda.to>
parents:
154
diff
changeset
|
34 (rdman)->dirty_geos.num != 0 || \ |
c1cdd3fcd28f
Postponing rdman_coord_free() and rdman_remove_shape().
Thinker K.F. Li <thinker@branda.to>
parents:
154
diff
changeset
|
35 (rdman)->dirty_areas.num != 0) |
c1cdd3fcd28f
Postponing rdman_coord_free() and rdman_remove_shape().
Thinker K.F. Li <thinker@branda.to>
parents:
154
diff
changeset
|
36 |
12 | 37 #define OK 0 |
38 #define ERR -1 | |
39 | |
139
1695a4b02b14
Members of coords are geos instead of shapes, now.
Thinker K.F. Li <thinker@branda.to>
parents:
138
diff
changeset
|
40 #define ARRAY_EXT_SZ 64 |
1695a4b02b14
Members of coords are geos instead of shapes, now.
Thinker K.F. Li <thinker@branda.to>
parents:
138
diff
changeset
|
41 |
13 | 42 #define SWAP(a, b, t) do { t c; c = a; a = b; b = c; } while(0) |
43 | |
17
41f0907b27ac
Unittest for rdman_redraw_changed().
Thinker K.F. Li <thinker@branda.to>
parents:
16
diff
changeset
|
44 #ifdef UNITTEST |
41f0907b27ac
Unittest for rdman_redraw_changed().
Thinker K.F. Li <thinker@branda.to>
parents:
16
diff
changeset
|
45 typedef struct _sh_dummy sh_dummy_t; |
41f0907b27ac
Unittest for rdman_redraw_changed().
Thinker K.F. Li <thinker@branda.to>
parents:
16
diff
changeset
|
46 |
41f0907b27ac
Unittest for rdman_redraw_changed().
Thinker K.F. Li <thinker@branda.to>
parents:
16
diff
changeset
|
47 extern void sh_dummy_transform(shape_t *shape); |
20
74d3d5dc9aaa
rename XXX_draw() to XXX_fill()
Thinker K.F. Li <thinker@branda.to>
parents:
19
diff
changeset
|
48 extern void sh_dummy_fill(shape_t *, cairo_t *); |
17
41f0907b27ac
Unittest for rdman_redraw_changed().
Thinker K.F. Li <thinker@branda.to>
parents:
16
diff
changeset
|
49 #endif /* UNITTEST */ |
41f0907b27ac
Unittest for rdman_redraw_changed().
Thinker K.F. Li <thinker@branda.to>
parents:
16
diff
changeset
|
50 |
73
9ab15ebc9061
Observer for mouse events
Thinker K.F. Li <thinker@branda.to>
parents:
58
diff
changeset
|
51 static subject_t *ob_subject_alloc(ob_factory_t *factory); |
9ab15ebc9061
Observer for mouse events
Thinker K.F. Li <thinker@branda.to>
parents:
58
diff
changeset
|
52 static void ob_subject_free(ob_factory_t *factory, subject_t *subject); |
9ab15ebc9061
Observer for mouse events
Thinker K.F. Li <thinker@branda.to>
parents:
58
diff
changeset
|
53 static observer_t *ob_observer_alloc(ob_factory_t *factory); |
9ab15ebc9061
Observer for mouse events
Thinker K.F. Li <thinker@branda.to>
parents:
58
diff
changeset
|
54 static void ob_observer_free(ob_factory_t *factory, observer_t *observer); |
9ab15ebc9061
Observer for mouse events
Thinker K.F. Li <thinker@branda.to>
parents:
58
diff
changeset
|
55 static subject_t *ob_get_parent_subject(ob_factory_t *factory, |
9ab15ebc9061
Observer for mouse events
Thinker K.F. Li <thinker@branda.to>
parents:
58
diff
changeset
|
56 subject_t *cur_subject); |
140
0de8fd11271e
Use macro to simplify the code.
Thinker K.F. Li <thinker@branda.to>
parents:
139
diff
changeset
|
57 /* Functions for children. */ |
0de8fd11271e
Use macro to simplify the code.
Thinker K.F. Li <thinker@branda.to>
parents:
139
diff
changeset
|
58 #define FORCHILDREN(coord, child) \ |
0de8fd11271e
Use macro to simplify the code.
Thinker K.F. Li <thinker@branda.to>
parents:
139
diff
changeset
|
59 for((child) = STAILQ_HEAD((coord)->children); \ |
0de8fd11271e
Use macro to simplify the code.
Thinker K.F. Li <thinker@branda.to>
parents:
139
diff
changeset
|
60 (child) != NULL; \ |
0de8fd11271e
Use macro to simplify the code.
Thinker K.F. Li <thinker@branda.to>
parents:
139
diff
changeset
|
61 (child) = STAILQ_NEXT(coord_t, sibling, (child))) |
0de8fd11271e
Use macro to simplify the code.
Thinker K.F. Li <thinker@branda.to>
parents:
139
diff
changeset
|
62 #define NEXT_CHILD(child) STAILQ_NEXT(coord_t, sibling, child) |
0de8fd11271e
Use macro to simplify the code.
Thinker K.F. Li <thinker@branda.to>
parents:
139
diff
changeset
|
63 #define ADD_CHILD(parent, child) \ |
0de8fd11271e
Use macro to simplify the code.
Thinker K.F. Li <thinker@branda.to>
parents:
139
diff
changeset
|
64 STAILQ_INS_TAIL((parent)->children, coord_t, sibling, (child)) |
0de8fd11271e
Use macro to simplify the code.
Thinker K.F. Li <thinker@branda.to>
parents:
139
diff
changeset
|
65 #define RM_CHILD(parent, child) \ |
0de8fd11271e
Use macro to simplify the code.
Thinker K.F. Li <thinker@branda.to>
parents:
139
diff
changeset
|
66 STAILQ_REMOVE((parent)->children, coord_t, sibling, (child)) |
0de8fd11271e
Use macro to simplify the code.
Thinker K.F. Li <thinker@branda.to>
parents:
139
diff
changeset
|
67 #define FIRST_CHILD(parent) STAILQ_HEAD((parent)->children) |
73
9ab15ebc9061
Observer for mouse events
Thinker K.F. Li <thinker@branda.to>
parents:
58
diff
changeset
|
68 |
140
0de8fd11271e
Use macro to simplify the code.
Thinker K.F. Li <thinker@branda.to>
parents:
139
diff
changeset
|
69 /* Functions for members. */ |
0de8fd11271e
Use macro to simplify the code.
Thinker K.F. Li <thinker@branda.to>
parents:
139
diff
changeset
|
70 #define FORMEMBERS(coord, member) \ |
0de8fd11271e
Use macro to simplify the code.
Thinker K.F. Li <thinker@branda.to>
parents:
139
diff
changeset
|
71 for((member) = STAILQ_HEAD((coord)->members); \ |
0de8fd11271e
Use macro to simplify the code.
Thinker K.F. Li <thinker@branda.to>
parents:
139
diff
changeset
|
72 (member) != NULL; \ |
0de8fd11271e
Use macro to simplify the code.
Thinker K.F. Li <thinker@branda.to>
parents:
139
diff
changeset
|
73 (member) = STAILQ_NEXT(geo_t, coord_next, (member))) |
0de8fd11271e
Use macro to simplify the code.
Thinker K.F. Li <thinker@branda.to>
parents:
139
diff
changeset
|
74 #define NEXT_MEMBER(member) STAILQ_NEXT(geo_t, coord_next, (member)) |
0de8fd11271e
Use macro to simplify the code.
Thinker K.F. Li <thinker@branda.to>
parents:
139
diff
changeset
|
75 #define ADD_MEMBER(coord, member) \ |
0de8fd11271e
Use macro to simplify the code.
Thinker K.F. Li <thinker@branda.to>
parents:
139
diff
changeset
|
76 STAILQ_INS_TAIL((coord)->members, geo_t, coord_next, (member)) |
0de8fd11271e
Use macro to simplify the code.
Thinker K.F. Li <thinker@branda.to>
parents:
139
diff
changeset
|
77 #define RM_MEMBER(coord, member) \ |
0de8fd11271e
Use macro to simplify the code.
Thinker K.F. Li <thinker@branda.to>
parents:
139
diff
changeset
|
78 STAILQ_REMOVE((coord)->members, geo_t, coord_next, (member)) |
0de8fd11271e
Use macro to simplify the code.
Thinker K.F. Li <thinker@branda.to>
parents:
139
diff
changeset
|
79 #define FIRST_MEMBER(coord) STAILQ_HEAD((coord)->members) |
73
9ab15ebc9061
Observer for mouse events
Thinker K.F. Li <thinker@branda.to>
parents:
58
diff
changeset
|
80 |
159
b90abd31a281
Postponse free of coords, shapes, and paints when the rdman is dirty.
Thinker K.F. Li <thinker@branda.to>
parents:
158
diff
changeset
|
81 /* Functions for paint members. */ |
b90abd31a281
Postponse free of coords, shapes, and paints when the rdman is dirty.
Thinker K.F. Li <thinker@branda.to>
parents:
158
diff
changeset
|
82 #define FORPAINTMEMBERS(paint, member) \ |
b90abd31a281
Postponse free of coords, shapes, and paints when the rdman is dirty.
Thinker K.F. Li <thinker@branda.to>
parents:
158
diff
changeset
|
83 for((member) = STAILQ_HEAD((paint)->members); \ |
b90abd31a281
Postponse free of coords, shapes, and paints when the rdman is dirty.
Thinker K.F. Li <thinker@branda.to>
parents:
158
diff
changeset
|
84 (member) != NULL; \ |
b90abd31a281
Postponse free of coords, shapes, and paints when the rdman is dirty.
Thinker K.F. Li <thinker@branda.to>
parents:
158
diff
changeset
|
85 (member) = STAILQ_NEXT(paint_t, next, member)) |
b90abd31a281
Postponse free of coords, shapes, and paints when the rdman is dirty.
Thinker K.F. Li <thinker@branda.to>
parents:
158
diff
changeset
|
86 #define RM_PAINTMEMBER(paint, member) \ |
b90abd31a281
Postponse free of coords, shapes, and paints when the rdman is dirty.
Thinker K.F. Li <thinker@branda.to>
parents:
158
diff
changeset
|
87 STAILQ_REMOVE((paint)->members, shnode_t, next, member) |
b90abd31a281
Postponse free of coords, shapes, and paints when the rdman is dirty.
Thinker K.F. Li <thinker@branda.to>
parents:
158
diff
changeset
|
88 #define RM_PAINT(rdman, paint) \ |
b90abd31a281
Postponse free of coords, shapes, and paints when the rdman is dirty.
Thinker K.F. Li <thinker@branda.to>
parents:
158
diff
changeset
|
89 STAILQ_REMOVE((rdman)->paints, paint_t, pnt_next, paint) |
b90abd31a281
Postponse free of coords, shapes, and paints when the rdman is dirty.
Thinker K.F. Li <thinker@branda.to>
parents:
158
diff
changeset
|
90 |
16
e17e12b112c4
A simple animation using rdman_redraw_changed().
Thinker K.F. Li <thinker@branda.to>
parents:
15
diff
changeset
|
91 /*! \brief Sort a list of element by a unsigned integer. |
e17e12b112c4
A simple animation using rdman_redraw_changed().
Thinker K.F. Li <thinker@branda.to>
parents:
15
diff
changeset
|
92 * |
e17e12b112c4
A simple animation using rdman_redraw_changed().
Thinker K.F. Li <thinker@branda.to>
parents:
15
diff
changeset
|
93 * The result is in ascend order. The unsigned integers is |
e17e12b112c4
A simple animation using rdman_redraw_changed().
Thinker K.F. Li <thinker@branda.to>
parents:
15
diff
changeset
|
94 * at offset specified by 'off' from start address of elemnts. |
e17e12b112c4
A simple animation using rdman_redraw_changed().
Thinker K.F. Li <thinker@branda.to>
parents:
15
diff
changeset
|
95 */ |
e17e12b112c4
A simple animation using rdman_redraw_changed().
Thinker K.F. Li <thinker@branda.to>
parents:
15
diff
changeset
|
96 static void _insert_sort(void **elms, int num, int off) { |
e17e12b112c4
A simple animation using rdman_redraw_changed().
Thinker K.F. Li <thinker@branda.to>
parents:
15
diff
changeset
|
97 int i, j; |
e17e12b112c4
A simple animation using rdman_redraw_changed().
Thinker K.F. Li <thinker@branda.to>
parents:
15
diff
changeset
|
98 unsigned int val; |
121
76ba6fd61c7d
More bug of insert sort.
Thinker K.F. Li <thinker@branda.to>
parents:
119
diff
changeset
|
99 void *elm_i; |
16
e17e12b112c4
A simple animation using rdman_redraw_changed().
Thinker K.F. Li <thinker@branda.to>
parents:
15
diff
changeset
|
100 |
e17e12b112c4
A simple animation using rdman_redraw_changed().
Thinker K.F. Li <thinker@branda.to>
parents:
15
diff
changeset
|
101 for(i = 1; i < num; i++) { |
121
76ba6fd61c7d
More bug of insert sort.
Thinker K.F. Li <thinker@branda.to>
parents:
119
diff
changeset
|
102 elm_i = elms[i]; |
76ba6fd61c7d
More bug of insert sort.
Thinker K.F. Li <thinker@branda.to>
parents:
119
diff
changeset
|
103 val = *(unsigned int *)(elm_i + off); |
119 | 104 for(j = i; j > 0; j--) { |
16
e17e12b112c4
A simple animation using rdman_redraw_changed().
Thinker K.F. Li <thinker@branda.to>
parents:
15
diff
changeset
|
105 if(*(unsigned int *)(elms[j - 1] + off) <= val) |
e17e12b112c4
A simple animation using rdman_redraw_changed().
Thinker K.F. Li <thinker@branda.to>
parents:
15
diff
changeset
|
106 break; |
e17e12b112c4
A simple animation using rdman_redraw_changed().
Thinker K.F. Li <thinker@branda.to>
parents:
15
diff
changeset
|
107 elms[j] = elms[j - 1]; |
e17e12b112c4
A simple animation using rdman_redraw_changed().
Thinker K.F. Li <thinker@branda.to>
parents:
15
diff
changeset
|
108 } |
121
76ba6fd61c7d
More bug of insert sort.
Thinker K.F. Li <thinker@branda.to>
parents:
119
diff
changeset
|
109 elms[j] = elm_i; |
16
e17e12b112c4
A simple animation using rdman_redraw_changed().
Thinker K.F. Li <thinker@branda.to>
parents:
15
diff
changeset
|
110 } |
e17e12b112c4
A simple animation using rdman_redraw_changed().
Thinker K.F. Li <thinker@branda.to>
parents:
15
diff
changeset
|
111 } |
e17e12b112c4
A simple animation using rdman_redraw_changed().
Thinker K.F. Li <thinker@branda.to>
parents:
15
diff
changeset
|
112 |
158
c1cdd3fcd28f
Postponing rdman_coord_free() and rdman_remove_shape().
Thinker K.F. Li <thinker@branda.to>
parents:
154
diff
changeset
|
113 DARRAY_DEFINE(coords, coord_t *); |
c1cdd3fcd28f
Postponing rdman_coord_free() and rdman_remove_shape().
Thinker K.F. Li <thinker@branda.to>
parents:
154
diff
changeset
|
114 DARRAY_DEFINE(geos, geo_t *); |
c1cdd3fcd28f
Postponing rdman_coord_free() and rdman_remove_shape().
Thinker K.F. Li <thinker@branda.to>
parents:
154
diff
changeset
|
115 DARRAY_DEFINE(areas, area_t *); |
16
e17e12b112c4
A simple animation using rdman_redraw_changed().
Thinker K.F. Li <thinker@branda.to>
parents:
15
diff
changeset
|
116 |
235 | 117 int rdman_add_gen_geos(redraw_man_t *rdman, geo_t *geo) { |
118 int r; | |
119 | |
120 r = geos_add(rdman_get_gen_geos(rdman), geo); | |
121 return r; | |
122 } | |
123 | |
158
c1cdd3fcd28f
Postponing rdman_coord_free() and rdman_remove_shape().
Thinker K.F. Li <thinker@branda.to>
parents:
154
diff
changeset
|
124 /*! Use \brief DARRAY to implement dirty & free lists. |
c1cdd3fcd28f
Postponing rdman_coord_free() and rdman_remove_shape().
Thinker K.F. Li <thinker@branda.to>
parents:
154
diff
changeset
|
125 */ |
c1cdd3fcd28f
Postponing rdman_coord_free() and rdman_remove_shape().
Thinker K.F. Li <thinker@branda.to>
parents:
154
diff
changeset
|
126 #define ADD_DATA(sttype, field, v) \ |
c1cdd3fcd28f
Postponing rdman_coord_free() and rdman_remove_shape().
Thinker K.F. Li <thinker@branda.to>
parents:
154
diff
changeset
|
127 int r; \ |
c1cdd3fcd28f
Postponing rdman_coord_free() and rdman_remove_shape().
Thinker K.F. Li <thinker@branda.to>
parents:
154
diff
changeset
|
128 r = sttype ## _add(&rdman->field, v); \ |
c1cdd3fcd28f
Postponing rdman_coord_free() and rdman_remove_shape().
Thinker K.F. Li <thinker@branda.to>
parents:
154
diff
changeset
|
129 return r == 0? OK: ERR; |
16
e17e12b112c4
A simple animation using rdman_redraw_changed().
Thinker K.F. Li <thinker@branda.to>
parents:
15
diff
changeset
|
130 |
e17e12b112c4
A simple animation using rdman_redraw_changed().
Thinker K.F. Li <thinker@branda.to>
parents:
15
diff
changeset
|
131 |
152
2b316b5d65f9
Refactory code snippets for making coords dirty.
Thinker K.F. Li <thinker@branda.to>
parents:
151
diff
changeset
|
132 static int add_dirty_coord(redraw_man_t *rdman, coord_t *coord) { |
2b316b5d65f9
Refactory code snippets for making coords dirty.
Thinker K.F. Li <thinker@branda.to>
parents:
151
diff
changeset
|
133 coord->flags |= COF_DIRTY; |
158
c1cdd3fcd28f
Postponing rdman_coord_free() and rdman_remove_shape().
Thinker K.F. Li <thinker@branda.to>
parents:
154
diff
changeset
|
134 ADD_DATA(coords, dirty_coords, coord); |
152
2b316b5d65f9
Refactory code snippets for making coords dirty.
Thinker K.F. Li <thinker@branda.to>
parents:
151
diff
changeset
|
135 } |
2b316b5d65f9
Refactory code snippets for making coords dirty.
Thinker K.F. Li <thinker@branda.to>
parents:
151
diff
changeset
|
136 |
16
e17e12b112c4
A simple animation using rdman_redraw_changed().
Thinker K.F. Li <thinker@branda.to>
parents:
15
diff
changeset
|
137 static int add_dirty_geo(redraw_man_t *rdman, geo_t *geo) { |
158
c1cdd3fcd28f
Postponing rdman_coord_free() and rdman_remove_shape().
Thinker K.F. Li <thinker@branda.to>
parents:
154
diff
changeset
|
138 geo->flags |= GEF_DIRTY; |
c1cdd3fcd28f
Postponing rdman_coord_free() and rdman_remove_shape().
Thinker K.F. Li <thinker@branda.to>
parents:
154
diff
changeset
|
139 ADD_DATA(geos, dirty_geos, geo); |
16
e17e12b112c4
A simple animation using rdman_redraw_changed().
Thinker K.F. Li <thinker@branda.to>
parents:
15
diff
changeset
|
140 } |
e17e12b112c4
A simple animation using rdman_redraw_changed().
Thinker K.F. Li <thinker@branda.to>
parents:
15
diff
changeset
|
141 |
e17e12b112c4
A simple animation using rdman_redraw_changed().
Thinker K.F. Li <thinker@branda.to>
parents:
15
diff
changeset
|
142 static int add_dirty_area(redraw_man_t *rdman, area_t *area) { |
158
c1cdd3fcd28f
Postponing rdman_coord_free() and rdman_remove_shape().
Thinker K.F. Li <thinker@branda.to>
parents:
154
diff
changeset
|
143 ADD_DATA(areas, dirty_areas, area); |
c1cdd3fcd28f
Postponing rdman_coord_free() and rdman_remove_shape().
Thinker K.F. Li <thinker@branda.to>
parents:
154
diff
changeset
|
144 } |
16
e17e12b112c4
A simple animation using rdman_redraw_changed().
Thinker K.F. Li <thinker@branda.to>
parents:
15
diff
changeset
|
145 |
159
b90abd31a281
Postponse free of coords, shapes, and paints when the rdman is dirty.
Thinker K.F. Li <thinker@branda.to>
parents:
158
diff
changeset
|
146 static int add_free_obj(redraw_man_t *rdman, void *obj, |
b90abd31a281
Postponse free of coords, shapes, and paints when the rdman is dirty.
Thinker K.F. Li <thinker@branda.to>
parents:
158
diff
changeset
|
147 free_func_t free_func) { |
b90abd31a281
Postponse free of coords, shapes, and paints when the rdman is dirty.
Thinker K.F. Li <thinker@branda.to>
parents:
158
diff
changeset
|
148 int max; |
b90abd31a281
Postponse free of coords, shapes, and paints when the rdman is dirty.
Thinker K.F. Li <thinker@branda.to>
parents:
158
diff
changeset
|
149 free_obj_t *new_objs, *free_obj; |
b90abd31a281
Postponse free of coords, shapes, and paints when the rdman is dirty.
Thinker K.F. Li <thinker@branda.to>
parents:
158
diff
changeset
|
150 |
b90abd31a281
Postponse free of coords, shapes, and paints when the rdman is dirty.
Thinker K.F. Li <thinker@branda.to>
parents:
158
diff
changeset
|
151 if(rdman->free_objs.num >= rdman->free_objs.max) { |
b90abd31a281
Postponse free of coords, shapes, and paints when the rdman is dirty.
Thinker K.F. Li <thinker@branda.to>
parents:
158
diff
changeset
|
152 max = rdman->free_objs.num + ARRAY_EXT_SZ; |
b90abd31a281
Postponse free of coords, shapes, and paints when the rdman is dirty.
Thinker K.F. Li <thinker@branda.to>
parents:
158
diff
changeset
|
153 new_objs = realloc(rdman->free_objs.objs, |
b90abd31a281
Postponse free of coords, shapes, and paints when the rdman is dirty.
Thinker K.F. Li <thinker@branda.to>
parents:
158
diff
changeset
|
154 max * sizeof(free_obj_t)); |
b90abd31a281
Postponse free of coords, shapes, and paints when the rdman is dirty.
Thinker K.F. Li <thinker@branda.to>
parents:
158
diff
changeset
|
155 if(new_objs == NULL) |
b90abd31a281
Postponse free of coords, shapes, and paints when the rdman is dirty.
Thinker K.F. Li <thinker@branda.to>
parents:
158
diff
changeset
|
156 return ERR; |
b90abd31a281
Postponse free of coords, shapes, and paints when the rdman is dirty.
Thinker K.F. Li <thinker@branda.to>
parents:
158
diff
changeset
|
157 rdman->free_objs.max = max; |
b90abd31a281
Postponse free of coords, shapes, and paints when the rdman is dirty.
Thinker K.F. Li <thinker@branda.to>
parents:
158
diff
changeset
|
158 rdman->free_objs.objs = new_objs; |
b90abd31a281
Postponse free of coords, shapes, and paints when the rdman is dirty.
Thinker K.F. Li <thinker@branda.to>
parents:
158
diff
changeset
|
159 } |
b90abd31a281
Postponse free of coords, shapes, and paints when the rdman is dirty.
Thinker K.F. Li <thinker@branda.to>
parents:
158
diff
changeset
|
160 |
b90abd31a281
Postponse free of coords, shapes, and paints when the rdman is dirty.
Thinker K.F. Li <thinker@branda.to>
parents:
158
diff
changeset
|
161 free_obj = rdman->free_objs.objs + rdman->free_objs.num++; |
b90abd31a281
Postponse free of coords, shapes, and paints when the rdman is dirty.
Thinker K.F. Li <thinker@branda.to>
parents:
158
diff
changeset
|
162 free_obj->obj = obj; |
b90abd31a281
Postponse free of coords, shapes, and paints when the rdman is dirty.
Thinker K.F. Li <thinker@branda.to>
parents:
158
diff
changeset
|
163 free_obj->free_func = free_func; |
b90abd31a281
Postponse free of coords, shapes, and paints when the rdman is dirty.
Thinker K.F. Li <thinker@branda.to>
parents:
158
diff
changeset
|
164 |
b90abd31a281
Postponse free of coords, shapes, and paints when the rdman is dirty.
Thinker K.F. Li <thinker@branda.to>
parents:
158
diff
changeset
|
165 return OK; |
158
c1cdd3fcd28f
Postponing rdman_coord_free() and rdman_remove_shape().
Thinker K.F. Li <thinker@branda.to>
parents:
154
diff
changeset
|
166 } |
16
e17e12b112c4
A simple animation using rdman_redraw_changed().
Thinker K.F. Li <thinker@branda.to>
parents:
15
diff
changeset
|
167 |
159
b90abd31a281
Postponse free of coords, shapes, and paints when the rdman is dirty.
Thinker K.F. Li <thinker@branda.to>
parents:
158
diff
changeset
|
168 static void free_free_objs(redraw_man_t *rdman) { |
b90abd31a281
Postponse free of coords, shapes, and paints when the rdman is dirty.
Thinker K.F. Li <thinker@branda.to>
parents:
158
diff
changeset
|
169 int i; |
b90abd31a281
Postponse free of coords, shapes, and paints when the rdman is dirty.
Thinker K.F. Li <thinker@branda.to>
parents:
158
diff
changeset
|
170 free_obj_t *free_obj; |
b90abd31a281
Postponse free of coords, shapes, and paints when the rdman is dirty.
Thinker K.F. Li <thinker@branda.to>
parents:
158
diff
changeset
|
171 |
b90abd31a281
Postponse free of coords, shapes, and paints when the rdman is dirty.
Thinker K.F. Li <thinker@branda.to>
parents:
158
diff
changeset
|
172 for(i = 0; i < rdman->free_objs.num; i++) { |
b90abd31a281
Postponse free of coords, shapes, and paints when the rdman is dirty.
Thinker K.F. Li <thinker@branda.to>
parents:
158
diff
changeset
|
173 free_obj = &rdman->free_objs.objs[i]; |
b90abd31a281
Postponse free of coords, shapes, and paints when the rdman is dirty.
Thinker K.F. Li <thinker@branda.to>
parents:
158
diff
changeset
|
174 free_obj->free_func(rdman, free_obj->obj); |
b90abd31a281
Postponse free of coords, shapes, and paints when the rdman is dirty.
Thinker K.F. Li <thinker@branda.to>
parents:
158
diff
changeset
|
175 } |
b90abd31a281
Postponse free of coords, shapes, and paints when the rdman is dirty.
Thinker K.F. Li <thinker@branda.to>
parents:
158
diff
changeset
|
176 rdman->free_objs.num = 0; |
b90abd31a281
Postponse free of coords, shapes, and paints when the rdman is dirty.
Thinker K.F. Li <thinker@branda.to>
parents:
158
diff
changeset
|
177 } |
b90abd31a281
Postponse free of coords, shapes, and paints when the rdman is dirty.
Thinker K.F. Li <thinker@branda.to>
parents:
158
diff
changeset
|
178 |
b90abd31a281
Postponse free of coords, shapes, and paints when the rdman is dirty.
Thinker K.F. Li <thinker@branda.to>
parents:
158
diff
changeset
|
179 static void free_objs_destroy(redraw_man_t *rdman) { |
b90abd31a281
Postponse free of coords, shapes, and paints when the rdman is dirty.
Thinker K.F. Li <thinker@branda.to>
parents:
158
diff
changeset
|
180 if(rdman->free_objs.objs != NULL) |
b90abd31a281
Postponse free of coords, shapes, and paints when the rdman is dirty.
Thinker K.F. Li <thinker@branda.to>
parents:
158
diff
changeset
|
181 free(rdman->free_objs.objs); |
16
e17e12b112c4
A simple animation using rdman_redraw_changed().
Thinker K.F. Li <thinker@branda.to>
parents:
15
diff
changeset
|
182 } |
e17e12b112c4
A simple animation using rdman_redraw_changed().
Thinker K.F. Li <thinker@branda.to>
parents:
15
diff
changeset
|
183 |
17
41f0907b27ac
Unittest for rdman_redraw_changed().
Thinker K.F. Li <thinker@branda.to>
parents:
16
diff
changeset
|
184 static void area_to_positions(area_t *area, co_aix (*poses)[2]) { |
41f0907b27ac
Unittest for rdman_redraw_changed().
Thinker K.F. Li <thinker@branda.to>
parents:
16
diff
changeset
|
185 poses[0][0] = area->x; |
41f0907b27ac
Unittest for rdman_redraw_changed().
Thinker K.F. Li <thinker@branda.to>
parents:
16
diff
changeset
|
186 poses[0][1] = area->y; |
41f0907b27ac
Unittest for rdman_redraw_changed().
Thinker K.F. Li <thinker@branda.to>
parents:
16
diff
changeset
|
187 poses[1][0] = area->x + area->w; |
41f0907b27ac
Unittest for rdman_redraw_changed().
Thinker K.F. Li <thinker@branda.to>
parents:
16
diff
changeset
|
188 poses[1][1] = area->y + area->h;; |
41f0907b27ac
Unittest for rdman_redraw_changed().
Thinker K.F. Li <thinker@branda.to>
parents:
16
diff
changeset
|
189 } |
41f0907b27ac
Unittest for rdman_redraw_changed().
Thinker K.F. Li <thinker@branda.to>
parents:
16
diff
changeset
|
190 |
138
9f4fc9ecfd1f
Make shapes and coords drawed in post-order of tree.
Thinker K.F. Li <thinker@branda.to>
parents:
135
diff
changeset
|
191 static cairo_t *new_canvas(redraw_man_t *rdman) { |
9f4fc9ecfd1f
Make shapes and coords drawed in post-order of tree.
Thinker K.F. Li <thinker@branda.to>
parents:
135
diff
changeset
|
192 #ifndef UNITTEST |
9f4fc9ecfd1f
Make shapes and coords drawed in post-order of tree.
Thinker K.F. Li <thinker@branda.to>
parents:
135
diff
changeset
|
193 cairo_t *cr; |
9f4fc9ecfd1f
Make shapes and coords drawed in post-order of tree.
Thinker K.F. Li <thinker@branda.to>
parents:
135
diff
changeset
|
194 cairo_surface_t *surface, *cr_surface; |
9f4fc9ecfd1f
Make shapes and coords drawed in post-order of tree.
Thinker K.F. Li <thinker@branda.to>
parents:
135
diff
changeset
|
195 int w, h; |
9f4fc9ecfd1f
Make shapes and coords drawed in post-order of tree.
Thinker K.F. Li <thinker@branda.to>
parents:
135
diff
changeset
|
196 |
9f4fc9ecfd1f
Make shapes and coords drawed in post-order of tree.
Thinker K.F. Li <thinker@branda.to>
parents:
135
diff
changeset
|
197 cr_surface = cairo_get_target(rdman->cr); |
9f4fc9ecfd1f
Make shapes and coords drawed in post-order of tree.
Thinker K.F. Li <thinker@branda.to>
parents:
135
diff
changeset
|
198 w = cairo_image_surface_get_width(cr_surface); |
9f4fc9ecfd1f
Make shapes and coords drawed in post-order of tree.
Thinker K.F. Li <thinker@branda.to>
parents:
135
diff
changeset
|
199 h = cairo_image_surface_get_height(cr_surface); |
9f4fc9ecfd1f
Make shapes and coords drawed in post-order of tree.
Thinker K.F. Li <thinker@branda.to>
parents:
135
diff
changeset
|
200 surface = cairo_image_surface_create(CAIRO_FORMAT_ARGB32, |
9f4fc9ecfd1f
Make shapes and coords drawed in post-order of tree.
Thinker K.F. Li <thinker@branda.to>
parents:
135
diff
changeset
|
201 w, h); |
9f4fc9ecfd1f
Make shapes and coords drawed in post-order of tree.
Thinker K.F. Li <thinker@branda.to>
parents:
135
diff
changeset
|
202 cr = cairo_create(surface); |
9f4fc9ecfd1f
Make shapes and coords drawed in post-order of tree.
Thinker K.F. Li <thinker@branda.to>
parents:
135
diff
changeset
|
203 |
9f4fc9ecfd1f
Make shapes and coords drawed in post-order of tree.
Thinker K.F. Li <thinker@branda.to>
parents:
135
diff
changeset
|
204 return cr; |
9f4fc9ecfd1f
Make shapes and coords drawed in post-order of tree.
Thinker K.F. Li <thinker@branda.to>
parents:
135
diff
changeset
|
205 #else |
9f4fc9ecfd1f
Make shapes and coords drawed in post-order of tree.
Thinker K.F. Li <thinker@branda.to>
parents:
135
diff
changeset
|
206 return NULL; |
9f4fc9ecfd1f
Make shapes and coords drawed in post-order of tree.
Thinker K.F. Li <thinker@branda.to>
parents:
135
diff
changeset
|
207 #endif |
9f4fc9ecfd1f
Make shapes and coords drawed in post-order of tree.
Thinker K.F. Li <thinker@branda.to>
parents:
135
diff
changeset
|
208 } |
9f4fc9ecfd1f
Make shapes and coords drawed in post-order of tree.
Thinker K.F. Li <thinker@branda.to>
parents:
135
diff
changeset
|
209 |
9f4fc9ecfd1f
Make shapes and coords drawed in post-order of tree.
Thinker K.F. Li <thinker@branda.to>
parents:
135
diff
changeset
|
210 static void free_canvas(cairo_t *canvas) { |
9f4fc9ecfd1f
Make shapes and coords drawed in post-order of tree.
Thinker K.F. Li <thinker@branda.to>
parents:
135
diff
changeset
|
211 #ifndef UNITTEST |
9f4fc9ecfd1f
Make shapes and coords drawed in post-order of tree.
Thinker K.F. Li <thinker@branda.to>
parents:
135
diff
changeset
|
212 cairo_destroy(canvas); |
9f4fc9ecfd1f
Make shapes and coords drawed in post-order of tree.
Thinker K.F. Li <thinker@branda.to>
parents:
135
diff
changeset
|
213 #endif |
9f4fc9ecfd1f
Make shapes and coords drawed in post-order of tree.
Thinker K.F. Li <thinker@branda.to>
parents:
135
diff
changeset
|
214 } |
9f4fc9ecfd1f
Make shapes and coords drawed in post-order of tree.
Thinker K.F. Li <thinker@branda.to>
parents:
135
diff
changeset
|
215 |
140
0de8fd11271e
Use macro to simplify the code.
Thinker K.F. Li <thinker@branda.to>
parents:
139
diff
changeset
|
216 static int geo_off_in_coord(geo_t *geo, coord_t *coord) { |
0de8fd11271e
Use macro to simplify the code.
Thinker K.F. Li <thinker@branda.to>
parents:
139
diff
changeset
|
217 int off = 0; |
0de8fd11271e
Use macro to simplify the code.
Thinker K.F. Li <thinker@branda.to>
parents:
139
diff
changeset
|
218 geo_t *vgeo; |
0de8fd11271e
Use macro to simplify the code.
Thinker K.F. Li <thinker@branda.to>
parents:
139
diff
changeset
|
219 |
0de8fd11271e
Use macro to simplify the code.
Thinker K.F. Li <thinker@branda.to>
parents:
139
diff
changeset
|
220 FORMEMBERS(coord, vgeo) { |
0de8fd11271e
Use macro to simplify the code.
Thinker K.F. Li <thinker@branda.to>
parents:
139
diff
changeset
|
221 if(vgeo == geo) |
0de8fd11271e
Use macro to simplify the code.
Thinker K.F. Li <thinker@branda.to>
parents:
139
diff
changeset
|
222 return off; |
0de8fd11271e
Use macro to simplify the code.
Thinker K.F. Li <thinker@branda.to>
parents:
139
diff
changeset
|
223 off++; |
0de8fd11271e
Use macro to simplify the code.
Thinker K.F. Li <thinker@branda.to>
parents:
139
diff
changeset
|
224 } |
0de8fd11271e
Use macro to simplify the code.
Thinker K.F. Li <thinker@branda.to>
parents:
139
diff
changeset
|
225 return -1; |
0de8fd11271e
Use macro to simplify the code.
Thinker K.F. Li <thinker@branda.to>
parents:
139
diff
changeset
|
226 } |
0de8fd11271e
Use macro to simplify the code.
Thinker K.F. Li <thinker@branda.to>
parents:
139
diff
changeset
|
227 |
0de8fd11271e
Use macro to simplify the code.
Thinker K.F. Li <thinker@branda.to>
parents:
139
diff
changeset
|
228 static void geo_attach_coord(geo_t *geo, coord_t *coord) { |
0de8fd11271e
Use macro to simplify the code.
Thinker K.F. Li <thinker@branda.to>
parents:
139
diff
changeset
|
229 ADD_MEMBER(coord, geo); |
0de8fd11271e
Use macro to simplify the code.
Thinker K.F. Li <thinker@branda.to>
parents:
139
diff
changeset
|
230 coord->num_members++; |
0de8fd11271e
Use macro to simplify the code.
Thinker K.F. Li <thinker@branda.to>
parents:
139
diff
changeset
|
231 } |
0de8fd11271e
Use macro to simplify the code.
Thinker K.F. Li <thinker@branda.to>
parents:
139
diff
changeset
|
232 |
0de8fd11271e
Use macro to simplify the code.
Thinker K.F. Li <thinker@branda.to>
parents:
139
diff
changeset
|
233 static void geo_detach_coord(geo_t *geo, coord_t *coord) { |
0de8fd11271e
Use macro to simplify the code.
Thinker K.F. Li <thinker@branda.to>
parents:
139
diff
changeset
|
234 int off; |
0de8fd11271e
Use macro to simplify the code.
Thinker K.F. Li <thinker@branda.to>
parents:
139
diff
changeset
|
235 coord_t *child; |
0de8fd11271e
Use macro to simplify the code.
Thinker K.F. Li <thinker@branda.to>
parents:
139
diff
changeset
|
236 |
0de8fd11271e
Use macro to simplify the code.
Thinker K.F. Li <thinker@branda.to>
parents:
139
diff
changeset
|
237 off = geo_off_in_coord(geo, coord); |
0de8fd11271e
Use macro to simplify the code.
Thinker K.F. Li <thinker@branda.to>
parents:
139
diff
changeset
|
238 if(off < 0) |
0de8fd11271e
Use macro to simplify the code.
Thinker K.F. Li <thinker@branda.to>
parents:
139
diff
changeset
|
239 return; |
0de8fd11271e
Use macro to simplify the code.
Thinker K.F. Li <thinker@branda.to>
parents:
139
diff
changeset
|
240 FORCHILDREN(coord, child) { |
0de8fd11271e
Use macro to simplify the code.
Thinker K.F. Li <thinker@branda.to>
parents:
139
diff
changeset
|
241 if(child->before_pmem >= off) |
0de8fd11271e
Use macro to simplify the code.
Thinker K.F. Li <thinker@branda.to>
parents:
139
diff
changeset
|
242 child->before_pmem--; |
0de8fd11271e
Use macro to simplify the code.
Thinker K.F. Li <thinker@branda.to>
parents:
139
diff
changeset
|
243 } |
0de8fd11271e
Use macro to simplify the code.
Thinker K.F. Li <thinker@branda.to>
parents:
139
diff
changeset
|
244 |
0de8fd11271e
Use macro to simplify the code.
Thinker K.F. Li <thinker@branda.to>
parents:
139
diff
changeset
|
245 RM_MEMBER(coord, geo); |
0de8fd11271e
Use macro to simplify the code.
Thinker K.F. Li <thinker@branda.to>
parents:
139
diff
changeset
|
246 coord->num_members--; |
0de8fd11271e
Use macro to simplify the code.
Thinker K.F. Li <thinker@branda.to>
parents:
139
diff
changeset
|
247 } |
0de8fd11271e
Use macro to simplify the code.
Thinker K.F. Li <thinker@branda.to>
parents:
139
diff
changeset
|
248 |
224
29e1b2bffe4c
X backend only sent EVT_MOUSE_MOVE_RAW to MadButterfly.
Thinker K.F. Li <thinker@branda.to>
parents:
196
diff
changeset
|
249 static void mouse_event_root_dummy(event_t *evt, void *arg) { |
29e1b2bffe4c
X backend only sent EVT_MOUSE_MOVE_RAW to MadButterfly.
Thinker K.F. Li <thinker@branda.to>
parents:
196
diff
changeset
|
250 } |
29e1b2bffe4c
X backend only sent EVT_MOUSE_MOVE_RAW to MadButterfly.
Thinker K.F. Li <thinker@branda.to>
parents:
196
diff
changeset
|
251 |
24
e598bc809c0f
No more flash when animation.
Thinker K.F. Li <thinker@branda.to>
parents:
23
diff
changeset
|
252 int redraw_man_init(redraw_man_t *rdman, cairo_t *cr, cairo_t *backend) { |
12 | 253 extern void redraw_man_destroy(redraw_man_t *rdman); |
147
995ee8fd5f1a
Use local static variable to hold position array to reduce using malloc().
Thinker K.F. Li <thinker@branda.to>
parents:
146
diff
changeset
|
254 extern int _paint_color_size; |
224
29e1b2bffe4c
X backend only sent EVT_MOUSE_MOVE_RAW to MadButterfly.
Thinker K.F. Li <thinker@branda.to>
parents:
196
diff
changeset
|
255 observer_t *addrm_ob; |
231
2637519e2bd7
Move mouse event handler and interpreter to src/mouse.c.
Thinker K.F. Li <thinker@branda.to>
parents:
224
diff
changeset
|
256 extern void addrm_monitor_hdlr(event_t *evt, void *arg); |
12 | 257 |
258 memset(rdman, 0, sizeof(redraw_man_t)); | |
259 | |
260 rdman->geo_pool = elmpool_new(sizeof(geo_t), 128); | |
261 rdman->coord_pool = elmpool_new(sizeof(coord_t), 16); | |
18
0f3baa488a62
Support solid color paint for fill.
Thinker K.F. Li <thinker@branda.to>
parents:
17
diff
changeset
|
262 rdman->shnode_pool = elmpool_new(sizeof(shnode_t), 16); |
75
23bc382d9683
find_geo_in_pos() should return shapes that is not hidden
Thinker K.F. Li <thinker@branda.to>
parents:
73
diff
changeset
|
263 rdman->observer_pool = elmpool_new(sizeof(observer_t), 32); |
23bc382d9683
find_geo_in_pos() should return shapes that is not hidden
Thinker K.F. Li <thinker@branda.to>
parents:
73
diff
changeset
|
264 rdman->subject_pool = elmpool_new(sizeof(subject_t), 32); |
147
995ee8fd5f1a
Use local static variable to hold position array to reduce using malloc().
Thinker K.F. Li <thinker@branda.to>
parents:
146
diff
changeset
|
265 rdman->paint_color_pool = elmpool_new(_paint_color_size, 64); |
224
29e1b2bffe4c
X backend only sent EVT_MOUSE_MOVE_RAW to MadButterfly.
Thinker K.F. Li <thinker@branda.to>
parents:
196
diff
changeset
|
266 rdman->pent_pool = elmpool_new(sizeof(mb_prop_entry_t), 128); |
29e1b2bffe4c
X backend only sent EVT_MOUSE_MOVE_RAW to MadButterfly.
Thinker K.F. Li <thinker@branda.to>
parents:
196
diff
changeset
|
267 if(!(rdman->geo_pool && rdman->coord_pool && rdman->shnode_pool && |
29e1b2bffe4c
X backend only sent EVT_MOUSE_MOVE_RAW to MadButterfly.
Thinker K.F. Li <thinker@branda.to>
parents:
196
diff
changeset
|
268 rdman->observer_pool && rdman->subject_pool && |
29e1b2bffe4c
X backend only sent EVT_MOUSE_MOVE_RAW to MadButterfly.
Thinker K.F. Li <thinker@branda.to>
parents:
196
diff
changeset
|
269 rdman->paint_color_pool)) |
29e1b2bffe4c
X backend only sent EVT_MOUSE_MOVE_RAW to MadButterfly.
Thinker K.F. Li <thinker@branda.to>
parents:
196
diff
changeset
|
270 goto err; |
146
e96a584487af
Use elmpool to manage paint_color_t objects.
Thinker K.F. Li <thinker@branda.to>
parents:
141
diff
changeset
|
271 |
73
9ab15ebc9061
Observer for mouse events
Thinker K.F. Li <thinker@branda.to>
parents:
58
diff
changeset
|
272 rdman->ob_factory.subject_alloc = ob_subject_alloc; |
9ab15ebc9061
Observer for mouse events
Thinker K.F. Li <thinker@branda.to>
parents:
58
diff
changeset
|
273 rdman->ob_factory.subject_free = ob_subject_free; |
9ab15ebc9061
Observer for mouse events
Thinker K.F. Li <thinker@branda.to>
parents:
58
diff
changeset
|
274 rdman->ob_factory.observer_alloc = ob_observer_alloc; |
9ab15ebc9061
Observer for mouse events
Thinker K.F. Li <thinker@branda.to>
parents:
58
diff
changeset
|
275 rdman->ob_factory.observer_free = ob_observer_free; |
9ab15ebc9061
Observer for mouse events
Thinker K.F. Li <thinker@branda.to>
parents:
58
diff
changeset
|
276 rdman->ob_factory.get_parent_subject = ob_get_parent_subject; |
9ab15ebc9061
Observer for mouse events
Thinker K.F. Li <thinker@branda.to>
parents:
58
diff
changeset
|
277 |
154 | 278 rdman->redraw = |
279 subject_new(&rdman->ob_factory, rdman, OBJT_RDMAN); | |
224
29e1b2bffe4c
X backend only sent EVT_MOUSE_MOVE_RAW to MadButterfly.
Thinker K.F. Li <thinker@branda.to>
parents:
196
diff
changeset
|
280 rdman->addrm_monitor = |
29e1b2bffe4c
X backend only sent EVT_MOUSE_MOVE_RAW to MadButterfly.
Thinker K.F. Li <thinker@branda.to>
parents:
196
diff
changeset
|
281 subject_new(&rdman->ob_factory, rdman, OBJT_RDMAN); |
29e1b2bffe4c
X backend only sent EVT_MOUSE_MOVE_RAW to MadButterfly.
Thinker K.F. Li <thinker@branda.to>
parents:
196
diff
changeset
|
282 if(!(rdman->redraw && rdman->addrm_monitor)) |
29e1b2bffe4c
X backend only sent EVT_MOUSE_MOVE_RAW to MadButterfly.
Thinker K.F. Li <thinker@branda.to>
parents:
196
diff
changeset
|
283 goto err; |
29e1b2bffe4c
X backend only sent EVT_MOUSE_MOVE_RAW to MadButterfly.
Thinker K.F. Li <thinker@branda.to>
parents:
196
diff
changeset
|
284 |
29e1b2bffe4c
X backend only sent EVT_MOUSE_MOVE_RAW to MadButterfly.
Thinker K.F. Li <thinker@branda.to>
parents:
196
diff
changeset
|
285 addrm_ob = subject_add_observer(rdman->addrm_monitor, |
29e1b2bffe4c
X backend only sent EVT_MOUSE_MOVE_RAW to MadButterfly.
Thinker K.F. Li <thinker@branda.to>
parents:
196
diff
changeset
|
286 addrm_monitor_hdlr, NULL); |
29e1b2bffe4c
X backend only sent EVT_MOUSE_MOVE_RAW to MadButterfly.
Thinker K.F. Li <thinker@branda.to>
parents:
196
diff
changeset
|
287 if(addrm_ob == NULL) |
29e1b2bffe4c
X backend only sent EVT_MOUSE_MOVE_RAW to MadButterfly.
Thinker K.F. Li <thinker@branda.to>
parents:
196
diff
changeset
|
288 goto err; |
29e1b2bffe4c
X backend only sent EVT_MOUSE_MOVE_RAW to MadButterfly.
Thinker K.F. Li <thinker@branda.to>
parents:
196
diff
changeset
|
289 |
29e1b2bffe4c
X backend only sent EVT_MOUSE_MOVE_RAW to MadButterfly.
Thinker K.F. Li <thinker@branda.to>
parents:
196
diff
changeset
|
290 rdman->last_mouse_over = NULL; |
154 | 291 |
12 | 292 rdman->root_coord = elmpool_elm_alloc(rdman->coord_pool); |
293 if(rdman->root_coord == NULL) | |
294 redraw_man_destroy(rdman); | |
13 | 295 rdman->n_coords = 1; |
12 | 296 coord_init(rdman->root_coord, NULL); |
224
29e1b2bffe4c
X backend only sent EVT_MOUSE_MOVE_RAW to MadButterfly.
Thinker K.F. Li <thinker@branda.to>
parents:
196
diff
changeset
|
297 mb_prop_store_init(&rdman->root_coord->obj.props, rdman->pent_pool); |
73
9ab15ebc9061
Observer for mouse events
Thinker K.F. Li <thinker@branda.to>
parents:
58
diff
changeset
|
298 rdman->root_coord->mouse_event = subject_new(&rdman->ob_factory, |
9ab15ebc9061
Observer for mouse events
Thinker K.F. Li <thinker@branda.to>
parents:
58
diff
changeset
|
299 rdman->root_coord, |
9ab15ebc9061
Observer for mouse events
Thinker K.F. Li <thinker@branda.to>
parents:
58
diff
changeset
|
300 OBJT_COORD); |
138
9f4fc9ecfd1f
Make shapes and coords drawed in post-order of tree.
Thinker K.F. Li <thinker@branda.to>
parents:
135
diff
changeset
|
301 rdman->root_coord->flags |= COF_OWN_CANVAS; |
9f4fc9ecfd1f
Make shapes and coords drawed in post-order of tree.
Thinker K.F. Li <thinker@branda.to>
parents:
135
diff
changeset
|
302 rdman->root_coord->canvas = cr; |
9f4fc9ecfd1f
Make shapes and coords drawed in post-order of tree.
Thinker K.F. Li <thinker@branda.to>
parents:
135
diff
changeset
|
303 rdman->root_coord->opacity = 1; |
12 | 304 |
15
c2ce186a5c37
X_main uses rdman_redraw_all()
Thinker K.F. Li <thinker@branda.to>
parents:
14
diff
changeset
|
305 rdman->cr = cr; |
24
e598bc809c0f
No more flash when animation.
Thinker K.F. Li <thinker@branda.to>
parents:
23
diff
changeset
|
306 rdman->backend = backend; |
15
c2ce186a5c37
X_main uses rdman_redraw_all()
Thinker K.F. Li <thinker@branda.to>
parents:
14
diff
changeset
|
307 |
159
b90abd31a281
Postponse free of coords, shapes, and paints when the rdman is dirty.
Thinker K.F. Li <thinker@branda.to>
parents:
158
diff
changeset
|
308 STAILQ_INIT(rdman->shapes); |
b90abd31a281
Postponse free of coords, shapes, and paints when the rdman is dirty.
Thinker K.F. Li <thinker@branda.to>
parents:
158
diff
changeset
|
309 STAILQ_INIT(rdman->paints); |
224
29e1b2bffe4c
X backend only sent EVT_MOUSE_MOVE_RAW to MadButterfly.
Thinker K.F. Li <thinker@branda.to>
parents:
196
diff
changeset
|
310 |
29e1b2bffe4c
X backend only sent EVT_MOUSE_MOVE_RAW to MadButterfly.
Thinker K.F. Li <thinker@branda.to>
parents:
196
diff
changeset
|
311 /* \note To make root coord always have at leat one observer. |
29e1b2bffe4c
X backend only sent EVT_MOUSE_MOVE_RAW to MadButterfly.
Thinker K.F. Li <thinker@branda.to>
parents:
196
diff
changeset
|
312 * It triggers mouse interpreter to be installed on root. |
29e1b2bffe4c
X backend only sent EVT_MOUSE_MOVE_RAW to MadButterfly.
Thinker K.F. Li <thinker@branda.to>
parents:
196
diff
changeset
|
313 */ |
29e1b2bffe4c
X backend only sent EVT_MOUSE_MOVE_RAW to MadButterfly.
Thinker K.F. Li <thinker@branda.to>
parents:
196
diff
changeset
|
314 subject_set_monitor(rdman->root_coord->mouse_event, |
29e1b2bffe4c
X backend only sent EVT_MOUSE_MOVE_RAW to MadButterfly.
Thinker K.F. Li <thinker@branda.to>
parents:
196
diff
changeset
|
315 rdman->addrm_monitor); |
29e1b2bffe4c
X backend only sent EVT_MOUSE_MOVE_RAW to MadButterfly.
Thinker K.F. Li <thinker@branda.to>
parents:
196
diff
changeset
|
316 subject_add_observer(rdman->root_coord->mouse_event, |
29e1b2bffe4c
X backend only sent EVT_MOUSE_MOVE_RAW to MadButterfly.
Thinker K.F. Li <thinker@branda.to>
parents:
196
diff
changeset
|
317 mouse_event_root_dummy, NULL); |
159
b90abd31a281
Postponse free of coords, shapes, and paints when the rdman is dirty.
Thinker K.F. Li <thinker@branda.to>
parents:
158
diff
changeset
|
318 |
257
50d253d0fcba
Simple image loader and image shape.
Thinker K.F. Li <thinker@branda.to>
parents:
251
diff
changeset
|
319 mb_prop_store_init(&rdman->props, rdman->pent_pool); |
12 | 320 return OK; |
224
29e1b2bffe4c
X backend only sent EVT_MOUSE_MOVE_RAW to MadButterfly.
Thinker K.F. Li <thinker@branda.to>
parents:
196
diff
changeset
|
321 |
29e1b2bffe4c
X backend only sent EVT_MOUSE_MOVE_RAW to MadButterfly.
Thinker K.F. Li <thinker@branda.to>
parents:
196
diff
changeset
|
322 err: |
29e1b2bffe4c
X backend only sent EVT_MOUSE_MOVE_RAW to MadButterfly.
Thinker K.F. Li <thinker@branda.to>
parents:
196
diff
changeset
|
323 if(rdman->geo_pool) |
29e1b2bffe4c
X backend only sent EVT_MOUSE_MOVE_RAW to MadButterfly.
Thinker K.F. Li <thinker@branda.to>
parents:
196
diff
changeset
|
324 elmpool_free(rdman->geo_pool); |
29e1b2bffe4c
X backend only sent EVT_MOUSE_MOVE_RAW to MadButterfly.
Thinker K.F. Li <thinker@branda.to>
parents:
196
diff
changeset
|
325 if(rdman->coord_pool) |
29e1b2bffe4c
X backend only sent EVT_MOUSE_MOVE_RAW to MadButterfly.
Thinker K.F. Li <thinker@branda.to>
parents:
196
diff
changeset
|
326 elmpool_free(rdman->coord_pool); |
29e1b2bffe4c
X backend only sent EVT_MOUSE_MOVE_RAW to MadButterfly.
Thinker K.F. Li <thinker@branda.to>
parents:
196
diff
changeset
|
327 if(rdman->shnode_pool) |
29e1b2bffe4c
X backend only sent EVT_MOUSE_MOVE_RAW to MadButterfly.
Thinker K.F. Li <thinker@branda.to>
parents:
196
diff
changeset
|
328 elmpool_free(rdman->shnode_pool); |
29e1b2bffe4c
X backend only sent EVT_MOUSE_MOVE_RAW to MadButterfly.
Thinker K.F. Li <thinker@branda.to>
parents:
196
diff
changeset
|
329 if(rdman->observer_pool) |
29e1b2bffe4c
X backend only sent EVT_MOUSE_MOVE_RAW to MadButterfly.
Thinker K.F. Li <thinker@branda.to>
parents:
196
diff
changeset
|
330 elmpool_free(rdman->observer_pool); |
29e1b2bffe4c
X backend only sent EVT_MOUSE_MOVE_RAW to MadButterfly.
Thinker K.F. Li <thinker@branda.to>
parents:
196
diff
changeset
|
331 if(rdman->subject_pool) |
29e1b2bffe4c
X backend only sent EVT_MOUSE_MOVE_RAW to MadButterfly.
Thinker K.F. Li <thinker@branda.to>
parents:
196
diff
changeset
|
332 elmpool_free(rdman->subject_pool); |
29e1b2bffe4c
X backend only sent EVT_MOUSE_MOVE_RAW to MadButterfly.
Thinker K.F. Li <thinker@branda.to>
parents:
196
diff
changeset
|
333 if(rdman->paint_color_pool) |
29e1b2bffe4c
X backend only sent EVT_MOUSE_MOVE_RAW to MadButterfly.
Thinker K.F. Li <thinker@branda.to>
parents:
196
diff
changeset
|
334 elmpool_free(rdman->paint_color_pool); |
29e1b2bffe4c
X backend only sent EVT_MOUSE_MOVE_RAW to MadButterfly.
Thinker K.F. Li <thinker@branda.to>
parents:
196
diff
changeset
|
335 if(rdman->pent_pool) |
29e1b2bffe4c
X backend only sent EVT_MOUSE_MOVE_RAW to MadButterfly.
Thinker K.F. Li <thinker@branda.to>
parents:
196
diff
changeset
|
336 elmpool_free(rdman->pent_pool); |
29e1b2bffe4c
X backend only sent EVT_MOUSE_MOVE_RAW to MadButterfly.
Thinker K.F. Li <thinker@branda.to>
parents:
196
diff
changeset
|
337 return ERR; |
12 | 338 } |
339 | |
340 void redraw_man_destroy(redraw_man_t *rdman) { | |
138
9f4fc9ecfd1f
Make shapes and coords drawed in post-order of tree.
Thinker K.F. Li <thinker@branda.to>
parents:
135
diff
changeset
|
341 coord_t *coord, *saved_coord; |
159
b90abd31a281
Postponse free of coords, shapes, and paints when the rdman is dirty.
Thinker K.F. Li <thinker@branda.to>
parents:
158
diff
changeset
|
342 shape_t *shape, *saved_shape; |
158
c1cdd3fcd28f
Postponing rdman_coord_free() and rdman_remove_shape().
Thinker K.F. Li <thinker@branda.to>
parents:
154
diff
changeset
|
343 geo_t *member; |
138
9f4fc9ecfd1f
Make shapes and coords drawed in post-order of tree.
Thinker K.F. Li <thinker@branda.to>
parents:
135
diff
changeset
|
344 |
257
50d253d0fcba
Simple image loader and image shape.
Thinker K.F. Li <thinker@branda.to>
parents:
251
diff
changeset
|
345 mb_prop_store_destroy(&rdman->props); |
50d253d0fcba
Simple image loader and image shape.
Thinker K.F. Li <thinker@branda.to>
parents:
251
diff
changeset
|
346 |
159
b90abd31a281
Postponse free of coords, shapes, and paints when the rdman is dirty.
Thinker K.F. Li <thinker@branda.to>
parents:
158
diff
changeset
|
347 free_free_objs(rdman); |
b90abd31a281
Postponse free of coords, shapes, and paints when the rdman is dirty.
Thinker K.F. Li <thinker@branda.to>
parents:
158
diff
changeset
|
348 free_objs_destroy(rdman); |
b90abd31a281
Postponse free of coords, shapes, and paints when the rdman is dirty.
Thinker K.F. Li <thinker@branda.to>
parents:
158
diff
changeset
|
349 |
138
9f4fc9ecfd1f
Make shapes and coords drawed in post-order of tree.
Thinker K.F. Li <thinker@branda.to>
parents:
135
diff
changeset
|
350 coord = postorder_coord_subtree(rdman->root_coord, NULL); |
9f4fc9ecfd1f
Make shapes and coords drawed in post-order of tree.
Thinker K.F. Li <thinker@branda.to>
parents:
135
diff
changeset
|
351 while(coord) { |
9f4fc9ecfd1f
Make shapes and coords drawed in post-order of tree.
Thinker K.F. Li <thinker@branda.to>
parents:
135
diff
changeset
|
352 saved_coord = coord; |
9f4fc9ecfd1f
Make shapes and coords drawed in post-order of tree.
Thinker K.F. Li <thinker@branda.to>
parents:
135
diff
changeset
|
353 coord = postorder_coord_subtree(rdman->root_coord, coord); |
158
c1cdd3fcd28f
Postponing rdman_coord_free() and rdman_remove_shape().
Thinker K.F. Li <thinker@branda.to>
parents:
154
diff
changeset
|
354 FORMEMBERS(saved_coord, member) { |
159
b90abd31a281
Postponse free of coords, shapes, and paints when the rdman is dirty.
Thinker K.F. Li <thinker@branda.to>
parents:
158
diff
changeset
|
355 rdman_shape_free(rdman, member->shape); |
158
c1cdd3fcd28f
Postponing rdman_coord_free() and rdman_remove_shape().
Thinker K.F. Li <thinker@branda.to>
parents:
154
diff
changeset
|
356 } |
138
9f4fc9ecfd1f
Make shapes and coords drawed in post-order of tree.
Thinker K.F. Li <thinker@branda.to>
parents:
135
diff
changeset
|
357 rdman_coord_free(rdman, saved_coord); |
9f4fc9ecfd1f
Make shapes and coords drawed in post-order of tree.
Thinker K.F. Li <thinker@branda.to>
parents:
135
diff
changeset
|
358 } |
224
29e1b2bffe4c
X backend only sent EVT_MOUSE_MOVE_RAW to MadButterfly.
Thinker K.F. Li <thinker@branda.to>
parents:
196
diff
changeset
|
359 #if 0 |
158
c1cdd3fcd28f
Postponing rdman_coord_free() and rdman_remove_shape().
Thinker K.F. Li <thinker@branda.to>
parents:
154
diff
changeset
|
360 FORMEMBERS(saved_coord, member) { |
159
b90abd31a281
Postponse free of coords, shapes, and paints when the rdman is dirty.
Thinker K.F. Li <thinker@branda.to>
parents:
158
diff
changeset
|
361 rdman_shape_free(rdman, member->shape); |
158
c1cdd3fcd28f
Postponing rdman_coord_free() and rdman_remove_shape().
Thinker K.F. Li <thinker@branda.to>
parents:
154
diff
changeset
|
362 } |
224
29e1b2bffe4c
X backend only sent EVT_MOUSE_MOVE_RAW to MadButterfly.
Thinker K.F. Li <thinker@branda.to>
parents:
196
diff
changeset
|
363 #endif |
158
c1cdd3fcd28f
Postponing rdman_coord_free() and rdman_remove_shape().
Thinker K.F. Li <thinker@branda.to>
parents:
154
diff
changeset
|
364 /* Resources of root_coord is free by elmpool_free() or |
c1cdd3fcd28f
Postponing rdman_coord_free() and rdman_remove_shape().
Thinker K.F. Li <thinker@branda.to>
parents:
154
diff
changeset
|
365 * caller; for canvas |
c1cdd3fcd28f
Postponing rdman_coord_free() and rdman_remove_shape().
Thinker K.F. Li <thinker@branda.to>
parents:
154
diff
changeset
|
366 */ |
138
9f4fc9ecfd1f
Make shapes and coords drawed in post-order of tree.
Thinker K.F. Li <thinker@branda.to>
parents:
135
diff
changeset
|
367 |
159
b90abd31a281
Postponse free of coords, shapes, and paints when the rdman is dirty.
Thinker K.F. Li <thinker@branda.to>
parents:
158
diff
changeset
|
368 shape = saved_shape = STAILQ_HEAD(rdman->shapes); |
b90abd31a281
Postponse free of coords, shapes, and paints when the rdman is dirty.
Thinker K.F. Li <thinker@branda.to>
parents:
158
diff
changeset
|
369 while(shape && (shape = STAILQ_NEXT(shape_t, sh_next, shape))) { |
b90abd31a281
Postponse free of coords, shapes, and paints when the rdman is dirty.
Thinker K.F. Li <thinker@branda.to>
parents:
158
diff
changeset
|
370 rdman_shape_free(rdman, saved_shape); |
b90abd31a281
Postponse free of coords, shapes, and paints when the rdman is dirty.
Thinker K.F. Li <thinker@branda.to>
parents:
158
diff
changeset
|
371 #if 0 |
b90abd31a281
Postponse free of coords, shapes, and paints when the rdman is dirty.
Thinker K.F. Li <thinker@branda.to>
parents:
158
diff
changeset
|
372 STAILQ_REMOVE(rdman->shapes, shape_t, sh_next, saved_shape); |
b90abd31a281
Postponse free of coords, shapes, and paints when the rdman is dirty.
Thinker K.F. Li <thinker@branda.to>
parents:
158
diff
changeset
|
373 #endif |
b90abd31a281
Postponse free of coords, shapes, and paints when the rdman is dirty.
Thinker K.F. Li <thinker@branda.to>
parents:
158
diff
changeset
|
374 saved_shape = shape; |
b90abd31a281
Postponse free of coords, shapes, and paints when the rdman is dirty.
Thinker K.F. Li <thinker@branda.to>
parents:
158
diff
changeset
|
375 } |
b90abd31a281
Postponse free of coords, shapes, and paints when the rdman is dirty.
Thinker K.F. Li <thinker@branda.to>
parents:
158
diff
changeset
|
376 if(saved_shape != NULL) |
b90abd31a281
Postponse free of coords, shapes, and paints when the rdman is dirty.
Thinker K.F. Li <thinker@branda.to>
parents:
158
diff
changeset
|
377 rdman_shape_free(rdman, saved_shape); |
b90abd31a281
Postponse free of coords, shapes, and paints when the rdman is dirty.
Thinker K.F. Li <thinker@branda.to>
parents:
158
diff
changeset
|
378 |
12 | 379 elmpool_free(rdman->coord_pool); |
380 elmpool_free(rdman->geo_pool); | |
18
0f3baa488a62
Support solid color paint for fill.
Thinker K.F. Li <thinker@branda.to>
parents:
17
diff
changeset
|
381 elmpool_free(rdman->shnode_pool); |
73
9ab15ebc9061
Observer for mouse events
Thinker K.F. Li <thinker@branda.to>
parents:
58
diff
changeset
|
382 elmpool_free(rdman->observer_pool); |
9ab15ebc9061
Observer for mouse events
Thinker K.F. Li <thinker@branda.to>
parents:
58
diff
changeset
|
383 elmpool_free(rdman->subject_pool); |
146
e96a584487af
Use elmpool to manage paint_color_t objects.
Thinker K.F. Li <thinker@branda.to>
parents:
141
diff
changeset
|
384 elmpool_free(rdman->paint_color_pool); |
224
29e1b2bffe4c
X backend only sent EVT_MOUSE_MOVE_RAW to MadButterfly.
Thinker K.F. Li <thinker@branda.to>
parents:
196
diff
changeset
|
385 elmpool_free(rdman->pent_pool); |
158
c1cdd3fcd28f
Postponing rdman_coord_free() and rdman_remove_shape().
Thinker K.F. Li <thinker@branda.to>
parents:
154
diff
changeset
|
386 |
c1cdd3fcd28f
Postponing rdman_coord_free() and rdman_remove_shape().
Thinker K.F. Li <thinker@branda.to>
parents:
154
diff
changeset
|
387 DARRAY_DESTROY(&rdman->dirty_coords); |
c1cdd3fcd28f
Postponing rdman_coord_free() and rdman_remove_shape().
Thinker K.F. Li <thinker@branda.to>
parents:
154
diff
changeset
|
388 DARRAY_DESTROY(&rdman->dirty_geos); |
c1cdd3fcd28f
Postponing rdman_coord_free() and rdman_remove_shape().
Thinker K.F. Li <thinker@branda.to>
parents:
154
diff
changeset
|
389 DARRAY_DESTROY(&rdman->dirty_areas); |
c1cdd3fcd28f
Postponing rdman_coord_free() and rdman_remove_shape().
Thinker K.F. Li <thinker@branda.to>
parents:
154
diff
changeset
|
390 DARRAY_DESTROY(&rdman->gen_geos); |
12 | 391 } |
392 | |
393 | |
394 #define ASSERT(x) | |
395 /* | |
396 * Change transformation matrix | |
397 * - update aggregated transformation matrix | |
398 * - of coord_t object been changed. | |
399 * - of children coord_t objects. | |
400 * - redraw members of coord_t objects. | |
401 * - redraw shape objects they are overlaid with members. | |
402 * - find out overlaid shape objects. | |
403 * - geo_t of a coord_t object | |
404 * - can make finding more efficiency. | |
405 * - fill overlay geo_t objects of members. | |
406 * | |
407 * Change a shape object | |
408 * - redraw changed object. | |
409 * - redraw shape objects they are overlaid with changed object. | |
410 * - find out overlaid shape objects. | |
411 * | |
412 * That coord and geo of shape objects are setted by user code | |
413 * give user code a chance to collect coord and geo objects together | |
414 * and gain interest of higher cache hit rate. | |
415 */ | |
416 | |
417 int rdman_add_shape(redraw_man_t *rdman, shape_t *shape, coord_t *coord) { | |
418 geo_t *geo; | |
16
e17e12b112c4
A simple animation using rdman_redraw_changed().
Thinker K.F. Li <thinker@branda.to>
parents:
15
diff
changeset
|
419 int r; |
12 | 420 |
421 geo = elmpool_elm_alloc(rdman->geo_pool); | |
422 if(geo == NULL) | |
423 return ERR; | |
17
41f0907b27ac
Unittest for rdman_redraw_changed().
Thinker K.F. Li <thinker@branda.to>
parents:
16
diff
changeset
|
424 |
41f0907b27ac
Unittest for rdman_redraw_changed().
Thinker K.F. Li <thinker@branda.to>
parents:
16
diff
changeset
|
425 geo_init(geo); |
73
9ab15ebc9061
Observer for mouse events
Thinker K.F. Li <thinker@branda.to>
parents:
58
diff
changeset
|
426 geo->mouse_event = subject_new(&rdman->ob_factory, geo, OBJT_GEO); |
224
29e1b2bffe4c
X backend only sent EVT_MOUSE_MOVE_RAW to MadButterfly.
Thinker K.F. Li <thinker@branda.to>
parents:
196
diff
changeset
|
427 subject_set_monitor(geo->mouse_event, rdman->addrm_monitor); |
17
41f0907b27ac
Unittest for rdman_redraw_changed().
Thinker K.F. Li <thinker@branda.to>
parents:
16
diff
changeset
|
428 |
140
0de8fd11271e
Use macro to simplify the code.
Thinker K.F. Li <thinker@branda.to>
parents:
139
diff
changeset
|
429 geo_attach_coord(geo, coord); |
16
e17e12b112c4
A simple animation using rdman_redraw_changed().
Thinker K.F. Li <thinker@branda.to>
parents:
15
diff
changeset
|
430 |
e17e12b112c4
A simple animation using rdman_redraw_changed().
Thinker K.F. Li <thinker@branda.to>
parents:
15
diff
changeset
|
431 /* New one should be dirty to recompute it when drawing. */ |
e17e12b112c4
A simple animation using rdman_redraw_changed().
Thinker K.F. Li <thinker@branda.to>
parents:
15
diff
changeset
|
432 r = add_dirty_geo(rdman, geo); |
e17e12b112c4
A simple animation using rdman_redraw_changed().
Thinker K.F. Li <thinker@branda.to>
parents:
15
diff
changeset
|
433 if(r != OK) |
e17e12b112c4
A simple animation using rdman_redraw_changed().
Thinker K.F. Li <thinker@branda.to>
parents:
15
diff
changeset
|
434 return ERR; |
13 | 435 |
12 | 436 sh_attach_coord(shape, coord); |
139
1695a4b02b14
Members of coords are geos instead of shapes, now.
Thinker K.F. Li <thinker@branda.to>
parents:
138
diff
changeset
|
437 sh_attach_geo(shape, geo); |
12 | 438 |
439 return OK; | |
440 } | |
441 | |
17
41f0907b27ac
Unittest for rdman_redraw_changed().
Thinker K.F. Li <thinker@branda.to>
parents:
16
diff
changeset
|
442 /*! \brief Remove a shape object from redraw manager. |
41f0907b27ac
Unittest for rdman_redraw_changed().
Thinker K.F. Li <thinker@branda.to>
parents:
16
diff
changeset
|
443 * |
154 | 444 * \note Shapes should be removed after redrawing or when rdman is in clean. |
158
c1cdd3fcd28f
Postponing rdman_coord_free() and rdman_remove_shape().
Thinker K.F. Li <thinker@branda.to>
parents:
154
diff
changeset
|
445 * \note Removing shapes or coords when a rdman is dirty, removing |
c1cdd3fcd28f
Postponing rdman_coord_free() and rdman_remove_shape().
Thinker K.F. Li <thinker@branda.to>
parents:
154
diff
changeset
|
446 * is postponsed. |
58 | 447 * \todo redraw shape objects that overlaid with removed one. |
17
41f0907b27ac
Unittest for rdman_redraw_changed().
Thinker K.F. Li <thinker@branda.to>
parents:
16
diff
changeset
|
448 */ |
159
b90abd31a281
Postponse free of coords, shapes, and paints when the rdman is dirty.
Thinker K.F. Li <thinker@branda.to>
parents:
158
diff
changeset
|
449 int rdman_shape_free(redraw_man_t *rdman, shape_t *shape) { |
139
1695a4b02b14
Members of coords are geos instead of shapes, now.
Thinker K.F. Li <thinker@branda.to>
parents:
138
diff
changeset
|
450 geo_t *geo; |
158
c1cdd3fcd28f
Postponing rdman_coord_free() and rdman_remove_shape().
Thinker K.F. Li <thinker@branda.to>
parents:
154
diff
changeset
|
451 int r; |
139
1695a4b02b14
Members of coords are geos instead of shapes, now.
Thinker K.F. Li <thinker@branda.to>
parents:
138
diff
changeset
|
452 |
1695a4b02b14
Members of coords are geos instead of shapes, now.
Thinker K.F. Li <thinker@branda.to>
parents:
138
diff
changeset
|
453 geo = shape->geo; |
158
c1cdd3fcd28f
Postponing rdman_coord_free() and rdman_remove_shape().
Thinker K.F. Li <thinker@branda.to>
parents:
154
diff
changeset
|
454 |
159
b90abd31a281
Postponse free of coords, shapes, and paints when the rdman is dirty.
Thinker K.F. Li <thinker@branda.to>
parents:
158
diff
changeset
|
455 if(rdman_is_dirty(rdman) && geo != NULL) { |
b90abd31a281
Postponse free of coords, shapes, and paints when the rdman is dirty.
Thinker K.F. Li <thinker@branda.to>
parents:
158
diff
changeset
|
456 if(geo->flags & GEF_FREE) |
b90abd31a281
Postponse free of coords, shapes, and paints when the rdman is dirty.
Thinker K.F. Li <thinker@branda.to>
parents:
158
diff
changeset
|
457 return ERR; |
b90abd31a281
Postponse free of coords, shapes, and paints when the rdman is dirty.
Thinker K.F. Li <thinker@branda.to>
parents:
158
diff
changeset
|
458 |
160
147c93163ef0
Fix bug of tank that bullet is not hidden when go out the map.
Thinker K.F. Li <thinker@branda.to>
parents:
159
diff
changeset
|
459 geo->flags |= GEF_FREE; |
147c93163ef0
Fix bug of tank that bullet is not hidden when go out the map.
Thinker K.F. Li <thinker@branda.to>
parents:
159
diff
changeset
|
460 sh_hide(shape); |
158
c1cdd3fcd28f
Postponing rdman_coord_free() and rdman_remove_shape().
Thinker K.F. Li <thinker@branda.to>
parents:
154
diff
changeset
|
461 if(!(geo->flags & GEF_DIRTY)) { |
c1cdd3fcd28f
Postponing rdman_coord_free() and rdman_remove_shape().
Thinker K.F. Li <thinker@branda.to>
parents:
154
diff
changeset
|
462 r = add_dirty_geo(rdman, geo); |
c1cdd3fcd28f
Postponing rdman_coord_free() and rdman_remove_shape().
Thinker K.F. Li <thinker@branda.to>
parents:
154
diff
changeset
|
463 if(r != OK) |
c1cdd3fcd28f
Postponing rdman_coord_free() and rdman_remove_shape().
Thinker K.F. Li <thinker@branda.to>
parents:
154
diff
changeset
|
464 return ERR; |
c1cdd3fcd28f
Postponing rdman_coord_free() and rdman_remove_shape().
Thinker K.F. Li <thinker@branda.to>
parents:
154
diff
changeset
|
465 } |
159
b90abd31a281
Postponse free of coords, shapes, and paints when the rdman is dirty.
Thinker K.F. Li <thinker@branda.to>
parents:
158
diff
changeset
|
466 r = add_free_obj(rdman, shape, (free_func_t)rdman_shape_free); |
158
c1cdd3fcd28f
Postponing rdman_coord_free() and rdman_remove_shape().
Thinker K.F. Li <thinker@branda.to>
parents:
154
diff
changeset
|
467 if(r != OK) |
c1cdd3fcd28f
Postponing rdman_coord_free() and rdman_remove_shape().
Thinker K.F. Li <thinker@branda.to>
parents:
154
diff
changeset
|
468 return ERR; |
c1cdd3fcd28f
Postponing rdman_coord_free() and rdman_remove_shape().
Thinker K.F. Li <thinker@branda.to>
parents:
154
diff
changeset
|
469 return OK; |
c1cdd3fcd28f
Postponing rdman_coord_free() and rdman_remove_shape().
Thinker K.F. Li <thinker@branda.to>
parents:
154
diff
changeset
|
470 } |
c1cdd3fcd28f
Postponing rdman_coord_free() and rdman_remove_shape().
Thinker K.F. Li <thinker@branda.to>
parents:
154
diff
changeset
|
471 |
159
b90abd31a281
Postponse free of coords, shapes, and paints when the rdman is dirty.
Thinker K.F. Li <thinker@branda.to>
parents:
158
diff
changeset
|
472 if(geo != NULL) { |
224
29e1b2bffe4c
X backend only sent EVT_MOUSE_MOVE_RAW to MadButterfly.
Thinker K.F. Li <thinker@branda.to>
parents:
196
diff
changeset
|
473 subject_free(geo->mouse_event); |
159
b90abd31a281
Postponse free of coords, shapes, and paints when the rdman is dirty.
Thinker K.F. Li <thinker@branda.to>
parents:
158
diff
changeset
|
474 geo_detach_coord(geo, shape->coord); |
b90abd31a281
Postponse free of coords, shapes, and paints when the rdman is dirty.
Thinker K.F. Li <thinker@branda.to>
parents:
158
diff
changeset
|
475 sh_detach_coord(shape); |
b90abd31a281
Postponse free of coords, shapes, and paints when the rdman is dirty.
Thinker K.F. Li <thinker@branda.to>
parents:
158
diff
changeset
|
476 sh_detach_geo(shape); |
b90abd31a281
Postponse free of coords, shapes, and paints when the rdman is dirty.
Thinker K.F. Li <thinker@branda.to>
parents:
158
diff
changeset
|
477 elmpool_elm_free(rdman->geo_pool, geo); |
b90abd31a281
Postponse free of coords, shapes, and paints when the rdman is dirty.
Thinker K.F. Li <thinker@branda.to>
parents:
158
diff
changeset
|
478 } |
b90abd31a281
Postponse free of coords, shapes, and paints when the rdman is dirty.
Thinker K.F. Li <thinker@branda.to>
parents:
158
diff
changeset
|
479 STAILQ_REMOVE(rdman->shapes, shape_t, sh_next, shape); |
251
f08b3ba9c1d8
Remove potential memory address error.
Thinker K.F. Li <thinker@branda.to>
parents:
235
diff
changeset
|
480 mb_prop_store_destroy(&shape->obj.props); |
159
b90abd31a281
Postponse free of coords, shapes, and paints when the rdman is dirty.
Thinker K.F. Li <thinker@branda.to>
parents:
158
diff
changeset
|
481 shape->free(shape); |
224
29e1b2bffe4c
X backend only sent EVT_MOUSE_MOVE_RAW to MadButterfly.
Thinker K.F. Li <thinker@branda.to>
parents:
196
diff
changeset
|
482 |
29e1b2bffe4c
X backend only sent EVT_MOUSE_MOVE_RAW to MadButterfly.
Thinker K.F. Li <thinker@branda.to>
parents:
196
diff
changeset
|
483 if(rdman->last_mouse_over == (mb_obj_t *)shape) |
29e1b2bffe4c
X backend only sent EVT_MOUSE_MOVE_RAW to MadButterfly.
Thinker K.F. Li <thinker@branda.to>
parents:
196
diff
changeset
|
484 rdman->last_mouse_over = NULL; |
29e1b2bffe4c
X backend only sent EVT_MOUSE_MOVE_RAW to MadButterfly.
Thinker K.F. Li <thinker@branda.to>
parents:
196
diff
changeset
|
485 |
12 | 486 return OK; |
487 } | |
488 | |
159
b90abd31a281
Postponse free of coords, shapes, and paints when the rdman is dirty.
Thinker K.F. Li <thinker@branda.to>
parents:
158
diff
changeset
|
489 shnode_t *shnode_new(redraw_man_t *rdman, shape_t *shape) { |
b90abd31a281
Postponse free of coords, shapes, and paints when the rdman is dirty.
Thinker K.F. Li <thinker@branda.to>
parents:
158
diff
changeset
|
490 shnode_t *node; |
b90abd31a281
Postponse free of coords, shapes, and paints when the rdman is dirty.
Thinker K.F. Li <thinker@branda.to>
parents:
158
diff
changeset
|
491 |
b90abd31a281
Postponse free of coords, shapes, and paints when the rdman is dirty.
Thinker K.F. Li <thinker@branda.to>
parents:
158
diff
changeset
|
492 node = (shnode_t *)elmpool_elm_alloc(rdman->shnode_pool); |
b90abd31a281
Postponse free of coords, shapes, and paints when the rdman is dirty.
Thinker K.F. Li <thinker@branda.to>
parents:
158
diff
changeset
|
493 if(node) { |
b90abd31a281
Postponse free of coords, shapes, and paints when the rdman is dirty.
Thinker K.F. Li <thinker@branda.to>
parents:
158
diff
changeset
|
494 node->shape = shape; |
b90abd31a281
Postponse free of coords, shapes, and paints when the rdman is dirty.
Thinker K.F. Li <thinker@branda.to>
parents:
158
diff
changeset
|
495 node->next = NULL; |
b90abd31a281
Postponse free of coords, shapes, and paints when the rdman is dirty.
Thinker K.F. Li <thinker@branda.to>
parents:
158
diff
changeset
|
496 } |
b90abd31a281
Postponse free of coords, shapes, and paints when the rdman is dirty.
Thinker K.F. Li <thinker@branda.to>
parents:
158
diff
changeset
|
497 return node; |
b90abd31a281
Postponse free of coords, shapes, and paints when the rdman is dirty.
Thinker K.F. Li <thinker@branda.to>
parents:
158
diff
changeset
|
498 } |
b90abd31a281
Postponse free of coords, shapes, and paints when the rdman is dirty.
Thinker K.F. Li <thinker@branda.to>
parents:
158
diff
changeset
|
499 |
b90abd31a281
Postponse free of coords, shapes, and paints when the rdman is dirty.
Thinker K.F. Li <thinker@branda.to>
parents:
158
diff
changeset
|
500 int rdman_paint_free(redraw_man_t *rdman, paint_t *paint) { |
b90abd31a281
Postponse free of coords, shapes, and paints when the rdman is dirty.
Thinker K.F. Li <thinker@branda.to>
parents:
158
diff
changeset
|
501 shnode_t *shnode, *saved_shnode; |
b90abd31a281
Postponse free of coords, shapes, and paints when the rdman is dirty.
Thinker K.F. Li <thinker@branda.to>
parents:
158
diff
changeset
|
502 |
b90abd31a281
Postponse free of coords, shapes, and paints when the rdman is dirty.
Thinker K.F. Li <thinker@branda.to>
parents:
158
diff
changeset
|
503 if(rdman_is_dirty(rdman)) { |
b90abd31a281
Postponse free of coords, shapes, and paints when the rdman is dirty.
Thinker K.F. Li <thinker@branda.to>
parents:
158
diff
changeset
|
504 if(!(paint->flags & PNTF_FREE)) |
b90abd31a281
Postponse free of coords, shapes, and paints when the rdman is dirty.
Thinker K.F. Li <thinker@branda.to>
parents:
158
diff
changeset
|
505 return ERR; |
b90abd31a281
Postponse free of coords, shapes, and paints when the rdman is dirty.
Thinker K.F. Li <thinker@branda.to>
parents:
158
diff
changeset
|
506 add_free_obj(rdman, paint, (free_func_t)rdman_paint_free); |
b90abd31a281
Postponse free of coords, shapes, and paints when the rdman is dirty.
Thinker K.F. Li <thinker@branda.to>
parents:
158
diff
changeset
|
507 paint->flags |= PNTF_FREE; |
b90abd31a281
Postponse free of coords, shapes, and paints when the rdman is dirty.
Thinker K.F. Li <thinker@branda.to>
parents:
158
diff
changeset
|
508 return OK; |
b90abd31a281
Postponse free of coords, shapes, and paints when the rdman is dirty.
Thinker K.F. Li <thinker@branda.to>
parents:
158
diff
changeset
|
509 } |
b90abd31a281
Postponse free of coords, shapes, and paints when the rdman is dirty.
Thinker K.F. Li <thinker@branda.to>
parents:
158
diff
changeset
|
510 |
b90abd31a281
Postponse free of coords, shapes, and paints when the rdman is dirty.
Thinker K.F. Li <thinker@branda.to>
parents:
158
diff
changeset
|
511 /* Free member shapes that using this paint. */ |
b90abd31a281
Postponse free of coords, shapes, and paints when the rdman is dirty.
Thinker K.F. Li <thinker@branda.to>
parents:
158
diff
changeset
|
512 saved_shnode = NULL; |
b90abd31a281
Postponse free of coords, shapes, and paints when the rdman is dirty.
Thinker K.F. Li <thinker@branda.to>
parents:
158
diff
changeset
|
513 FORPAINTMEMBERS(paint, shnode) { |
b90abd31a281
Postponse free of coords, shapes, and paints when the rdman is dirty.
Thinker K.F. Li <thinker@branda.to>
parents:
158
diff
changeset
|
514 if(saved_shnode) { |
b90abd31a281
Postponse free of coords, shapes, and paints when the rdman is dirty.
Thinker K.F. Li <thinker@branda.to>
parents:
158
diff
changeset
|
515 RM_PAINTMEMBER(paint, saved_shnode); |
b90abd31a281
Postponse free of coords, shapes, and paints when the rdman is dirty.
Thinker K.F. Li <thinker@branda.to>
parents:
158
diff
changeset
|
516 shnode_free(rdman, saved_shnode); |
b90abd31a281
Postponse free of coords, shapes, and paints when the rdman is dirty.
Thinker K.F. Li <thinker@branda.to>
parents:
158
diff
changeset
|
517 } |
b90abd31a281
Postponse free of coords, shapes, and paints when the rdman is dirty.
Thinker K.F. Li <thinker@branda.to>
parents:
158
diff
changeset
|
518 saved_shnode = shnode; |
b90abd31a281
Postponse free of coords, shapes, and paints when the rdman is dirty.
Thinker K.F. Li <thinker@branda.to>
parents:
158
diff
changeset
|
519 } |
b90abd31a281
Postponse free of coords, shapes, and paints when the rdman is dirty.
Thinker K.F. Li <thinker@branda.to>
parents:
158
diff
changeset
|
520 if(saved_shnode) { |
b90abd31a281
Postponse free of coords, shapes, and paints when the rdman is dirty.
Thinker K.F. Li <thinker@branda.to>
parents:
158
diff
changeset
|
521 RM_PAINTMEMBER(paint, saved_shnode); |
b90abd31a281
Postponse free of coords, shapes, and paints when the rdman is dirty.
Thinker K.F. Li <thinker@branda.to>
parents:
158
diff
changeset
|
522 shnode_free(rdman, saved_shnode); |
b90abd31a281
Postponse free of coords, shapes, and paints when the rdman is dirty.
Thinker K.F. Li <thinker@branda.to>
parents:
158
diff
changeset
|
523 } |
b90abd31a281
Postponse free of coords, shapes, and paints when the rdman is dirty.
Thinker K.F. Li <thinker@branda.to>
parents:
158
diff
changeset
|
524 |
b90abd31a281
Postponse free of coords, shapes, and paints when the rdman is dirty.
Thinker K.F. Li <thinker@branda.to>
parents:
158
diff
changeset
|
525 RM_PAINT(rdman, paint); |
b90abd31a281
Postponse free of coords, shapes, and paints when the rdman is dirty.
Thinker K.F. Li <thinker@branda.to>
parents:
158
diff
changeset
|
526 paint->free(rdman, paint); |
b90abd31a281
Postponse free of coords, shapes, and paints when the rdman is dirty.
Thinker K.F. Li <thinker@branda.to>
parents:
158
diff
changeset
|
527 return OK; |
b90abd31a281
Postponse free of coords, shapes, and paints when the rdman is dirty.
Thinker K.F. Li <thinker@branda.to>
parents:
158
diff
changeset
|
528 } |
b90abd31a281
Postponse free of coords, shapes, and paints when the rdman is dirty.
Thinker K.F. Li <thinker@branda.to>
parents:
158
diff
changeset
|
529 |
b90abd31a281
Postponse free of coords, shapes, and paints when the rdman is dirty.
Thinker K.F. Li <thinker@branda.to>
parents:
158
diff
changeset
|
530 void _rdman_paint_real_remove_child(redraw_man_t *rdman, |
b90abd31a281
Postponse free of coords, shapes, and paints when the rdman is dirty.
Thinker K.F. Li <thinker@branda.to>
parents:
158
diff
changeset
|
531 paint_t *paint, |
b90abd31a281
Postponse free of coords, shapes, and paints when the rdman is dirty.
Thinker K.F. Li <thinker@branda.to>
parents:
158
diff
changeset
|
532 shape_t *shape) { |
b90abd31a281
Postponse free of coords, shapes, and paints when the rdman is dirty.
Thinker K.F. Li <thinker@branda.to>
parents:
158
diff
changeset
|
533 shnode_t *shnode; |
b90abd31a281
Postponse free of coords, shapes, and paints when the rdman is dirty.
Thinker K.F. Li <thinker@branda.to>
parents:
158
diff
changeset
|
534 |
b90abd31a281
Postponse free of coords, shapes, and paints when the rdman is dirty.
Thinker K.F. Li <thinker@branda.to>
parents:
158
diff
changeset
|
535 FORPAINTMEMBERS(paint, shnode) { |
b90abd31a281
Postponse free of coords, shapes, and paints when the rdman is dirty.
Thinker K.F. Li <thinker@branda.to>
parents:
158
diff
changeset
|
536 if(shnode->shape == shape) { |
b90abd31a281
Postponse free of coords, shapes, and paints when the rdman is dirty.
Thinker K.F. Li <thinker@branda.to>
parents:
158
diff
changeset
|
537 RM_PAINTMEMBER(paint, shnode); |
b90abd31a281
Postponse free of coords, shapes, and paints when the rdman is dirty.
Thinker K.F. Li <thinker@branda.to>
parents:
158
diff
changeset
|
538 shnode_free(rdman, shnode); |
b90abd31a281
Postponse free of coords, shapes, and paints when the rdman is dirty.
Thinker K.F. Li <thinker@branda.to>
parents:
158
diff
changeset
|
539 break; |
b90abd31a281
Postponse free of coords, shapes, and paints when the rdman is dirty.
Thinker K.F. Li <thinker@branda.to>
parents:
158
diff
changeset
|
540 } |
b90abd31a281
Postponse free of coords, shapes, and paints when the rdman is dirty.
Thinker K.F. Li <thinker@branda.to>
parents:
158
diff
changeset
|
541 } |
b90abd31a281
Postponse free of coords, shapes, and paints when the rdman is dirty.
Thinker K.F. Li <thinker@branda.to>
parents:
158
diff
changeset
|
542 } |
b90abd31a281
Postponse free of coords, shapes, and paints when the rdman is dirty.
Thinker K.F. Li <thinker@branda.to>
parents:
158
diff
changeset
|
543 |
12 | 544 coord_t *rdman_coord_new(redraw_man_t *rdman, coord_t *parent) { |
13 | 545 coord_t *coord, *root_coord; |
546 coord_t *visit; | |
12 | 547 |
548 coord = elmpool_elm_alloc(rdman->coord_pool); | |
549 if(coord == NULL) | |
550 return NULL; | |
551 | |
552 coord_init(coord, parent); | |
224
29e1b2bffe4c
X backend only sent EVT_MOUSE_MOVE_RAW to MadButterfly.
Thinker K.F. Li <thinker@branda.to>
parents:
196
diff
changeset
|
553 mb_prop_store_init(&coord->obj.props, rdman->pent_pool); |
73
9ab15ebc9061
Observer for mouse events
Thinker K.F. Li <thinker@branda.to>
parents:
58
diff
changeset
|
554 coord->mouse_event = subject_new(&rdman->ob_factory, |
9ab15ebc9061
Observer for mouse events
Thinker K.F. Li <thinker@branda.to>
parents:
58
diff
changeset
|
555 coord, |
9ab15ebc9061
Observer for mouse events
Thinker K.F. Li <thinker@branda.to>
parents:
58
diff
changeset
|
556 OBJT_COORD); |
224
29e1b2bffe4c
X backend only sent EVT_MOUSE_MOVE_RAW to MadButterfly.
Thinker K.F. Li <thinker@branda.to>
parents:
196
diff
changeset
|
557 subject_set_monitor(coord->mouse_event, rdman->addrm_monitor); |
138
9f4fc9ecfd1f
Make shapes and coords drawed in post-order of tree.
Thinker K.F. Li <thinker@branda.to>
parents:
135
diff
changeset
|
558 /*! \note default opacity == 1 */ |
9f4fc9ecfd1f
Make shapes and coords drawed in post-order of tree.
Thinker K.F. Li <thinker@branda.to>
parents:
135
diff
changeset
|
559 coord->opacity = 1; |
9f4fc9ecfd1f
Make shapes and coords drawed in post-order of tree.
Thinker K.F. Li <thinker@branda.to>
parents:
135
diff
changeset
|
560 if(parent) |
9f4fc9ecfd1f
Make shapes and coords drawed in post-order of tree.
Thinker K.F. Li <thinker@branda.to>
parents:
135
diff
changeset
|
561 coord->canvas = parent->canvas; |
13 | 562 rdman->n_coords++; |
563 | |
564 coord->order = ++rdman->next_coord_order; | |
565 if(coord->order == 0) { | |
566 rdman->next_coord_order = 0; | |
567 root_coord = visit = rdman->root_coord; | |
568 /* skip root coord. */ | |
569 visit = preorder_coord_subtree(root_coord, visit); | |
570 while(visit) { | |
571 visit->order = ++rdman->next_coord_order; | |
572 visit = preorder_coord_subtree(root_coord, visit); | |
573 } | |
574 } | |
12 | 575 |
139
1695a4b02b14
Members of coords are geos instead of shapes, now.
Thinker K.F. Li <thinker@branda.to>
parents:
138
diff
changeset
|
576 coord->before_pmem = parent->num_members; |
1695a4b02b14
Members of coords are geos instead of shapes, now.
Thinker K.F. Li <thinker@branda.to>
parents:
138
diff
changeset
|
577 |
151
d11aa8fc06c7
Fix bug of tanks do not show at right places.
Thinker K.F. Li <thinker@branda.to>
parents:
150
diff
changeset
|
578 /* If parent is dirty, children should be dirty. */ |
d11aa8fc06c7
Fix bug of tanks do not show at right places.
Thinker K.F. Li <thinker@branda.to>
parents:
150
diff
changeset
|
579 if(parent && (parent->flags & COF_DIRTY)) |
152
2b316b5d65f9
Refactory code snippets for making coords dirty.
Thinker K.F. Li <thinker@branda.to>
parents:
151
diff
changeset
|
580 add_dirty_coord(rdman, coord); |
151
d11aa8fc06c7
Fix bug of tanks do not show at right places.
Thinker K.F. Li <thinker@branda.to>
parents:
150
diff
changeset
|
581 |
12 | 582 return coord; |
583 } | |
584 | |
192
54fdc2a65242
Remove factory from observer APIs.
Thinker K.F. Li <thinker@branda.to>
parents:
189
diff
changeset
|
585 static int rdman_coord_free_postponse(redraw_man_t *rdman, coord_t *coord) { |
54fdc2a65242
Remove factory from observer APIs.
Thinker K.F. Li <thinker@branda.to>
parents:
189
diff
changeset
|
586 int r; |
54fdc2a65242
Remove factory from observer APIs.
Thinker K.F. Li <thinker@branda.to>
parents:
189
diff
changeset
|
587 |
54fdc2a65242
Remove factory from observer APIs.
Thinker K.F. Li <thinker@branda.to>
parents:
189
diff
changeset
|
588 if(coord->flags & COF_FREE) |
54fdc2a65242
Remove factory from observer APIs.
Thinker K.F. Li <thinker@branda.to>
parents:
189
diff
changeset
|
589 return ERR; |
54fdc2a65242
Remove factory from observer APIs.
Thinker K.F. Li <thinker@branda.to>
parents:
189
diff
changeset
|
590 |
54fdc2a65242
Remove factory from observer APIs.
Thinker K.F. Li <thinker@branda.to>
parents:
189
diff
changeset
|
591 coord->flags |= COF_FREE; |
54fdc2a65242
Remove factory from observer APIs.
Thinker K.F. Li <thinker@branda.to>
parents:
189
diff
changeset
|
592 coord_hide(coord); |
54fdc2a65242
Remove factory from observer APIs.
Thinker K.F. Li <thinker@branda.to>
parents:
189
diff
changeset
|
593 if(!(coord->flags & COF_DIRTY)) { |
54fdc2a65242
Remove factory from observer APIs.
Thinker K.F. Li <thinker@branda.to>
parents:
189
diff
changeset
|
594 r = add_dirty_coord(rdman, coord); |
54fdc2a65242
Remove factory from observer APIs.
Thinker K.F. Li <thinker@branda.to>
parents:
189
diff
changeset
|
595 if(r != OK) |
54fdc2a65242
Remove factory from observer APIs.
Thinker K.F. Li <thinker@branda.to>
parents:
189
diff
changeset
|
596 return ERR; |
54fdc2a65242
Remove factory from observer APIs.
Thinker K.F. Li <thinker@branda.to>
parents:
189
diff
changeset
|
597 } |
54fdc2a65242
Remove factory from observer APIs.
Thinker K.F. Li <thinker@branda.to>
parents:
189
diff
changeset
|
598 r = add_free_obj(rdman, coord, (free_func_t)rdman_coord_free); |
54fdc2a65242
Remove factory from observer APIs.
Thinker K.F. Li <thinker@branda.to>
parents:
189
diff
changeset
|
599 if(r != OK) |
54fdc2a65242
Remove factory from observer APIs.
Thinker K.F. Li <thinker@branda.to>
parents:
189
diff
changeset
|
600 return ERR; |
54fdc2a65242
Remove factory from observer APIs.
Thinker K.F. Li <thinker@branda.to>
parents:
189
diff
changeset
|
601 return OK; |
54fdc2a65242
Remove factory from observer APIs.
Thinker K.F. Li <thinker@branda.to>
parents:
189
diff
changeset
|
602 } |
54fdc2a65242
Remove factory from observer APIs.
Thinker K.F. Li <thinker@branda.to>
parents:
189
diff
changeset
|
603 |
12 | 604 /*! \brief Free a coord of a redraw_man_t object. |
605 * | |
192
54fdc2a65242
Remove factory from observer APIs.
Thinker K.F. Li <thinker@branda.to>
parents:
189
diff
changeset
|
606 * All children and members should be freed before parent being freed. |
54fdc2a65242
Remove factory from observer APIs.
Thinker K.F. Li <thinker@branda.to>
parents:
189
diff
changeset
|
607 * |
12 | 608 * \param coord is a coord_t without children and members. |
609 * \return 0 for successful, -1 for error. | |
158
c1cdd3fcd28f
Postponing rdman_coord_free() and rdman_remove_shape().
Thinker K.F. Li <thinker@branda.to>
parents:
154
diff
changeset
|
610 * |
192
54fdc2a65242
Remove factory from observer APIs.
Thinker K.F. Li <thinker@branda.to>
parents:
189
diff
changeset
|
611 * \note Free is postponsed if the coord is dirty or it has children |
54fdc2a65242
Remove factory from observer APIs.
Thinker K.F. Li <thinker@branda.to>
parents:
189
diff
changeset
|
612 * or members postponsed for free. |
12 | 613 */ |
614 int rdman_coord_free(redraw_man_t *rdman, coord_t *coord) { | |
615 coord_t *parent; | |
158
c1cdd3fcd28f
Postponing rdman_coord_free() and rdman_remove_shape().
Thinker K.F. Li <thinker@branda.to>
parents:
154
diff
changeset
|
616 coord_t *child; |
c1cdd3fcd28f
Postponing rdman_coord_free() and rdman_remove_shape().
Thinker K.F. Li <thinker@branda.to>
parents:
154
diff
changeset
|
617 geo_t *member; |
192
54fdc2a65242
Remove factory from observer APIs.
Thinker K.F. Li <thinker@branda.to>
parents:
189
diff
changeset
|
618 int cm_cnt; /* children & members counter */ |
12 | 619 |
620 parent = coord->parent; | |
621 if(parent == NULL) | |
622 return ERR; | |
623 | |
192
54fdc2a65242
Remove factory from observer APIs.
Thinker K.F. Li <thinker@branda.to>
parents:
189
diff
changeset
|
624 cm_cnt = 0; |
54fdc2a65242
Remove factory from observer APIs.
Thinker K.F. Li <thinker@branda.to>
parents:
189
diff
changeset
|
625 FORCHILDREN(coord, child) { |
54fdc2a65242
Remove factory from observer APIs.
Thinker K.F. Li <thinker@branda.to>
parents:
189
diff
changeset
|
626 cm_cnt++; |
54fdc2a65242
Remove factory from observer APIs.
Thinker K.F. Li <thinker@branda.to>
parents:
189
diff
changeset
|
627 if(!(child->flags & COF_FREE)) |
159
b90abd31a281
Postponse free of coords, shapes, and paints when the rdman is dirty.
Thinker K.F. Li <thinker@branda.to>
parents:
158
diff
changeset
|
628 return ERR; |
192
54fdc2a65242
Remove factory from observer APIs.
Thinker K.F. Li <thinker@branda.to>
parents:
189
diff
changeset
|
629 } |
54fdc2a65242
Remove factory from observer APIs.
Thinker K.F. Li <thinker@branda.to>
parents:
189
diff
changeset
|
630 FORMEMBERS(coord, member) { |
54fdc2a65242
Remove factory from observer APIs.
Thinker K.F. Li <thinker@branda.to>
parents:
189
diff
changeset
|
631 cm_cnt++; |
54fdc2a65242
Remove factory from observer APIs.
Thinker K.F. Li <thinker@branda.to>
parents:
189
diff
changeset
|
632 if(!(member->flags & GEF_FREE)) |
158
c1cdd3fcd28f
Postponing rdman_coord_free() and rdman_remove_shape().
Thinker K.F. Li <thinker@branda.to>
parents:
154
diff
changeset
|
633 return ERR; |
c1cdd3fcd28f
Postponing rdman_coord_free() and rdman_remove_shape().
Thinker K.F. Li <thinker@branda.to>
parents:
154
diff
changeset
|
634 } |
192
54fdc2a65242
Remove factory from observer APIs.
Thinker K.F. Li <thinker@branda.to>
parents:
189
diff
changeset
|
635 |
54fdc2a65242
Remove factory from observer APIs.
Thinker K.F. Li <thinker@branda.to>
parents:
189
diff
changeset
|
636 if(cm_cnt || rdman_is_dirty(rdman)) |
54fdc2a65242
Remove factory from observer APIs.
Thinker K.F. Li <thinker@branda.to>
parents:
189
diff
changeset
|
637 return rdman_coord_free_postponse(rdman, coord); |
12 | 638 |
138
9f4fc9ecfd1f
Make shapes and coords drawed in post-order of tree.
Thinker K.F. Li <thinker@branda.to>
parents:
135
diff
changeset
|
639 /* Free canvas (\ref redraw) */ |
9f4fc9ecfd1f
Make shapes and coords drawed in post-order of tree.
Thinker K.F. Li <thinker@branda.to>
parents:
135
diff
changeset
|
640 if(coord->flags & COF_OWN_CANVAS) |
9f4fc9ecfd1f
Make shapes and coords drawed in post-order of tree.
Thinker K.F. Li <thinker@branda.to>
parents:
135
diff
changeset
|
641 free_canvas(coord->canvas); |
9f4fc9ecfd1f
Make shapes and coords drawed in post-order of tree.
Thinker K.F. Li <thinker@branda.to>
parents:
135
diff
changeset
|
642 |
140
0de8fd11271e
Use macro to simplify the code.
Thinker K.F. Li <thinker@branda.to>
parents:
139
diff
changeset
|
643 RM_CHILD(parent, coord); |
192
54fdc2a65242
Remove factory from observer APIs.
Thinker K.F. Li <thinker@branda.to>
parents:
189
diff
changeset
|
644 subject_free(coord->mouse_event); |
251
f08b3ba9c1d8
Remove potential memory address error.
Thinker K.F. Li <thinker@branda.to>
parents:
235
diff
changeset
|
645 mb_prop_store_destroy(&coord->obj.props); |
12 | 646 elmpool_elm_free(rdman->coord_pool, coord); |
13 | 647 rdman->n_coords--; |
648 | |
649 return OK; | |
650 } | |
651 | |
224
29e1b2bffe4c
X backend only sent EVT_MOUSE_MOVE_RAW to MadButterfly.
Thinker K.F. Li <thinker@branda.to>
parents:
196
diff
changeset
|
652 static int _rdman_coord_free_members(redraw_man_t *rdman, coord_t *coord) { |
194
45d9a1e2764d
Add mb_subtree_free animate action and fix bugs.
Thinker K.F. Li <thinker@branda.to>
parents:
192
diff
changeset
|
653 geo_t *member; |
45d9a1e2764d
Add mb_subtree_free animate action and fix bugs.
Thinker K.F. Li <thinker@branda.to>
parents:
192
diff
changeset
|
654 shape_t *shape; |
45d9a1e2764d
Add mb_subtree_free animate action and fix bugs.
Thinker K.F. Li <thinker@branda.to>
parents:
192
diff
changeset
|
655 int r; |
45d9a1e2764d
Add mb_subtree_free animate action and fix bugs.
Thinker K.F. Li <thinker@branda.to>
parents:
192
diff
changeset
|
656 |
45d9a1e2764d
Add mb_subtree_free animate action and fix bugs.
Thinker K.F. Li <thinker@branda.to>
parents:
192
diff
changeset
|
657 FORMEMBERS(coord, member) { |
45d9a1e2764d
Add mb_subtree_free animate action and fix bugs.
Thinker K.F. Li <thinker@branda.to>
parents:
192
diff
changeset
|
658 shape = geo_get_shape(member); |
45d9a1e2764d
Add mb_subtree_free animate action and fix bugs.
Thinker K.F. Li <thinker@branda.to>
parents:
192
diff
changeset
|
659 r = rdman_shape_free(rdman, shape); |
45d9a1e2764d
Add mb_subtree_free animate action and fix bugs.
Thinker K.F. Li <thinker@branda.to>
parents:
192
diff
changeset
|
660 if(r != OK) |
45d9a1e2764d
Add mb_subtree_free animate action and fix bugs.
Thinker K.F. Li <thinker@branda.to>
parents:
192
diff
changeset
|
661 return ERR; |
45d9a1e2764d
Add mb_subtree_free animate action and fix bugs.
Thinker K.F. Li <thinker@branda.to>
parents:
192
diff
changeset
|
662 } |
45d9a1e2764d
Add mb_subtree_free animate action and fix bugs.
Thinker K.F. Li <thinker@branda.to>
parents:
192
diff
changeset
|
663 return OK; |
45d9a1e2764d
Add mb_subtree_free animate action and fix bugs.
Thinker K.F. Li <thinker@branda.to>
parents:
192
diff
changeset
|
664 } |
45d9a1e2764d
Add mb_subtree_free animate action and fix bugs.
Thinker K.F. Li <thinker@branda.to>
parents:
192
diff
changeset
|
665 |
45d9a1e2764d
Add mb_subtree_free animate action and fix bugs.
Thinker K.F. Li <thinker@branda.to>
parents:
192
diff
changeset
|
666 /*! \brief Free descendant coords and shapes of a coord. |
45d9a1e2764d
Add mb_subtree_free animate action and fix bugs.
Thinker K.F. Li <thinker@branda.to>
parents:
192
diff
changeset
|
667 * |
45d9a1e2764d
Add mb_subtree_free animate action and fix bugs.
Thinker K.F. Li <thinker@branda.to>
parents:
192
diff
changeset
|
668 * The specified coord is also freed. |
45d9a1e2764d
Add mb_subtree_free animate action and fix bugs.
Thinker K.F. Li <thinker@branda.to>
parents:
192
diff
changeset
|
669 */ |
154 | 670 int rdman_coord_subtree_free(redraw_man_t *rdman, coord_t *subtree) { |
671 coord_t *coord, *prev_coord; | |
672 int r; | |
673 | |
674 if(subtree == NULL) | |
675 return OK; | |
676 | |
677 prev_coord = postorder_coord_subtree(subtree, NULL); | |
678 for(coord = postorder_coord_subtree(subtree, prev_coord); | |
679 coord != NULL; | |
680 coord = postorder_coord_subtree(subtree, coord)) { | |
159
b90abd31a281
Postponse free of coords, shapes, and paints when the rdman is dirty.
Thinker K.F. Li <thinker@branda.to>
parents:
158
diff
changeset
|
681 if(!(prev_coord->flags & COF_FREE)) { |
194
45d9a1e2764d
Add mb_subtree_free animate action and fix bugs.
Thinker K.F. Li <thinker@branda.to>
parents:
192
diff
changeset
|
682 r = _rdman_coord_free_members(rdman, prev_coord); |
45d9a1e2764d
Add mb_subtree_free animate action and fix bugs.
Thinker K.F. Li <thinker@branda.to>
parents:
192
diff
changeset
|
683 if(r != OK) |
45d9a1e2764d
Add mb_subtree_free animate action and fix bugs.
Thinker K.F. Li <thinker@branda.to>
parents:
192
diff
changeset
|
684 return ERR; |
45d9a1e2764d
Add mb_subtree_free animate action and fix bugs.
Thinker K.F. Li <thinker@branda.to>
parents:
192
diff
changeset
|
685 |
159
b90abd31a281
Postponse free of coords, shapes, and paints when the rdman is dirty.
Thinker K.F. Li <thinker@branda.to>
parents:
158
diff
changeset
|
686 r = rdman_coord_free(rdman, prev_coord); |
b90abd31a281
Postponse free of coords, shapes, and paints when the rdman is dirty.
Thinker K.F. Li <thinker@branda.to>
parents:
158
diff
changeset
|
687 if(r != OK) |
b90abd31a281
Postponse free of coords, shapes, and paints when the rdman is dirty.
Thinker K.F. Li <thinker@branda.to>
parents:
158
diff
changeset
|
688 return ERR; |
b90abd31a281
Postponse free of coords, shapes, and paints when the rdman is dirty.
Thinker K.F. Li <thinker@branda.to>
parents:
158
diff
changeset
|
689 } |
b90abd31a281
Postponse free of coords, shapes, and paints when the rdman is dirty.
Thinker K.F. Li <thinker@branda.to>
parents:
158
diff
changeset
|
690 prev_coord = coord; |
b90abd31a281
Postponse free of coords, shapes, and paints when the rdman is dirty.
Thinker K.F. Li <thinker@branda.to>
parents:
158
diff
changeset
|
691 } |
b90abd31a281
Postponse free of coords, shapes, and paints when the rdman is dirty.
Thinker K.F. Li <thinker@branda.to>
parents:
158
diff
changeset
|
692 if(!(prev_coord->flags & COF_FREE)) { |
194
45d9a1e2764d
Add mb_subtree_free animate action and fix bugs.
Thinker K.F. Li <thinker@branda.to>
parents:
192
diff
changeset
|
693 r = _rdman_coord_free_members(rdman, prev_coord); |
45d9a1e2764d
Add mb_subtree_free animate action and fix bugs.
Thinker K.F. Li <thinker@branda.to>
parents:
192
diff
changeset
|
694 if(r != OK) |
45d9a1e2764d
Add mb_subtree_free animate action and fix bugs.
Thinker K.F. Li <thinker@branda.to>
parents:
192
diff
changeset
|
695 return ERR; |
45d9a1e2764d
Add mb_subtree_free animate action and fix bugs.
Thinker K.F. Li <thinker@branda.to>
parents:
192
diff
changeset
|
696 |
154 | 697 r = rdman_coord_free(rdman, prev_coord); |
698 if(r != OK) | |
699 return ERR; | |
700 } | |
701 | |
702 return OK; | |
703 } | |
704 | |
13 | 705 /*! \brief Mark a coord is changed. |
706 * | |
707 * A changed coord_t object is marked as dirty and put | |
160
147c93163ef0
Fix bug of tank that bullet is not hidden when go out the map.
Thinker K.F. Li <thinker@branda.to>
parents:
159
diff
changeset
|
708 * into dirty_coords list. rdman_coord_changed() should be called |
147c93163ef0
Fix bug of tank that bullet is not hidden when go out the map.
Thinker K.F. Li <thinker@branda.to>
parents:
159
diff
changeset
|
709 * for a coord after it been changed to notify redraw manager to |
147c93163ef0
Fix bug of tank that bullet is not hidden when go out the map.
Thinker K.F. Li <thinker@branda.to>
parents:
159
diff
changeset
|
710 * redraw shapes grouped by it. |
13 | 711 */ |
712 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
|
713 coord_t *child; |
13 | 714 |
715 if(coord->flags & COF_DIRTY) | |
716 return OK; | |
151
d11aa8fc06c7
Fix bug of tanks do not show at right places.
Thinker K.F. Li <thinker@branda.to>
parents:
150
diff
changeset
|
717 |
152
2b316b5d65f9
Refactory code snippets for making coords dirty.
Thinker K.F. Li <thinker@branda.to>
parents:
151
diff
changeset
|
718 add_dirty_coord(rdman, coord); |
151
d11aa8fc06c7
Fix bug of tanks do not show at right places.
Thinker K.F. Li <thinker@branda.to>
parents:
150
diff
changeset
|
719 |
189
257af0ed5852
When a bullet hits a tank or wall, it shows a bang animation.
Thinker K.F. Li <thinker@branda.to>
parents:
186
diff
changeset
|
720 #if 0 |
160
147c93163ef0
Fix bug of tank that bullet is not hidden when go out the map.
Thinker K.F. Li <thinker@branda.to>
parents:
159
diff
changeset
|
721 if(coord->flags & COF_HIDDEN) |
147c93163ef0
Fix bug of tank that bullet is not hidden when go out the map.
Thinker K.F. Li <thinker@branda.to>
parents:
159
diff
changeset
|
722 return OK; |
189
257af0ed5852
When a bullet hits a tank or wall, it shows a bang animation.
Thinker K.F. Li <thinker@branda.to>
parents:
186
diff
changeset
|
723 #endif |
160
147c93163ef0
Fix bug of tank that bullet is not hidden when go out the map.
Thinker K.F. Li <thinker@branda.to>
parents:
159
diff
changeset
|
724 |
151
d11aa8fc06c7
Fix bug of tanks do not show at right places.
Thinker K.F. Li <thinker@branda.to>
parents:
150
diff
changeset
|
725 /* Make child coords dirty. */ |
d11aa8fc06c7
Fix bug of tanks do not show at right places.
Thinker K.F. Li <thinker@branda.to>
parents:
150
diff
changeset
|
726 for(child = preorder_coord_subtree(coord, coord); |
16
e17e12b112c4
A simple animation using rdman_redraw_changed().
Thinker K.F. Li <thinker@branda.to>
parents:
15
diff
changeset
|
727 child != NULL; |
e17e12b112c4
A simple animation using rdman_redraw_changed().
Thinker K.F. Li <thinker@branda.to>
parents:
15
diff
changeset
|
728 child = preorder_coord_subtree(coord, child)) { |
151
d11aa8fc06c7
Fix bug of tanks do not show at right places.
Thinker K.F. Li <thinker@branda.to>
parents:
150
diff
changeset
|
729 if(child->flags & (COF_DIRTY | COF_HIDDEN)) { |
d11aa8fc06c7
Fix bug of tanks do not show at right places.
Thinker K.F. Li <thinker@branda.to>
parents:
150
diff
changeset
|
730 preorder_coord_skip_subtree(child); |
114
1909d53071ab
Check if a coord dirty before dirty it
Thinker K.F. Li <thinker@branda.to>
parents:
104
diff
changeset
|
731 continue; |
151
d11aa8fc06c7
Fix bug of tanks do not show at right places.
Thinker K.F. Li <thinker@branda.to>
parents:
150
diff
changeset
|
732 } |
d11aa8fc06c7
Fix bug of tanks do not show at right places.
Thinker K.F. Li <thinker@branda.to>
parents:
150
diff
changeset
|
733 |
152
2b316b5d65f9
Refactory code snippets for making coords dirty.
Thinker K.F. Li <thinker@branda.to>
parents:
151
diff
changeset
|
734 add_dirty_coord(rdman, child); |
16
e17e12b112c4
A simple animation using rdman_redraw_changed().
Thinker K.F. Li <thinker@branda.to>
parents:
15
diff
changeset
|
735 } |
13 | 736 |
737 return OK; | |
738 } | |
739 | |
18
0f3baa488a62
Support solid color paint for fill.
Thinker K.F. Li <thinker@branda.to>
parents:
17
diff
changeset
|
740 static int _rdman_shape_changed(redraw_man_t *rdman, shape_t *shape) { |
13 | 741 geo_t *geo; |
742 int r; | |
743 | |
744 geo = shape->geo; | |
745 | |
746 if(geo->flags & GEF_DIRTY) | |
747 return OK; | |
748 | |
749 r = add_dirty_geo(rdman, geo); | |
750 if(r == ERR) | |
751 return ERR; | |
12 | 752 |
753 return OK; | |
754 } | |
755 | |
18
0f3baa488a62
Support solid color paint for fill.
Thinker K.F. Li <thinker@branda.to>
parents:
17
diff
changeset
|
756 /*! \brief Mark a shape is changed. |
0f3baa488a62
Support solid color paint for fill.
Thinker K.F. Li <thinker@branda.to>
parents:
17
diff
changeset
|
757 * |
0f3baa488a62
Support solid color paint for fill.
Thinker K.F. Li <thinker@branda.to>
parents:
17
diff
changeset
|
758 * The geo_t object of a changed shape is mark as dirty and |
0f3baa488a62
Support solid color paint for fill.
Thinker K.F. Li <thinker@branda.to>
parents:
17
diff
changeset
|
759 * put into dirty_geos list. |
0f3baa488a62
Support solid color paint for fill.
Thinker K.F. Li <thinker@branda.to>
parents:
17
diff
changeset
|
760 */ |
0f3baa488a62
Support solid color paint for fill.
Thinker K.F. Li <thinker@branda.to>
parents:
17
diff
changeset
|
761 int rdman_shape_changed(redraw_man_t *rdman, shape_t *shape) { |
0f3baa488a62
Support solid color paint for fill.
Thinker K.F. Li <thinker@branda.to>
parents:
17
diff
changeset
|
762 return _rdman_shape_changed(rdman, shape); |
0f3baa488a62
Support solid color paint for fill.
Thinker K.F. Li <thinker@branda.to>
parents:
17
diff
changeset
|
763 } |
0f3baa488a62
Support solid color paint for fill.
Thinker K.F. Li <thinker@branda.to>
parents:
17
diff
changeset
|
764 |
29 | 765 int rdman_paint_changed(redraw_man_t *rdman, paint_t *paint) { |
159
b90abd31a281
Postponse free of coords, shapes, and paints when the rdman is dirty.
Thinker K.F. Li <thinker@branda.to>
parents:
158
diff
changeset
|
766 shnode_t *shnode; |
29 | 767 int r; |
768 | |
159
b90abd31a281
Postponse free of coords, shapes, and paints when the rdman is dirty.
Thinker K.F. Li <thinker@branda.to>
parents:
158
diff
changeset
|
769 FORPAINTMEMBERS(paint, shnode) { |
b90abd31a281
Postponse free of coords, shapes, and paints when the rdman is dirty.
Thinker K.F. Li <thinker@branda.to>
parents:
158
diff
changeset
|
770 r = _rdman_shape_changed(rdman, shnode->shape); |
29 | 771 if(r != OK) |
772 return ERR; | |
773 } | |
774 return OK; | |
775 } | |
776 | |
28 | 777 /* Clean dirties */ |
778 | |
57
ab028c9f0930
Ability to hidden shapes and action of visibility.
Thinker K.F. Li <thinker@branda.to>
parents:
38
diff
changeset
|
779 static int is_coord_subtree_hidden(coord_t *coord) { |
ab028c9f0930
Ability to hidden shapes and action of visibility.
Thinker K.F. Li <thinker@branda.to>
parents:
38
diff
changeset
|
780 while(coord) { |
ab028c9f0930
Ability to hidden shapes and action of visibility.
Thinker K.F. Li <thinker@branda.to>
parents:
38
diff
changeset
|
781 if(coord->flags & COF_HIDDEN) |
ab028c9f0930
Ability to hidden shapes and action of visibility.
Thinker K.F. Li <thinker@branda.to>
parents:
38
diff
changeset
|
782 return 1; |
ab028c9f0930
Ability to hidden shapes and action of visibility.
Thinker K.F. Li <thinker@branda.to>
parents:
38
diff
changeset
|
783 coord = coord->parent; |
ab028c9f0930
Ability to hidden shapes and action of visibility.
Thinker K.F. Li <thinker@branda.to>
parents:
38
diff
changeset
|
784 } |
ab028c9f0930
Ability to hidden shapes and action of visibility.
Thinker K.F. Li <thinker@branda.to>
parents:
38
diff
changeset
|
785 return 0; |
ab028c9f0930
Ability to hidden shapes and action of visibility.
Thinker K.F. Li <thinker@branda.to>
parents:
38
diff
changeset
|
786 } |
ab028c9f0930
Ability to hidden shapes and action of visibility.
Thinker K.F. Li <thinker@branda.to>
parents:
38
diff
changeset
|
787 |
28 | 788 static void clean_shape(shape_t *shape) { |
196
c234ee745ceb
Start moving to mb_obj_t
Thinker K.F. Li <thinker@branda.to>
parents:
194
diff
changeset
|
789 switch(MBO_TYPE(shape)) { |
c234ee745ceb
Start moving to mb_obj_t
Thinker K.F. Li <thinker@branda.to>
parents:
194
diff
changeset
|
790 case MBO_PATH: |
28 | 791 sh_path_transform(shape); |
792 break; | |
196
c234ee745ceb
Start moving to mb_obj_t
Thinker K.F. Li <thinker@branda.to>
parents:
194
diff
changeset
|
793 case MBO_TEXT: |
28 | 794 sh_text_transform(shape); |
795 break; | |
196
c234ee745ceb
Start moving to mb_obj_t
Thinker K.F. Li <thinker@branda.to>
parents:
194
diff
changeset
|
796 case MBO_RECT: |
35
581a03196093
Support rectangle tag of SVG.
Thinker K.F. Li <thinker@branda.to>
parents:
33
diff
changeset
|
797 sh_rect_transform(shape); |
581a03196093
Support rectangle tag of SVG.
Thinker K.F. Li <thinker@branda.to>
parents:
33
diff
changeset
|
798 break; |
28 | 799 #ifdef UNITTEST |
800 default: | |
801 sh_dummy_transform(shape); | |
802 break; | |
803 #endif /* UNITTEST */ | |
804 } | |
805 shape->geo->flags &= ~GEF_DIRTY; | |
57
ab028c9f0930
Ability to hidden shapes and action of visibility.
Thinker K.F. Li <thinker@branda.to>
parents:
38
diff
changeset
|
806 |
ab028c9f0930
Ability to hidden shapes and action of visibility.
Thinker K.F. Li <thinker@branda.to>
parents:
38
diff
changeset
|
807 if(is_coord_subtree_hidden(shape->coord)) |
160
147c93163ef0
Fix bug of tank that bullet is not hidden when go out the map.
Thinker K.F. Li <thinker@branda.to>
parents:
159
diff
changeset
|
808 sh_hide(shape); |
57
ab028c9f0930
Ability to hidden shapes and action of visibility.
Thinker K.F. Li <thinker@branda.to>
parents:
38
diff
changeset
|
809 else |
160
147c93163ef0
Fix bug of tank that bullet is not hidden when go out the map.
Thinker K.F. Li <thinker@branda.to>
parents:
159
diff
changeset
|
810 sh_show(shape); |
28 | 811 } |
812 | |
138
9f4fc9ecfd1f
Make shapes and coords drawed in post-order of tree.
Thinker K.F. Li <thinker@branda.to>
parents:
135
diff
changeset
|
813 /*! \brief Setup canvas for the coord. |
9f4fc9ecfd1f
Make shapes and coords drawed in post-order of tree.
Thinker K.F. Li <thinker@branda.to>
parents:
135
diff
changeset
|
814 * |
9f4fc9ecfd1f
Make shapes and coords drawed in post-order of tree.
Thinker K.F. Li <thinker@branda.to>
parents:
135
diff
changeset
|
815 * Own a canvas or inherit it from parent. |
9f4fc9ecfd1f
Make shapes and coords drawed in post-order of tree.
Thinker K.F. Li <thinker@branda.to>
parents:
135
diff
changeset
|
816 * \sa |
9f4fc9ecfd1f
Make shapes and coords drawed in post-order of tree.
Thinker K.F. Li <thinker@branda.to>
parents:
135
diff
changeset
|
817 * - \ref redraw |
9f4fc9ecfd1f
Make shapes and coords drawed in post-order of tree.
Thinker K.F. Li <thinker@branda.to>
parents:
135
diff
changeset
|
818 */ |
9f4fc9ecfd1f
Make shapes and coords drawed in post-order of tree.
Thinker K.F. Li <thinker@branda.to>
parents:
135
diff
changeset
|
819 static void setup_canvas(redraw_man_t *rdman, coord_t *coord) { |
9f4fc9ecfd1f
Make shapes and coords drawed in post-order of tree.
Thinker K.F. Li <thinker@branda.to>
parents:
135
diff
changeset
|
820 if(coord->parent == NULL) |
9f4fc9ecfd1f
Make shapes and coords drawed in post-order of tree.
Thinker K.F. Li <thinker@branda.to>
parents:
135
diff
changeset
|
821 return; |
9f4fc9ecfd1f
Make shapes and coords drawed in post-order of tree.
Thinker K.F. Li <thinker@branda.to>
parents:
135
diff
changeset
|
822 |
9f4fc9ecfd1f
Make shapes and coords drawed in post-order of tree.
Thinker K.F. Li <thinker@branda.to>
parents:
135
diff
changeset
|
823 if(coord->opacity != 1) { |
9f4fc9ecfd1f
Make shapes and coords drawed in post-order of tree.
Thinker K.F. Li <thinker@branda.to>
parents:
135
diff
changeset
|
824 if(!(coord->flags & COF_OWN_CANVAS)) { |
9f4fc9ecfd1f
Make shapes and coords drawed in post-order of tree.
Thinker K.F. Li <thinker@branda.to>
parents:
135
diff
changeset
|
825 coord->canvas = new_canvas(rdman); |
9f4fc9ecfd1f
Make shapes and coords drawed in post-order of tree.
Thinker K.F. Li <thinker@branda.to>
parents:
135
diff
changeset
|
826 coord->flags |= COF_OWN_CANVAS; |
9f4fc9ecfd1f
Make shapes and coords drawed in post-order of tree.
Thinker K.F. Li <thinker@branda.to>
parents:
135
diff
changeset
|
827 } |
9f4fc9ecfd1f
Make shapes and coords drawed in post-order of tree.
Thinker K.F. Li <thinker@branda.to>
parents:
135
diff
changeset
|
828 } else { |
9f4fc9ecfd1f
Make shapes and coords drawed in post-order of tree.
Thinker K.F. Li <thinker@branda.to>
parents:
135
diff
changeset
|
829 if(coord->flags & COF_OWN_CANVAS) { |
9f4fc9ecfd1f
Make shapes and coords drawed in post-order of tree.
Thinker K.F. Li <thinker@branda.to>
parents:
135
diff
changeset
|
830 free_canvas(coord->canvas); |
9f4fc9ecfd1f
Make shapes and coords drawed in post-order of tree.
Thinker K.F. Li <thinker@branda.to>
parents:
135
diff
changeset
|
831 coord->flags &= ~COF_OWN_CANVAS; |
9f4fc9ecfd1f
Make shapes and coords drawed in post-order of tree.
Thinker K.F. Li <thinker@branda.to>
parents:
135
diff
changeset
|
832 } |
9f4fc9ecfd1f
Make shapes and coords drawed in post-order of tree.
Thinker K.F. Li <thinker@branda.to>
parents:
135
diff
changeset
|
833 coord->canvas = coord->parent->canvas; |
9f4fc9ecfd1f
Make shapes and coords drawed in post-order of tree.
Thinker K.F. Li <thinker@branda.to>
parents:
135
diff
changeset
|
834 } |
9f4fc9ecfd1f
Make shapes and coords drawed in post-order of tree.
Thinker K.F. Li <thinker@branda.to>
parents:
135
diff
changeset
|
835 } |
9f4fc9ecfd1f
Make shapes and coords drawed in post-order of tree.
Thinker K.F. Li <thinker@branda.to>
parents:
135
diff
changeset
|
836 |
9f4fc9ecfd1f
Make shapes and coords drawed in post-order of tree.
Thinker K.F. Li <thinker@branda.to>
parents:
135
diff
changeset
|
837 static int clean_coord(redraw_man_t *rdman, coord_t *coord) { |
28 | 838 geo_t *geo; |
147
995ee8fd5f1a
Use local static variable to hold position array to reduce using malloc().
Thinker K.F. Li <thinker@branda.to>
parents:
146
diff
changeset
|
839 /*! \note poses is shared by invokings, it is not support reentrying. */ |
995ee8fd5f1a
Use local static variable to hold position array to reduce using malloc().
Thinker K.F. Li <thinker@branda.to>
parents:
146
diff
changeset
|
840 static co_aix (*poses)[2]; |
995ee8fd5f1a
Use local static variable to hold position array to reduce using malloc().
Thinker K.F. Li <thinker@branda.to>
parents:
146
diff
changeset
|
841 static int max_poses = 0; |
28 | 842 int cnt, pos_cnt; |
843 | |
138
9f4fc9ecfd1f
Make shapes and coords drawed in post-order of tree.
Thinker K.F. Li <thinker@branda.to>
parents:
135
diff
changeset
|
844 setup_canvas(rdman, coord); |
9f4fc9ecfd1f
Make shapes and coords drawed in post-order of tree.
Thinker K.F. Li <thinker@branda.to>
parents:
135
diff
changeset
|
845 |
28 | 846 compute_aggr_of_coord(coord); |
847 | |
848 /* Clean member shapes. */ | |
849 cnt = 0; | |
140
0de8fd11271e
Use macro to simplify the code.
Thinker K.F. Li <thinker@branda.to>
parents:
139
diff
changeset
|
850 FORMEMBERS(coord, geo) { |
28 | 851 SWAP(geo->cur_area, geo->last_area, area_t *); |
139
1695a4b02b14
Members of coords are geos instead of shapes, now.
Thinker K.F. Li <thinker@branda.to>
parents:
138
diff
changeset
|
852 clean_shape(geo->shape); |
28 | 853 cnt++; |
854 } | |
855 | |
147
995ee8fd5f1a
Use local static variable to hold position array to reduce using malloc().
Thinker K.F. Li <thinker@branda.to>
parents:
146
diff
changeset
|
856 if(max_poses < (cnt * 2)) { |
995ee8fd5f1a
Use local static variable to hold position array to reduce using malloc().
Thinker K.F. Li <thinker@branda.to>
parents:
146
diff
changeset
|
857 free(poses); |
995ee8fd5f1a
Use local static variable to hold position array to reduce using malloc().
Thinker K.F. Li <thinker@branda.to>
parents:
146
diff
changeset
|
858 max_poses = cnt * 2; |
995ee8fd5f1a
Use local static variable to hold position array to reduce using malloc().
Thinker K.F. Li <thinker@branda.to>
parents:
146
diff
changeset
|
859 poses = (co_aix (*)[2])malloc(sizeof(co_aix [2]) * max_poses); |
995ee8fd5f1a
Use local static variable to hold position array to reduce using malloc().
Thinker K.F. Li <thinker@branda.to>
parents:
146
diff
changeset
|
860 if(poses == NULL) |
995ee8fd5f1a
Use local static variable to hold position array to reduce using malloc().
Thinker K.F. Li <thinker@branda.to>
parents:
146
diff
changeset
|
861 return ERR; |
995ee8fd5f1a
Use local static variable to hold position array to reduce using malloc().
Thinker K.F. Li <thinker@branda.to>
parents:
146
diff
changeset
|
862 } |
28 | 863 |
148 | 864 /* Compute area of the coord. */ |
28 | 865 pos_cnt = 0; |
140
0de8fd11271e
Use macro to simplify the code.
Thinker K.F. Li <thinker@branda.to>
parents:
139
diff
changeset
|
866 FORMEMBERS(coord, geo) { |
28 | 867 area_to_positions(geo->cur_area, poses + pos_cnt); |
868 pos_cnt += 2; | |
869 } | |
870 | |
871 SWAP(coord->cur_area, coord->last_area, area_t *); | |
872 area_init(coord->cur_area, pos_cnt, poses); | |
873 | |
874 coord->flags &= ~COF_DIRTY; | |
875 | |
876 return OK; | |
877 } | |
878 | |
135 | 879 /*! \brief Clean coord_t objects. |
133 | 880 */ |
28 | 881 static int clean_rdman_coords(redraw_man_t *rdman) { |
882 coord_t *coord; | |
883 coord_t **dirty_coords; | |
884 int n_dirty_coords; | |
885 int i, r; | |
886 | |
158
c1cdd3fcd28f
Postponing rdman_coord_free() and rdman_remove_shape().
Thinker K.F. Li <thinker@branda.to>
parents:
154
diff
changeset
|
887 n_dirty_coords = rdman->dirty_coords.num; |
28 | 888 if(n_dirty_coords > 0) { |
158
c1cdd3fcd28f
Postponing rdman_coord_free() and rdman_remove_shape().
Thinker K.F. Li <thinker@branda.to>
parents:
154
diff
changeset
|
889 dirty_coords = rdman->dirty_coords.ds; |
28 | 890 _insert_sort((void **)dirty_coords, n_dirty_coords, |
891 OFFSET(coord_t, order)); | |
892 for(i = 0; i < n_dirty_coords; i++) { | |
893 coord = dirty_coords[i]; | |
894 if(!(coord->flags & COF_DIRTY)) | |
895 continue; | |
138
9f4fc9ecfd1f
Make shapes and coords drawed in post-order of tree.
Thinker K.F. Li <thinker@branda.to>
parents:
135
diff
changeset
|
896 r = clean_coord(rdman, coord); |
28 | 897 if(r != OK) |
898 return ERR; | |
899 /* These two steps can be avoided for drawing all. */ | |
900 add_dirty_area(rdman, &coord->areas[0]); | |
901 add_dirty_area(rdman, &coord->areas[1]); | |
902 } | |
158
c1cdd3fcd28f
Postponing rdman_coord_free() and rdman_remove_shape().
Thinker K.F. Li <thinker@branda.to>
parents:
154
diff
changeset
|
903 rdman->dirty_coords.num = 0; |
28 | 904 } |
905 return OK; | |
906 } | |
907 | |
908 static int clean_rdman_geos(redraw_man_t *rdman) { | |
909 int i; | |
910 int n_dirty_geos; | |
911 geo_t **dirty_geos; | |
912 geo_t *visit_geo; | |
913 | |
158
c1cdd3fcd28f
Postponing rdman_coord_free() and rdman_remove_shape().
Thinker K.F. Li <thinker@branda.to>
parents:
154
diff
changeset
|
914 n_dirty_geos = rdman->dirty_geos.num; |
28 | 915 if(n_dirty_geos > 0) { |
158
c1cdd3fcd28f
Postponing rdman_coord_free() and rdman_remove_shape().
Thinker K.F. Li <thinker@branda.to>
parents:
154
diff
changeset
|
916 dirty_geos = rdman->dirty_geos.ds; |
28 | 917 for(i = 0; i < n_dirty_geos; i++) { |
918 visit_geo = dirty_geos[i]; | |
919 if(!(visit_geo->flags & GEF_DIRTY)) | |
920 continue; | |
921 | |
922 SWAP(visit_geo->cur_area, visit_geo->last_area, area_t *); | |
923 clean_shape(visit_geo->shape); | |
924 add_dirty_area(rdman, visit_geo->cur_area); | |
925 add_dirty_area(rdman, visit_geo->last_area); | |
926 } | |
158
c1cdd3fcd28f
Postponing rdman_coord_free() and rdman_remove_shape().
Thinker K.F. Li <thinker@branda.to>
parents:
154
diff
changeset
|
927 rdman->dirty_geos.num = 0; |
28 | 928 } |
929 | |
930 return OK; | |
931 } | |
932 | |
29 | 933 static int clean_rdman_dirties(redraw_man_t *rdman) { |
934 int r; | |
935 | |
936 r = clean_rdman_coords(rdman); | |
937 if(r != OK) | |
938 return ERR; | |
939 | |
940 r = clean_rdman_geos(rdman); | |
941 if(r != OK) | |
942 return ERR; | |
943 | |
944 return OK; | |
945 } | |
946 | |
947 | |
17
41f0907b27ac
Unittest for rdman_redraw_changed().
Thinker K.F. Li <thinker@branda.to>
parents:
16
diff
changeset
|
948 /* Drawing and Redrawing |
41f0907b27ac
Unittest for rdman_redraw_changed().
Thinker K.F. Li <thinker@branda.to>
parents:
16
diff
changeset
|
949 * ============================================================ |
41f0907b27ac
Unittest for rdman_redraw_changed().
Thinker K.F. Li <thinker@branda.to>
parents:
16
diff
changeset
|
950 */ |
16
e17e12b112c4
A simple animation using rdman_redraw_changed().
Thinker K.F. Li <thinker@branda.to>
parents:
15
diff
changeset
|
951 |
26
d50f33040de6
Set line width for path.
Thinker K.F. Li <thinker@branda.to>
parents:
25
diff
changeset
|
952 #ifndef UNITTEST |
d50f33040de6
Set line width for path.
Thinker K.F. Li <thinker@branda.to>
parents:
25
diff
changeset
|
953 static void set_shape_stroke_param(shape_t *shape, cairo_t *cr) { |
d50f33040de6
Set line width for path.
Thinker K.F. Li <thinker@branda.to>
parents:
25
diff
changeset
|
954 cairo_set_line_width(cr, shape->stroke_width); |
d50f33040de6
Set line width for path.
Thinker K.F. Li <thinker@branda.to>
parents:
25
diff
changeset
|
955 } |
33
d82749f77108
Fix bug of demo and remove *_fill() and *_stroke().
Thinker K.F. Li <thinker@branda.to>
parents:
30
diff
changeset
|
956 |
d82749f77108
Fix bug of demo and remove *_fill() and *_stroke().
Thinker K.F. Li <thinker@branda.to>
parents:
30
diff
changeset
|
957 static void fill_path_preserve(redraw_man_t *rdman) { |
d82749f77108
Fix bug of demo and remove *_fill() and *_stroke().
Thinker K.F. Li <thinker@branda.to>
parents:
30
diff
changeset
|
958 cairo_fill_preserve(rdman->cr); |
d82749f77108
Fix bug of demo and remove *_fill() and *_stroke().
Thinker K.F. Li <thinker@branda.to>
parents:
30
diff
changeset
|
959 } |
d82749f77108
Fix bug of demo and remove *_fill() and *_stroke().
Thinker K.F. Li <thinker@branda.to>
parents:
30
diff
changeset
|
960 |
d82749f77108
Fix bug of demo and remove *_fill() and *_stroke().
Thinker K.F. Li <thinker@branda.to>
parents:
30
diff
changeset
|
961 static void fill_path(redraw_man_t *rdman) { |
d82749f77108
Fix bug of demo and remove *_fill() and *_stroke().
Thinker K.F. Li <thinker@branda.to>
parents:
30
diff
changeset
|
962 cairo_fill(rdman->cr); |
d82749f77108
Fix bug of demo and remove *_fill() and *_stroke().
Thinker K.F. Li <thinker@branda.to>
parents:
30
diff
changeset
|
963 } |
d82749f77108
Fix bug of demo and remove *_fill() and *_stroke().
Thinker K.F. Li <thinker@branda.to>
parents:
30
diff
changeset
|
964 |
d82749f77108
Fix bug of demo and remove *_fill() and *_stroke().
Thinker K.F. Li <thinker@branda.to>
parents:
30
diff
changeset
|
965 static void stroke_path(redraw_man_t *rdman) { |
d82749f77108
Fix bug of demo and remove *_fill() and *_stroke().
Thinker K.F. Li <thinker@branda.to>
parents:
30
diff
changeset
|
966 cairo_stroke(rdman->cr); |
d82749f77108
Fix bug of demo and remove *_fill() and *_stroke().
Thinker K.F. Li <thinker@branda.to>
parents:
30
diff
changeset
|
967 } |
26
d50f33040de6
Set line width for path.
Thinker K.F. Li <thinker@branda.to>
parents:
25
diff
changeset
|
968 #else |
d50f33040de6
Set line width for path.
Thinker K.F. Li <thinker@branda.to>
parents:
25
diff
changeset
|
969 static void set_shape_stroke_param(shape_t *shape, cairo_t *cr) { |
d50f33040de6
Set line width for path.
Thinker K.F. Li <thinker@branda.to>
parents:
25
diff
changeset
|
970 } |
33
d82749f77108
Fix bug of demo and remove *_fill() and *_stroke().
Thinker K.F. Li <thinker@branda.to>
parents:
30
diff
changeset
|
971 |
d82749f77108
Fix bug of demo and remove *_fill() and *_stroke().
Thinker K.F. Li <thinker@branda.to>
parents:
30
diff
changeset
|
972 static void fill_path_preserve(redraw_man_t *rdman) { |
d82749f77108
Fix bug of demo and remove *_fill() and *_stroke().
Thinker K.F. Li <thinker@branda.to>
parents:
30
diff
changeset
|
973 } |
d82749f77108
Fix bug of demo and remove *_fill() and *_stroke().
Thinker K.F. Li <thinker@branda.to>
parents:
30
diff
changeset
|
974 |
d82749f77108
Fix bug of demo and remove *_fill() and *_stroke().
Thinker K.F. Li <thinker@branda.to>
parents:
30
diff
changeset
|
975 static void fill_path(redraw_man_t *rdman) { |
d82749f77108
Fix bug of demo and remove *_fill() and *_stroke().
Thinker K.F. Li <thinker@branda.to>
parents:
30
diff
changeset
|
976 } |
d82749f77108
Fix bug of demo and remove *_fill() and *_stroke().
Thinker K.F. Li <thinker@branda.to>
parents:
30
diff
changeset
|
977 |
d82749f77108
Fix bug of demo and remove *_fill() and *_stroke().
Thinker K.F. Li <thinker@branda.to>
parents:
30
diff
changeset
|
978 static void stroke_path(redraw_man_t *rdman) { |
d82749f77108
Fix bug of demo and remove *_fill() and *_stroke().
Thinker K.F. Li <thinker@branda.to>
parents:
30
diff
changeset
|
979 } |
26
d50f33040de6
Set line width for path.
Thinker K.F. Li <thinker@branda.to>
parents:
25
diff
changeset
|
980 #endif |
d50f33040de6
Set line width for path.
Thinker K.F. Li <thinker@branda.to>
parents:
25
diff
changeset
|
981 |
138
9f4fc9ecfd1f
Make shapes and coords drawed in post-order of tree.
Thinker K.F. Li <thinker@branda.to>
parents:
135
diff
changeset
|
982 static void draw_shape(redraw_man_t *rdman, cairo_t *cr, shape_t *shape) { |
22 | 983 paint_t *fill, *stroke; |
18
0f3baa488a62
Support solid color paint for fill.
Thinker K.F. Li <thinker@branda.to>
parents:
17
diff
changeset
|
984 |
189
257af0ed5852
When a bullet hits a tank or wall, it shows a bang animation.
Thinker K.F. Li <thinker@branda.to>
parents:
186
diff
changeset
|
985 /*! \todo Move operator of shapes into singleton structures that define |
257af0ed5852
When a bullet hits a tank or wall, it shows a bang animation.
Thinker K.F. Li <thinker@branda.to>
parents:
186
diff
changeset
|
986 * operators for them. |
257af0ed5852
When a bullet hits a tank or wall, it shows a bang animation.
Thinker K.F. Li <thinker@branda.to>
parents:
186
diff
changeset
|
987 */ |
33
d82749f77108
Fix bug of demo and remove *_fill() and *_stroke().
Thinker K.F. Li <thinker@branda.to>
parents:
30
diff
changeset
|
988 if(shape->fill || shape->stroke) { |
196
c234ee745ceb
Start moving to mb_obj_t
Thinker K.F. Li <thinker@branda.to>
parents:
194
diff
changeset
|
989 switch(MBO_TYPE(shape)) { |
c234ee745ceb
Start moving to mb_obj_t
Thinker K.F. Li <thinker@branda.to>
parents:
194
diff
changeset
|
990 case MBO_PATH: |
138
9f4fc9ecfd1f
Make shapes and coords drawed in post-order of tree.
Thinker K.F. Li <thinker@branda.to>
parents:
135
diff
changeset
|
991 sh_path_draw(shape, cr); |
19 | 992 break; |
196
c234ee745ceb
Start moving to mb_obj_t
Thinker K.F. Li <thinker@branda.to>
parents:
194
diff
changeset
|
993 case MBO_TEXT: |
138
9f4fc9ecfd1f
Make shapes and coords drawed in post-order of tree.
Thinker K.F. Li <thinker@branda.to>
parents:
135
diff
changeset
|
994 sh_text_draw(shape, cr); |
27 | 995 break; |
196
c234ee745ceb
Start moving to mb_obj_t
Thinker K.F. Li <thinker@branda.to>
parents:
194
diff
changeset
|
996 case MBO_RECT: |
138
9f4fc9ecfd1f
Make shapes and coords drawed in post-order of tree.
Thinker K.F. Li <thinker@branda.to>
parents:
135
diff
changeset
|
997 sh_rect_draw(shape, cr); |
35
581a03196093
Support rectangle tag of SVG.
Thinker K.F. Li <thinker@branda.to>
parents:
33
diff
changeset
|
998 break; |
17
41f0907b27ac
Unittest for rdman_redraw_changed().
Thinker K.F. Li <thinker@branda.to>
parents:
16
diff
changeset
|
999 #ifdef UNITTEST |
19 | 1000 default: |
138
9f4fc9ecfd1f
Make shapes and coords drawed in post-order of tree.
Thinker K.F. Li <thinker@branda.to>
parents:
135
diff
changeset
|
1001 sh_dummy_fill(shape, cr); |
19 | 1002 break; |
17
41f0907b27ac
Unittest for rdman_redraw_changed().
Thinker K.F. Li <thinker@branda.to>
parents:
16
diff
changeset
|
1003 #endif /* UNITTEST */ |
19 | 1004 } |
33
d82749f77108
Fix bug of demo and remove *_fill() and *_stroke().
Thinker K.F. Li <thinker@branda.to>
parents:
30
diff
changeset
|
1005 |
d82749f77108
Fix bug of demo and remove *_fill() and *_stroke().
Thinker K.F. Li <thinker@branda.to>
parents:
30
diff
changeset
|
1006 fill = shape->fill; |
d82749f77108
Fix bug of demo and remove *_fill() and *_stroke().
Thinker K.F. Li <thinker@branda.to>
parents:
30
diff
changeset
|
1007 if(shape->fill) { |
138
9f4fc9ecfd1f
Make shapes and coords drawed in post-order of tree.
Thinker K.F. Li <thinker@branda.to>
parents:
135
diff
changeset
|
1008 fill->prepare(fill, cr); |
33
d82749f77108
Fix bug of demo and remove *_fill() and *_stroke().
Thinker K.F. Li <thinker@branda.to>
parents:
30
diff
changeset
|
1009 if(shape->stroke) |
d82749f77108
Fix bug of demo and remove *_fill() and *_stroke().
Thinker K.F. Li <thinker@branda.to>
parents:
30
diff
changeset
|
1010 fill_path_preserve(rdman); |
d82749f77108
Fix bug of demo and remove *_fill() and *_stroke().
Thinker K.F. Li <thinker@branda.to>
parents:
30
diff
changeset
|
1011 else |
d82749f77108
Fix bug of demo and remove *_fill() and *_stroke().
Thinker K.F. Li <thinker@branda.to>
parents:
30
diff
changeset
|
1012 fill_path(rdman); |
d82749f77108
Fix bug of demo and remove *_fill() and *_stroke().
Thinker K.F. Li <thinker@branda.to>
parents:
30
diff
changeset
|
1013 } |
d82749f77108
Fix bug of demo and remove *_fill() and *_stroke().
Thinker K.F. Li <thinker@branda.to>
parents:
30
diff
changeset
|
1014 |
d82749f77108
Fix bug of demo and remove *_fill() and *_stroke().
Thinker K.F. Li <thinker@branda.to>
parents:
30
diff
changeset
|
1015 stroke = shape->stroke; |
d82749f77108
Fix bug of demo and remove *_fill() and *_stroke().
Thinker K.F. Li <thinker@branda.to>
parents:
30
diff
changeset
|
1016 if(stroke) { |
138
9f4fc9ecfd1f
Make shapes and coords drawed in post-order of tree.
Thinker K.F. Li <thinker@branda.to>
parents:
135
diff
changeset
|
1017 stroke->prepare(stroke, cr); |
9f4fc9ecfd1f
Make shapes and coords drawed in post-order of tree.
Thinker K.F. Li <thinker@branda.to>
parents:
135
diff
changeset
|
1018 set_shape_stroke_param(shape, cr); |
33
d82749f77108
Fix bug of demo and remove *_fill() and *_stroke().
Thinker K.F. Li <thinker@branda.to>
parents:
30
diff
changeset
|
1019 stroke_path(rdman); |
22 | 1020 } |
1021 } | |
13 | 1022 } |
1023 | |
17
41f0907b27ac
Unittest for rdman_redraw_changed().
Thinker K.F. Li <thinker@branda.to>
parents:
16
diff
changeset
|
1024 #ifndef UNITTEST |
25
29937c26bb01
Fix bug of a dark line appear when animating.
Thinker K.F. Li <thinker@branda.to>
parents:
24
diff
changeset
|
1025 static void clean_canvas(cairo_t *cr) { |
58 | 1026 /*! \todo clean to background color. */ |
79
5bcb329a5157
Fix bug of core dump caused by forget to check if parent is NULL, root.
Thinker K.F. Li <thinker@branda.to>
parents:
75
diff
changeset
|
1027 cairo_set_source_rgb(cr, 1, 1, 1); |
24
e598bc809c0f
No more flash when animation.
Thinker K.F. Li <thinker@branda.to>
parents:
23
diff
changeset
|
1028 cairo_paint(cr); |
16
e17e12b112c4
A simple animation using rdman_redraw_changed().
Thinker K.F. Li <thinker@branda.to>
parents:
15
diff
changeset
|
1029 } |
e17e12b112c4
A simple animation using rdman_redraw_changed().
Thinker K.F. Li <thinker@branda.to>
parents:
15
diff
changeset
|
1030 |
138
9f4fc9ecfd1f
Make shapes and coords drawed in post-order of tree.
Thinker K.F. Li <thinker@branda.to>
parents:
135
diff
changeset
|
1031 static void clean_canvas_black(cairo_t *cr) { |
9f4fc9ecfd1f
Make shapes and coords drawed in post-order of tree.
Thinker K.F. Li <thinker@branda.to>
parents:
135
diff
changeset
|
1032 /*! \todo clean to background color. */ |
9f4fc9ecfd1f
Make shapes and coords drawed in post-order of tree.
Thinker K.F. Li <thinker@branda.to>
parents:
135
diff
changeset
|
1033 cairo_set_source_rgba(cr, 0, 0, 0, 0); |
9f4fc9ecfd1f
Make shapes and coords drawed in post-order of tree.
Thinker K.F. Li <thinker@branda.to>
parents:
135
diff
changeset
|
1034 cairo_paint(cr); |
9f4fc9ecfd1f
Make shapes and coords drawed in post-order of tree.
Thinker K.F. Li <thinker@branda.to>
parents:
135
diff
changeset
|
1035 } |
9f4fc9ecfd1f
Make shapes and coords drawed in post-order of tree.
Thinker K.F. Li <thinker@branda.to>
parents:
135
diff
changeset
|
1036 |
24
e598bc809c0f
No more flash when animation.
Thinker K.F. Li <thinker@branda.to>
parents:
23
diff
changeset
|
1037 static void make_clip(cairo_t *cr, int n_dirty_areas, |
15
c2ce186a5c37
X_main uses rdman_redraw_all()
Thinker K.F. Li <thinker@branda.to>
parents:
14
diff
changeset
|
1038 area_t **dirty_areas) { |
c2ce186a5c37
X_main uses rdman_redraw_all()
Thinker K.F. Li <thinker@branda.to>
parents:
14
diff
changeset
|
1039 int i; |
c2ce186a5c37
X_main uses rdman_redraw_all()
Thinker K.F. Li <thinker@branda.to>
parents:
14
diff
changeset
|
1040 area_t *area; |
c2ce186a5c37
X_main uses rdman_redraw_all()
Thinker K.F. Li <thinker@branda.to>
parents:
14
diff
changeset
|
1041 |
c2ce186a5c37
X_main uses rdman_redraw_all()
Thinker K.F. Li <thinker@branda.to>
parents:
14
diff
changeset
|
1042 for(i = 0; i < n_dirty_areas; i++) { |
c2ce186a5c37
X_main uses rdman_redraw_all()
Thinker K.F. Li <thinker@branda.to>
parents:
14
diff
changeset
|
1043 area = dirty_areas[i]; |
c2ce186a5c37
X_main uses rdman_redraw_all()
Thinker K.F. Li <thinker@branda.to>
parents:
14
diff
changeset
|
1044 cairo_rectangle(cr, area->x, area->y, area->w, area->h); |
c2ce186a5c37
X_main uses rdman_redraw_all()
Thinker K.F. Li <thinker@branda.to>
parents:
14
diff
changeset
|
1045 } |
c2ce186a5c37
X_main uses rdman_redraw_all()
Thinker K.F. Li <thinker@branda.to>
parents:
14
diff
changeset
|
1046 cairo_clip(cr); |
c2ce186a5c37
X_main uses rdman_redraw_all()
Thinker K.F. Li <thinker@branda.to>
parents:
14
diff
changeset
|
1047 } |
c2ce186a5c37
X_main uses rdman_redraw_all()
Thinker K.F. Li <thinker@branda.to>
parents:
14
diff
changeset
|
1048 |
17
41f0907b27ac
Unittest for rdman_redraw_changed().
Thinker K.F. Li <thinker@branda.to>
parents:
16
diff
changeset
|
1049 static void reset_clip(redraw_man_t *rdman) { |
24
e598bc809c0f
No more flash when animation.
Thinker K.F. Li <thinker@branda.to>
parents:
23
diff
changeset
|
1050 cairo_reset_clip(rdman->backend); |
e598bc809c0f
No more flash when animation.
Thinker K.F. Li <thinker@branda.to>
parents:
23
diff
changeset
|
1051 } |
e598bc809c0f
No more flash when animation.
Thinker K.F. Li <thinker@branda.to>
parents:
23
diff
changeset
|
1052 |
e598bc809c0f
No more flash when animation.
Thinker K.F. Li <thinker@branda.to>
parents:
23
diff
changeset
|
1053 static void copy_cr_2_backend(redraw_man_t *rdman, int n_dirty_areas, |
e598bc809c0f
No more flash when animation.
Thinker K.F. Li <thinker@branda.to>
parents:
23
diff
changeset
|
1054 area_t **dirty_areas) { |
e598bc809c0f
No more flash when animation.
Thinker K.F. Li <thinker@branda.to>
parents:
23
diff
changeset
|
1055 if(n_dirty_areas) |
e598bc809c0f
No more flash when animation.
Thinker K.F. Li <thinker@branda.to>
parents:
23
diff
changeset
|
1056 make_clip(rdman->backend, n_dirty_areas, dirty_areas); |
e598bc809c0f
No more flash when animation.
Thinker K.F. Li <thinker@branda.to>
parents:
23
diff
changeset
|
1057 |
e598bc809c0f
No more flash when animation.
Thinker K.F. Li <thinker@branda.to>
parents:
23
diff
changeset
|
1058 cairo_paint(rdman->backend); |
17
41f0907b27ac
Unittest for rdman_redraw_changed().
Thinker K.F. Li <thinker@branda.to>
parents:
16
diff
changeset
|
1059 } |
41f0907b27ac
Unittest for rdman_redraw_changed().
Thinker K.F. Li <thinker@branda.to>
parents:
16
diff
changeset
|
1060 #else /* UNITTEST */ |
25
29937c26bb01
Fix bug of a dark line appear when animating.
Thinker K.F. Li <thinker@branda.to>
parents:
24
diff
changeset
|
1061 static void clean_canvas(cairo_t *cr) { |
24
e598bc809c0f
No more flash when animation.
Thinker K.F. Li <thinker@branda.to>
parents:
23
diff
changeset
|
1062 } |
e598bc809c0f
No more flash when animation.
Thinker K.F. Li <thinker@branda.to>
parents:
23
diff
changeset
|
1063 |
138
9f4fc9ecfd1f
Make shapes and coords drawed in post-order of tree.
Thinker K.F. Li <thinker@branda.to>
parents:
135
diff
changeset
|
1064 static void clean_canvas_black(cairo_t *cr) { |
9f4fc9ecfd1f
Make shapes and coords drawed in post-order of tree.
Thinker K.F. Li <thinker@branda.to>
parents:
135
diff
changeset
|
1065 } |
9f4fc9ecfd1f
Make shapes and coords drawed in post-order of tree.
Thinker K.F. Li <thinker@branda.to>
parents:
135
diff
changeset
|
1066 |
17
41f0907b27ac
Unittest for rdman_redraw_changed().
Thinker K.F. Li <thinker@branda.to>
parents:
16
diff
changeset
|
1067 static void reset_clip(redraw_man_t *rdman) { |
41f0907b27ac
Unittest for rdman_redraw_changed().
Thinker K.F. Li <thinker@branda.to>
parents:
16
diff
changeset
|
1068 } |
24
e598bc809c0f
No more flash when animation.
Thinker K.F. Li <thinker@branda.to>
parents:
23
diff
changeset
|
1069 |
e598bc809c0f
No more flash when animation.
Thinker K.F. Li <thinker@branda.to>
parents:
23
diff
changeset
|
1070 static void copy_cr_2_backend(redraw_man_t *rdman, int n_dirty_areas, |
e598bc809c0f
No more flash when animation.
Thinker K.F. Li <thinker@branda.to>
parents:
23
diff
changeset
|
1071 area_t **dirty_areas) { |
e598bc809c0f
No more flash when animation.
Thinker K.F. Li <thinker@branda.to>
parents:
23
diff
changeset
|
1072 } |
17
41f0907b27ac
Unittest for rdman_redraw_changed().
Thinker K.F. Li <thinker@branda.to>
parents:
16
diff
changeset
|
1073 #endif /* UNITTEST */ |
41f0907b27ac
Unittest for rdman_redraw_changed().
Thinker K.F. Li <thinker@branda.to>
parents:
16
diff
changeset
|
1074 |
139
1695a4b02b14
Members of coords are geos instead of shapes, now.
Thinker K.F. Li <thinker@branda.to>
parents:
138
diff
changeset
|
1075 static int is_geo_in_areas(geo_t *geo, |
138
9f4fc9ecfd1f
Make shapes and coords drawed in post-order of tree.
Thinker K.F. Li <thinker@branda.to>
parents:
135
diff
changeset
|
1076 int n_areas, |
9f4fc9ecfd1f
Make shapes and coords drawed in post-order of tree.
Thinker K.F. Li <thinker@branda.to>
parents:
135
diff
changeset
|
1077 area_t **areas) { |
9f4fc9ecfd1f
Make shapes and coords drawed in post-order of tree.
Thinker K.F. Li <thinker@branda.to>
parents:
135
diff
changeset
|
1078 int i; |
9f4fc9ecfd1f
Make shapes and coords drawed in post-order of tree.
Thinker K.F. Li <thinker@branda.to>
parents:
135
diff
changeset
|
1079 |
9f4fc9ecfd1f
Make shapes and coords drawed in post-order of tree.
Thinker K.F. Li <thinker@branda.to>
parents:
135
diff
changeset
|
1080 for(i = 0; i < n_areas; i++) { |
235 | 1081 if(areas_are_overlay(geo->cur_area, areas[i])) |
138
9f4fc9ecfd1f
Make shapes and coords drawed in post-order of tree.
Thinker K.F. Li <thinker@branda.to>
parents:
135
diff
changeset
|
1082 return 1; |
9f4fc9ecfd1f
Make shapes and coords drawed in post-order of tree.
Thinker K.F. Li <thinker@branda.to>
parents:
135
diff
changeset
|
1083 } |
9f4fc9ecfd1f
Make shapes and coords drawed in post-order of tree.
Thinker K.F. Li <thinker@branda.to>
parents:
135
diff
changeset
|
1084 return 0; |
9f4fc9ecfd1f
Make shapes and coords drawed in post-order of tree.
Thinker K.F. Li <thinker@branda.to>
parents:
135
diff
changeset
|
1085 } |
9f4fc9ecfd1f
Make shapes and coords drawed in post-order of tree.
Thinker K.F. Li <thinker@branda.to>
parents:
135
diff
changeset
|
1086 |
9f4fc9ecfd1f
Make shapes and coords drawed in post-order of tree.
Thinker K.F. Li <thinker@branda.to>
parents:
135
diff
changeset
|
1087 static void update_canvas_2_parent(redraw_man_t *rdman, coord_t *coord) { |
9f4fc9ecfd1f
Make shapes and coords drawed in post-order of tree.
Thinker K.F. Li <thinker@branda.to>
parents:
135
diff
changeset
|
1088 cairo_t *pcanvas, *canvas; |
9f4fc9ecfd1f
Make shapes and coords drawed in post-order of tree.
Thinker K.F. Li <thinker@branda.to>
parents:
135
diff
changeset
|
1089 cairo_surface_t *surface; |
9f4fc9ecfd1f
Make shapes and coords drawed in post-order of tree.
Thinker K.F. Li <thinker@branda.to>
parents:
135
diff
changeset
|
1090 |
9f4fc9ecfd1f
Make shapes and coords drawed in post-order of tree.
Thinker K.F. Li <thinker@branda.to>
parents:
135
diff
changeset
|
1091 if(coord == rdman->root_coord) |
9f4fc9ecfd1f
Make shapes and coords drawed in post-order of tree.
Thinker K.F. Li <thinker@branda.to>
parents:
135
diff
changeset
|
1092 return; |
9f4fc9ecfd1f
Make shapes and coords drawed in post-order of tree.
Thinker K.F. Li <thinker@branda.to>
parents:
135
diff
changeset
|
1093 |
9f4fc9ecfd1f
Make shapes and coords drawed in post-order of tree.
Thinker K.F. Li <thinker@branda.to>
parents:
135
diff
changeset
|
1094 canvas = coord->canvas; |
9f4fc9ecfd1f
Make shapes and coords drawed in post-order of tree.
Thinker K.F. Li <thinker@branda.to>
parents:
135
diff
changeset
|
1095 pcanvas = coord->parent->canvas; |
9f4fc9ecfd1f
Make shapes and coords drawed in post-order of tree.
Thinker K.F. Li <thinker@branda.to>
parents:
135
diff
changeset
|
1096 surface = cairo_get_target(canvas); |
9f4fc9ecfd1f
Make shapes and coords drawed in post-order of tree.
Thinker K.F. Li <thinker@branda.to>
parents:
135
diff
changeset
|
1097 cairo_set_source_surface(pcanvas, surface, 0, 0); |
9f4fc9ecfd1f
Make shapes and coords drawed in post-order of tree.
Thinker K.F. Li <thinker@branda.to>
parents:
135
diff
changeset
|
1098 cairo_paint_with_alpha(pcanvas, coord->opacity); |
9f4fc9ecfd1f
Make shapes and coords drawed in post-order of tree.
Thinker K.F. Li <thinker@branda.to>
parents:
135
diff
changeset
|
1099 } |
9f4fc9ecfd1f
Make shapes and coords drawed in post-order of tree.
Thinker K.F. Li <thinker@branda.to>
parents:
135
diff
changeset
|
1100 |
9f4fc9ecfd1f
Make shapes and coords drawed in post-order of tree.
Thinker K.F. Li <thinker@branda.to>
parents:
135
diff
changeset
|
1101 static int draw_coord_shapes_in_areas(redraw_man_t *rdman, |
9f4fc9ecfd1f
Make shapes and coords drawed in post-order of tree.
Thinker K.F. Li <thinker@branda.to>
parents:
135
diff
changeset
|
1102 coord_t *coord, |
9f4fc9ecfd1f
Make shapes and coords drawed in post-order of tree.
Thinker K.F. Li <thinker@branda.to>
parents:
135
diff
changeset
|
1103 int n_areas, |
9f4fc9ecfd1f
Make shapes and coords drawed in post-order of tree.
Thinker K.F. Li <thinker@branda.to>
parents:
135
diff
changeset
|
1104 area_t **areas) { |
9f4fc9ecfd1f
Make shapes and coords drawed in post-order of tree.
Thinker K.F. Li <thinker@branda.to>
parents:
135
diff
changeset
|
1105 int dirty = 0; |
9f4fc9ecfd1f
Make shapes and coords drawed in post-order of tree.
Thinker K.F. Li <thinker@branda.to>
parents:
135
diff
changeset
|
1106 int r; |
139
1695a4b02b14
Members of coords are geos instead of shapes, now.
Thinker K.F. Li <thinker@branda.to>
parents:
138
diff
changeset
|
1107 geo_t *member; |
138
9f4fc9ecfd1f
Make shapes and coords drawed in post-order of tree.
Thinker K.F. Li <thinker@branda.to>
parents:
135
diff
changeset
|
1108 coord_t *child; |
9f4fc9ecfd1f
Make shapes and coords drawed in post-order of tree.
Thinker K.F. Li <thinker@branda.to>
parents:
135
diff
changeset
|
1109 cairo_t *canvas; |
9f4fc9ecfd1f
Make shapes and coords drawed in post-order of tree.
Thinker K.F. Li <thinker@branda.to>
parents:
135
diff
changeset
|
1110 int mem_idx; |
9f4fc9ecfd1f
Make shapes and coords drawed in post-order of tree.
Thinker K.F. Li <thinker@branda.to>
parents:
135
diff
changeset
|
1111 |
160
147c93163ef0
Fix bug of tank that bullet is not hidden when go out the map.
Thinker K.F. Li <thinker@branda.to>
parents:
159
diff
changeset
|
1112 if(coord->flags & COF_HIDDEN) |
147c93163ef0
Fix bug of tank that bullet is not hidden when go out the map.
Thinker K.F. Li <thinker@branda.to>
parents:
159
diff
changeset
|
1113 return OK; |
147c93163ef0
Fix bug of tank that bullet is not hidden when go out the map.
Thinker K.F. Li <thinker@branda.to>
parents:
159
diff
changeset
|
1114 |
138
9f4fc9ecfd1f
Make shapes and coords drawed in post-order of tree.
Thinker K.F. Li <thinker@branda.to>
parents:
135
diff
changeset
|
1115 canvas = coord->canvas; |
140
0de8fd11271e
Use macro to simplify the code.
Thinker K.F. Li <thinker@branda.to>
parents:
139
diff
changeset
|
1116 member = FIRST_MEMBER(coord); |
138
9f4fc9ecfd1f
Make shapes and coords drawed in post-order of tree.
Thinker K.F. Li <thinker@branda.to>
parents:
135
diff
changeset
|
1117 mem_idx = 0; |
140
0de8fd11271e
Use macro to simplify the code.
Thinker K.F. Li <thinker@branda.to>
parents:
139
diff
changeset
|
1118 child = FIRST_CHILD(coord); |
138
9f4fc9ecfd1f
Make shapes and coords drawed in post-order of tree.
Thinker K.F. Li <thinker@branda.to>
parents:
135
diff
changeset
|
1119 while(child != NULL || member != NULL) { |
9f4fc9ecfd1f
Make shapes and coords drawed in post-order of tree.
Thinker K.F. Li <thinker@branda.to>
parents:
135
diff
changeset
|
1120 if(child && child->before_pmem == mem_idx) { |
9f4fc9ecfd1f
Make shapes and coords drawed in post-order of tree.
Thinker K.F. Li <thinker@branda.to>
parents:
135
diff
changeset
|
1121 r = draw_coord_shapes_in_areas(rdman, child, n_areas, areas); |
9f4fc9ecfd1f
Make shapes and coords drawed in post-order of tree.
Thinker K.F. Li <thinker@branda.to>
parents:
135
diff
changeset
|
1122 dirty |= r; |
140
0de8fd11271e
Use macro to simplify the code.
Thinker K.F. Li <thinker@branda.to>
parents:
139
diff
changeset
|
1123 child = NEXT_CHILD(child); |
138
9f4fc9ecfd1f
Make shapes and coords drawed in post-order of tree.
Thinker K.F. Li <thinker@branda.to>
parents:
135
diff
changeset
|
1124 } else { |
9f4fc9ecfd1f
Make shapes and coords drawed in post-order of tree.
Thinker K.F. Li <thinker@branda.to>
parents:
135
diff
changeset
|
1125 ASSERT(member != NULL); |
150
0824f4804ee0
Fix bug of broken coord_hide() and shape_hide().
Thinker K.F. Li <thinker@branda.to>
parents:
148
diff
changeset
|
1126 if((!(member->flags & GEF_HIDDEN)) && |
0824f4804ee0
Fix bug of broken coord_hide() and shape_hide().
Thinker K.F. Li <thinker@branda.to>
parents:
148
diff
changeset
|
1127 is_geo_in_areas(member, n_areas, areas)) { |
139
1695a4b02b14
Members of coords are geos instead of shapes, now.
Thinker K.F. Li <thinker@branda.to>
parents:
138
diff
changeset
|
1128 draw_shape(rdman, canvas, member->shape); |
138
9f4fc9ecfd1f
Make shapes and coords drawed in post-order of tree.
Thinker K.F. Li <thinker@branda.to>
parents:
135
diff
changeset
|
1129 dirty = 1; |
9f4fc9ecfd1f
Make shapes and coords drawed in post-order of tree.
Thinker K.F. Li <thinker@branda.to>
parents:
135
diff
changeset
|
1130 } |
160
147c93163ef0
Fix bug of tank that bullet is not hidden when go out the map.
Thinker K.F. Li <thinker@branda.to>
parents:
159
diff
changeset
|
1131 |
140
0de8fd11271e
Use macro to simplify the code.
Thinker K.F. Li <thinker@branda.to>
parents:
139
diff
changeset
|
1132 member = NEXT_MEMBER(member); |
139
1695a4b02b14
Members of coords are geos instead of shapes, now.
Thinker K.F. Li <thinker@branda.to>
parents:
138
diff
changeset
|
1133 mem_idx++; |
138
9f4fc9ecfd1f
Make shapes and coords drawed in post-order of tree.
Thinker K.F. Li <thinker@branda.to>
parents:
135
diff
changeset
|
1134 } |
9f4fc9ecfd1f
Make shapes and coords drawed in post-order of tree.
Thinker K.F. Li <thinker@branda.to>
parents:
135
diff
changeset
|
1135 } |
9f4fc9ecfd1f
Make shapes and coords drawed in post-order of tree.
Thinker K.F. Li <thinker@branda.to>
parents:
135
diff
changeset
|
1136 |
9f4fc9ecfd1f
Make shapes and coords drawed in post-order of tree.
Thinker K.F. Li <thinker@branda.to>
parents:
135
diff
changeset
|
1137 if(dirty && coord->flags & COF_OWN_CANVAS) { |
9f4fc9ecfd1f
Make shapes and coords drawed in post-order of tree.
Thinker K.F. Li <thinker@branda.to>
parents:
135
diff
changeset
|
1138 update_canvas_2_parent(rdman, coord); |
9f4fc9ecfd1f
Make shapes and coords drawed in post-order of tree.
Thinker K.F. Li <thinker@branda.to>
parents:
135
diff
changeset
|
1139 clean_canvas_black(coord->canvas); |
9f4fc9ecfd1f
Make shapes and coords drawed in post-order of tree.
Thinker K.F. Li <thinker@branda.to>
parents:
135
diff
changeset
|
1140 } |
9f4fc9ecfd1f
Make shapes and coords drawed in post-order of tree.
Thinker K.F. Li <thinker@branda.to>
parents:
135
diff
changeset
|
1141 |
9f4fc9ecfd1f
Make shapes and coords drawed in post-order of tree.
Thinker K.F. Li <thinker@branda.to>
parents:
135
diff
changeset
|
1142 return dirty; |
9f4fc9ecfd1f
Make shapes and coords drawed in post-order of tree.
Thinker K.F. Li <thinker@branda.to>
parents:
135
diff
changeset
|
1143 } |
9f4fc9ecfd1f
Make shapes and coords drawed in post-order of tree.
Thinker K.F. Li <thinker@branda.to>
parents:
135
diff
changeset
|
1144 |
22 | 1145 static void draw_shapes_in_areas(redraw_man_t *rdman, |
15
c2ce186a5c37
X_main uses rdman_redraw_all()
Thinker K.F. Li <thinker@branda.to>
parents:
14
diff
changeset
|
1146 int n_areas, |
c2ce186a5c37
X_main uses rdman_redraw_all()
Thinker K.F. Li <thinker@branda.to>
parents:
14
diff
changeset
|
1147 area_t **areas) { |
138
9f4fc9ecfd1f
Make shapes and coords drawed in post-order of tree.
Thinker K.F. Li <thinker@branda.to>
parents:
135
diff
changeset
|
1148 draw_coord_shapes_in_areas(rdman, rdman->root_coord, n_areas, areas); |
13 | 1149 } |
1150 | |
24
e598bc809c0f
No more flash when animation.
Thinker K.F. Li <thinker@branda.to>
parents:
23
diff
changeset
|
1151 |
13 | 1152 /*! \brief Re-draw all changed shapes or shapes affected by changed coords. |
1153 * | |
1154 * A coord object has a geo to keep track the range that it's members will | |
1155 * draw on. Geo of a coord should be recomputed when the coord is changed. | |
1156 * Geo of a coord used to accelerate finding overlay shape objects of | |
1157 * a specified geo. A coord object also must be recomputed when one of | |
1158 * it's members is changed. | |
1159 * | |
1160 * New and old geo values of a coord object that is recomputed for | |
1161 * changing of it-self must be used to find overlay shape objects. | |
1162 * New and old geo values of a shape should also be used to find | |
1163 * overlay shape objects, too. If a shape's coord is changed, shape's | |
1164 * geo object is not used to find overlay shape objects any more. | |
1165 * | |
1166 * steps: | |
1167 * - update chagned coord objects | |
14 | 1168 * - recompute area for changed coord objects |
13 | 1169 * - recompute geo for members shape objects |
14 | 1170 * - clear dirty of geo for members to prevent from |
1171 * recomputing for change of shape objects. | |
1172 * - add old and new area value to list of dirty areas. | |
13 | 1173 * - recompute geo for changed shape objects |
14 | 1174 * - only if a shape object is dirty. |
1175 * - put new and old value of area of geo to list of dirty areas. | |
1176 * - Scan all shapes and redraw shapes overlaid with dirty areas. | |
13 | 1177 * |
14 | 1178 * dirty flag of coord objects is cleared after update. |
15
c2ce186a5c37
X_main uses rdman_redraw_all()
Thinker K.F. Li <thinker@branda.to>
parents:
14
diff
changeset
|
1179 * dirty flag of geo objects is also cleared after recomputing. |
c2ce186a5c37
X_main uses rdman_redraw_all()
Thinker K.F. Li <thinker@branda.to>
parents:
14
diff
changeset
|
1180 * Clean dirty flag can prevent redundant computing for geo and |
c2ce186a5c37
X_main uses rdman_redraw_all()
Thinker K.F. Li <thinker@branda.to>
parents:
14
diff
changeset
|
1181 * corod objects. |
14 | 1182 * |
13 | 1183 */ |
1184 int rdman_redraw_changed(redraw_man_t *rdman) { | |
28 | 1185 int r; |
13 | 1186 int n_dirty_areas; |
14 | 1187 area_t **dirty_areas; |
154 | 1188 event_t event; |
1189 subject_t *redraw; | |
13 | 1190 |
29 | 1191 r = clean_rdman_dirties(rdman); |
16
e17e12b112c4
A simple animation using rdman_redraw_changed().
Thinker K.F. Li <thinker@branda.to>
parents:
15
diff
changeset
|
1192 if(r != OK) |
e17e12b112c4
A simple animation using rdman_redraw_changed().
Thinker K.F. Li <thinker@branda.to>
parents:
15
diff
changeset
|
1193 return ERR; |
13 | 1194 |
158
c1cdd3fcd28f
Postponing rdman_coord_free() and rdman_remove_shape().
Thinker K.F. Li <thinker@branda.to>
parents:
154
diff
changeset
|
1195 n_dirty_areas = rdman->dirty_areas.num; |
c1cdd3fcd28f
Postponing rdman_coord_free() and rdman_remove_shape().
Thinker K.F. Li <thinker@branda.to>
parents:
154
diff
changeset
|
1196 dirty_areas = rdman->dirty_areas.ds; |
15
c2ce186a5c37
X_main uses rdman_redraw_all()
Thinker K.F. Li <thinker@branda.to>
parents:
14
diff
changeset
|
1197 if(n_dirty_areas > 0) { |
135 | 1198 /*! \brief Draw shapes in preorder of coord tree and support opacity |
1199 * rules. | |
1200 */ | |
25
29937c26bb01
Fix bug of a dark line appear when animating.
Thinker K.F. Li <thinker@branda.to>
parents:
24
diff
changeset
|
1201 clean_canvas(rdman->cr); |
22 | 1202 draw_shapes_in_areas(rdman, n_dirty_areas, dirty_areas); |
158
c1cdd3fcd28f
Postponing rdman_coord_free() and rdman_remove_shape().
Thinker K.F. Li <thinker@branda.to>
parents:
154
diff
changeset
|
1203 copy_cr_2_backend(rdman, rdman->dirty_areas.num, |
c1cdd3fcd28f
Postponing rdman_coord_free() and rdman_remove_shape().
Thinker K.F. Li <thinker@branda.to>
parents:
154
diff
changeset
|
1204 rdman->dirty_areas.ds); |
17
41f0907b27ac
Unittest for rdman_redraw_changed().
Thinker K.F. Li <thinker@branda.to>
parents:
16
diff
changeset
|
1205 reset_clip(rdman); |
15
c2ce186a5c37
X_main uses rdman_redraw_all()
Thinker K.F. Li <thinker@branda.to>
parents:
14
diff
changeset
|
1206 } |
158
c1cdd3fcd28f
Postponing rdman_coord_free() and rdman_remove_shape().
Thinker K.F. Li <thinker@branda.to>
parents:
154
diff
changeset
|
1207 rdman->dirty_areas.num = 0; |
c1cdd3fcd28f
Postponing rdman_coord_free() and rdman_remove_shape().
Thinker K.F. Li <thinker@branda.to>
parents:
154
diff
changeset
|
1208 |
c1cdd3fcd28f
Postponing rdman_coord_free() and rdman_remove_shape().
Thinker K.F. Li <thinker@branda.to>
parents:
154
diff
changeset
|
1209 /* Free postponsed removing */ |
159
b90abd31a281
Postponse free of coords, shapes, and paints when the rdman is dirty.
Thinker K.F. Li <thinker@branda.to>
parents:
158
diff
changeset
|
1210 free_free_objs(rdman); |
16
e17e12b112c4
A simple animation using rdman_redraw_changed().
Thinker K.F. Li <thinker@branda.to>
parents:
15
diff
changeset
|
1211 |
154 | 1212 redraw = rdman_get_redraw_subject(rdman); |
1213 event.type = EVT_RDMAN_REDRAW; | |
1214 event.tgt = event.cur_tgt = redraw; | |
192
54fdc2a65242
Remove factory from observer APIs.
Thinker K.F. Li <thinker@branda.to>
parents:
189
diff
changeset
|
1215 subject_notify(redraw, &event); |
154 | 1216 |
15
c2ce186a5c37
X_main uses rdman_redraw_all()
Thinker K.F. Li <thinker@branda.to>
parents:
14
diff
changeset
|
1217 return OK; |
c2ce186a5c37
X_main uses rdman_redraw_all()
Thinker K.F. Li <thinker@branda.to>
parents:
14
diff
changeset
|
1218 } |
c2ce186a5c37
X_main uses rdman_redraw_all()
Thinker K.F. Li <thinker@branda.to>
parents:
14
diff
changeset
|
1219 |
38 | 1220 /* NOTE: Before redrawing, the canvas/surface must be cleaned. |
1221 * NOTE: After redrawing, the content must be copied to the backend surface. | |
1222 */ | |
1223 | |
138
9f4fc9ecfd1f
Make shapes and coords drawed in post-order of tree.
Thinker K.F. Li <thinker@branda.to>
parents:
135
diff
changeset
|
1224 /*! \page redraw How to Redraw Shapes? |
9f4fc9ecfd1f
Make shapes and coords drawed in post-order of tree.
Thinker K.F. Li <thinker@branda.to>
parents:
135
diff
changeset
|
1225 * |
9f4fc9ecfd1f
Make shapes and coords drawed in post-order of tree.
Thinker K.F. Li <thinker@branda.to>
parents:
135
diff
changeset
|
1226 * Coords are corresponding objects for group tags of SVG files. |
9f4fc9ecfd1f
Make shapes and coords drawed in post-order of tree.
Thinker K.F. Li <thinker@branda.to>
parents:
135
diff
changeset
|
1227 * In conceptional, every SVG group has a canvas, graphics of child shapes |
9f4fc9ecfd1f
Make shapes and coords drawed in post-order of tree.
Thinker K.F. Li <thinker@branda.to>
parents:
135
diff
changeset
|
1228 * are drawed into the canvas, applied filters of group, and blended into |
9f4fc9ecfd1f
Make shapes and coords drawed in post-order of tree.
Thinker K.F. Li <thinker@branda.to>
parents:
135
diff
changeset
|
1229 * canvas of parent of the group. |
9f4fc9ecfd1f
Make shapes and coords drawed in post-order of tree.
Thinker K.F. Li <thinker@branda.to>
parents:
135
diff
changeset
|
1230 * |
9f4fc9ecfd1f
Make shapes and coords drawed in post-order of tree.
Thinker K.F. Li <thinker@branda.to>
parents:
135
diff
changeset
|
1231 * But, we don't need to create actually a surface/canvas for every coord. |
9f4fc9ecfd1f
Make shapes and coords drawed in post-order of tree.
Thinker K.F. Li <thinker@branda.to>
parents:
135
diff
changeset
|
1232 * We only create surface for coords their opacity value are not 1 or they |
9f4fc9ecfd1f
Make shapes and coords drawed in post-order of tree.
Thinker K.F. Li <thinker@branda.to>
parents:
135
diff
changeset
|
1233 * apply filters on background. Child shapes of coords without canvas |
9f4fc9ecfd1f
Make shapes and coords drawed in post-order of tree.
Thinker K.F. Li <thinker@branda.to>
parents:
135
diff
changeset
|
1234 * are drawed on canvas of nearest ancestor which have canvas. It said |
9f4fc9ecfd1f
Make shapes and coords drawed in post-order of tree.
Thinker K.F. Li <thinker@branda.to>
parents:
135
diff
changeset
|
1235 * a coord owns a canvas or inherits from an ancestor. (\ref COF_OWN_CANVAS, |
9f4fc9ecfd1f
Make shapes and coords drawed in post-order of tree.
Thinker K.F. Li <thinker@branda.to>
parents:
135
diff
changeset
|
1236 * clean_coord()) Except, root_coord always owns a canvas. |
9f4fc9ecfd1f
Make shapes and coords drawed in post-order of tree.
Thinker K.F. Li <thinker@branda.to>
parents:
135
diff
changeset
|
1237 * |
9f4fc9ecfd1f
Make shapes and coords drawed in post-order of tree.
Thinker K.F. Li <thinker@branda.to>
parents:
135
diff
changeset
|
1238 * \note Default opacity of a coord is 1. |
9f4fc9ecfd1f
Make shapes and coords drawed in post-order of tree.
Thinker K.F. Li <thinker@branda.to>
parents:
135
diff
changeset
|
1239 * |
9f4fc9ecfd1f
Make shapes and coords drawed in post-order of tree.
Thinker K.F. Li <thinker@branda.to>
parents:
135
diff
changeset
|
1240 * \sa |
9f4fc9ecfd1f
Make shapes and coords drawed in post-order of tree.
Thinker K.F. Li <thinker@branda.to>
parents:
135
diff
changeset
|
1241 * - rdman_redraw_all() |
9f4fc9ecfd1f
Make shapes and coords drawed in post-order of tree.
Thinker K.F. Li <thinker@branda.to>
parents:
135
diff
changeset
|
1242 * - rdman_redraw_changed() |
158
c1cdd3fcd28f
Postponing rdman_coord_free() and rdman_remove_shape().
Thinker K.F. Li <thinker@branda.to>
parents:
154
diff
changeset
|
1243 * - draw_shapes_in_areas() |
138
9f4fc9ecfd1f
Make shapes and coords drawed in post-order of tree.
Thinker K.F. Li <thinker@branda.to>
parents:
135
diff
changeset
|
1244 */ |
9f4fc9ecfd1f
Make shapes and coords drawed in post-order of tree.
Thinker K.F. Li <thinker@branda.to>
parents:
135
diff
changeset
|
1245 |
15
c2ce186a5c37
X_main uses rdman_redraw_all()
Thinker K.F. Li <thinker@branda.to>
parents:
14
diff
changeset
|
1246 int rdman_redraw_all(redraw_man_t *rdman) { |
159
b90abd31a281
Postponse free of coords, shapes, and paints when the rdman is dirty.
Thinker K.F. Li <thinker@branda.to>
parents:
158
diff
changeset
|
1247 area_t area; |
b90abd31a281
Postponse free of coords, shapes, and paints when the rdman is dirty.
Thinker K.F. Li <thinker@branda.to>
parents:
158
diff
changeset
|
1248 #ifndef UNITTEST |
138
9f4fc9ecfd1f
Make shapes and coords drawed in post-order of tree.
Thinker K.F. Li <thinker@branda.to>
parents:
135
diff
changeset
|
1249 cairo_surface_t *surface; |
159
b90abd31a281
Postponse free of coords, shapes, and paints when the rdman is dirty.
Thinker K.F. Li <thinker@branda.to>
parents:
158
diff
changeset
|
1250 #endif |
29 | 1251 int r; |
15
c2ce186a5c37
X_main uses rdman_redraw_all()
Thinker K.F. Li <thinker@branda.to>
parents:
14
diff
changeset
|
1252 |
138
9f4fc9ecfd1f
Make shapes and coords drawed in post-order of tree.
Thinker K.F. Li <thinker@branda.to>
parents:
135
diff
changeset
|
1253 area.x = area.y = 0; |
9f4fc9ecfd1f
Make shapes and coords drawed in post-order of tree.
Thinker K.F. Li <thinker@branda.to>
parents:
135
diff
changeset
|
1254 #ifndef UNITTEST |
9f4fc9ecfd1f
Make shapes and coords drawed in post-order of tree.
Thinker K.F. Li <thinker@branda.to>
parents:
135
diff
changeset
|
1255 surface = cairo_get_target(rdman->cr); |
9f4fc9ecfd1f
Make shapes and coords drawed in post-order of tree.
Thinker K.F. Li <thinker@branda.to>
parents:
135
diff
changeset
|
1256 area.w = cairo_image_surface_get_width(surface); |
9f4fc9ecfd1f
Make shapes and coords drawed in post-order of tree.
Thinker K.F. Li <thinker@branda.to>
parents:
135
diff
changeset
|
1257 area.h = cairo_image_surface_get_height(surface); |
9f4fc9ecfd1f
Make shapes and coords drawed in post-order of tree.
Thinker K.F. Li <thinker@branda.to>
parents:
135
diff
changeset
|
1258 #else |
9f4fc9ecfd1f
Make shapes and coords drawed in post-order of tree.
Thinker K.F. Li <thinker@branda.to>
parents:
135
diff
changeset
|
1259 area.w = 1024; |
9f4fc9ecfd1f
Make shapes and coords drawed in post-order of tree.
Thinker K.F. Li <thinker@branda.to>
parents:
135
diff
changeset
|
1260 area.h = 1024; |
9f4fc9ecfd1f
Make shapes and coords drawed in post-order of tree.
Thinker K.F. Li <thinker@branda.to>
parents:
135
diff
changeset
|
1261 #endif |
9f4fc9ecfd1f
Make shapes and coords drawed in post-order of tree.
Thinker K.F. Li <thinker@branda.to>
parents:
135
diff
changeset
|
1262 add_dirty_area(rdman, &area); |
9f4fc9ecfd1f
Make shapes and coords drawed in post-order of tree.
Thinker K.F. Li <thinker@branda.to>
parents:
135
diff
changeset
|
1263 |
9f4fc9ecfd1f
Make shapes and coords drawed in post-order of tree.
Thinker K.F. Li <thinker@branda.to>
parents:
135
diff
changeset
|
1264 r = rdman_redraw_changed(rdman); |
29 | 1265 if(r != OK) |
1266 return ERR; | |
16
e17e12b112c4
A simple animation using rdman_redraw_changed().
Thinker K.F. Li <thinker@branda.to>
parents:
15
diff
changeset
|
1267 |
13 | 1268 return OK; |
12 | 1269 } |
1270 | |
37 | 1271 int rdman_redraw_area(redraw_man_t *rdman, co_aix x, co_aix y, |
1272 co_aix w, co_aix h) { | |
1273 area_t area; | |
1274 int r; | |
1275 | |
1276 area.x = x; | |
1277 area.y = y; | |
1278 area.w = w; | |
1279 area.h = h; | |
1280 add_dirty_area(rdman, &area); | |
1281 | |
1282 r = rdman_redraw_changed(rdman); | |
1283 | |
1284 return r; | |
1285 } | |
1286 | |
139
1695a4b02b14
Members of coords are geos instead of shapes, now.
Thinker K.F. Li <thinker@branda.to>
parents:
138
diff
changeset
|
1287 geo_t *rdman_geos(redraw_man_t *rdman, geo_t *last) { |
1695a4b02b14
Members of coords are geos instead of shapes, now.
Thinker K.F. Li <thinker@branda.to>
parents:
138
diff
changeset
|
1288 geo_t *next; |
1695a4b02b14
Members of coords are geos instead of shapes, now.
Thinker K.F. Li <thinker@branda.to>
parents:
138
diff
changeset
|
1289 coord_t *coord; |
1695a4b02b14
Members of coords are geos instead of shapes, now.
Thinker K.F. Li <thinker@branda.to>
parents:
138
diff
changeset
|
1290 |
1695a4b02b14
Members of coords are geos instead of shapes, now.
Thinker K.F. Li <thinker@branda.to>
parents:
138
diff
changeset
|
1291 if(last == NULL) { |
1695a4b02b14
Members of coords are geos instead of shapes, now.
Thinker K.F. Li <thinker@branda.to>
parents:
138
diff
changeset
|
1292 coord = rdman->root_coord; |
140
0de8fd11271e
Use macro to simplify the code.
Thinker K.F. Li <thinker@branda.to>
parents:
139
diff
changeset
|
1293 while(coord != NULL && FIRST_MEMBER(coord) == NULL) |
139
1695a4b02b14
Members of coords are geos instead of shapes, now.
Thinker K.F. Li <thinker@branda.to>
parents:
138
diff
changeset
|
1294 coord = preorder_coord_subtree(rdman->root_coord, coord); |
1695a4b02b14
Members of coords are geos instead of shapes, now.
Thinker K.F. Li <thinker@branda.to>
parents:
138
diff
changeset
|
1295 if(coord == NULL) |
1695a4b02b14
Members of coords are geos instead of shapes, now.
Thinker K.F. Li <thinker@branda.to>
parents:
138
diff
changeset
|
1296 return NULL; |
140
0de8fd11271e
Use macro to simplify the code.
Thinker K.F. Li <thinker@branda.to>
parents:
139
diff
changeset
|
1297 return FIRST_MEMBER(coord); |
139
1695a4b02b14
Members of coords are geos instead of shapes, now.
Thinker K.F. Li <thinker@branda.to>
parents:
138
diff
changeset
|
1298 } |
1695a4b02b14
Members of coords are geos instead of shapes, now.
Thinker K.F. Li <thinker@branda.to>
parents:
138
diff
changeset
|
1299 |
1695a4b02b14
Members of coords are geos instead of shapes, now.
Thinker K.F. Li <thinker@branda.to>
parents:
138
diff
changeset
|
1300 coord = last->shape->coord; |
140
0de8fd11271e
Use macro to simplify the code.
Thinker K.F. Li <thinker@branda.to>
parents:
139
diff
changeset
|
1301 next = NEXT_MEMBER(last); |
139
1695a4b02b14
Members of coords are geos instead of shapes, now.
Thinker K.F. Li <thinker@branda.to>
parents:
138
diff
changeset
|
1302 while(next == NULL) { |
1695a4b02b14
Members of coords are geos instead of shapes, now.
Thinker K.F. Li <thinker@branda.to>
parents:
138
diff
changeset
|
1303 coord = preorder_coord_subtree(rdman->root_coord, coord); |
1695a4b02b14
Members of coords are geos instead of shapes, now.
Thinker K.F. Li <thinker@branda.to>
parents:
138
diff
changeset
|
1304 if(coord == NULL) |
1695a4b02b14
Members of coords are geos instead of shapes, now.
Thinker K.F. Li <thinker@branda.to>
parents:
138
diff
changeset
|
1305 return NULL; |
140
0de8fd11271e
Use macro to simplify the code.
Thinker K.F. Li <thinker@branda.to>
parents:
139
diff
changeset
|
1306 next = FIRST_MEMBER(coord); |
139
1695a4b02b14
Members of coords are geos instead of shapes, now.
Thinker K.F. Li <thinker@branda.to>
parents:
138
diff
changeset
|
1307 } |
1695a4b02b14
Members of coords are geos instead of shapes, now.
Thinker K.F. Li <thinker@branda.to>
parents:
138
diff
changeset
|
1308 return next; |
1695a4b02b14
Members of coords are geos instead of shapes, now.
Thinker K.F. Li <thinker@branda.to>
parents:
138
diff
changeset
|
1309 } |
1695a4b02b14
Members of coords are geos instead of shapes, now.
Thinker K.F. Li <thinker@branda.to>
parents:
138
diff
changeset
|
1310 |
30
e06a4a667ce2
Accept mouse/pointer event and hint the shape that the pointer is over.
Thinker K.F. Li <thinker@branda.to>
parents:
29
diff
changeset
|
1311 int rdman_force_clean(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:
29
diff
changeset
|
1312 int r; |
e06a4a667ce2
Accept mouse/pointer event and hint the shape that the pointer is over.
Thinker K.F. Li <thinker@branda.to>
parents:
29
diff
changeset
|
1313 |
e06a4a667ce2
Accept mouse/pointer event and hint the shape that the pointer is over.
Thinker K.F. Li <thinker@branda.to>
parents:
29
diff
changeset
|
1314 r = clean_rdman_dirties(rdman); |
e06a4a667ce2
Accept mouse/pointer event and hint the shape that the pointer is over.
Thinker K.F. Li <thinker@branda.to>
parents:
29
diff
changeset
|
1315 |
e06a4a667ce2
Accept mouse/pointer event and hint the shape that the pointer is over.
Thinker K.F. Li <thinker@branda.to>
parents:
29
diff
changeset
|
1316 return r; |
e06a4a667ce2
Accept mouse/pointer event and hint the shape that the pointer is over.
Thinker K.F. Li <thinker@branda.to>
parents:
29
diff
changeset
|
1317 } |
e06a4a667ce2
Accept mouse/pointer event and hint the shape that the pointer is over.
Thinker K.F. Li <thinker@branda.to>
parents:
29
diff
changeset
|
1318 |
135 | 1319 /*! \page dirty Dirty geo, coord, and area. |
1320 * | |
1321 * \section dirty_of_ego Dirty of geo | |
16
e17e12b112c4
A simple animation using rdman_redraw_changed().
Thinker K.F. Li <thinker@branda.to>
parents:
15
diff
changeset
|
1322 * A geo is dirty when any of the shape, size or positions is changed. |
e17e12b112c4
A simple animation using rdman_redraw_changed().
Thinker K.F. Li <thinker@branda.to>
parents:
15
diff
changeset
|
1323 * It's geo and positions should be recomputed before drawing. So, |
e17e12b112c4
A simple animation using rdman_redraw_changed().
Thinker K.F. Li <thinker@branda.to>
parents:
15
diff
changeset
|
1324 * dirty geos are marked as dirty and put into dirty_geos list. |
e17e12b112c4
A simple animation using rdman_redraw_changed().
Thinker K.F. Li <thinker@branda.to>
parents:
15
diff
changeset
|
1325 * The list is inspected before drawing to make sure the right shape, |
e17e12b112c4
A simple animation using rdman_redraw_changed().
Thinker K.F. Li <thinker@branda.to>
parents:
15
diff
changeset
|
1326 * size, and positions. |
e17e12b112c4
A simple animation using rdman_redraw_changed().
Thinker K.F. Li <thinker@branda.to>
parents:
15
diff
changeset
|
1327 * |
135 | 1328 * \section dirty_of_coord Dirty of coord |
16
e17e12b112c4
A simple animation using rdman_redraw_changed().
Thinker K.F. Li <thinker@branda.to>
parents:
15
diff
changeset
|
1329 * A coord is dirty when it's transformation matrix being changed. |
e17e12b112c4
A simple animation using rdman_redraw_changed().
Thinker K.F. Li <thinker@branda.to>
parents:
15
diff
changeset
|
1330 * Dirty coords are marked as dirty and put into dirty_coords list. |
e17e12b112c4
A simple animation using rdman_redraw_changed().
Thinker K.F. Li <thinker@branda.to>
parents:
15
diff
changeset
|
1331 * Once a coord is dirty, every member geos of it are also dirty. |
e17e12b112c4
A simple animation using rdman_redraw_changed().
Thinker K.F. Li <thinker@branda.to>
parents:
15
diff
changeset
|
1332 * Because, their shape, size and positions will be changed. But, |
e17e12b112c4
A simple animation using rdman_redraw_changed().
Thinker K.F. Li <thinker@branda.to>
parents:
15
diff
changeset
|
1333 * they are not marked as dirty and put into dirty_geos list, since |
e17e12b112c4
A simple animation using rdman_redraw_changed().
Thinker K.F. Li <thinker@branda.to>
parents:
15
diff
changeset
|
1334 * all these member geos will be recomputed for computing new current |
e17e12b112c4
A simple animation using rdman_redraw_changed().
Thinker K.F. Li <thinker@branda.to>
parents:
15
diff
changeset
|
1335 * area of the coord. The changes of a coord also affect child |
e17e12b112c4
A simple animation using rdman_redraw_changed().
Thinker K.F. Li <thinker@branda.to>
parents:
15
diff
changeset
|
1336 * coords. Once parent is dirty, all children are also dirty for |
e17e12b112c4
A simple animation using rdman_redraw_changed().
Thinker K.F. Li <thinker@branda.to>
parents:
15
diff
changeset
|
1337 * their aggregate matrix out of date. Dirty coords should be |
e17e12b112c4
A simple animation using rdman_redraw_changed().
Thinker K.F. Li <thinker@branda.to>
parents:
15
diff
changeset
|
1338 * clean in preorder of tree traversal. The dirty_coords list |
e17e12b112c4
A simple animation using rdman_redraw_changed().
Thinker K.F. Li <thinker@branda.to>
parents:
15
diff
changeset
|
1339 * are sorted to keep the order before cleaning. |
e17e12b112c4
A simple animation using rdman_redraw_changed().
Thinker K.F. Li <thinker@branda.to>
parents:
15
diff
changeset
|
1340 * Whenever a coord is marked dirty and put into dirty_coords list, |
e17e12b112c4
A simple animation using rdman_redraw_changed().
Thinker K.F. Li <thinker@branda.to>
parents:
15
diff
changeset
|
1341 * all it's children should also be marked and put. |
e17e12b112c4
A simple animation using rdman_redraw_changed().
Thinker K.F. Li <thinker@branda.to>
parents:
15
diff
changeset
|
1342 * |
e17e12b112c4
A simple animation using rdman_redraw_changed().
Thinker K.F. Li <thinker@branda.to>
parents:
15
diff
changeset
|
1343 * The procedure of clean coords comprises recomputing aggregate |
e17e12b112c4
A simple animation using rdman_redraw_changed().
Thinker K.F. Li <thinker@branda.to>
parents:
15
diff
changeset
|
1344 * tranform matrix and area where members spreading in. |
e17e12b112c4
A simple animation using rdman_redraw_changed().
Thinker K.F. Li <thinker@branda.to>
parents:
15
diff
changeset
|
1345 * |
e17e12b112c4
A simple animation using rdman_redraw_changed().
Thinker K.F. Li <thinker@branda.to>
parents:
15
diff
changeset
|
1346 * The list is inspected before drawing to recompute new shape, size, |
e17e12b112c4
A simple animation using rdman_redraw_changed().
Thinker K.F. Li <thinker@branda.to>
parents:
15
diff
changeset
|
1347 * and positions of member geos of coords in the list. The drity |
e17e12b112c4
A simple animation using rdman_redraw_changed().
Thinker K.F. Li <thinker@branda.to>
parents:
15
diff
changeset
|
1348 * flag of member geos will be clean. |
e17e12b112c4
A simple animation using rdman_redraw_changed().
Thinker K.F. Li <thinker@branda.to>
parents:
15
diff
changeset
|
1349 * |
e17e12b112c4
A simple animation using rdman_redraw_changed().
Thinker K.F. Li <thinker@branda.to>
parents:
15
diff
changeset
|
1350 * Clean coords should be performed before clean geos, since clean |
e17e12b112c4
A simple animation using rdman_redraw_changed().
Thinker K.F. Li <thinker@branda.to>
parents:
15
diff
changeset
|
1351 * coords will also clean member geos. |
e17e12b112c4
A simple animation using rdman_redraw_changed().
Thinker K.F. Li <thinker@branda.to>
parents:
15
diff
changeset
|
1352 */ |
e17e12b112c4
A simple animation using rdman_redraw_changed().
Thinker K.F. Li <thinker@branda.to>
parents:
15
diff
changeset
|
1353 |
159
b90abd31a281
Postponse free of coords, shapes, and paints when the rdman is dirty.
Thinker K.F. Li <thinker@branda.to>
parents:
158
diff
changeset
|
1354 /*! \page man_obj Manage Objects. |
b90abd31a281
Postponse free of coords, shapes, and paints when the rdman is dirty.
Thinker K.F. Li <thinker@branda.to>
parents:
158
diff
changeset
|
1355 * |
b90abd31a281
Postponse free of coords, shapes, and paints when the rdman is dirty.
Thinker K.F. Li <thinker@branda.to>
parents:
158
diff
changeset
|
1356 * Shapes and paints should also be managed by redraw manager. Redraw |
b90abd31a281
Postponse free of coords, shapes, and paints when the rdman is dirty.
Thinker K.F. Li <thinker@branda.to>
parents:
158
diff
changeset
|
1357 * manager must know life-cycle of shapes and paints to avoid to use them |
b90abd31a281
Postponse free of coords, shapes, and paints when the rdman is dirty.
Thinker K.F. Li <thinker@branda.to>
parents:
158
diff
changeset
|
1358 * after being free. If a shape is released when it is dirty, redraw |
b90abd31a281
Postponse free of coords, shapes, and paints when the rdman is dirty.
Thinker K.F. Li <thinker@branda.to>
parents:
158
diff
changeset
|
1359 * manager will try to access them, after released, for redrawing. |
b90abd31a281
Postponse free of coords, shapes, and paints when the rdman is dirty.
Thinker K.F. Li <thinker@branda.to>
parents:
158
diff
changeset
|
1360 * We can make a copy information need by redraw manager to redraw them, |
b90abd31a281
Postponse free of coords, shapes, and paints when the rdman is dirty.
Thinker K.F. Li <thinker@branda.to>
parents:
158
diff
changeset
|
1361 * but it is more complicate, and induce runtime overhead. |
b90abd31a281
Postponse free of coords, shapes, and paints when the rdman is dirty.
Thinker K.F. Li <thinker@branda.to>
parents:
158
diff
changeset
|
1362 * |
b90abd31a281
Postponse free of coords, shapes, and paints when the rdman is dirty.
Thinker K.F. Li <thinker@branda.to>
parents:
158
diff
changeset
|
1363 * So, redraw manage had better also manage life-cycle of shapes and paints. |
b90abd31a281
Postponse free of coords, shapes, and paints when the rdman is dirty.
Thinker K.F. Li <thinker@branda.to>
parents:
158
diff
changeset
|
1364 * Shapes and paints should be created and freed through interfaces |
b90abd31a281
Postponse free of coords, shapes, and paints when the rdman is dirty.
Thinker K.F. Li <thinker@branda.to>
parents:
158
diff
changeset
|
1365 * provided by redraw manager. To reduce overhead of interfaces, they can |
b90abd31a281
Postponse free of coords, shapes, and paints when the rdman is dirty.
Thinker K.F. Li <thinker@branda.to>
parents:
158
diff
changeset
|
1366 * be implemented as C macros. |
b90abd31a281
Postponse free of coords, shapes, and paints when the rdman is dirty.
Thinker K.F. Li <thinker@branda.to>
parents:
158
diff
changeset
|
1367 * |
b90abd31a281
Postponse free of coords, shapes, and paints when the rdman is dirty.
Thinker K.F. Li <thinker@branda.to>
parents:
158
diff
changeset
|
1368 * To refactory redraw manage to manage life-cycle of shapes and paints, |
b90abd31a281
Postponse free of coords, shapes, and paints when the rdman is dirty.
Thinker K.F. Li <thinker@branda.to>
parents:
158
diff
changeset
|
1369 * following functions/macros are introduced. |
b90abd31a281
Postponse free of coords, shapes, and paints when the rdman is dirty.
Thinker K.F. Li <thinker@branda.to>
parents:
158
diff
changeset
|
1370 * - rdman_paint_*_new() |
b90abd31a281
Postponse free of coords, shapes, and paints when the rdman is dirty.
Thinker K.F. Li <thinker@branda.to>
parents:
158
diff
changeset
|
1371 * - rdman_paint_free() |
b90abd31a281
Postponse free of coords, shapes, and paints when the rdman is dirty.
Thinker K.F. Li <thinker@branda.to>
parents:
158
diff
changeset
|
1372 * - rdman_shape_*_new() |
b90abd31a281
Postponse free of coords, shapes, and paints when the rdman is dirty.
Thinker K.F. Li <thinker@branda.to>
parents:
158
diff
changeset
|
1373 * - rdman_shape_free() |
b90abd31a281
Postponse free of coords, shapes, and paints when the rdman is dirty.
Thinker K.F. Li <thinker@branda.to>
parents:
158
diff
changeset
|
1374 */ |
b90abd31a281
Postponse free of coords, shapes, and paints when the rdman is dirty.
Thinker K.F. Li <thinker@branda.to>
parents:
158
diff
changeset
|
1375 |
16
e17e12b112c4
A simple animation using rdman_redraw_changed().
Thinker K.F. Li <thinker@branda.to>
parents:
15
diff
changeset
|
1376 /* |
12 | 1377 * When redraw an area, the affected elements may also extend to |
1378 * outside of the area. Since the order of drawing will change | |
1379 * the result, it will infect more and more elements to keep | |
1380 * drawing order althrough they are overlaid directly with | |
1381 * specified area. | |
1382 * | |
1383 * To fix the problem, we don't extend the set of redrawing to | |
1384 * elements they are not overliad directly. The redrawing is | |
1385 * performed on a temporary surface, clipped to fit the area, and | |
1386 * update only specified area on the destinate surface. | |
1387 */ | |
1388 | |
1389 /* | |
1390 * To accelerate speed of transformation, when a matrix changed, | |
1391 * transformation should be aggregated and computed in a loop. | |
1392 * It can get intereset of higher hit rate of cache. | |
1393 * - shapes prvoide list of positions needed to be transformed. | |
1394 * - redraw_man transforms positions from shapes. | |
1395 * - shapes drawing with result of transforms. | |
1396 * - shapes should be called to give them a chance to update geometries. | |
1397 */ | |
1398 | |
13 | 1399 /* |
1400 * functions: | |
1401 * - redraw all | |
1402 * - redraw changed | |
1403 */ | |
1404 | |
73
9ab15ebc9061
Observer for mouse events
Thinker K.F. Li <thinker@branda.to>
parents:
58
diff
changeset
|
1405 /* Implment factory and strategy functions for observers and subjects. |
9ab15ebc9061
Observer for mouse events
Thinker K.F. Li <thinker@branda.to>
parents:
58
diff
changeset
|
1406 */ |
9ab15ebc9061
Observer for mouse events
Thinker K.F. Li <thinker@branda.to>
parents:
58
diff
changeset
|
1407 static subject_t *ob_subject_alloc(ob_factory_t *factory) { |
9ab15ebc9061
Observer for mouse events
Thinker K.F. Li <thinker@branda.to>
parents:
58
diff
changeset
|
1408 redraw_man_t *rdman; |
9ab15ebc9061
Observer for mouse events
Thinker K.F. Li <thinker@branda.to>
parents:
58
diff
changeset
|
1409 subject_t *subject; |
9ab15ebc9061
Observer for mouse events
Thinker K.F. Li <thinker@branda.to>
parents:
58
diff
changeset
|
1410 |
9ab15ebc9061
Observer for mouse events
Thinker K.F. Li <thinker@branda.to>
parents:
58
diff
changeset
|
1411 rdman = MEM2OBJ(factory, redraw_man_t, ob_factory); |
9ab15ebc9061
Observer for mouse events
Thinker K.F. Li <thinker@branda.to>
parents:
58
diff
changeset
|
1412 subject = elmpool_elm_alloc(rdman->subject_pool); |
9ab15ebc9061
Observer for mouse events
Thinker K.F. Li <thinker@branda.to>
parents:
58
diff
changeset
|
1413 |
9ab15ebc9061
Observer for mouse events
Thinker K.F. Li <thinker@branda.to>
parents:
58
diff
changeset
|
1414 return subject; |
9ab15ebc9061
Observer for mouse events
Thinker K.F. Li <thinker@branda.to>
parents:
58
diff
changeset
|
1415 } |
9ab15ebc9061
Observer for mouse events
Thinker K.F. Li <thinker@branda.to>
parents:
58
diff
changeset
|
1416 |
9ab15ebc9061
Observer for mouse events
Thinker K.F. Li <thinker@branda.to>
parents:
58
diff
changeset
|
1417 static void ob_subject_free(ob_factory_t *factory, subject_t *subject) { |
9ab15ebc9061
Observer for mouse events
Thinker K.F. Li <thinker@branda.to>
parents:
58
diff
changeset
|
1418 redraw_man_t *rdman; |
9ab15ebc9061
Observer for mouse events
Thinker K.F. Li <thinker@branda.to>
parents:
58
diff
changeset
|
1419 |
9ab15ebc9061
Observer for mouse events
Thinker K.F. Li <thinker@branda.to>
parents:
58
diff
changeset
|
1420 rdman = MEM2OBJ(factory, redraw_man_t, ob_factory); |
9ab15ebc9061
Observer for mouse events
Thinker K.F. Li <thinker@branda.to>
parents:
58
diff
changeset
|
1421 elmpool_elm_free(rdman->subject_pool, subject); |
9ab15ebc9061
Observer for mouse events
Thinker K.F. Li <thinker@branda.to>
parents:
58
diff
changeset
|
1422 } |
9ab15ebc9061
Observer for mouse events
Thinker K.F. Li <thinker@branda.to>
parents:
58
diff
changeset
|
1423 |
9ab15ebc9061
Observer for mouse events
Thinker K.F. Li <thinker@branda.to>
parents:
58
diff
changeset
|
1424 static observer_t *ob_observer_alloc(ob_factory_t *factory) { |
9ab15ebc9061
Observer for mouse events
Thinker K.F. Li <thinker@branda.to>
parents:
58
diff
changeset
|
1425 redraw_man_t *rdman; |
9ab15ebc9061
Observer for mouse events
Thinker K.F. Li <thinker@branda.to>
parents:
58
diff
changeset
|
1426 observer_t *observer; |
9ab15ebc9061
Observer for mouse events
Thinker K.F. Li <thinker@branda.to>
parents:
58
diff
changeset
|
1427 |
9ab15ebc9061
Observer for mouse events
Thinker K.F. Li <thinker@branda.to>
parents:
58
diff
changeset
|
1428 rdman = MEM2OBJ(factory, redraw_man_t, ob_factory); |
9ab15ebc9061
Observer for mouse events
Thinker K.F. Li <thinker@branda.to>
parents:
58
diff
changeset
|
1429 observer = elmpool_elm_alloc(rdman->observer_pool); |
9ab15ebc9061
Observer for mouse events
Thinker K.F. Li <thinker@branda.to>
parents:
58
diff
changeset
|
1430 |
9ab15ebc9061
Observer for mouse events
Thinker K.F. Li <thinker@branda.to>
parents:
58
diff
changeset
|
1431 return observer; |
9ab15ebc9061
Observer for mouse events
Thinker K.F. Li <thinker@branda.to>
parents:
58
diff
changeset
|
1432 } |
9ab15ebc9061
Observer for mouse events
Thinker K.F. Li <thinker@branda.to>
parents:
58
diff
changeset
|
1433 |
9ab15ebc9061
Observer for mouse events
Thinker K.F. Li <thinker@branda.to>
parents:
58
diff
changeset
|
1434 static void ob_observer_free(ob_factory_t *factory, observer_t *observer) { |
9ab15ebc9061
Observer for mouse events
Thinker K.F. Li <thinker@branda.to>
parents:
58
diff
changeset
|
1435 redraw_man_t *rdman; |
9ab15ebc9061
Observer for mouse events
Thinker K.F. Li <thinker@branda.to>
parents:
58
diff
changeset
|
1436 |
9ab15ebc9061
Observer for mouse events
Thinker K.F. Li <thinker@branda.to>
parents:
58
diff
changeset
|
1437 rdman = MEM2OBJ(factory, redraw_man_t, ob_factory); |
9ab15ebc9061
Observer for mouse events
Thinker K.F. Li <thinker@branda.to>
parents:
58
diff
changeset
|
1438 elmpool_elm_free(rdman->observer_pool, observer); |
9ab15ebc9061
Observer for mouse events
Thinker K.F. Li <thinker@branda.to>
parents:
58
diff
changeset
|
1439 } |
9ab15ebc9061
Observer for mouse events
Thinker K.F. Li <thinker@branda.to>
parents:
58
diff
changeset
|
1440 |
9ab15ebc9061
Observer for mouse events
Thinker K.F. Li <thinker@branda.to>
parents:
58
diff
changeset
|
1441 static subject_t *ob_get_parent_subject(ob_factory_t *factory, |
9ab15ebc9061
Observer for mouse events
Thinker K.F. Li <thinker@branda.to>
parents:
58
diff
changeset
|
1442 subject_t *cur_subject) { |
9ab15ebc9061
Observer for mouse events
Thinker K.F. Li <thinker@branda.to>
parents:
58
diff
changeset
|
1443 redraw_man_t *rdman; |
79
5bcb329a5157
Fix bug of core dump caused by forget to check if parent is NULL, root.
Thinker K.F. Li <thinker@branda.to>
parents:
75
diff
changeset
|
1444 coord_t *coord, *parent_coord; |
73
9ab15ebc9061
Observer for mouse events
Thinker K.F. Li <thinker@branda.to>
parents:
58
diff
changeset
|
1445 geo_t *geo; |
9ab15ebc9061
Observer for mouse events
Thinker K.F. Li <thinker@branda.to>
parents:
58
diff
changeset
|
1446 subject_t *parent; |
9ab15ebc9061
Observer for mouse events
Thinker K.F. Li <thinker@branda.to>
parents:
58
diff
changeset
|
1447 |
9ab15ebc9061
Observer for mouse events
Thinker K.F. Li <thinker@branda.to>
parents:
58
diff
changeset
|
1448 rdman = MEM2OBJ(factory, redraw_man_t, ob_factory); |
9ab15ebc9061
Observer for mouse events
Thinker K.F. Li <thinker@branda.to>
parents:
58
diff
changeset
|
1449 switch(cur_subject->obj_type) { |
9ab15ebc9061
Observer for mouse events
Thinker K.F. Li <thinker@branda.to>
parents:
58
diff
changeset
|
1450 case OBJT_GEO: |
9ab15ebc9061
Observer for mouse events
Thinker K.F. Li <thinker@branda.to>
parents:
58
diff
changeset
|
1451 geo = (geo_t *)cur_subject->obj; |
79
5bcb329a5157
Fix bug of core dump caused by forget to check if parent is NULL, root.
Thinker K.F. Li <thinker@branda.to>
parents:
75
diff
changeset
|
1452 parent_coord = geo->shape->coord; |
5bcb329a5157
Fix bug of core dump caused by forget to check if parent is NULL, root.
Thinker K.F. Li <thinker@branda.to>
parents:
75
diff
changeset
|
1453 parent = parent_coord->mouse_event; |
73
9ab15ebc9061
Observer for mouse events
Thinker K.F. Li <thinker@branda.to>
parents:
58
diff
changeset
|
1454 break; |
9ab15ebc9061
Observer for mouse events
Thinker K.F. Li <thinker@branda.to>
parents:
58
diff
changeset
|
1455 case OBJT_COORD: |
9ab15ebc9061
Observer for mouse events
Thinker K.F. Li <thinker@branda.to>
parents:
58
diff
changeset
|
1456 coord = (coord_t *)cur_subject->obj; |
79
5bcb329a5157
Fix bug of core dump caused by forget to check if parent is NULL, root.
Thinker K.F. Li <thinker@branda.to>
parents:
75
diff
changeset
|
1457 parent_coord = coord->parent; |
5bcb329a5157
Fix bug of core dump caused by forget to check if parent is NULL, root.
Thinker K.F. Li <thinker@branda.to>
parents:
75
diff
changeset
|
1458 if(parent_coord == NULL) { |
5bcb329a5157
Fix bug of core dump caused by forget to check if parent is NULL, root.
Thinker K.F. Li <thinker@branda.to>
parents:
75
diff
changeset
|
1459 parent = NULL; |
5bcb329a5157
Fix bug of core dump caused by forget to check if parent is NULL, root.
Thinker K.F. Li <thinker@branda.to>
parents:
75
diff
changeset
|
1460 break; |
5bcb329a5157
Fix bug of core dump caused by forget to check if parent is NULL, root.
Thinker K.F. Li <thinker@branda.to>
parents:
75
diff
changeset
|
1461 } |
5bcb329a5157
Fix bug of core dump caused by forget to check if parent is NULL, root.
Thinker K.F. Li <thinker@branda.to>
parents:
75
diff
changeset
|
1462 parent = parent_coord->mouse_event; |
73
9ab15ebc9061
Observer for mouse events
Thinker K.F. Li <thinker@branda.to>
parents:
58
diff
changeset
|
1463 break; |
9ab15ebc9061
Observer for mouse events
Thinker K.F. Li <thinker@branda.to>
parents:
58
diff
changeset
|
1464 default: |
9ab15ebc9061
Observer for mouse events
Thinker K.F. Li <thinker@branda.to>
parents:
58
diff
changeset
|
1465 parent = NULL; |
9ab15ebc9061
Observer for mouse events
Thinker K.F. Li <thinker@branda.to>
parents:
58
diff
changeset
|
1466 break; |
9ab15ebc9061
Observer for mouse events
Thinker K.F. Li <thinker@branda.to>
parents:
58
diff
changeset
|
1467 } |
9ab15ebc9061
Observer for mouse events
Thinker K.F. Li <thinker@branda.to>
parents:
58
diff
changeset
|
1468 |
9ab15ebc9061
Observer for mouse events
Thinker K.F. Li <thinker@branda.to>
parents:
58
diff
changeset
|
1469 return parent; |
9ab15ebc9061
Observer for mouse events
Thinker K.F. Li <thinker@branda.to>
parents:
58
diff
changeset
|
1470 } |
9ab15ebc9061
Observer for mouse events
Thinker K.F. Li <thinker@branda.to>
parents:
58
diff
changeset
|
1471 |
12 | 1472 #ifdef UNITTEST |
73
9ab15ebc9061
Observer for mouse events
Thinker K.F. Li <thinker@branda.to>
parents:
58
diff
changeset
|
1473 /* Test cases */ |
12 | 1474 |
1475 #include <CUnit/Basic.h> | |
186
530bb7728546
Move header files to $(top_srcdir)/include/ and prefixed with 'mb_'.
Thinker K.F. Li <thinker@branda.to>
parents:
185
diff
changeset
|
1476 #include "mb_paint.h" |
12 | 1477 |
1478 struct _sh_dummy { | |
1479 shape_t shape; | |
1480 co_aix x, y; | |
1481 co_aix w, h; | |
119 | 1482 int trans_cnt; |
17
41f0907b27ac
Unittest for rdman_redraw_changed().
Thinker K.F. Li <thinker@branda.to>
parents:
16
diff
changeset
|
1483 int draw_cnt; |
12 | 1484 }; |
1485 | |
159
b90abd31a281
Postponse free of coords, shapes, and paints when the rdman is dirty.
Thinker K.F. Li <thinker@branda.to>
parents:
158
diff
changeset
|
1486 void sh_dummy_free(shape_t *sh) { |
b90abd31a281
Postponse free of coords, shapes, and paints when the rdman is dirty.
Thinker K.F. Li <thinker@branda.to>
parents:
158
diff
changeset
|
1487 free(sh); |
b90abd31a281
Postponse free of coords, shapes, and paints when the rdman is dirty.
Thinker K.F. Li <thinker@branda.to>
parents:
158
diff
changeset
|
1488 } |
b90abd31a281
Postponse free of coords, shapes, and paints when the rdman is dirty.
Thinker K.F. Li <thinker@branda.to>
parents:
158
diff
changeset
|
1489 |
b90abd31a281
Postponse free of coords, shapes, and paints when the rdman is dirty.
Thinker K.F. Li <thinker@branda.to>
parents:
158
diff
changeset
|
1490 shape_t *sh_dummy_new(redraw_man_t *rdman, |
b90abd31a281
Postponse free of coords, shapes, and paints when the rdman is dirty.
Thinker K.F. Li <thinker@branda.to>
parents:
158
diff
changeset
|
1491 co_aix x, co_aix y, co_aix w, co_aix h) { |
12 | 1492 sh_dummy_t *dummy; |
1493 | |
1494 dummy = (sh_dummy_t *)malloc(sizeof(sh_dummy_t)); | |
1495 if(dummy == NULL) | |
1496 return NULL; | |
1497 | |
17
41f0907b27ac
Unittest for rdman_redraw_changed().
Thinker K.F. Li <thinker@branda.to>
parents:
16
diff
changeset
|
1498 memset(dummy, 0, sizeof(sh_dummy_t)); |
41f0907b27ac
Unittest for rdman_redraw_changed().
Thinker K.F. Li <thinker@branda.to>
parents:
16
diff
changeset
|
1499 |
12 | 1500 dummy->x = x; |
1501 dummy->y = y; | |
1502 dummy->w = w; | |
1503 dummy->h = h; | |
119 | 1504 dummy->trans_cnt = 0; |
17
41f0907b27ac
Unittest for rdman_redraw_changed().
Thinker K.F. Li <thinker@branda.to>
parents:
16
diff
changeset
|
1505 dummy->draw_cnt = 0; |
159
b90abd31a281
Postponse free of coords, shapes, and paints when the rdman is dirty.
Thinker K.F. Li <thinker@branda.to>
parents:
158
diff
changeset
|
1506 dummy->shape.free = sh_dummy_free; |
224
29e1b2bffe4c
X backend only sent EVT_MOUSE_MOVE_RAW to MadButterfly.
Thinker K.F. Li <thinker@branda.to>
parents:
196
diff
changeset
|
1507 |
159
b90abd31a281
Postponse free of coords, shapes, and paints when the rdman is dirty.
Thinker K.F. Li <thinker@branda.to>
parents:
158
diff
changeset
|
1508 rdman_shape_man(rdman, (shape_t *)dummy); |
12 | 1509 |
1510 return (shape_t *)dummy; | |
1511 } | |
1512 | |
1513 void sh_dummy_transform(shape_t *shape) { | |
1514 sh_dummy_t *dummy = (sh_dummy_t *)shape; | |
1515 co_aix poses[2][2]; | |
1516 co_aix x1, y1, x2, y2; | |
1517 | |
1518 if(shape->geo && shape->coord) { | |
1519 x1 = dummy->x; | |
1520 y1 = dummy->y; | |
1521 x2 = x1 + dummy->w; | |
1522 y2 = y1 + dummy->h; | |
1523 | |
1524 coord_trans_pos(shape->coord, &x1, &y1); | |
1525 coord_trans_pos(shape->coord, &x2, &y2); | |
1526 poses[0][0] = x1; | |
1527 poses[0][1] = y1; | |
1528 poses[1][0] = x2; | |
1529 poses[1][1] = y2; | |
1530 | |
17
41f0907b27ac
Unittest for rdman_redraw_changed().
Thinker K.F. Li <thinker@branda.to>
parents:
16
diff
changeset
|
1531 if(shape->geo) |
41f0907b27ac
Unittest for rdman_redraw_changed().
Thinker K.F. Li <thinker@branda.to>
parents:
16
diff
changeset
|
1532 geo_from_positions(shape->geo, 2, poses); |
12 | 1533 } |
119 | 1534 dummy->trans_cnt++; |
12 | 1535 } |
1536 | |
20
74d3d5dc9aaa
rename XXX_draw() to XXX_fill()
Thinker K.F. Li <thinker@branda.to>
parents:
19
diff
changeset
|
1537 void sh_dummy_fill(shape_t *shape, cairo_t *cr) { |
17
41f0907b27ac
Unittest for rdman_redraw_changed().
Thinker K.F. Li <thinker@branda.to>
parents:
16
diff
changeset
|
1538 sh_dummy_t *dummy; |
41f0907b27ac
Unittest for rdman_redraw_changed().
Thinker K.F. Li <thinker@branda.to>
parents:
16
diff
changeset
|
1539 |
41f0907b27ac
Unittest for rdman_redraw_changed().
Thinker K.F. Li <thinker@branda.to>
parents:
16
diff
changeset
|
1540 dummy = (sh_dummy_t *)shape; |
41f0907b27ac
Unittest for rdman_redraw_changed().
Thinker K.F. Li <thinker@branda.to>
parents:
16
diff
changeset
|
1541 dummy->draw_cnt++; |
41f0907b27ac
Unittest for rdman_redraw_changed().
Thinker K.F. Li <thinker@branda.to>
parents:
16
diff
changeset
|
1542 } |
41f0907b27ac
Unittest for rdman_redraw_changed().
Thinker K.F. Li <thinker@branda.to>
parents:
16
diff
changeset
|
1543 |
19 | 1544 static void dummy_paint_prepare(paint_t *paint, cairo_t *cr) { |
1545 } | |
1546 | |
159
b90abd31a281
Postponse free of coords, shapes, and paints when the rdman is dirty.
Thinker K.F. Li <thinker@branda.to>
parents:
158
diff
changeset
|
1547 static void dummy_paint_free(redraw_man_t *rdman, paint_t *paint) { |
19 | 1548 if(paint) |
1549 free(paint); | |
1550 } | |
1551 | |
1552 paint_t *dummy_paint_new(redraw_man_t *rdman) { | |
1553 paint_t *paint; | |
1554 | |
1555 paint = (paint_t *)malloc(sizeof(paint_t)); | |
1556 if(paint == NULL) | |
1557 return NULL; | |
1558 | |
1559 paint_init(paint, dummy_paint_prepare, dummy_paint_free); | |
1560 | |
1561 return paint; | |
1562 } | |
1563 | |
159
b90abd31a281
Postponse free of coords, shapes, and paints when the rdman is dirty.
Thinker K.F. Li <thinker@branda.to>
parents:
158
diff
changeset
|
1564 static void test_rdman_redraw_changed(void) { |
17
41f0907b27ac
Unittest for rdman_redraw_changed().
Thinker K.F. Li <thinker@branda.to>
parents:
16
diff
changeset
|
1565 coord_t *coords[3]; |
41f0907b27ac
Unittest for rdman_redraw_changed().
Thinker K.F. Li <thinker@branda.to>
parents:
16
diff
changeset
|
1566 shape_t *shapes[3]; |
41f0907b27ac
Unittest for rdman_redraw_changed().
Thinker K.F. Li <thinker@branda.to>
parents:
16
diff
changeset
|
1567 sh_dummy_t **dummys; |
19 | 1568 paint_t *paint; |
17
41f0907b27ac
Unittest for rdman_redraw_changed().
Thinker K.F. Li <thinker@branda.to>
parents:
16
diff
changeset
|
1569 redraw_man_t *rdman; |
41f0907b27ac
Unittest for rdman_redraw_changed().
Thinker K.F. Li <thinker@branda.to>
parents:
16
diff
changeset
|
1570 redraw_man_t _rdman; |
41f0907b27ac
Unittest for rdman_redraw_changed().
Thinker K.F. Li <thinker@branda.to>
parents:
16
diff
changeset
|
1571 int i; |
41f0907b27ac
Unittest for rdman_redraw_changed().
Thinker K.F. Li <thinker@branda.to>
parents:
16
diff
changeset
|
1572 |
41f0907b27ac
Unittest for rdman_redraw_changed().
Thinker K.F. Li <thinker@branda.to>
parents:
16
diff
changeset
|
1573 dummys = (sh_dummy_t **)shapes; |
41f0907b27ac
Unittest for rdman_redraw_changed().
Thinker K.F. Li <thinker@branda.to>
parents:
16
diff
changeset
|
1574 |
41f0907b27ac
Unittest for rdman_redraw_changed().
Thinker K.F. Li <thinker@branda.to>
parents:
16
diff
changeset
|
1575 rdman = &_rdman; |
24
e598bc809c0f
No more flash when animation.
Thinker K.F. Li <thinker@branda.to>
parents:
23
diff
changeset
|
1576 redraw_man_init(rdman, NULL, NULL); |
19 | 1577 paint = dummy_paint_new(rdman); |
17
41f0907b27ac
Unittest for rdman_redraw_changed().
Thinker K.F. Li <thinker@branda.to>
parents:
16
diff
changeset
|
1578 for(i = 0; i < 3; i++) { |
159
b90abd31a281
Postponse free of coords, shapes, and paints when the rdman is dirty.
Thinker K.F. Li <thinker@branda.to>
parents:
158
diff
changeset
|
1579 shapes[i] = sh_dummy_new(rdman, 0, 0, 50, 50); |
19 | 1580 rdman_paint_fill(rdman, paint, shapes[i]); |
17
41f0907b27ac
Unittest for rdman_redraw_changed().
Thinker K.F. Li <thinker@branda.to>
parents:
16
diff
changeset
|
1581 coords[i] = rdman_coord_new(rdman, rdman->root_coord); |
41f0907b27ac
Unittest for rdman_redraw_changed().
Thinker K.F. Li <thinker@branda.to>
parents:
16
diff
changeset
|
1582 coords[i]->matrix[2] = 10 + i * 100; |
41f0907b27ac
Unittest for rdman_redraw_changed().
Thinker K.F. Li <thinker@branda.to>
parents:
16
diff
changeset
|
1583 coords[i]->matrix[5] = 10 + i * 100; |
41f0907b27ac
Unittest for rdman_redraw_changed().
Thinker K.F. Li <thinker@branda.to>
parents:
16
diff
changeset
|
1584 rdman_coord_changed(rdman, coords[i]); |
41f0907b27ac
Unittest for rdman_redraw_changed().
Thinker K.F. Li <thinker@branda.to>
parents:
16
diff
changeset
|
1585 rdman_add_shape(rdman, shapes[i], coords[i]); |
41f0907b27ac
Unittest for rdman_redraw_changed().
Thinker K.F. Li <thinker@branda.to>
parents:
16
diff
changeset
|
1586 } |
41f0907b27ac
Unittest for rdman_redraw_changed().
Thinker K.F. Li <thinker@branda.to>
parents:
16
diff
changeset
|
1587 rdman_redraw_all(rdman); |
119 | 1588 CU_ASSERT(dummys[0]->trans_cnt == 1); |
1589 CU_ASSERT(dummys[1]->trans_cnt == 1); | |
1590 CU_ASSERT(dummys[2]->trans_cnt == 1); | |
17
41f0907b27ac
Unittest for rdman_redraw_changed().
Thinker K.F. Li <thinker@branda.to>
parents:
16
diff
changeset
|
1591 CU_ASSERT(dummys[0]->draw_cnt == 1); |
41f0907b27ac
Unittest for rdman_redraw_changed().
Thinker K.F. Li <thinker@branda.to>
parents:
16
diff
changeset
|
1592 CU_ASSERT(dummys[1]->draw_cnt == 1); |
41f0907b27ac
Unittest for rdman_redraw_changed().
Thinker K.F. Li <thinker@branda.to>
parents:
16
diff
changeset
|
1593 CU_ASSERT(dummys[2]->draw_cnt == 1); |
41f0907b27ac
Unittest for rdman_redraw_changed().
Thinker K.F. Li <thinker@branda.to>
parents:
16
diff
changeset
|
1594 |
41f0907b27ac
Unittest for rdman_redraw_changed().
Thinker K.F. Li <thinker@branda.to>
parents:
16
diff
changeset
|
1595 coords[2]->matrix[2] = 100; |
41f0907b27ac
Unittest for rdman_redraw_changed().
Thinker K.F. Li <thinker@branda.to>
parents:
16
diff
changeset
|
1596 coords[2]->matrix[5] = 100; |
119 | 1597 rdman_coord_changed(rdman, coords[0]); |
17
41f0907b27ac
Unittest for rdman_redraw_changed().
Thinker K.F. Li <thinker@branda.to>
parents:
16
diff
changeset
|
1598 rdman_coord_changed(rdman, coords[2]); |
41f0907b27ac
Unittest for rdman_redraw_changed().
Thinker K.F. Li <thinker@branda.to>
parents:
16
diff
changeset
|
1599 rdman_redraw_changed(rdman); |
41f0907b27ac
Unittest for rdman_redraw_changed().
Thinker K.F. Li <thinker@branda.to>
parents:
16
diff
changeset
|
1600 |
119 | 1601 CU_ASSERT(dummys[0]->draw_cnt == 2); |
17
41f0907b27ac
Unittest for rdman_redraw_changed().
Thinker K.F. Li <thinker@branda.to>
parents:
16
diff
changeset
|
1602 CU_ASSERT(dummys[1]->draw_cnt == 2); |
41f0907b27ac
Unittest for rdman_redraw_changed().
Thinker K.F. Li <thinker@branda.to>
parents:
16
diff
changeset
|
1603 CU_ASSERT(dummys[2]->draw_cnt == 2); |
19 | 1604 |
159
b90abd31a281
Postponse free of coords, shapes, and paints when the rdman is dirty.
Thinker K.F. Li <thinker@branda.to>
parents:
158
diff
changeset
|
1605 rdman_paint_free(rdman, paint); |
19 | 1606 redraw_man_destroy(rdman); |
17
41f0907b27ac
Unittest for rdman_redraw_changed().
Thinker K.F. Li <thinker@branda.to>
parents:
16
diff
changeset
|
1607 } |
41f0907b27ac
Unittest for rdman_redraw_changed().
Thinker K.F. Li <thinker@branda.to>
parents:
16
diff
changeset
|
1608 |
159
b90abd31a281
Postponse free of coords, shapes, and paints when the rdman is dirty.
Thinker K.F. Li <thinker@branda.to>
parents:
158
diff
changeset
|
1609 static int test_free_pass = 0; |
b90abd31a281
Postponse free of coords, shapes, and paints when the rdman is dirty.
Thinker K.F. Li <thinker@branda.to>
parents:
158
diff
changeset
|
1610 |
b90abd31a281
Postponse free of coords, shapes, and paints when the rdman is dirty.
Thinker K.F. Li <thinker@branda.to>
parents:
158
diff
changeset
|
1611 static void test_free(redraw_man_t *rdman, void *obj) { |
b90abd31a281
Postponse free of coords, shapes, and paints when the rdman is dirty.
Thinker K.F. Li <thinker@branda.to>
parents:
158
diff
changeset
|
1612 test_free_pass++; |
b90abd31a281
Postponse free of coords, shapes, and paints when the rdman is dirty.
Thinker K.F. Li <thinker@branda.to>
parents:
158
diff
changeset
|
1613 } |
b90abd31a281
Postponse free of coords, shapes, and paints when the rdman is dirty.
Thinker K.F. Li <thinker@branda.to>
parents:
158
diff
changeset
|
1614 |
b90abd31a281
Postponse free of coords, shapes, and paints when the rdman is dirty.
Thinker K.F. Li <thinker@branda.to>
parents:
158
diff
changeset
|
1615 static void test_rdman_free_objs(void) { |
b90abd31a281
Postponse free of coords, shapes, and paints when the rdman is dirty.
Thinker K.F. Li <thinker@branda.to>
parents:
158
diff
changeset
|
1616 redraw_man_t *rdman; |
b90abd31a281
Postponse free of coords, shapes, and paints when the rdman is dirty.
Thinker K.F. Li <thinker@branda.to>
parents:
158
diff
changeset
|
1617 redraw_man_t _rdman; |
b90abd31a281
Postponse free of coords, shapes, and paints when the rdman is dirty.
Thinker K.F. Li <thinker@branda.to>
parents:
158
diff
changeset
|
1618 int i; |
b90abd31a281
Postponse free of coords, shapes, and paints when the rdman is dirty.
Thinker K.F. Li <thinker@branda.to>
parents:
158
diff
changeset
|
1619 |
b90abd31a281
Postponse free of coords, shapes, and paints when the rdman is dirty.
Thinker K.F. Li <thinker@branda.to>
parents:
158
diff
changeset
|
1620 redraw_man_init(&_rdman, NULL, NULL); |
b90abd31a281
Postponse free of coords, shapes, and paints when the rdman is dirty.
Thinker K.F. Li <thinker@branda.to>
parents:
158
diff
changeset
|
1621 rdman = &_rdman; |
b90abd31a281
Postponse free of coords, shapes, and paints when the rdman is dirty.
Thinker K.F. Li <thinker@branda.to>
parents:
158
diff
changeset
|
1622 |
b90abd31a281
Postponse free of coords, shapes, and paints when the rdman is dirty.
Thinker K.F. Li <thinker@branda.to>
parents:
158
diff
changeset
|
1623 test_free_pass = 0; |
b90abd31a281
Postponse free of coords, shapes, and paints when the rdman is dirty.
Thinker K.F. Li <thinker@branda.to>
parents:
158
diff
changeset
|
1624 |
b90abd31a281
Postponse free of coords, shapes, and paints when the rdman is dirty.
Thinker K.F. Li <thinker@branda.to>
parents:
158
diff
changeset
|
1625 for(i = 0; i < 4; i++) |
b90abd31a281
Postponse free of coords, shapes, and paints when the rdman is dirty.
Thinker K.F. Li <thinker@branda.to>
parents:
158
diff
changeset
|
1626 add_free_obj(rdman, NULL, test_free); |
b90abd31a281
Postponse free of coords, shapes, and paints when the rdman is dirty.
Thinker K.F. Li <thinker@branda.to>
parents:
158
diff
changeset
|
1627 |
b90abd31a281
Postponse free of coords, shapes, and paints when the rdman is dirty.
Thinker K.F. Li <thinker@branda.to>
parents:
158
diff
changeset
|
1628 redraw_man_destroy(rdman); |
b90abd31a281
Postponse free of coords, shapes, and paints when the rdman is dirty.
Thinker K.F. Li <thinker@branda.to>
parents:
158
diff
changeset
|
1629 CU_ASSERT(test_free_pass == 4); |
b90abd31a281
Postponse free of coords, shapes, and paints when the rdman is dirty.
Thinker K.F. Li <thinker@branda.to>
parents:
158
diff
changeset
|
1630 } |
b90abd31a281
Postponse free of coords, shapes, and paints when the rdman is dirty.
Thinker K.F. Li <thinker@branda.to>
parents:
158
diff
changeset
|
1631 |
12 | 1632 CU_pSuite get_redraw_man_suite(void) { |
1633 CU_pSuite suite; | |
1634 | |
1635 suite = CU_add_suite("Suite_redraw_man", NULL, NULL); | |
17
41f0907b27ac
Unittest for rdman_redraw_changed().
Thinker K.F. Li <thinker@branda.to>
parents:
16
diff
changeset
|
1636 CU_ADD_TEST(suite, test_rdman_redraw_changed); |
159
b90abd31a281
Postponse free of coords, shapes, and paints when the rdman is dirty.
Thinker K.F. Li <thinker@branda.to>
parents:
158
diff
changeset
|
1637 CU_ADD_TEST(suite, test_rdman_free_objs); |
12 | 1638 |
1639 return suite; | |
1640 } | |
1641 | |
1642 #endif /* UNITTEST */ |