annotate src/redraw_man.c @ 139:1695a4b02b14

Members of coords are geos instead of shapes, now.
author Thinker K.F. Li <thinker@branda.to>
date Mon, 22 Sep 2008 19:22:57 +0800
parents 9f4fc9ecfd1f
children 0de8fd11271e
rev   line source
12
79e9edf4c00a Add redraw manager
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
1 #include <stdio.h>
79e9edf4c00a Add redraw manager
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
2 #include <stdlib.h>
79e9edf4c00a Add redraw manager
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
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>
12
79e9edf4c00a Add redraw manager
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
5 #include "mb_types.h"
79e9edf4c00a Add redraw manager
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
6 #include "shapes.h"
79e9edf4c00a Add redraw manager
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
7 #include "tools.h"
79e9edf4c00a Add redraw manager
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
8 #include "redraw_man.h"
73
9ab15ebc9061 Observer for mouse events
Thinker K.F. Li <thinker@branda.to>
parents: 58
diff changeset
9 #include "observer.h"
9ab15ebc9061 Observer for mouse events
Thinker K.F. Li <thinker@branda.to>
parents: 58
diff changeset
10
12
79e9edf4c00a Add redraw manager
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
11
26
d50f33040de6 Set line width for path.
Thinker K.F. Li <thinker@branda.to>
parents: 25
diff changeset
12 /* 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
13 */
d50f33040de6 Set line width for path.
Thinker K.F. Li <thinker@branda.to>
parents: 25
diff changeset
14
12
79e9edf4c00a Add redraw manager
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
15 #define OK 0
79e9edf4c00a Add redraw manager
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
16 #define ERR -1
79e9edf4c00a Add redraw manager
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
17
139
1695a4b02b14 Members of coords are geos instead of shapes, now.
Thinker K.F. Li <thinker@branda.to>
parents: 138
diff changeset
18 #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
19
13
ed55009d96d3 refactory for redrawing
Thinker K.F. Li <thinker@branda.to>
parents: 12
diff changeset
20 #define SWAP(a, b, t) do { t c; c = a; a = b; b = c; } while(0)
ed55009d96d3 refactory for redrawing
Thinker K.F. Li <thinker@branda.to>
parents: 12
diff changeset
21
17
41f0907b27ac Unittest for rdman_redraw_changed().
Thinker K.F. Li <thinker@branda.to>
parents: 16
diff changeset
22 #ifdef UNITTEST
41f0907b27ac Unittest for rdman_redraw_changed().
Thinker K.F. Li <thinker@branda.to>
parents: 16
diff changeset
23 typedef struct _sh_dummy sh_dummy_t;
41f0907b27ac Unittest for rdman_redraw_changed().
Thinker K.F. Li <thinker@branda.to>
parents: 16
diff changeset
24
41f0907b27ac Unittest for rdman_redraw_changed().
Thinker K.F. Li <thinker@branda.to>
parents: 16
diff changeset
25 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
26 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
27 #endif /* UNITTEST */
41f0907b27ac Unittest for rdman_redraw_changed().
Thinker K.F. Li <thinker@branda.to>
parents: 16
diff changeset
28
73
9ab15ebc9061 Observer for mouse events
Thinker K.F. Li <thinker@branda.to>
parents: 58
diff changeset
29 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
30 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
31 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
32 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
33 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
34 subject_t *cur_subject);
9ab15ebc9061 Observer for mouse events
Thinker K.F. Li <thinker@branda.to>
parents: 58
diff changeset
35
9ab15ebc9061 Observer for mouse events
Thinker K.F. Li <thinker@branda.to>
parents: 58
diff changeset
36
16
e17e12b112c4 A simple animation using rdman_redraw_changed().
Thinker K.F. Li <thinker@branda.to>
parents: 15
diff changeset
37 /*! \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
38 *
e17e12b112c4 A simple animation using rdman_redraw_changed().
Thinker K.F. Li <thinker@branda.to>
parents: 15
diff changeset
39 * 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
40 * 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
41 */
e17e12b112c4 A simple animation using rdman_redraw_changed().
Thinker K.F. Li <thinker@branda.to>
parents: 15
diff changeset
42 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
43 int i, j;
e17e12b112c4 A simple animation using rdman_redraw_changed().
Thinker K.F. Li <thinker@branda.to>
parents: 15
diff changeset
44 unsigned int val;
121
76ba6fd61c7d More bug of insert sort.
Thinker K.F. Li <thinker@branda.to>
parents: 119
diff changeset
45 void *elm_i;
16
e17e12b112c4 A simple animation using rdman_redraw_changed().
Thinker K.F. Li <thinker@branda.to>
parents: 15
diff changeset
46
e17e12b112c4 A simple animation using rdman_redraw_changed().
Thinker K.F. Li <thinker@branda.to>
parents: 15
diff changeset
47 for(i = 1; i < num; i++) {
121
76ba6fd61c7d More bug of insert sort.
Thinker K.F. Li <thinker@branda.to>
parents: 119
diff changeset
48 elm_i = elms[i];
76ba6fd61c7d More bug of insert sort.
Thinker K.F. Li <thinker@branda.to>
parents: 119
diff changeset
49 val = *(unsigned int *)(elm_i + off);
119
257a1d314bcd Bug of insert sort
Thinker K.F. Li <thinker@branda.to>
parents: 115
diff changeset
50 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
51 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
52 break;
e17e12b112c4 A simple animation using rdman_redraw_changed().
Thinker K.F. Li <thinker@branda.to>
parents: 15
diff changeset
53 elms[j] = elms[j - 1];
e17e12b112c4 A simple animation using rdman_redraw_changed().
Thinker K.F. Li <thinker@branda.to>
parents: 15
diff changeset
54 }
121
76ba6fd61c7d More bug of insert sort.
Thinker K.F. Li <thinker@branda.to>
parents: 119
diff changeset
55 elms[j] = elm_i;
16
e17e12b112c4 A simple animation using rdman_redraw_changed().
Thinker K.F. Li <thinker@branda.to>
parents: 15
diff changeset
56 }
e17e12b112c4 A simple animation using rdman_redraw_changed().
Thinker K.F. Li <thinker@branda.to>
parents: 15
diff changeset
57 }
e17e12b112c4 A simple animation using rdman_redraw_changed().
Thinker K.F. Li <thinker@branda.to>
parents: 15
diff changeset
58
e17e12b112c4 A simple animation using rdman_redraw_changed().
Thinker K.F. Li <thinker@branda.to>
parents: 15
diff changeset
59 static int extend_memblk(void **buf, int o_size, int n_size) {
e17e12b112c4 A simple animation using rdman_redraw_changed().
Thinker K.F. Li <thinker@branda.to>
parents: 15
diff changeset
60 void *new_buf;
e17e12b112c4 A simple animation using rdman_redraw_changed().
Thinker K.F. Li <thinker@branda.to>
parents: 15
diff changeset
61
e17e12b112c4 A simple animation using rdman_redraw_changed().
Thinker K.F. Li <thinker@branda.to>
parents: 15
diff changeset
62 new_buf = realloc(*buf, n_size);
e17e12b112c4 A simple animation using rdman_redraw_changed().
Thinker K.F. Li <thinker@branda.to>
parents: 15
diff changeset
63 if(new_buf == NULL)
e17e12b112c4 A simple animation using rdman_redraw_changed().
Thinker K.F. Li <thinker@branda.to>
parents: 15
diff changeset
64 return ERR;
e17e12b112c4 A simple animation using rdman_redraw_changed().
Thinker K.F. Li <thinker@branda.to>
parents: 15
diff changeset
65
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
66 *buf = new_buf;
16
e17e12b112c4 A simple animation using rdman_redraw_changed().
Thinker K.F. Li <thinker@branda.to>
parents: 15
diff changeset
67
e17e12b112c4 A simple animation using rdman_redraw_changed().
Thinker K.F. Li <thinker@branda.to>
parents: 15
diff changeset
68 return OK;
e17e12b112c4 A simple animation using rdman_redraw_changed().
Thinker K.F. Li <thinker@branda.to>
parents: 15
diff changeset
69 }
e17e12b112c4 A simple animation using rdman_redraw_changed().
Thinker K.F. Li <thinker@branda.to>
parents: 15
diff changeset
70
e17e12b112c4 A simple animation using rdman_redraw_changed().
Thinker K.F. Li <thinker@branda.to>
parents: 15
diff changeset
71 static int add_dirty_geo(redraw_man_t *rdman, geo_t *geo) {
e17e12b112c4 A simple animation using rdman_redraw_changed().
Thinker K.F. Li <thinker@branda.to>
parents: 15
diff changeset
72 int max_dirty_geos;
e17e12b112c4 A simple animation using rdman_redraw_changed().
Thinker K.F. Li <thinker@branda.to>
parents: 15
diff changeset
73 int r;
e17e12b112c4 A simple animation using rdman_redraw_changed().
Thinker K.F. Li <thinker@branda.to>
parents: 15
diff changeset
74
e17e12b112c4 A simple animation using rdman_redraw_changed().
Thinker K.F. Li <thinker@branda.to>
parents: 15
diff changeset
75 if(rdman->n_dirty_geos >= rdman->max_dirty_geos) {
139
1695a4b02b14 Members of coords are geos instead of shapes, now.
Thinker K.F. Li <thinker@branda.to>
parents: 138
diff changeset
76 max_dirty_geos = rdman->max_dirty_geos + ARRAY_EXT_SZ;
16
e17e12b112c4 A simple animation using rdman_redraw_changed().
Thinker K.F. Li <thinker@branda.to>
parents: 15
diff changeset
77 r = extend_memblk((void **)&rdman->dirty_geos,
e17e12b112c4 A simple animation using rdman_redraw_changed().
Thinker K.F. Li <thinker@branda.to>
parents: 15
diff changeset
78 sizeof(geo_t *) * rdman->n_dirty_geos,
e17e12b112c4 A simple animation using rdman_redraw_changed().
Thinker K.F. Li <thinker@branda.to>
parents: 15
diff changeset
79 sizeof(geo_t *) * max_dirty_geos);
e17e12b112c4 A simple animation using rdman_redraw_changed().
Thinker K.F. Li <thinker@branda.to>
parents: 15
diff changeset
80 if(r != OK)
e17e12b112c4 A simple animation using rdman_redraw_changed().
Thinker K.F. Li <thinker@branda.to>
parents: 15
diff changeset
81 return ERR;
e17e12b112c4 A simple animation using rdman_redraw_changed().
Thinker K.F. Li <thinker@branda.to>
parents: 15
diff changeset
82 rdman->max_dirty_geos = max_dirty_geos;
e17e12b112c4 A simple animation using rdman_redraw_changed().
Thinker K.F. Li <thinker@branda.to>
parents: 15
diff changeset
83 }
e17e12b112c4 A simple animation using rdman_redraw_changed().
Thinker K.F. Li <thinker@branda.to>
parents: 15
diff changeset
84
e17e12b112c4 A simple animation using rdman_redraw_changed().
Thinker K.F. Li <thinker@branda.to>
parents: 15
diff changeset
85 rdman->dirty_geos[rdman->n_dirty_geos++] = geo;
e17e12b112c4 A simple animation using rdman_redraw_changed().
Thinker K.F. Li <thinker@branda.to>
parents: 15
diff changeset
86 return OK;
e17e12b112c4 A simple animation using rdman_redraw_changed().
Thinker K.F. Li <thinker@branda.to>
parents: 15
diff changeset
87 }
e17e12b112c4 A simple animation using rdman_redraw_changed().
Thinker K.F. Li <thinker@branda.to>
parents: 15
diff changeset
88
e17e12b112c4 A simple animation using rdman_redraw_changed().
Thinker K.F. Li <thinker@branda.to>
parents: 15
diff changeset
89 static int add_dirty_area(redraw_man_t *rdman, area_t *area) {
e17e12b112c4 A simple animation using rdman_redraw_changed().
Thinker K.F. Li <thinker@branda.to>
parents: 15
diff changeset
90 int max_dirty_areas;
e17e12b112c4 A simple animation using rdman_redraw_changed().
Thinker K.F. Li <thinker@branda.to>
parents: 15
diff changeset
91 int r;
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 if(rdman->n_dirty_areas >= rdman->max_dirty_areas) {
37
943acee7f346 update exposed area
Thinker K.F. Li <thinker@branda.to>
parents: 35
diff changeset
94 /* every geo object and coord object can contribute 2 areas.
943acee7f346 update exposed area
Thinker K.F. Li <thinker@branda.to>
parents: 35
diff changeset
95 * rdman_draw_area() may also contribute 1 area.
943acee7f346 update exposed area
Thinker K.F. Li <thinker@branda.to>
parents: 35
diff changeset
96 */
139
1695a4b02b14 Members of coords are geos instead of shapes, now.
Thinker K.F. Li <thinker@branda.to>
parents: 138
diff changeset
97 max_dirty_areas = rdman->max_dirty_areas + ARRAY_EXT_SZ;
16
e17e12b112c4 A simple animation using rdman_redraw_changed().
Thinker K.F. Li <thinker@branda.to>
parents: 15
diff changeset
98 r = extend_memblk((void **)&rdman->dirty_areas,
e17e12b112c4 A simple animation using rdman_redraw_changed().
Thinker K.F. Li <thinker@branda.to>
parents: 15
diff changeset
99 sizeof(area_t *) * rdman->n_dirty_areas,
e17e12b112c4 A simple animation using rdman_redraw_changed().
Thinker K.F. Li <thinker@branda.to>
parents: 15
diff changeset
100 sizeof(area_t *) * max_dirty_areas);
e17e12b112c4 A simple animation using rdman_redraw_changed().
Thinker K.F. Li <thinker@branda.to>
parents: 15
diff changeset
101 if(r != OK)
e17e12b112c4 A simple animation using rdman_redraw_changed().
Thinker K.F. Li <thinker@branda.to>
parents: 15
diff changeset
102 return ERR;
e17e12b112c4 A simple animation using rdman_redraw_changed().
Thinker K.F. Li <thinker@branda.to>
parents: 15
diff changeset
103 rdman->max_dirty_areas = max_dirty_areas;
e17e12b112c4 A simple animation using rdman_redraw_changed().
Thinker K.F. Li <thinker@branda.to>
parents: 15
diff changeset
104 }
e17e12b112c4 A simple animation using rdman_redraw_changed().
Thinker K.F. Li <thinker@branda.to>
parents: 15
diff changeset
105
e17e12b112c4 A simple animation using rdman_redraw_changed().
Thinker K.F. Li <thinker@branda.to>
parents: 15
diff changeset
106 rdman->dirty_areas[rdman->n_dirty_areas++] = area;
e17e12b112c4 A simple animation using rdman_redraw_changed().
Thinker K.F. Li <thinker@branda.to>
parents: 15
diff changeset
107 return OK;
e17e12b112c4 A simple animation using rdman_redraw_changed().
Thinker K.F. Li <thinker@branda.to>
parents: 15
diff changeset
108 }
e17e12b112c4 A simple animation using rdman_redraw_changed().
Thinker K.F. Li <thinker@branda.to>
parents: 15
diff changeset
109
17
41f0907b27ac Unittest for rdman_redraw_changed().
Thinker K.F. Li <thinker@branda.to>
parents: 16
diff changeset
110 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
111 poses[0][0] = area->x;
41f0907b27ac Unittest for rdman_redraw_changed().
Thinker K.F. Li <thinker@branda.to>
parents: 16
diff changeset
112 poses[0][1] = area->y;
41f0907b27ac Unittest for rdman_redraw_changed().
Thinker K.F. Li <thinker@branda.to>
parents: 16
diff changeset
113 poses[1][0] = area->x + area->w;
41f0907b27ac Unittest for rdman_redraw_changed().
Thinker K.F. Li <thinker@branda.to>
parents: 16
diff changeset
114 poses[1][1] = area->y + area->h;;
41f0907b27ac Unittest for rdman_redraw_changed().
Thinker K.F. Li <thinker@branda.to>
parents: 16
diff changeset
115 }
41f0907b27ac Unittest for rdman_redraw_changed().
Thinker K.F. Li <thinker@branda.to>
parents: 16
diff changeset
116
138
9f4fc9ecfd1f Make shapes and coords drawed in post-order of tree.
Thinker K.F. Li <thinker@branda.to>
parents: 135
diff changeset
117 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
118 #ifndef UNITTEST
9f4fc9ecfd1f Make shapes and coords drawed in post-order of tree.
Thinker K.F. Li <thinker@branda.to>
parents: 135
diff changeset
119 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
120 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
121 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
122
9f4fc9ecfd1f Make shapes and coords drawed in post-order of tree.
Thinker K.F. Li <thinker@branda.to>
parents: 135
diff changeset
123 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
124 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
125 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
126 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
127 w, h);
9f4fc9ecfd1f Make shapes and coords drawed in post-order of tree.
Thinker K.F. Li <thinker@branda.to>
parents: 135
diff changeset
128 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
129
9f4fc9ecfd1f Make shapes and coords drawed in post-order of tree.
Thinker K.F. Li <thinker@branda.to>
parents: 135
diff changeset
130 return cr;
9f4fc9ecfd1f Make shapes and coords drawed in post-order of tree.
Thinker K.F. Li <thinker@branda.to>
parents: 135
diff changeset
131 #else
9f4fc9ecfd1f Make shapes and coords drawed in post-order of tree.
Thinker K.F. Li <thinker@branda.to>
parents: 135
diff changeset
132 return NULL;
9f4fc9ecfd1f Make shapes and coords drawed in post-order of tree.
Thinker K.F. Li <thinker@branda.to>
parents: 135
diff changeset
133 #endif
9f4fc9ecfd1f Make shapes and coords drawed in post-order of tree.
Thinker K.F. Li <thinker@branda.to>
parents: 135
diff changeset
134 }
9f4fc9ecfd1f Make shapes and coords drawed in post-order of tree.
Thinker K.F. Li <thinker@branda.to>
parents: 135
diff changeset
135
9f4fc9ecfd1f Make shapes and coords drawed in post-order of tree.
Thinker K.F. Li <thinker@branda.to>
parents: 135
diff changeset
136 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
137 #ifndef UNITTEST
9f4fc9ecfd1f Make shapes and coords drawed in post-order of tree.
Thinker K.F. Li <thinker@branda.to>
parents: 135
diff changeset
138 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
139 #endif
9f4fc9ecfd1f Make shapes and coords drawed in post-order of tree.
Thinker K.F. Li <thinker@branda.to>
parents: 135
diff changeset
140 }
9f4fc9ecfd1f Make shapes and coords drawed in post-order of tree.
Thinker K.F. Li <thinker@branda.to>
parents: 135
diff changeset
141
24
e598bc809c0f No more flash when animation.
Thinker K.F. Li <thinker@branda.to>
parents: 23
diff changeset
142 int redraw_man_init(redraw_man_t *rdman, cairo_t *cr, cairo_t *backend) {
12
79e9edf4c00a Add redraw manager
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
143 extern void redraw_man_destroy(redraw_man_t *rdman);
79e9edf4c00a Add redraw manager
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
144
79e9edf4c00a Add redraw manager
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
145 memset(rdman, 0, sizeof(redraw_man_t));
79e9edf4c00a Add redraw manager
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
146
79e9edf4c00a Add redraw manager
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
147 rdman->geo_pool = elmpool_new(sizeof(geo_t), 128);
79e9edf4c00a Add redraw manager
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
148 if(rdman->geo_pool == NULL)
79e9edf4c00a Add redraw manager
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
149 return ERR;
79e9edf4c00a Add redraw manager
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
150
79e9edf4c00a Add redraw manager
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
151 rdman->coord_pool = elmpool_new(sizeof(coord_t), 16);
79e9edf4c00a Add redraw manager
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
152 if(rdman->coord_pool == NULL) {
79e9edf4c00a Add redraw manager
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
153 elmpool_free(rdman->geo_pool);
79e9edf4c00a Add redraw manager
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
154 return ERR;
79e9edf4c00a Add redraw manager
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
155 }
79e9edf4c00a Add redraw manager
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
156
18
0f3baa488a62 Support solid color paint for fill.
Thinker K.F. Li <thinker@branda.to>
parents: 17
diff changeset
157 rdman->shnode_pool = elmpool_new(sizeof(shnode_t), 16);
0f3baa488a62 Support solid color paint for fill.
Thinker K.F. Li <thinker@branda.to>
parents: 17
diff changeset
158 if(rdman->shnode_pool == NULL) {
0f3baa488a62 Support solid color paint for fill.
Thinker K.F. Li <thinker@branda.to>
parents: 17
diff changeset
159 elmpool_free(rdman->geo_pool);
0f3baa488a62 Support solid color paint for fill.
Thinker K.F. Li <thinker@branda.to>
parents: 17
diff changeset
160 elmpool_free(rdman->coord_pool);
0f3baa488a62 Support solid color paint for fill.
Thinker K.F. Li <thinker@branda.to>
parents: 17
diff changeset
161 return ERR;
0f3baa488a62 Support solid color paint for fill.
Thinker K.F. Li <thinker@branda.to>
parents: 17
diff changeset
162 }
0f3baa488a62 Support solid color paint for fill.
Thinker K.F. Li <thinker@branda.to>
parents: 17
diff changeset
163
75
23bc382d9683 find_geo_in_pos() should return shapes that is not hidden
Thinker K.F. Li <thinker@branda.to>
parents: 73
diff changeset
164 rdman->observer_pool = elmpool_new(sizeof(observer_t), 32);
73
9ab15ebc9061 Observer for mouse events
Thinker K.F. Li <thinker@branda.to>
parents: 58
diff changeset
165 if(rdman->observer_pool == NULL) {
9ab15ebc9061 Observer for mouse events
Thinker K.F. Li <thinker@branda.to>
parents: 58
diff changeset
166 elmpool_free(rdman->geo_pool);
9ab15ebc9061 Observer for mouse events
Thinker K.F. Li <thinker@branda.to>
parents: 58
diff changeset
167 elmpool_free(rdman->coord_pool);
9ab15ebc9061 Observer for mouse events
Thinker K.F. Li <thinker@branda.to>
parents: 58
diff changeset
168 elmpool_free(rdman->shnode_pool);
9ab15ebc9061 Observer for mouse events
Thinker K.F. Li <thinker@branda.to>
parents: 58
diff changeset
169 return ERR;
9ab15ebc9061 Observer for mouse events
Thinker K.F. Li <thinker@branda.to>
parents: 58
diff changeset
170 }
9ab15ebc9061 Observer for mouse events
Thinker K.F. Li <thinker@branda.to>
parents: 58
diff changeset
171
75
23bc382d9683 find_geo_in_pos() should return shapes that is not hidden
Thinker K.F. Li <thinker@branda.to>
parents: 73
diff changeset
172 rdman->subject_pool = elmpool_new(sizeof(subject_t), 32);
73
9ab15ebc9061 Observer for mouse events
Thinker K.F. Li <thinker@branda.to>
parents: 58
diff changeset
173 if(rdman->subject_pool == NULL) {
9ab15ebc9061 Observer for mouse events
Thinker K.F. Li <thinker@branda.to>
parents: 58
diff changeset
174 elmpool_free(rdman->geo_pool);
9ab15ebc9061 Observer for mouse events
Thinker K.F. Li <thinker@branda.to>
parents: 58
diff changeset
175 elmpool_free(rdman->coord_pool);
9ab15ebc9061 Observer for mouse events
Thinker K.F. Li <thinker@branda.to>
parents: 58
diff changeset
176 elmpool_free(rdman->shnode_pool);
9ab15ebc9061 Observer for mouse events
Thinker K.F. Li <thinker@branda.to>
parents: 58
diff changeset
177 elmpool_free(rdman->observer_pool);
9ab15ebc9061 Observer for mouse events
Thinker K.F. Li <thinker@branda.to>
parents: 58
diff changeset
178 return ERR;
9ab15ebc9061 Observer for mouse events
Thinker K.F. Li <thinker@branda.to>
parents: 58
diff changeset
179 }
9ab15ebc9061 Observer for mouse events
Thinker K.F. Li <thinker@branda.to>
parents: 58
diff changeset
180
9ab15ebc9061 Observer for mouse events
Thinker K.F. Li <thinker@branda.to>
parents: 58
diff changeset
181 rdman->ob_factory.subject_alloc = ob_subject_alloc;
9ab15ebc9061 Observer for mouse events
Thinker K.F. Li <thinker@branda.to>
parents: 58
diff changeset
182 rdman->ob_factory.subject_free = ob_subject_free;
9ab15ebc9061 Observer for mouse events
Thinker K.F. Li <thinker@branda.to>
parents: 58
diff changeset
183 rdman->ob_factory.observer_alloc = ob_observer_alloc;
9ab15ebc9061 Observer for mouse events
Thinker K.F. Li <thinker@branda.to>
parents: 58
diff changeset
184 rdman->ob_factory.observer_free = ob_observer_free;
9ab15ebc9061 Observer for mouse events
Thinker K.F. Li <thinker@branda.to>
parents: 58
diff changeset
185 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
186
12
79e9edf4c00a Add redraw manager
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
187 rdman->root_coord = elmpool_elm_alloc(rdman->coord_pool);
79e9edf4c00a Add redraw manager
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
188 if(rdman->root_coord == NULL)
79e9edf4c00a Add redraw manager
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
189 redraw_man_destroy(rdman);
13
ed55009d96d3 refactory for redrawing
Thinker K.F. Li <thinker@branda.to>
parents: 12
diff changeset
190 rdman->n_coords = 1;
12
79e9edf4c00a Add redraw manager
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
191 coord_init(rdman->root_coord, NULL);
73
9ab15ebc9061 Observer for mouse events
Thinker K.F. Li <thinker@branda.to>
parents: 58
diff changeset
192 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
193 rdman->root_coord,
9ab15ebc9061 Observer for mouse events
Thinker K.F. Li <thinker@branda.to>
parents: 58
diff changeset
194 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
195 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
196 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
197 rdman->root_coord->opacity = 1;
12
79e9edf4c00a Add redraw manager
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
198
15
c2ce186a5c37 X_main uses rdman_redraw_all()
Thinker K.F. Li <thinker@branda.to>
parents: 14
diff changeset
199 rdman->cr = cr;
24
e598bc809c0f No more flash when animation.
Thinker K.F. Li <thinker@branda.to>
parents: 23
diff changeset
200 rdman->backend = backend;
15
c2ce186a5c37 X_main uses rdman_redraw_all()
Thinker K.F. Li <thinker@branda.to>
parents: 14
diff changeset
201
12
79e9edf4c00a Add redraw manager
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
202 return OK;
79e9edf4c00a Add redraw manager
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
203 }
79e9edf4c00a Add redraw manager
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
204
79e9edf4c00a Add redraw manager
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
205 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
206 coord_t *coord, *saved_coord;
9f4fc9ecfd1f Make shapes and coords drawed in post-order of tree.
Thinker K.F. Li <thinker@branda.to>
parents: 135
diff changeset
207
9f4fc9ecfd1f Make shapes and coords drawed in post-order of tree.
Thinker K.F. Li <thinker@branda.to>
parents: 135
diff changeset
208 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
209 while(coord) {
9f4fc9ecfd1f Make shapes and coords drawed in post-order of tree.
Thinker K.F. Li <thinker@branda.to>
parents: 135
diff changeset
210 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
211 coord = postorder_coord_subtree(rdman->root_coord, coord);
9f4fc9ecfd1f Make shapes and coords drawed in post-order of tree.
Thinker K.F. Li <thinker@branda.to>
parents: 135
diff changeset
212 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
213 }
9f4fc9ecfd1f Make shapes and coords drawed in post-order of tree.
Thinker K.F. Li <thinker@branda.to>
parents: 135
diff changeset
214
12
79e9edf4c00a Add redraw manager
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
215 elmpool_free(rdman->coord_pool);
79e9edf4c00a Add redraw manager
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
216 elmpool_free(rdman->geo_pool);
18
0f3baa488a62 Support solid color paint for fill.
Thinker K.F. Li <thinker@branda.to>
parents: 17
diff changeset
217 elmpool_free(rdman->shnode_pool);
73
9ab15ebc9061 Observer for mouse events
Thinker K.F. Li <thinker@branda.to>
parents: 58
diff changeset
218 elmpool_free(rdman->observer_pool);
9ab15ebc9061 Observer for mouse events
Thinker K.F. Li <thinker@branda.to>
parents: 58
diff changeset
219 elmpool_free(rdman->subject_pool);
13
ed55009d96d3 refactory for redrawing
Thinker K.F. Li <thinker@branda.to>
parents: 12
diff changeset
220 if(rdman->dirty_coords)
ed55009d96d3 refactory for redrawing
Thinker K.F. Li <thinker@branda.to>
parents: 12
diff changeset
221 free(rdman->dirty_coords);
14
Thinker K.F. Li <thinker@branda.to>
parents: 13
diff changeset
222 if(rdman->dirty_geos)
Thinker K.F. Li <thinker@branda.to>
parents: 13
diff changeset
223 free(rdman->dirty_geos);
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
224 if(rdman->gen_geos)
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
225 free(rdman->gen_geos);
12
79e9edf4c00a Add redraw manager
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
226 }
79e9edf4c00a Add redraw manager
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
227
79e9edf4c00a Add redraw manager
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
228
79e9edf4c00a Add redraw manager
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
229 #define ASSERT(x)
79e9edf4c00a Add redraw manager
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
230 /*
79e9edf4c00a Add redraw manager
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
231 * Change transformation matrix
79e9edf4c00a Add redraw manager
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
232 * - update aggregated transformation matrix
79e9edf4c00a Add redraw manager
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
233 * - of coord_t object been changed.
79e9edf4c00a Add redraw manager
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
234 * - of children coord_t objects.
79e9edf4c00a Add redraw manager
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
235 * - redraw members of coord_t objects.
79e9edf4c00a Add redraw manager
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
236 * - redraw shape objects they are overlaid with members.
79e9edf4c00a Add redraw manager
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
237 * - find out overlaid shape objects.
79e9edf4c00a Add redraw manager
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
238 * - geo_t of a coord_t object
79e9edf4c00a Add redraw manager
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
239 * - can make finding more efficiency.
79e9edf4c00a Add redraw manager
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
240 * - fill overlay geo_t objects of members.
79e9edf4c00a Add redraw manager
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
241 *
79e9edf4c00a Add redraw manager
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
242 * Change a shape object
79e9edf4c00a Add redraw manager
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
243 * - redraw changed object.
79e9edf4c00a Add redraw manager
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
244 * - redraw shape objects they are overlaid with changed object.
79e9edf4c00a Add redraw manager
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
245 * - find out overlaid shape objects.
79e9edf4c00a Add redraw manager
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
246 *
79e9edf4c00a Add redraw manager
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
247 * That coord and geo of shape objects are setted by user code
79e9edf4c00a Add redraw manager
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
248 * give user code a chance to collect coord and geo objects together
79e9edf4c00a Add redraw manager
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
249 * and gain interest of higher cache hit rate.
79e9edf4c00a Add redraw manager
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
250 */
79e9edf4c00a Add redraw manager
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
251
79e9edf4c00a Add redraw manager
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
252 int rdman_add_shape(redraw_man_t *rdman, shape_t *shape, coord_t *coord) {
79e9edf4c00a Add redraw manager
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
253 geo_t *geo;
16
e17e12b112c4 A simple animation using rdman_redraw_changed().
Thinker K.F. Li <thinker@branda.to>
parents: 15
diff changeset
254 int r;
12
79e9edf4c00a Add redraw manager
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
255
79e9edf4c00a Add redraw manager
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
256 geo = elmpool_elm_alloc(rdman->geo_pool);
79e9edf4c00a Add redraw manager
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
257 if(geo == NULL)
79e9edf4c00a Add redraw manager
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
258 return ERR;
17
41f0907b27ac Unittest for rdman_redraw_changed().
Thinker K.F. Li <thinker@branda.to>
parents: 16
diff changeset
259
41f0907b27ac Unittest for rdman_redraw_changed().
Thinker K.F. Li <thinker@branda.to>
parents: 16
diff changeset
260 geo_init(geo);
73
9ab15ebc9061 Observer for mouse events
Thinker K.F. Li <thinker@branda.to>
parents: 58
diff changeset
261 geo->mouse_event = subject_new(&rdman->ob_factory, geo, OBJT_GEO);
17
41f0907b27ac Unittest for rdman_redraw_changed().
Thinker K.F. Li <thinker@branda.to>
parents: 16
diff changeset
262
139
1695a4b02b14 Members of coords are geos instead of shapes, now.
Thinker K.F. Li <thinker@branda.to>
parents: 138
diff changeset
263 STAILQ_INS_TAIL(coord->members, geo_t, coord_next, geo);
1695a4b02b14 Members of coords are geos instead of shapes, now.
Thinker K.F. Li <thinker@branda.to>
parents: 138
diff changeset
264 coord->num_members++;
16
e17e12b112c4 A simple animation using rdman_redraw_changed().
Thinker K.F. Li <thinker@branda.to>
parents: 15
diff changeset
265
e17e12b112c4 A simple animation using rdman_redraw_changed().
Thinker K.F. Li <thinker@branda.to>
parents: 15
diff changeset
266 /* New one should be dirty to recompute it when drawing. */
15
c2ce186a5c37 X_main uses rdman_redraw_all()
Thinker K.F. Li <thinker@branda.to>
parents: 14
diff changeset
267 geo->flags |= GEF_DIRTY;
16
e17e12b112c4 A simple animation using rdman_redraw_changed().
Thinker K.F. Li <thinker@branda.to>
parents: 15
diff changeset
268 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
269 if(r != OK)
e17e12b112c4 A simple animation using rdman_redraw_changed().
Thinker K.F. Li <thinker@branda.to>
parents: 15
diff changeset
270 return ERR;
13
ed55009d96d3 refactory for redrawing
Thinker K.F. Li <thinker@branda.to>
parents: 12
diff changeset
271
12
79e9edf4c00a Add redraw manager
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
272 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
273 sh_attach_geo(shape, geo);
12
79e9edf4c00a Add redraw manager
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
274
79e9edf4c00a Add redraw manager
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
275 return OK;
79e9edf4c00a Add redraw manager
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
276 }
79e9edf4c00a Add redraw manager
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
277
17
41f0907b27ac Unittest for rdman_redraw_changed().
Thinker K.F. Li <thinker@branda.to>
parents: 16
diff changeset
278 /*! \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
279 *
58
Thinker K.F. Li <thinker@branda.to>
parents: 57
diff changeset
280 * \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
281 */
12
79e9edf4c00a Add redraw manager
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
282 int rdman_remove_shape(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
283 geo_t *geo;
1695a4b02b14 Members of coords are geos instead of shapes, now.
Thinker K.F. Li <thinker@branda.to>
parents: 138
diff changeset
284 coord_t *coord;
1695a4b02b14 Members of coords are geos instead of shapes, now.
Thinker K.F. Li <thinker@branda.to>
parents: 138
diff changeset
285
1695a4b02b14 Members of coords are geos instead of shapes, now.
Thinker K.F. Li <thinker@branda.to>
parents: 138
diff changeset
286 geo = shape->geo;
1695a4b02b14 Members of coords are geos instead of shapes, now.
Thinker K.F. Li <thinker@branda.to>
parents: 138
diff changeset
287 coord = shape->coord;
1695a4b02b14 Members of coords are geos instead of shapes, now.
Thinker K.F. Li <thinker@branda.to>
parents: 138
diff changeset
288 STAILQ_REMOVE(coord->members, geo_t, coord_next, geo);
1695a4b02b14 Members of coords are geos instead of shapes, now.
Thinker K.F. Li <thinker@branda.to>
parents: 138
diff changeset
289 subject_free(&rdman->ob_factory, geo->mouse_event);
104
Thinker K.F. Li <thinker@branda.to>
parents: 85
diff changeset
290 sh_detach_geo(shape);
12
79e9edf4c00a Add redraw manager
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
291 elmpool_elm_free(rdman->geo_pool, shape->geo);
79e9edf4c00a Add redraw manager
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
292 sh_detach_coord(shape);
79e9edf4c00a Add redraw manager
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
293 return OK;
79e9edf4c00a Add redraw manager
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
294 }
79e9edf4c00a Add redraw manager
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
295
79e9edf4c00a Add redraw manager
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
296 coord_t *rdman_coord_new(redraw_man_t *rdman, coord_t *parent) {
13
ed55009d96d3 refactory for redrawing
Thinker K.F. Li <thinker@branda.to>
parents: 12
diff changeset
297 coord_t *coord, *root_coord;
ed55009d96d3 refactory for redrawing
Thinker K.F. Li <thinker@branda.to>
parents: 12
diff changeset
298 coord_t *visit;
12
79e9edf4c00a Add redraw manager
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
299
79e9edf4c00a Add redraw manager
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
300 coord = elmpool_elm_alloc(rdman->coord_pool);
79e9edf4c00a Add redraw manager
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
301 if(coord == NULL)
79e9edf4c00a Add redraw manager
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
302 return NULL;
79e9edf4c00a Add redraw manager
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
303
79e9edf4c00a Add redraw manager
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
304 coord_init(coord, parent);
73
9ab15ebc9061 Observer for mouse events
Thinker K.F. Li <thinker@branda.to>
parents: 58
diff changeset
305 coord->mouse_event = subject_new(&rdman->ob_factory,
9ab15ebc9061 Observer for mouse events
Thinker K.F. Li <thinker@branda.to>
parents: 58
diff changeset
306 coord,
9ab15ebc9061 Observer for mouse events
Thinker K.F. Li <thinker@branda.to>
parents: 58
diff changeset
307 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
308 /*! \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
309 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
310 if(parent)
9f4fc9ecfd1f Make shapes and coords drawed in post-order of tree.
Thinker K.F. Li <thinker@branda.to>
parents: 135
diff changeset
311 coord->canvas = parent->canvas;
13
ed55009d96d3 refactory for redrawing
Thinker K.F. Li <thinker@branda.to>
parents: 12
diff changeset
312 rdman->n_coords++;
ed55009d96d3 refactory for redrawing
Thinker K.F. Li <thinker@branda.to>
parents: 12
diff changeset
313
ed55009d96d3 refactory for redrawing
Thinker K.F. Li <thinker@branda.to>
parents: 12
diff changeset
314 coord->order = ++rdman->next_coord_order;
ed55009d96d3 refactory for redrawing
Thinker K.F. Li <thinker@branda.to>
parents: 12
diff changeset
315 if(coord->order == 0) {
ed55009d96d3 refactory for redrawing
Thinker K.F. Li <thinker@branda.to>
parents: 12
diff changeset
316 rdman->next_coord_order = 0;
ed55009d96d3 refactory for redrawing
Thinker K.F. Li <thinker@branda.to>
parents: 12
diff changeset
317 root_coord = visit = rdman->root_coord;
ed55009d96d3 refactory for redrawing
Thinker K.F. Li <thinker@branda.to>
parents: 12
diff changeset
318 /* skip root coord. */
ed55009d96d3 refactory for redrawing
Thinker K.F. Li <thinker@branda.to>
parents: 12
diff changeset
319 visit = preorder_coord_subtree(root_coord, visit);
ed55009d96d3 refactory for redrawing
Thinker K.F. Li <thinker@branda.to>
parents: 12
diff changeset
320 while(visit) {
ed55009d96d3 refactory for redrawing
Thinker K.F. Li <thinker@branda.to>
parents: 12
diff changeset
321 visit->order = ++rdman->next_coord_order;
ed55009d96d3 refactory for redrawing
Thinker K.F. Li <thinker@branda.to>
parents: 12
diff changeset
322 visit = preorder_coord_subtree(root_coord, visit);
ed55009d96d3 refactory for redrawing
Thinker K.F. Li <thinker@branda.to>
parents: 12
diff changeset
323 }
ed55009d96d3 refactory for redrawing
Thinker K.F. Li <thinker@branda.to>
parents: 12
diff changeset
324 }
12
79e9edf4c00a Add redraw manager
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
325
139
1695a4b02b14 Members of coords are geos instead of shapes, now.
Thinker K.F. Li <thinker@branda.to>
parents: 138
diff changeset
326 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
327
12
79e9edf4c00a Add redraw manager
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
328 return coord;
79e9edf4c00a Add redraw manager
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
329 }
79e9edf4c00a Add redraw manager
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
330
79e9edf4c00a Add redraw manager
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
331 /*! \brief Free a coord of a redraw_man_t object.
79e9edf4c00a Add redraw manager
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
332 *
79e9edf4c00a Add redraw manager
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
333 * \param coord is a coord_t without children and members.
79e9edf4c00a Add redraw manager
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
334 * \return 0 for successful, -1 for error.
79e9edf4c00a Add redraw manager
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
335 */
79e9edf4c00a Add redraw manager
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
336 int rdman_coord_free(redraw_man_t *rdman, coord_t *coord) {
79e9edf4c00a Add redraw manager
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
337 coord_t *parent;
79e9edf4c00a Add redraw manager
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
338
79e9edf4c00a Add redraw manager
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
339 parent = coord->parent;
79e9edf4c00a Add redraw manager
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
340 if(parent == NULL)
79e9edf4c00a Add redraw manager
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
341 return ERR;
79e9edf4c00a Add redraw manager
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
342
79e9edf4c00a Add redraw manager
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
343 if(STAILQ_HEAD(coord->members) != NULL)
79e9edf4c00a Add redraw manager
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
344 return ERR;
79e9edf4c00a Add redraw manager
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
345
79e9edf4c00a Add redraw manager
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
346 if(STAILQ_HEAD(coord->children) != NULL)
79e9edf4c00a Add redraw manager
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
347 return ERR;
79e9edf4c00a Add redraw manager
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
348
138
9f4fc9ecfd1f Make shapes and coords drawed in post-order of tree.
Thinker K.F. Li <thinker@branda.to>
parents: 135
diff changeset
349 /* 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
350 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
351 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
352
12
79e9edf4c00a Add redraw manager
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
353 STAILQ_REMOVE(parent->children, coord_t, sibling, coord);
73
9ab15ebc9061 Observer for mouse events
Thinker K.F. Li <thinker@branda.to>
parents: 58
diff changeset
354 subject_free(&rdman->ob_factory, coord->mouse_event);
12
79e9edf4c00a Add redraw manager
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
355 elmpool_elm_free(rdman->coord_pool, coord);
13
ed55009d96d3 refactory for redrawing
Thinker K.F. Li <thinker@branda.to>
parents: 12
diff changeset
356 rdman->n_coords--;
ed55009d96d3 refactory for redrawing
Thinker K.F. Li <thinker@branda.to>
parents: 12
diff changeset
357
ed55009d96d3 refactory for redrawing
Thinker K.F. Li <thinker@branda.to>
parents: 12
diff changeset
358 return OK;
ed55009d96d3 refactory for redrawing
Thinker K.F. Li <thinker@branda.to>
parents: 12
diff changeset
359 }
ed55009d96d3 refactory for redrawing
Thinker K.F. Li <thinker@branda.to>
parents: 12
diff changeset
360
85
9b4a02bcaeb1 matrix() function in transform attribute of group and shapes
Thinker K.F. Li <thinker@branda.to>
parents: 79
diff changeset
361 static void make_sure_dirty_coords(redraw_man_t *rdman) {
9b4a02bcaeb1 matrix() function in transform attribute of group and shapes
Thinker K.F. Li <thinker@branda.to>
parents: 79
diff changeset
362 int max_dirty_coords;
9b4a02bcaeb1 matrix() function in transform attribute of group and shapes
Thinker K.F. Li <thinker@branda.to>
parents: 79
diff changeset
363 int r;
9b4a02bcaeb1 matrix() function in transform attribute of group and shapes
Thinker K.F. Li <thinker@branda.to>
parents: 79
diff changeset
364
9b4a02bcaeb1 matrix() function in transform attribute of group and shapes
Thinker K.F. Li <thinker@branda.to>
parents: 79
diff changeset
365 if(rdman->n_dirty_coords >= rdman->max_dirty_coords) {
9b4a02bcaeb1 matrix() function in transform attribute of group and shapes
Thinker K.F. Li <thinker@branda.to>
parents: 79
diff changeset
366 /* Max of dirty_coords is not big enough. */
9b4a02bcaeb1 matrix() function in transform attribute of group and shapes
Thinker K.F. Li <thinker@branda.to>
parents: 79
diff changeset
367 max_dirty_coords = rdman->max_dirty_coords + 16;
9b4a02bcaeb1 matrix() function in transform attribute of group and shapes
Thinker K.F. Li <thinker@branda.to>
parents: 79
diff changeset
368
9b4a02bcaeb1 matrix() function in transform attribute of group and shapes
Thinker K.F. Li <thinker@branda.to>
parents: 79
diff changeset
369 r = extend_memblk((void **)&rdman->dirty_coords,
9b4a02bcaeb1 matrix() function in transform attribute of group and shapes
Thinker K.F. Li <thinker@branda.to>
parents: 79
diff changeset
370 sizeof(coord_t *) * rdman->n_dirty_coords,
9b4a02bcaeb1 matrix() function in transform attribute of group and shapes
Thinker K.F. Li <thinker@branda.to>
parents: 79
diff changeset
371 sizeof(coord_t *) * max_dirty_coords);
9b4a02bcaeb1 matrix() function in transform attribute of group and shapes
Thinker K.F. Li <thinker@branda.to>
parents: 79
diff changeset
372 rdman->max_dirty_coords = max_dirty_coords;
9b4a02bcaeb1 matrix() function in transform attribute of group and shapes
Thinker K.F. Li <thinker@branda.to>
parents: 79
diff changeset
373 }
9b4a02bcaeb1 matrix() function in transform attribute of group and shapes
Thinker K.F. Li <thinker@branda.to>
parents: 79
diff changeset
374 }
9b4a02bcaeb1 matrix() function in transform attribute of group and shapes
Thinker K.F. Li <thinker@branda.to>
parents: 79
diff changeset
375
13
ed55009d96d3 refactory for redrawing
Thinker K.F. Li <thinker@branda.to>
parents: 12
diff changeset
376 /*! \brief Mark a coord is changed.
ed55009d96d3 refactory for redrawing
Thinker K.F. Li <thinker@branda.to>
parents: 12
diff changeset
377 *
ed55009d96d3 refactory for redrawing
Thinker K.F. Li <thinker@branda.to>
parents: 12
diff changeset
378 * A changed coord_t object is marked as dirty and put
ed55009d96d3 refactory for redrawing
Thinker K.F. Li <thinker@branda.to>
parents: 12
diff changeset
379 * into dirty_coords list.
ed55009d96d3 refactory for redrawing
Thinker K.F. Li <thinker@branda.to>
parents: 12
diff changeset
380 */
ed55009d96d3 refactory for redrawing
Thinker K.F. Li <thinker@branda.to>
parents: 12
diff changeset
381 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
382 coord_t *child;
13
ed55009d96d3 refactory for redrawing
Thinker K.F. Li <thinker@branda.to>
parents: 12
diff changeset
383
ed55009d96d3 refactory for redrawing
Thinker K.F. Li <thinker@branda.to>
parents: 12
diff changeset
384 if(coord->flags & COF_DIRTY)
ed55009d96d3 refactory for redrawing
Thinker K.F. Li <thinker@branda.to>
parents: 12
diff changeset
385 return OK;
ed55009d96d3 refactory for redrawing
Thinker K.F. Li <thinker@branda.to>
parents: 12
diff changeset
386
16
e17e12b112c4 A simple animation using rdman_redraw_changed().
Thinker K.F. Li <thinker@branda.to>
parents: 15
diff changeset
387 /* Make the coord and child coords dirty. */
e17e12b112c4 A simple animation using rdman_redraw_changed().
Thinker K.F. Li <thinker@branda.to>
parents: 15
diff changeset
388 for(child = coord;
e17e12b112c4 A simple animation using rdman_redraw_changed().
Thinker K.F. Li <thinker@branda.to>
parents: 15
diff changeset
389 child != NULL;
e17e12b112c4 A simple animation using rdman_redraw_changed().
Thinker K.F. Li <thinker@branda.to>
parents: 15
diff changeset
390 child = preorder_coord_subtree(coord, child)) {
114
1909d53071ab Check if a coord dirty before dirty it
Thinker K.F. Li <thinker@branda.to>
parents: 104
diff changeset
391 if(child->flags & COF_DIRTY)
1909d53071ab Check if a coord dirty before dirty it
Thinker K.F. Li <thinker@branda.to>
parents: 104
diff changeset
392 continue;
85
9b4a02bcaeb1 matrix() function in transform attribute of group and shapes
Thinker K.F. Li <thinker@branda.to>
parents: 79
diff changeset
393 make_sure_dirty_coords(rdman);
9b4a02bcaeb1 matrix() function in transform attribute of group and shapes
Thinker K.F. Li <thinker@branda.to>
parents: 79
diff changeset
394
9b4a02bcaeb1 matrix() function in transform attribute of group and shapes
Thinker K.F. Li <thinker@branda.to>
parents: 79
diff changeset
395 rdman->dirty_coords[rdman->n_dirty_coords++] = child;
9b4a02bcaeb1 matrix() function in transform attribute of group and shapes
Thinker K.F. Li <thinker@branda.to>
parents: 79
diff changeset
396 child->flags |= COF_DIRTY;
16
e17e12b112c4 A simple animation using rdman_redraw_changed().
Thinker K.F. Li <thinker@branda.to>
parents: 15
diff changeset
397 }
13
ed55009d96d3 refactory for redrawing
Thinker K.F. Li <thinker@branda.to>
parents: 12
diff changeset
398
ed55009d96d3 refactory for redrawing
Thinker K.F. Li <thinker@branda.to>
parents: 12
diff changeset
399 return OK;
ed55009d96d3 refactory for redrawing
Thinker K.F. Li <thinker@branda.to>
parents: 12
diff changeset
400 }
ed55009d96d3 refactory for redrawing
Thinker K.F. Li <thinker@branda.to>
parents: 12
diff changeset
401
18
0f3baa488a62 Support solid color paint for fill.
Thinker K.F. Li <thinker@branda.to>
parents: 17
diff changeset
402 static int _rdman_shape_changed(redraw_man_t *rdman, shape_t *shape) {
13
ed55009d96d3 refactory for redrawing
Thinker K.F. Li <thinker@branda.to>
parents: 12
diff changeset
403 geo_t *geo;
ed55009d96d3 refactory for redrawing
Thinker K.F. Li <thinker@branda.to>
parents: 12
diff changeset
404 int r;
ed55009d96d3 refactory for redrawing
Thinker K.F. Li <thinker@branda.to>
parents: 12
diff changeset
405
ed55009d96d3 refactory for redrawing
Thinker K.F. Li <thinker@branda.to>
parents: 12
diff changeset
406 geo = shape->geo;
ed55009d96d3 refactory for redrawing
Thinker K.F. Li <thinker@branda.to>
parents: 12
diff changeset
407
ed55009d96d3 refactory for redrawing
Thinker K.F. Li <thinker@branda.to>
parents: 12
diff changeset
408 if(geo->flags & GEF_DIRTY)
ed55009d96d3 refactory for redrawing
Thinker K.F. Li <thinker@branda.to>
parents: 12
diff changeset
409 return OK;
ed55009d96d3 refactory for redrawing
Thinker K.F. Li <thinker@branda.to>
parents: 12
diff changeset
410
ed55009d96d3 refactory for redrawing
Thinker K.F. Li <thinker@branda.to>
parents: 12
diff changeset
411 r = add_dirty_geo(rdman, geo);
ed55009d96d3 refactory for redrawing
Thinker K.F. Li <thinker@branda.to>
parents: 12
diff changeset
412 if(r == ERR)
ed55009d96d3 refactory for redrawing
Thinker K.F. Li <thinker@branda.to>
parents: 12
diff changeset
413 return ERR;
ed55009d96d3 refactory for redrawing
Thinker K.F. Li <thinker@branda.to>
parents: 12
diff changeset
414 geo->flags |= GEF_DIRTY;
12
79e9edf4c00a Add redraw manager
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
415
79e9edf4c00a Add redraw manager
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
416 return OK;
79e9edf4c00a Add redraw manager
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
417 }
79e9edf4c00a Add redraw manager
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
418
18
0f3baa488a62 Support solid color paint for fill.
Thinker K.F. Li <thinker@branda.to>
parents: 17
diff changeset
419 /*! \brief Mark a shape is changed.
0f3baa488a62 Support solid color paint for fill.
Thinker K.F. Li <thinker@branda.to>
parents: 17
diff changeset
420 *
0f3baa488a62 Support solid color paint for fill.
Thinker K.F. Li <thinker@branda.to>
parents: 17
diff changeset
421 * 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
422 * put into dirty_geos list.
0f3baa488a62 Support solid color paint for fill.
Thinker K.F. Li <thinker@branda.to>
parents: 17
diff changeset
423 */
0f3baa488a62 Support solid color paint for fill.
Thinker K.F. Li <thinker@branda.to>
parents: 17
diff changeset
424 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
425 return _rdman_shape_changed(rdman, shape);
0f3baa488a62 Support solid color paint for fill.
Thinker K.F. Li <thinker@branda.to>
parents: 17
diff changeset
426 }
0f3baa488a62 Support solid color paint for fill.
Thinker K.F. Li <thinker@branda.to>
parents: 17
diff changeset
427
29
Thinker K.F. Li <thinker@branda.to>
parents: 28
diff changeset
428 int rdman_paint_changed(redraw_man_t *rdman, paint_t *paint) {
Thinker K.F. Li <thinker@branda.to>
parents: 28
diff changeset
429 shnode_t *node;
Thinker K.F. Li <thinker@branda.to>
parents: 28
diff changeset
430 int r;
Thinker K.F. Li <thinker@branda.to>
parents: 28
diff changeset
431
Thinker K.F. Li <thinker@branda.to>
parents: 28
diff changeset
432 for(node = STAILQ_HEAD(paint->members);
Thinker K.F. Li <thinker@branda.to>
parents: 28
diff changeset
433 node != NULL;
Thinker K.F. Li <thinker@branda.to>
parents: 28
diff changeset
434 node = STAILQ_NEXT(shnode_t, next, node)) {
Thinker K.F. Li <thinker@branda.to>
parents: 28
diff changeset
435 r = _rdman_shape_changed(rdman, node->shape);
Thinker K.F. Li <thinker@branda.to>
parents: 28
diff changeset
436 if(r != OK)
Thinker K.F. Li <thinker@branda.to>
parents: 28
diff changeset
437 return ERR;
Thinker K.F. Li <thinker@branda.to>
parents: 28
diff changeset
438 }
Thinker K.F. Li <thinker@branda.to>
parents: 28
diff changeset
439 return OK;
Thinker K.F. Li <thinker@branda.to>
parents: 28
diff changeset
440 }
Thinker K.F. Li <thinker@branda.to>
parents: 28
diff changeset
441
28
604bc90d509d Refactory
Thinker K.F. Li <thinker@branda.to>
parents: 27
diff changeset
442 /* Clean dirties */
604bc90d509d Refactory
Thinker K.F. Li <thinker@branda.to>
parents: 27
diff changeset
443
57
ab028c9f0930 Ability to hidden shapes and action of visibility.
Thinker K.F. Li <thinker@branda.to>
parents: 38
diff changeset
444 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
445 while(coord) {
ab028c9f0930 Ability to hidden shapes and action of visibility.
Thinker K.F. Li <thinker@branda.to>
parents: 38
diff changeset
446 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
447 return 1;
ab028c9f0930 Ability to hidden shapes and action of visibility.
Thinker K.F. Li <thinker@branda.to>
parents: 38
diff changeset
448 coord = coord->parent;
ab028c9f0930 Ability to hidden shapes and action of visibility.
Thinker K.F. Li <thinker@branda.to>
parents: 38
diff changeset
449 }
ab028c9f0930 Ability to hidden shapes and action of visibility.
Thinker K.F. Li <thinker@branda.to>
parents: 38
diff changeset
450 return 0;
ab028c9f0930 Ability to hidden shapes and action of visibility.
Thinker K.F. Li <thinker@branda.to>
parents: 38
diff changeset
451 }
ab028c9f0930 Ability to hidden shapes and action of visibility.
Thinker K.F. Li <thinker@branda.to>
parents: 38
diff changeset
452
28
604bc90d509d Refactory
Thinker K.F. Li <thinker@branda.to>
parents: 27
diff changeset
453 static void clean_shape(shape_t *shape) {
604bc90d509d Refactory
Thinker K.F. Li <thinker@branda.to>
parents: 27
diff changeset
454 switch(shape->sh_type) {
604bc90d509d Refactory
Thinker K.F. Li <thinker@branda.to>
parents: 27
diff changeset
455 case SHT_PATH:
604bc90d509d Refactory
Thinker K.F. Li <thinker@branda.to>
parents: 27
diff changeset
456 sh_path_transform(shape);
604bc90d509d Refactory
Thinker K.F. Li <thinker@branda.to>
parents: 27
diff changeset
457 break;
604bc90d509d Refactory
Thinker K.F. Li <thinker@branda.to>
parents: 27
diff changeset
458 case SHT_TEXT:
604bc90d509d Refactory
Thinker K.F. Li <thinker@branda.to>
parents: 27
diff changeset
459 sh_text_transform(shape);
604bc90d509d Refactory
Thinker K.F. Li <thinker@branda.to>
parents: 27
diff changeset
460 break;
35
581a03196093 Support rectangle tag of SVG.
Thinker K.F. Li <thinker@branda.to>
parents: 33
diff changeset
461 case SHT_RECT:
581a03196093 Support rectangle tag of SVG.
Thinker K.F. Li <thinker@branda.to>
parents: 33
diff changeset
462 sh_rect_transform(shape);
581a03196093 Support rectangle tag of SVG.
Thinker K.F. Li <thinker@branda.to>
parents: 33
diff changeset
463 break;
28
604bc90d509d Refactory
Thinker K.F. Li <thinker@branda.to>
parents: 27
diff changeset
464 #ifdef UNITTEST
604bc90d509d Refactory
Thinker K.F. Li <thinker@branda.to>
parents: 27
diff changeset
465 default:
604bc90d509d Refactory
Thinker K.F. Li <thinker@branda.to>
parents: 27
diff changeset
466 sh_dummy_transform(shape);
604bc90d509d Refactory
Thinker K.F. Li <thinker@branda.to>
parents: 27
diff changeset
467 break;
604bc90d509d Refactory
Thinker K.F. Li <thinker@branda.to>
parents: 27
diff changeset
468 #endif /* UNITTEST */
604bc90d509d Refactory
Thinker K.F. Li <thinker@branda.to>
parents: 27
diff changeset
469 }
604bc90d509d Refactory
Thinker K.F. Li <thinker@branda.to>
parents: 27
diff changeset
470 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
471
ab028c9f0930 Ability to hidden shapes and action of visibility.
Thinker K.F. Li <thinker@branda.to>
parents: 38
diff changeset
472 if(is_coord_subtree_hidden(shape->coord))
ab028c9f0930 Ability to hidden shapes and action of visibility.
Thinker K.F. Li <thinker@branda.to>
parents: 38
diff changeset
473 shape->geo->flags |= GEF_HIDDEN;
ab028c9f0930 Ability to hidden shapes and action of visibility.
Thinker K.F. Li <thinker@branda.to>
parents: 38
diff changeset
474 else
ab028c9f0930 Ability to hidden shapes and action of visibility.
Thinker K.F. Li <thinker@branda.to>
parents: 38
diff changeset
475 shape->geo->flags &= ~GEF_HIDDEN;
28
604bc90d509d Refactory
Thinker K.F. Li <thinker@branda.to>
parents: 27
diff changeset
476 }
604bc90d509d Refactory
Thinker K.F. Li <thinker@branda.to>
parents: 27
diff changeset
477
138
9f4fc9ecfd1f Make shapes and coords drawed in post-order of tree.
Thinker K.F. Li <thinker@branda.to>
parents: 135
diff changeset
478 /*! \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
479 *
9f4fc9ecfd1f Make shapes and coords drawed in post-order of tree.
Thinker K.F. Li <thinker@branda.to>
parents: 135
diff changeset
480 * 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
481 * \sa
9f4fc9ecfd1f Make shapes and coords drawed in post-order of tree.
Thinker K.F. Li <thinker@branda.to>
parents: 135
diff changeset
482 * - \ref redraw
9f4fc9ecfd1f Make shapes and coords drawed in post-order of tree.
Thinker K.F. Li <thinker@branda.to>
parents: 135
diff changeset
483 */
9f4fc9ecfd1f Make shapes and coords drawed in post-order of tree.
Thinker K.F. Li <thinker@branda.to>
parents: 135
diff changeset
484 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
485 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
486 return;
9f4fc9ecfd1f Make shapes and coords drawed in post-order of tree.
Thinker K.F. Li <thinker@branda.to>
parents: 135
diff changeset
487
9f4fc9ecfd1f Make shapes and coords drawed in post-order of tree.
Thinker K.F. Li <thinker@branda.to>
parents: 135
diff changeset
488 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
489 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
490 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
491 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
492 }
9f4fc9ecfd1f Make shapes and coords drawed in post-order of tree.
Thinker K.F. Li <thinker@branda.to>
parents: 135
diff changeset
493 } else {
9f4fc9ecfd1f Make shapes and coords drawed in post-order of tree.
Thinker K.F. Li <thinker@branda.to>
parents: 135
diff changeset
494 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
495 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
496 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
497 }
9f4fc9ecfd1f Make shapes and coords drawed in post-order of tree.
Thinker K.F. Li <thinker@branda.to>
parents: 135
diff changeset
498 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
499 }
9f4fc9ecfd1f Make shapes and coords drawed in post-order of tree.
Thinker K.F. Li <thinker@branda.to>
parents: 135
diff changeset
500 }
9f4fc9ecfd1f Make shapes and coords drawed in post-order of tree.
Thinker K.F. Li <thinker@branda.to>
parents: 135
diff changeset
501
9f4fc9ecfd1f Make shapes and coords drawed in post-order of tree.
Thinker K.F. Li <thinker@branda.to>
parents: 135
diff changeset
502 static int clean_coord(redraw_man_t *rdman, coord_t *coord) {
28
604bc90d509d Refactory
Thinker K.F. Li <thinker@branda.to>
parents: 27
diff changeset
503 geo_t *geo;
604bc90d509d Refactory
Thinker K.F. Li <thinker@branda.to>
parents: 27
diff changeset
504 co_aix (*poses)[2];
604bc90d509d Refactory
Thinker K.F. Li <thinker@branda.to>
parents: 27
diff changeset
505 int cnt, pos_cnt;
604bc90d509d Refactory
Thinker K.F. Li <thinker@branda.to>
parents: 27
diff changeset
506
138
9f4fc9ecfd1f Make shapes and coords drawed in post-order of tree.
Thinker K.F. Li <thinker@branda.to>
parents: 135
diff changeset
507 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
508
28
604bc90d509d Refactory
Thinker K.F. Li <thinker@branda.to>
parents: 27
diff changeset
509 compute_aggr_of_coord(coord);
604bc90d509d Refactory
Thinker K.F. Li <thinker@branda.to>
parents: 27
diff changeset
510
604bc90d509d Refactory
Thinker K.F. Li <thinker@branda.to>
parents: 27
diff changeset
511 /* Clean member shapes. */
604bc90d509d Refactory
Thinker K.F. Li <thinker@branda.to>
parents: 27
diff changeset
512 cnt = 0;
139
1695a4b02b14 Members of coords are geos instead of shapes, now.
Thinker K.F. Li <thinker@branda.to>
parents: 138
diff changeset
513 for(geo = STAILQ_HEAD(coord->members);
1695a4b02b14 Members of coords are geos instead of shapes, now.
Thinker K.F. Li <thinker@branda.to>
parents: 138
diff changeset
514 geo != NULL;
1695a4b02b14 Members of coords are geos instead of shapes, now.
Thinker K.F. Li <thinker@branda.to>
parents: 138
diff changeset
515 geo = STAILQ_NEXT(geo_t, coord_next, geo)) {
28
604bc90d509d Refactory
Thinker K.F. Li <thinker@branda.to>
parents: 27
diff changeset
516 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
517 clean_shape(geo->shape);
28
604bc90d509d Refactory
Thinker K.F. Li <thinker@branda.to>
parents: 27
diff changeset
518 cnt++;
604bc90d509d Refactory
Thinker K.F. Li <thinker@branda.to>
parents: 27
diff changeset
519 }
604bc90d509d Refactory
Thinker K.F. Li <thinker@branda.to>
parents: 27
diff changeset
520
604bc90d509d Refactory
Thinker K.F. Li <thinker@branda.to>
parents: 27
diff changeset
521 /* Compute area of the coord. */
604bc90d509d Refactory
Thinker K.F. Li <thinker@branda.to>
parents: 27
diff changeset
522 poses = (co_aix (*)[2])malloc(sizeof(co_aix [2]) * 2 * cnt);
604bc90d509d Refactory
Thinker K.F. Li <thinker@branda.to>
parents: 27
diff changeset
523 if(poses == NULL)
604bc90d509d Refactory
Thinker K.F. Li <thinker@branda.to>
parents: 27
diff changeset
524 return ERR;
604bc90d509d Refactory
Thinker K.F. Li <thinker@branda.to>
parents: 27
diff changeset
525
604bc90d509d Refactory
Thinker K.F. Li <thinker@branda.to>
parents: 27
diff changeset
526 pos_cnt = 0;
139
1695a4b02b14 Members of coords are geos instead of shapes, now.
Thinker K.F. Li <thinker@branda.to>
parents: 138
diff changeset
527 for(geo = STAILQ_HEAD(coord->members);
1695a4b02b14 Members of coords are geos instead of shapes, now.
Thinker K.F. Li <thinker@branda.to>
parents: 138
diff changeset
528 geo != NULL;
1695a4b02b14 Members of coords are geos instead of shapes, now.
Thinker K.F. Li <thinker@branda.to>
parents: 138
diff changeset
529 geo = STAILQ_NEXT(geo_t, coord_next, geo)) {
28
604bc90d509d Refactory
Thinker K.F. Li <thinker@branda.to>
parents: 27
diff changeset
530 area_to_positions(geo->cur_area, poses + pos_cnt);
604bc90d509d Refactory
Thinker K.F. Li <thinker@branda.to>
parents: 27
diff changeset
531 pos_cnt += 2;
604bc90d509d Refactory
Thinker K.F. Li <thinker@branda.to>
parents: 27
diff changeset
532 }
604bc90d509d Refactory
Thinker K.F. Li <thinker@branda.to>
parents: 27
diff changeset
533
604bc90d509d Refactory
Thinker K.F. Li <thinker@branda.to>
parents: 27
diff changeset
534 SWAP(coord->cur_area, coord->last_area, area_t *);
604bc90d509d Refactory
Thinker K.F. Li <thinker@branda.to>
parents: 27
diff changeset
535 area_init(coord->cur_area, pos_cnt, poses);
604bc90d509d Refactory
Thinker K.F. Li <thinker@branda.to>
parents: 27
diff changeset
536 free(poses);
604bc90d509d Refactory
Thinker K.F. Li <thinker@branda.to>
parents: 27
diff changeset
537
604bc90d509d Refactory
Thinker K.F. Li <thinker@branda.to>
parents: 27
diff changeset
538 coord->flags &= ~COF_DIRTY;
604bc90d509d Refactory
Thinker K.F. Li <thinker@branda.to>
parents: 27
diff changeset
539
604bc90d509d Refactory
Thinker K.F. Li <thinker@branda.to>
parents: 27
diff changeset
540 return OK;
604bc90d509d Refactory
Thinker K.F. Li <thinker@branda.to>
parents: 27
diff changeset
541 }
604bc90d509d Refactory
Thinker K.F. Li <thinker@branda.to>
parents: 27
diff changeset
542
135
Thinker K.F. Li <thinker@branda.to>
parents: 133
diff changeset
543 /*! \brief Clean coord_t objects.
133
Thinker K.F. Li <thinker@branda.to>
parents: 121
diff changeset
544 */
28
604bc90d509d Refactory
Thinker K.F. Li <thinker@branda.to>
parents: 27
diff changeset
545 static int clean_rdman_coords(redraw_man_t *rdman) {
604bc90d509d Refactory
Thinker K.F. Li <thinker@branda.to>
parents: 27
diff changeset
546 coord_t *coord;
604bc90d509d Refactory
Thinker K.F. Li <thinker@branda.to>
parents: 27
diff changeset
547 coord_t **dirty_coords;
604bc90d509d Refactory
Thinker K.F. Li <thinker@branda.to>
parents: 27
diff changeset
548 int n_dirty_coords;
604bc90d509d Refactory
Thinker K.F. Li <thinker@branda.to>
parents: 27
diff changeset
549 int i, r;
604bc90d509d Refactory
Thinker K.F. Li <thinker@branda.to>
parents: 27
diff changeset
550
604bc90d509d Refactory
Thinker K.F. Li <thinker@branda.to>
parents: 27
diff changeset
551 n_dirty_coords = rdman->n_dirty_coords;
604bc90d509d Refactory
Thinker K.F. Li <thinker@branda.to>
parents: 27
diff changeset
552 if(n_dirty_coords > 0) {
604bc90d509d Refactory
Thinker K.F. Li <thinker@branda.to>
parents: 27
diff changeset
553 dirty_coords = rdman->dirty_coords;
604bc90d509d Refactory
Thinker K.F. Li <thinker@branda.to>
parents: 27
diff changeset
554 _insert_sort((void **)dirty_coords, n_dirty_coords,
604bc90d509d Refactory
Thinker K.F. Li <thinker@branda.to>
parents: 27
diff changeset
555 OFFSET(coord_t, order));
604bc90d509d Refactory
Thinker K.F. Li <thinker@branda.to>
parents: 27
diff changeset
556 for(i = 0; i < n_dirty_coords; i++) {
604bc90d509d Refactory
Thinker K.F. Li <thinker@branda.to>
parents: 27
diff changeset
557 coord = dirty_coords[i];
604bc90d509d Refactory
Thinker K.F. Li <thinker@branda.to>
parents: 27
diff changeset
558 if(!(coord->flags & COF_DIRTY))
604bc90d509d Refactory
Thinker K.F. Li <thinker@branda.to>
parents: 27
diff changeset
559 continue;
138
9f4fc9ecfd1f Make shapes and coords drawed in post-order of tree.
Thinker K.F. Li <thinker@branda.to>
parents: 135
diff changeset
560 r = clean_coord(rdman, coord);
28
604bc90d509d Refactory
Thinker K.F. Li <thinker@branda.to>
parents: 27
diff changeset
561 if(r != OK)
604bc90d509d Refactory
Thinker K.F. Li <thinker@branda.to>
parents: 27
diff changeset
562 return ERR;
604bc90d509d Refactory
Thinker K.F. Li <thinker@branda.to>
parents: 27
diff changeset
563 /* These two steps can be avoided for drawing all. */
604bc90d509d Refactory
Thinker K.F. Li <thinker@branda.to>
parents: 27
diff changeset
564 add_dirty_area(rdman, &coord->areas[0]);
604bc90d509d Refactory
Thinker K.F. Li <thinker@branda.to>
parents: 27
diff changeset
565 add_dirty_area(rdman, &coord->areas[1]);
604bc90d509d Refactory
Thinker K.F. Li <thinker@branda.to>
parents: 27
diff changeset
566 }
604bc90d509d Refactory
Thinker K.F. Li <thinker@branda.to>
parents: 27
diff changeset
567 rdman->n_dirty_coords = 0;
604bc90d509d Refactory
Thinker K.F. Li <thinker@branda.to>
parents: 27
diff changeset
568 }
604bc90d509d Refactory
Thinker K.F. Li <thinker@branda.to>
parents: 27
diff changeset
569 return OK;
604bc90d509d Refactory
Thinker K.F. Li <thinker@branda.to>
parents: 27
diff changeset
570 }
604bc90d509d Refactory
Thinker K.F. Li <thinker@branda.to>
parents: 27
diff changeset
571
604bc90d509d Refactory
Thinker K.F. Li <thinker@branda.to>
parents: 27
diff changeset
572 static int clean_rdman_geos(redraw_man_t *rdman) {
604bc90d509d Refactory
Thinker K.F. Li <thinker@branda.to>
parents: 27
diff changeset
573 int i;
604bc90d509d Refactory
Thinker K.F. Li <thinker@branda.to>
parents: 27
diff changeset
574 int n_dirty_geos;
604bc90d509d Refactory
Thinker K.F. Li <thinker@branda.to>
parents: 27
diff changeset
575 geo_t **dirty_geos;
604bc90d509d Refactory
Thinker K.F. Li <thinker@branda.to>
parents: 27
diff changeset
576 geo_t *visit_geo;
604bc90d509d Refactory
Thinker K.F. Li <thinker@branda.to>
parents: 27
diff changeset
577
604bc90d509d Refactory
Thinker K.F. Li <thinker@branda.to>
parents: 27
diff changeset
578 n_dirty_geos = rdman->n_dirty_geos;
604bc90d509d Refactory
Thinker K.F. Li <thinker@branda.to>
parents: 27
diff changeset
579 if(n_dirty_geos > 0) {
604bc90d509d Refactory
Thinker K.F. Li <thinker@branda.to>
parents: 27
diff changeset
580 dirty_geos = rdman->dirty_geos;
604bc90d509d Refactory
Thinker K.F. Li <thinker@branda.to>
parents: 27
diff changeset
581 for(i = 0; i < n_dirty_geos; i++) {
604bc90d509d Refactory
Thinker K.F. Li <thinker@branda.to>
parents: 27
diff changeset
582 visit_geo = dirty_geos[i];
604bc90d509d Refactory
Thinker K.F. Li <thinker@branda.to>
parents: 27
diff changeset
583 if(!(visit_geo->flags & GEF_DIRTY))
604bc90d509d Refactory
Thinker K.F. Li <thinker@branda.to>
parents: 27
diff changeset
584 continue;
604bc90d509d Refactory
Thinker K.F. Li <thinker@branda.to>
parents: 27
diff changeset
585
604bc90d509d Refactory
Thinker K.F. Li <thinker@branda.to>
parents: 27
diff changeset
586 SWAP(visit_geo->cur_area, visit_geo->last_area, area_t *);
604bc90d509d Refactory
Thinker K.F. Li <thinker@branda.to>
parents: 27
diff changeset
587 clean_shape(visit_geo->shape);
604bc90d509d Refactory
Thinker K.F. Li <thinker@branda.to>
parents: 27
diff changeset
588 add_dirty_area(rdman, visit_geo->cur_area);
604bc90d509d Refactory
Thinker K.F. Li <thinker@branda.to>
parents: 27
diff changeset
589 add_dirty_area(rdman, visit_geo->last_area);
604bc90d509d Refactory
Thinker K.F. Li <thinker@branda.to>
parents: 27
diff changeset
590 }
604bc90d509d Refactory
Thinker K.F. Li <thinker@branda.to>
parents: 27
diff changeset
591 rdman->n_dirty_geos = 0;
604bc90d509d Refactory
Thinker K.F. Li <thinker@branda.to>
parents: 27
diff changeset
592 }
604bc90d509d Refactory
Thinker K.F. Li <thinker@branda.to>
parents: 27
diff changeset
593
604bc90d509d Refactory
Thinker K.F. Li <thinker@branda.to>
parents: 27
diff changeset
594 return OK;
604bc90d509d Refactory
Thinker K.F. Li <thinker@branda.to>
parents: 27
diff changeset
595 }
604bc90d509d Refactory
Thinker K.F. Li <thinker@branda.to>
parents: 27
diff changeset
596
29
Thinker K.F. Li <thinker@branda.to>
parents: 28
diff changeset
597 static int clean_rdman_dirties(redraw_man_t *rdman) {
Thinker K.F. Li <thinker@branda.to>
parents: 28
diff changeset
598 int r;
Thinker K.F. Li <thinker@branda.to>
parents: 28
diff changeset
599
Thinker K.F. Li <thinker@branda.to>
parents: 28
diff changeset
600 r = clean_rdman_coords(rdman);
Thinker K.F. Li <thinker@branda.to>
parents: 28
diff changeset
601 if(r != OK)
Thinker K.F. Li <thinker@branda.to>
parents: 28
diff changeset
602 return ERR;
Thinker K.F. Li <thinker@branda.to>
parents: 28
diff changeset
603
Thinker K.F. Li <thinker@branda.to>
parents: 28
diff changeset
604 r = clean_rdman_geos(rdman);
Thinker K.F. Li <thinker@branda.to>
parents: 28
diff changeset
605 if(r != OK)
Thinker K.F. Li <thinker@branda.to>
parents: 28
diff changeset
606 return ERR;
Thinker K.F. Li <thinker@branda.to>
parents: 28
diff changeset
607
Thinker K.F. Li <thinker@branda.to>
parents: 28
diff changeset
608 return OK;
Thinker K.F. Li <thinker@branda.to>
parents: 28
diff changeset
609 }
Thinker K.F. Li <thinker@branda.to>
parents: 28
diff changeset
610
Thinker K.F. Li <thinker@branda.to>
parents: 28
diff changeset
611
17
41f0907b27ac Unittest for rdman_redraw_changed().
Thinker K.F. Li <thinker@branda.to>
parents: 16
diff changeset
612 /* Drawing and Redrawing
41f0907b27ac Unittest for rdman_redraw_changed().
Thinker K.F. Li <thinker@branda.to>
parents: 16
diff changeset
613 * ============================================================
41f0907b27ac Unittest for rdman_redraw_changed().
Thinker K.F. Li <thinker@branda.to>
parents: 16
diff changeset
614 */
16
e17e12b112c4 A simple animation using rdman_redraw_changed().
Thinker K.F. Li <thinker@branda.to>
parents: 15
diff changeset
615
26
d50f33040de6 Set line width for path.
Thinker K.F. Li <thinker@branda.to>
parents: 25
diff changeset
616 #ifndef UNITTEST
d50f33040de6 Set line width for path.
Thinker K.F. Li <thinker@branda.to>
parents: 25
diff changeset
617 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
618 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
619 }
33
d82749f77108 Fix bug of demo and remove *_fill() and *_stroke().
Thinker K.F. Li <thinker@branda.to>
parents: 30
diff changeset
620
d82749f77108 Fix bug of demo and remove *_fill() and *_stroke().
Thinker K.F. Li <thinker@branda.to>
parents: 30
diff changeset
621 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
622 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
623 }
d82749f77108 Fix bug of demo and remove *_fill() and *_stroke().
Thinker K.F. Li <thinker@branda.to>
parents: 30
diff changeset
624
d82749f77108 Fix bug of demo and remove *_fill() and *_stroke().
Thinker K.F. Li <thinker@branda.to>
parents: 30
diff changeset
625 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
626 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
627 }
d82749f77108 Fix bug of demo and remove *_fill() and *_stroke().
Thinker K.F. Li <thinker@branda.to>
parents: 30
diff changeset
628
d82749f77108 Fix bug of demo and remove *_fill() and *_stroke().
Thinker K.F. Li <thinker@branda.to>
parents: 30
diff changeset
629 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
630 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
631 }
26
d50f33040de6 Set line width for path.
Thinker K.F. Li <thinker@branda.to>
parents: 25
diff changeset
632 #else
d50f33040de6 Set line width for path.
Thinker K.F. Li <thinker@branda.to>
parents: 25
diff changeset
633 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
634 }
33
d82749f77108 Fix bug of demo and remove *_fill() and *_stroke().
Thinker K.F. Li <thinker@branda.to>
parents: 30
diff changeset
635
d82749f77108 Fix bug of demo and remove *_fill() and *_stroke().
Thinker K.F. Li <thinker@branda.to>
parents: 30
diff changeset
636 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
637 }
d82749f77108 Fix bug of demo and remove *_fill() and *_stroke().
Thinker K.F. Li <thinker@branda.to>
parents: 30
diff changeset
638
d82749f77108 Fix bug of demo and remove *_fill() and *_stroke().
Thinker K.F. Li <thinker@branda.to>
parents: 30
diff changeset
639 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
640 }
d82749f77108 Fix bug of demo and remove *_fill() and *_stroke().
Thinker K.F. Li <thinker@branda.to>
parents: 30
diff changeset
641
d82749f77108 Fix bug of demo and remove *_fill() and *_stroke().
Thinker K.F. Li <thinker@branda.to>
parents: 30
diff changeset
642 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
643 }
26
d50f33040de6 Set line width for path.
Thinker K.F. Li <thinker@branda.to>
parents: 25
diff changeset
644 #endif
d50f33040de6 Set line width for path.
Thinker K.F. Li <thinker@branda.to>
parents: 25
diff changeset
645
138
9f4fc9ecfd1f Make shapes and coords drawed in post-order of tree.
Thinker K.F. Li <thinker@branda.to>
parents: 135
diff changeset
646 static void draw_shape(redraw_man_t *rdman, cairo_t *cr, shape_t *shape) {
22
8fcf2d878ecd shapes with stroke
Thinker K.F. Li <thinker@branda.to>
parents: 20
diff changeset
647 paint_t *fill, *stroke;
18
0f3baa488a62 Support solid color paint for fill.
Thinker K.F. Li <thinker@branda.to>
parents: 17
diff changeset
648
33
d82749f77108 Fix bug of demo and remove *_fill() and *_stroke().
Thinker K.F. Li <thinker@branda.to>
parents: 30
diff changeset
649 if(shape->fill || shape->stroke) {
19
cf6d65398619 More animation demo
Thinker K.F. Li <thinker@branda.to>
parents: 18
diff changeset
650 switch(shape->sh_type) {
cf6d65398619 More animation demo
Thinker K.F. Li <thinker@branda.to>
parents: 18
diff changeset
651 case SHT_PATH:
138
9f4fc9ecfd1f Make shapes and coords drawed in post-order of tree.
Thinker K.F. Li <thinker@branda.to>
parents: 135
diff changeset
652 sh_path_draw(shape, cr);
19
cf6d65398619 More animation demo
Thinker K.F. Li <thinker@branda.to>
parents: 18
diff changeset
653 break;
27
19c603dd6ff9 Add text shape.
Thinker K.F. Li <thinker@branda.to>
parents: 26
diff changeset
654 case SHT_TEXT:
138
9f4fc9ecfd1f Make shapes and coords drawed in post-order of tree.
Thinker K.F. Li <thinker@branda.to>
parents: 135
diff changeset
655 sh_text_draw(shape, cr);
27
19c603dd6ff9 Add text shape.
Thinker K.F. Li <thinker@branda.to>
parents: 26
diff changeset
656 break;
35
581a03196093 Support rectangle tag of SVG.
Thinker K.F. Li <thinker@branda.to>
parents: 33
diff changeset
657 case SHT_RECT:
138
9f4fc9ecfd1f Make shapes and coords drawed in post-order of tree.
Thinker K.F. Li <thinker@branda.to>
parents: 135
diff changeset
658 sh_rect_draw(shape, cr);
35
581a03196093 Support rectangle tag of SVG.
Thinker K.F. Li <thinker@branda.to>
parents: 33
diff changeset
659 break;
17
41f0907b27ac Unittest for rdman_redraw_changed().
Thinker K.F. Li <thinker@branda.to>
parents: 16
diff changeset
660 #ifdef UNITTEST
19
cf6d65398619 More animation demo
Thinker K.F. Li <thinker@branda.to>
parents: 18
diff changeset
661 default:
138
9f4fc9ecfd1f Make shapes and coords drawed in post-order of tree.
Thinker K.F. Li <thinker@branda.to>
parents: 135
diff changeset
662 sh_dummy_fill(shape, cr);
19
cf6d65398619 More animation demo
Thinker K.F. Li <thinker@branda.to>
parents: 18
diff changeset
663 break;
17
41f0907b27ac Unittest for rdman_redraw_changed().
Thinker K.F. Li <thinker@branda.to>
parents: 16
diff changeset
664 #endif /* UNITTEST */
19
cf6d65398619 More animation demo
Thinker K.F. Li <thinker@branda.to>
parents: 18
diff changeset
665 }
33
d82749f77108 Fix bug of demo and remove *_fill() and *_stroke().
Thinker K.F. Li <thinker@branda.to>
parents: 30
diff changeset
666
d82749f77108 Fix bug of demo and remove *_fill() and *_stroke().
Thinker K.F. Li <thinker@branda.to>
parents: 30
diff changeset
667 fill = shape->fill;
d82749f77108 Fix bug of demo and remove *_fill() and *_stroke().
Thinker K.F. Li <thinker@branda.to>
parents: 30
diff changeset
668 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
669 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
670 if(shape->stroke)
d82749f77108 Fix bug of demo and remove *_fill() and *_stroke().
Thinker K.F. Li <thinker@branda.to>
parents: 30
diff changeset
671 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
672 else
d82749f77108 Fix bug of demo and remove *_fill() and *_stroke().
Thinker K.F. Li <thinker@branda.to>
parents: 30
diff changeset
673 fill_path(rdman);
d82749f77108 Fix bug of demo and remove *_fill() and *_stroke().
Thinker K.F. Li <thinker@branda.to>
parents: 30
diff changeset
674 }
d82749f77108 Fix bug of demo and remove *_fill() and *_stroke().
Thinker K.F. Li <thinker@branda.to>
parents: 30
diff changeset
675
d82749f77108 Fix bug of demo and remove *_fill() and *_stroke().
Thinker K.F. Li <thinker@branda.to>
parents: 30
diff changeset
676 stroke = shape->stroke;
d82749f77108 Fix bug of demo and remove *_fill() and *_stroke().
Thinker K.F. Li <thinker@branda.to>
parents: 30
diff changeset
677 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
678 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
679 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
680 stroke_path(rdman);
22
8fcf2d878ecd shapes with stroke
Thinker K.F. Li <thinker@branda.to>
parents: 20
diff changeset
681 }
8fcf2d878ecd shapes with stroke
Thinker K.F. Li <thinker@branda.to>
parents: 20
diff changeset
682 }
13
ed55009d96d3 refactory for redrawing
Thinker K.F. Li <thinker@branda.to>
parents: 12
diff changeset
683 }
ed55009d96d3 refactory for redrawing
Thinker K.F. Li <thinker@branda.to>
parents: 12
diff changeset
684
17
41f0907b27ac Unittest for rdman_redraw_changed().
Thinker K.F. Li <thinker@branda.to>
parents: 16
diff changeset
685 #ifndef UNITTEST
25
29937c26bb01 Fix bug of a dark line appear when animating.
Thinker K.F. Li <thinker@branda.to>
parents: 24
diff changeset
686 static void clean_canvas(cairo_t *cr) {
58
Thinker K.F. Li <thinker@branda.to>
parents: 57
diff changeset
687 /*! \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
688 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
689 cairo_paint(cr);
16
e17e12b112c4 A simple animation using rdman_redraw_changed().
Thinker K.F. Li <thinker@branda.to>
parents: 15
diff changeset
690 }
e17e12b112c4 A simple animation using rdman_redraw_changed().
Thinker K.F. Li <thinker@branda.to>
parents: 15
diff changeset
691
138
9f4fc9ecfd1f Make shapes and coords drawed in post-order of tree.
Thinker K.F. Li <thinker@branda.to>
parents: 135
diff changeset
692 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
693 /*! \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
694 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
695 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
696 }
9f4fc9ecfd1f Make shapes and coords drawed in post-order of tree.
Thinker K.F. Li <thinker@branda.to>
parents: 135
diff changeset
697
24
e598bc809c0f No more flash when animation.
Thinker K.F. Li <thinker@branda.to>
parents: 23
diff changeset
698 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
699 area_t **dirty_areas) {
c2ce186a5c37 X_main uses rdman_redraw_all()
Thinker K.F. Li <thinker@branda.to>
parents: 14
diff changeset
700 int i;
c2ce186a5c37 X_main uses rdman_redraw_all()
Thinker K.F. Li <thinker@branda.to>
parents: 14
diff changeset
701 area_t *area;
c2ce186a5c37 X_main uses rdman_redraw_all()
Thinker K.F. Li <thinker@branda.to>
parents: 14
diff changeset
702
c2ce186a5c37 X_main uses rdman_redraw_all()
Thinker K.F. Li <thinker@branda.to>
parents: 14
diff changeset
703 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
704 area = dirty_areas[i];
c2ce186a5c37 X_main uses rdman_redraw_all()
Thinker K.F. Li <thinker@branda.to>
parents: 14
diff changeset
705 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
706 }
c2ce186a5c37 X_main uses rdman_redraw_all()
Thinker K.F. Li <thinker@branda.to>
parents: 14
diff changeset
707 cairo_clip(cr);
c2ce186a5c37 X_main uses rdman_redraw_all()
Thinker K.F. Li <thinker@branda.to>
parents: 14
diff changeset
708 }
c2ce186a5c37 X_main uses rdman_redraw_all()
Thinker K.F. Li <thinker@branda.to>
parents: 14
diff changeset
709
17
41f0907b27ac Unittest for rdman_redraw_changed().
Thinker K.F. Li <thinker@branda.to>
parents: 16
diff changeset
710 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
711 cairo_reset_clip(rdman->backend);
e598bc809c0f No more flash when animation.
Thinker K.F. Li <thinker@branda.to>
parents: 23
diff changeset
712 }
e598bc809c0f No more flash when animation.
Thinker K.F. Li <thinker@branda.to>
parents: 23
diff changeset
713
e598bc809c0f No more flash when animation.
Thinker K.F. Li <thinker@branda.to>
parents: 23
diff changeset
714 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
715 area_t **dirty_areas) {
e598bc809c0f No more flash when animation.
Thinker K.F. Li <thinker@branda.to>
parents: 23
diff changeset
716 if(n_dirty_areas)
e598bc809c0f No more flash when animation.
Thinker K.F. Li <thinker@branda.to>
parents: 23
diff changeset
717 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
718
e598bc809c0f No more flash when animation.
Thinker K.F. Li <thinker@branda.to>
parents: 23
diff changeset
719 cairo_paint(rdman->backend);
17
41f0907b27ac Unittest for rdman_redraw_changed().
Thinker K.F. Li <thinker@branda.to>
parents: 16
diff changeset
720 }
41f0907b27ac Unittest for rdman_redraw_changed().
Thinker K.F. Li <thinker@branda.to>
parents: 16
diff changeset
721 #else /* UNITTEST */
25
29937c26bb01 Fix bug of a dark line appear when animating.
Thinker K.F. Li <thinker@branda.to>
parents: 24
diff changeset
722 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
723 }
e598bc809c0f No more flash when animation.
Thinker K.F. Li <thinker@branda.to>
parents: 23
diff changeset
724
138
9f4fc9ecfd1f Make shapes and coords drawed in post-order of tree.
Thinker K.F. Li <thinker@branda.to>
parents: 135
diff changeset
725 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
726 }
9f4fc9ecfd1f Make shapes and coords drawed in post-order of tree.
Thinker K.F. Li <thinker@branda.to>
parents: 135
diff changeset
727
17
41f0907b27ac Unittest for rdman_redraw_changed().
Thinker K.F. Li <thinker@branda.to>
parents: 16
diff changeset
728 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
729 }
24
e598bc809c0f No more flash when animation.
Thinker K.F. Li <thinker@branda.to>
parents: 23
diff changeset
730
e598bc809c0f No more flash when animation.
Thinker K.F. Li <thinker@branda.to>
parents: 23
diff changeset
731 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
732 area_t **dirty_areas) {
e598bc809c0f No more flash when animation.
Thinker K.F. Li <thinker@branda.to>
parents: 23
diff changeset
733 }
17
41f0907b27ac Unittest for rdman_redraw_changed().
Thinker K.F. Li <thinker@branda.to>
parents: 16
diff changeset
734 #endif /* UNITTEST */
41f0907b27ac Unittest for rdman_redraw_changed().
Thinker K.F. Li <thinker@branda.to>
parents: 16
diff changeset
735
139
1695a4b02b14 Members of coords are geos instead of shapes, now.
Thinker K.F. Li <thinker@branda.to>
parents: 138
diff changeset
736 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
737 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
738 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
739 int i;
9f4fc9ecfd1f Make shapes and coords drawed in post-order of tree.
Thinker K.F. Li <thinker@branda.to>
parents: 135
diff changeset
740
9f4fc9ecfd1f Make shapes and coords drawed in post-order of tree.
Thinker K.F. Li <thinker@branda.to>
parents: 135
diff changeset
741 for(i = 0; i < n_areas; i++) {
9f4fc9ecfd1f Make shapes and coords drawed in post-order of tree.
Thinker K.F. Li <thinker@branda.to>
parents: 135
diff changeset
742 if(is_overlay(geo->cur_area, areas[i]))
9f4fc9ecfd1f Make shapes and coords drawed in post-order of tree.
Thinker K.F. Li <thinker@branda.to>
parents: 135
diff changeset
743 return 1;
9f4fc9ecfd1f Make shapes and coords drawed in post-order of tree.
Thinker K.F. Li <thinker@branda.to>
parents: 135
diff changeset
744 }
9f4fc9ecfd1f Make shapes and coords drawed in post-order of tree.
Thinker K.F. Li <thinker@branda.to>
parents: 135
diff changeset
745 return 0;
9f4fc9ecfd1f Make shapes and coords drawed in post-order of tree.
Thinker K.F. Li <thinker@branda.to>
parents: 135
diff changeset
746 }
9f4fc9ecfd1f Make shapes and coords drawed in post-order of tree.
Thinker K.F. Li <thinker@branda.to>
parents: 135
diff changeset
747
9f4fc9ecfd1f Make shapes and coords drawed in post-order of tree.
Thinker K.F. Li <thinker@branda.to>
parents: 135
diff changeset
748 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
749 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
750 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
751
9f4fc9ecfd1f Make shapes and coords drawed in post-order of tree.
Thinker K.F. Li <thinker@branda.to>
parents: 135
diff changeset
752 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
753 return;
9f4fc9ecfd1f Make shapes and coords drawed in post-order of tree.
Thinker K.F. Li <thinker@branda.to>
parents: 135
diff changeset
754
9f4fc9ecfd1f Make shapes and coords drawed in post-order of tree.
Thinker K.F. Li <thinker@branda.to>
parents: 135
diff changeset
755 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
756 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
757 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
758 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
759 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
760 }
9f4fc9ecfd1f Make shapes and coords drawed in post-order of tree.
Thinker K.F. Li <thinker@branda.to>
parents: 135
diff changeset
761
9f4fc9ecfd1f Make shapes and coords drawed in post-order of tree.
Thinker K.F. Li <thinker@branda.to>
parents: 135
diff changeset
762 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
763 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
764 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
765 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
766 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
767 int r;
139
1695a4b02b14 Members of coords are geos instead of shapes, now.
Thinker K.F. Li <thinker@branda.to>
parents: 138
diff changeset
768 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
769 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
770 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
771 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
772
9f4fc9ecfd1f Make shapes and coords drawed in post-order of tree.
Thinker K.F. Li <thinker@branda.to>
parents: 135
diff changeset
773 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
774 member = STAILQ_HEAD(coord->members);
9f4fc9ecfd1f Make shapes and coords drawed in post-order of tree.
Thinker K.F. Li <thinker@branda.to>
parents: 135
diff changeset
775 mem_idx = 0;
9f4fc9ecfd1f Make shapes and coords drawed in post-order of tree.
Thinker K.F. Li <thinker@branda.to>
parents: 135
diff changeset
776 child = STAILQ_HEAD(coord->children);
9f4fc9ecfd1f Make shapes and coords drawed in post-order of tree.
Thinker K.F. Li <thinker@branda.to>
parents: 135
diff changeset
777 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
778 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
779 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
780 dirty |= r;
9f4fc9ecfd1f Make shapes and coords drawed in post-order of tree.
Thinker K.F. Li <thinker@branda.to>
parents: 135
diff changeset
781 child = STAILQ_NEXT(coord_t, sibling, child);
9f4fc9ecfd1f Make shapes and coords drawed in post-order of tree.
Thinker K.F. Li <thinker@branda.to>
parents: 135
diff changeset
782 } else {
9f4fc9ecfd1f Make shapes and coords drawed in post-order of tree.
Thinker K.F. Li <thinker@branda.to>
parents: 135
diff changeset
783 ASSERT(member != NULL);
139
1695a4b02b14 Members of coords are geos instead of shapes, now.
Thinker K.F. Li <thinker@branda.to>
parents: 138
diff changeset
784 if(is_geo_in_areas(member, n_areas, areas)) {
1695a4b02b14 Members of coords are geos instead of shapes, now.
Thinker K.F. Li <thinker@branda.to>
parents: 138
diff changeset
785 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
786 dirty = 1;
9f4fc9ecfd1f Make shapes and coords drawed in post-order of tree.
Thinker K.F. Li <thinker@branda.to>
parents: 135
diff changeset
787 }
139
1695a4b02b14 Members of coords are geos instead of shapes, now.
Thinker K.F. Li <thinker@branda.to>
parents: 138
diff changeset
788 member = STAILQ_NEXT(geo_t, coord_next, member);
1695a4b02b14 Members of coords are geos instead of shapes, now.
Thinker K.F. Li <thinker@branda.to>
parents: 138
diff changeset
789 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
790 }
9f4fc9ecfd1f Make shapes and coords drawed in post-order of tree.
Thinker K.F. Li <thinker@branda.to>
parents: 135
diff changeset
791 }
9f4fc9ecfd1f Make shapes and coords drawed in post-order of tree.
Thinker K.F. Li <thinker@branda.to>
parents: 135
diff changeset
792
9f4fc9ecfd1f Make shapes and coords drawed in post-order of tree.
Thinker K.F. Li <thinker@branda.to>
parents: 135
diff changeset
793 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
794 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
795 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
796 }
9f4fc9ecfd1f Make shapes and coords drawed in post-order of tree.
Thinker K.F. Li <thinker@branda.to>
parents: 135
diff changeset
797
9f4fc9ecfd1f Make shapes and coords drawed in post-order of tree.
Thinker K.F. Li <thinker@branda.to>
parents: 135
diff changeset
798 return dirty;
9f4fc9ecfd1f Make shapes and coords drawed in post-order of tree.
Thinker K.F. Li <thinker@branda.to>
parents: 135
diff changeset
799 }
9f4fc9ecfd1f Make shapes and coords drawed in post-order of tree.
Thinker K.F. Li <thinker@branda.to>
parents: 135
diff changeset
800
22
8fcf2d878ecd shapes with stroke
Thinker K.F. Li <thinker@branda.to>
parents: 20
diff changeset
801 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
802 int n_areas,
c2ce186a5c37 X_main uses rdman_redraw_all()
Thinker K.F. Li <thinker@branda.to>
parents: 14
diff changeset
803 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
804 draw_coord_shapes_in_areas(rdman, rdman->root_coord, n_areas, areas);
13
ed55009d96d3 refactory for redrawing
Thinker K.F. Li <thinker@branda.to>
parents: 12
diff changeset
805 }
ed55009d96d3 refactory for redrawing
Thinker K.F. Li <thinker@branda.to>
parents: 12
diff changeset
806
24
e598bc809c0f No more flash when animation.
Thinker K.F. Li <thinker@branda.to>
parents: 23
diff changeset
807
135
Thinker K.F. Li <thinker@branda.to>
parents: 133
diff changeset
808 /*! \page coord_opacity How to support opacity attribute for group (coord)?
Thinker K.F. Li <thinker@branda.to>
parents: 133
diff changeset
809 *
Thinker K.F. Li <thinker@branda.to>
parents: 133
diff changeset
810 * I have several ideas to do that. This page show you all ideas.
Thinker K.F. Li <thinker@branda.to>
parents: 133
diff changeset
811 *
Thinker K.F. Li <thinker@branda.to>
parents: 133
diff changeset
812 * \section idea_one First One
Thinker K.F. Li <thinker@branda.to>
parents: 133
diff changeset
813 * Change the structure of tree of coords. It is organized as tree of
Thinker K.F. Li <thinker@branda.to>
parents: 133
diff changeset
814 * SVG document, shapes and coords are putten in tree with order the same
Thinker K.F. Li <thinker@branda.to>
parents: 133
diff changeset
815 * as the document. The idea can solve the problem, but also seriously
Thinker K.F. Li <thinker@branda.to>
parents: 133
diff changeset
816 * impact current code.
Thinker K.F. Li <thinker@branda.to>
parents: 133
diff changeset
817 *
Thinker K.F. Li <thinker@branda.to>
parents: 133
diff changeset
818 * \section idea_two Second One
Thinker K.F. Li <thinker@branda.to>
parents: 133
diff changeset
819 * Add opacity and agg_opacity attribute to coord_t, and update
Thinker K.F. Li <thinker@branda.to>
parents: 133
diff changeset
820 *
Thinker K.F. Li <thinker@branda.to>
parents: 133
diff changeset
821 */
Thinker K.F. Li <thinker@branda.to>
parents: 133
diff changeset
822
13
ed55009d96d3 refactory for redrawing
Thinker K.F. Li <thinker@branda.to>
parents: 12
diff changeset
823 /*! \brief Re-draw all changed shapes or shapes affected by changed coords.
ed55009d96d3 refactory for redrawing
Thinker K.F. Li <thinker@branda.to>
parents: 12
diff changeset
824 *
ed55009d96d3 refactory for redrawing
Thinker K.F. Li <thinker@branda.to>
parents: 12
diff changeset
825 * A coord object has a geo to keep track the range that it's members will
ed55009d96d3 refactory for redrawing
Thinker K.F. Li <thinker@branda.to>
parents: 12
diff changeset
826 * draw on. Geo of a coord should be recomputed when the coord is changed.
ed55009d96d3 refactory for redrawing
Thinker K.F. Li <thinker@branda.to>
parents: 12
diff changeset
827 * Geo of a coord used to accelerate finding overlay shape objects of
ed55009d96d3 refactory for redrawing
Thinker K.F. Li <thinker@branda.to>
parents: 12
diff changeset
828 * a specified geo. A coord object also must be recomputed when one of
ed55009d96d3 refactory for redrawing
Thinker K.F. Li <thinker@branda.to>
parents: 12
diff changeset
829 * it's members is changed.
ed55009d96d3 refactory for redrawing
Thinker K.F. Li <thinker@branda.to>
parents: 12
diff changeset
830 *
ed55009d96d3 refactory for redrawing
Thinker K.F. Li <thinker@branda.to>
parents: 12
diff changeset
831 * New and old geo values of a coord object that is recomputed for
ed55009d96d3 refactory for redrawing
Thinker K.F. Li <thinker@branda.to>
parents: 12
diff changeset
832 * changing of it-self must be used to find overlay shape objects.
ed55009d96d3 refactory for redrawing
Thinker K.F. Li <thinker@branda.to>
parents: 12
diff changeset
833 * New and old geo values of a shape should also be used to find
ed55009d96d3 refactory for redrawing
Thinker K.F. Li <thinker@branda.to>
parents: 12
diff changeset
834 * overlay shape objects, too. If a shape's coord is changed, shape's
ed55009d96d3 refactory for redrawing
Thinker K.F. Li <thinker@branda.to>
parents: 12
diff changeset
835 * geo object is not used to find overlay shape objects any more.
ed55009d96d3 refactory for redrawing
Thinker K.F. Li <thinker@branda.to>
parents: 12
diff changeset
836 *
ed55009d96d3 refactory for redrawing
Thinker K.F. Li <thinker@branda.to>
parents: 12
diff changeset
837 * steps:
ed55009d96d3 refactory for redrawing
Thinker K.F. Li <thinker@branda.to>
parents: 12
diff changeset
838 * - update chagned coord objects
14
Thinker K.F. Li <thinker@branda.to>
parents: 13
diff changeset
839 * - recompute area for changed coord objects
13
ed55009d96d3 refactory for redrawing
Thinker K.F. Li <thinker@branda.to>
parents: 12
diff changeset
840 * - recompute geo for members shape objects
14
Thinker K.F. Li <thinker@branda.to>
parents: 13
diff changeset
841 * - clear dirty of geo for members to prevent from
Thinker K.F. Li <thinker@branda.to>
parents: 13
diff changeset
842 * recomputing for change of shape objects.
Thinker K.F. Li <thinker@branda.to>
parents: 13
diff changeset
843 * - add old and new area value to list of dirty areas.
13
ed55009d96d3 refactory for redrawing
Thinker K.F. Li <thinker@branda.to>
parents: 12
diff changeset
844 * - recompute geo for changed shape objects
14
Thinker K.F. Li <thinker@branda.to>
parents: 13
diff changeset
845 * - only if a shape object is dirty.
Thinker K.F. Li <thinker@branda.to>
parents: 13
diff changeset
846 * - put new and old value of area of geo to list of dirty areas.
Thinker K.F. Li <thinker@branda.to>
parents: 13
diff changeset
847 * - Scan all shapes and redraw shapes overlaid with dirty areas.
13
ed55009d96d3 refactory for redrawing
Thinker K.F. Li <thinker@branda.to>
parents: 12
diff changeset
848 *
14
Thinker K.F. Li <thinker@branda.to>
parents: 13
diff changeset
849 * 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
850 * 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
851 * 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
852 * corod objects.
14
Thinker K.F. Li <thinker@branda.to>
parents: 13
diff changeset
853 *
13
ed55009d96d3 refactory for redrawing
Thinker K.F. Li <thinker@branda.to>
parents: 12
diff changeset
854 */
ed55009d96d3 refactory for redrawing
Thinker K.F. Li <thinker@branda.to>
parents: 12
diff changeset
855 int rdman_redraw_changed(redraw_man_t *rdman) {
28
604bc90d509d Refactory
Thinker K.F. Li <thinker@branda.to>
parents: 27
diff changeset
856 int r;
13
ed55009d96d3 refactory for redrawing
Thinker K.F. Li <thinker@branda.to>
parents: 12
diff changeset
857 int n_dirty_areas;
14
Thinker K.F. Li <thinker@branda.to>
parents: 13
diff changeset
858 area_t **dirty_areas;
13
ed55009d96d3 refactory for redrawing
Thinker K.F. Li <thinker@branda.to>
parents: 12
diff changeset
859
29
Thinker K.F. Li <thinker@branda.to>
parents: 28
diff changeset
860 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
861 if(r != OK)
e17e12b112c4 A simple animation using rdman_redraw_changed().
Thinker K.F. Li <thinker@branda.to>
parents: 15
diff changeset
862 return ERR;
13
ed55009d96d3 refactory for redrawing
Thinker K.F. Li <thinker@branda.to>
parents: 12
diff changeset
863
15
c2ce186a5c37 X_main uses rdman_redraw_all()
Thinker K.F. Li <thinker@branda.to>
parents: 14
diff changeset
864 n_dirty_areas = rdman->n_dirty_areas;
c2ce186a5c37 X_main uses rdman_redraw_all()
Thinker K.F. Li <thinker@branda.to>
parents: 14
diff changeset
865 dirty_areas = rdman->dirty_areas;
c2ce186a5c37 X_main uses rdman_redraw_all()
Thinker K.F. Li <thinker@branda.to>
parents: 14
diff changeset
866 if(n_dirty_areas > 0) {
135
Thinker K.F. Li <thinker@branda.to>
parents: 133
diff changeset
867 /*! \brief Draw shapes in preorder of coord tree and support opacity
Thinker K.F. Li <thinker@branda.to>
parents: 133
diff changeset
868 * rules.
Thinker K.F. Li <thinker@branda.to>
parents: 133
diff changeset
869 */
25
29937c26bb01 Fix bug of a dark line appear when animating.
Thinker K.F. Li <thinker@branda.to>
parents: 24
diff changeset
870 clean_canvas(rdman->cr);
22
8fcf2d878ecd shapes with stroke
Thinker K.F. Li <thinker@branda.to>
parents: 20
diff changeset
871 draw_shapes_in_areas(rdman, n_dirty_areas, dirty_areas);
24
e598bc809c0f No more flash when animation.
Thinker K.F. Li <thinker@branda.to>
parents: 23
diff changeset
872 copy_cr_2_backend(rdman, rdman->n_dirty_areas, rdman->dirty_areas);
15
c2ce186a5c37 X_main uses rdman_redraw_all()
Thinker K.F. Li <thinker@branda.to>
parents: 14
diff changeset
873 rdman->n_dirty_areas = 0;
17
41f0907b27ac Unittest for rdman_redraw_changed().
Thinker K.F. Li <thinker@branda.to>
parents: 16
diff changeset
874 reset_clip(rdman);
15
c2ce186a5c37 X_main uses rdman_redraw_all()
Thinker K.F. Li <thinker@branda.to>
parents: 14
diff changeset
875 }
16
e17e12b112c4 A simple animation using rdman_redraw_changed().
Thinker K.F. Li <thinker@branda.to>
parents: 15
diff changeset
876 rdman->n_dirty_areas = 0;
e17e12b112c4 A simple animation using rdman_redraw_changed().
Thinker K.F. Li <thinker@branda.to>
parents: 15
diff changeset
877
15
c2ce186a5c37 X_main uses rdman_redraw_all()
Thinker K.F. Li <thinker@branda.to>
parents: 14
diff changeset
878 return OK;
c2ce186a5c37 X_main uses rdman_redraw_all()
Thinker K.F. Li <thinker@branda.to>
parents: 14
diff changeset
879 }
c2ce186a5c37 X_main uses rdman_redraw_all()
Thinker K.F. Li <thinker@branda.to>
parents: 14
diff changeset
880
38
Thinker K.F. Li <thinker@branda.to>
parents: 37
diff changeset
881 /* NOTE: Before redrawing, the canvas/surface must be cleaned.
Thinker K.F. Li <thinker@branda.to>
parents: 37
diff changeset
882 * NOTE: After redrawing, the content must be copied to the backend surface.
Thinker K.F. Li <thinker@branda.to>
parents: 37
diff changeset
883 */
Thinker K.F. Li <thinker@branda.to>
parents: 37
diff changeset
884
138
9f4fc9ecfd1f Make shapes and coords drawed in post-order of tree.
Thinker K.F. Li <thinker@branda.to>
parents: 135
diff changeset
885 /*! \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
886 *
9f4fc9ecfd1f Make shapes and coords drawed in post-order of tree.
Thinker K.F. Li <thinker@branda.to>
parents: 135
diff changeset
887 * 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
888 * 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
889 * 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
890 * 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
891 *
9f4fc9ecfd1f Make shapes and coords drawed in post-order of tree.
Thinker K.F. Li <thinker@branda.to>
parents: 135
diff changeset
892 * 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
893 * 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
894 * 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
895 * 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
896 * 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
897 * 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
898 *
9f4fc9ecfd1f Make shapes and coords drawed in post-order of tree.
Thinker K.F. Li <thinker@branda.to>
parents: 135
diff changeset
899 * \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
900 *
9f4fc9ecfd1f Make shapes and coords drawed in post-order of tree.
Thinker K.F. Li <thinker@branda.to>
parents: 135
diff changeset
901 * \sa
9f4fc9ecfd1f Make shapes and coords drawed in post-order of tree.
Thinker K.F. Li <thinker@branda.to>
parents: 135
diff changeset
902 * - 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
903 * - rdman_redraw_changed()
9f4fc9ecfd1f Make shapes and coords drawed in post-order of tree.
Thinker K.F. Li <thinker@branda.to>
parents: 135
diff changeset
904 * = draw_shapes_in_areas()
9f4fc9ecfd1f Make shapes and coords drawed in post-order of tree.
Thinker K.F. Li <thinker@branda.to>
parents: 135
diff changeset
905 */
9f4fc9ecfd1f Make shapes and coords drawed in post-order of tree.
Thinker K.F. Li <thinker@branda.to>
parents: 135
diff changeset
906
15
c2ce186a5c37 X_main uses rdman_redraw_all()
Thinker K.F. Li <thinker@branda.to>
parents: 14
diff changeset
907 int rdman_redraw_all(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
908 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
909 area_t area;
29
Thinker K.F. Li <thinker@branda.to>
parents: 28
diff changeset
910 int r;
15
c2ce186a5c37 X_main uses rdman_redraw_all()
Thinker K.F. Li <thinker@branda.to>
parents: 14
diff changeset
911
138
9f4fc9ecfd1f Make shapes and coords drawed in post-order of tree.
Thinker K.F. Li <thinker@branda.to>
parents: 135
diff changeset
912 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
913 #ifndef UNITTEST
9f4fc9ecfd1f Make shapes and coords drawed in post-order of tree.
Thinker K.F. Li <thinker@branda.to>
parents: 135
diff changeset
914 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
915 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
916 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
917 #else
9f4fc9ecfd1f Make shapes and coords drawed in post-order of tree.
Thinker K.F. Li <thinker@branda.to>
parents: 135
diff changeset
918 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
919 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
920 #endif
9f4fc9ecfd1f Make shapes and coords drawed in post-order of tree.
Thinker K.F. Li <thinker@branda.to>
parents: 135
diff changeset
921 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
922
9f4fc9ecfd1f Make shapes and coords drawed in post-order of tree.
Thinker K.F. Li <thinker@branda.to>
parents: 135
diff changeset
923 r = rdman_redraw_changed(rdman);
29
Thinker K.F. Li <thinker@branda.to>
parents: 28
diff changeset
924 if(r != OK)
Thinker K.F. Li <thinker@branda.to>
parents: 28
diff changeset
925 return ERR;
16
e17e12b112c4 A simple animation using rdman_redraw_changed().
Thinker K.F. Li <thinker@branda.to>
parents: 15
diff changeset
926
13
ed55009d96d3 refactory for redrawing
Thinker K.F. Li <thinker@branda.to>
parents: 12
diff changeset
927 return OK;
12
79e9edf4c00a Add redraw manager
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
928 }
79e9edf4c00a Add redraw manager
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
929
37
943acee7f346 update exposed area
Thinker K.F. Li <thinker@branda.to>
parents: 35
diff changeset
930 int rdman_redraw_area(redraw_man_t *rdman, co_aix x, co_aix y,
943acee7f346 update exposed area
Thinker K.F. Li <thinker@branda.to>
parents: 35
diff changeset
931 co_aix w, co_aix h) {
943acee7f346 update exposed area
Thinker K.F. Li <thinker@branda.to>
parents: 35
diff changeset
932 area_t area;
943acee7f346 update exposed area
Thinker K.F. Li <thinker@branda.to>
parents: 35
diff changeset
933 int r;
943acee7f346 update exposed area
Thinker K.F. Li <thinker@branda.to>
parents: 35
diff changeset
934
943acee7f346 update exposed area
Thinker K.F. Li <thinker@branda.to>
parents: 35
diff changeset
935 area.x = x;
943acee7f346 update exposed area
Thinker K.F. Li <thinker@branda.to>
parents: 35
diff changeset
936 area.y = y;
943acee7f346 update exposed area
Thinker K.F. Li <thinker@branda.to>
parents: 35
diff changeset
937 area.w = w;
943acee7f346 update exposed area
Thinker K.F. Li <thinker@branda.to>
parents: 35
diff changeset
938 area.h = h;
943acee7f346 update exposed area
Thinker K.F. Li <thinker@branda.to>
parents: 35
diff changeset
939 add_dirty_area(rdman, &area);
943acee7f346 update exposed area
Thinker K.F. Li <thinker@branda.to>
parents: 35
diff changeset
940
943acee7f346 update exposed area
Thinker K.F. Li <thinker@branda.to>
parents: 35
diff changeset
941 r = rdman_redraw_changed(rdman);
943acee7f346 update exposed area
Thinker K.F. Li <thinker@branda.to>
parents: 35
diff changeset
942
943acee7f346 update exposed area
Thinker K.F. Li <thinker@branda.to>
parents: 35
diff changeset
943 return r;
943acee7f346 update exposed area
Thinker K.F. Li <thinker@branda.to>
parents: 35
diff changeset
944 }
943acee7f346 update exposed area
Thinker K.F. Li <thinker@branda.to>
parents: 35
diff changeset
945
139
1695a4b02b14 Members of coords are geos instead of shapes, now.
Thinker K.F. Li <thinker@branda.to>
parents: 138
diff changeset
946 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
947 geo_t *next;
1695a4b02b14 Members of coords are geos instead of shapes, now.
Thinker K.F. Li <thinker@branda.to>
parents: 138
diff changeset
948 coord_t *coord;
1695a4b02b14 Members of coords are geos instead of shapes, now.
Thinker K.F. Li <thinker@branda.to>
parents: 138
diff changeset
949
1695a4b02b14 Members of coords are geos instead of shapes, now.
Thinker K.F. Li <thinker@branda.to>
parents: 138
diff changeset
950 if(last == NULL) {
1695a4b02b14 Members of coords are geos instead of shapes, now.
Thinker K.F. Li <thinker@branda.to>
parents: 138
diff changeset
951 coord = rdman->root_coord;
1695a4b02b14 Members of coords are geos instead of shapes, now.
Thinker K.F. Li <thinker@branda.to>
parents: 138
diff changeset
952 while(coord != NULL && STAILQ_HEAD(coord->members) == NULL)
1695a4b02b14 Members of coords are geos instead of shapes, now.
Thinker K.F. Li <thinker@branda.to>
parents: 138
diff changeset
953 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
954 if(coord == NULL)
1695a4b02b14 Members of coords are geos instead of shapes, now.
Thinker K.F. Li <thinker@branda.to>
parents: 138
diff changeset
955 return NULL;
1695a4b02b14 Members of coords are geos instead of shapes, now.
Thinker K.F. Li <thinker@branda.to>
parents: 138
diff changeset
956 return STAILQ_HEAD(coord->members);
1695a4b02b14 Members of coords are geos instead of shapes, now.
Thinker K.F. Li <thinker@branda.to>
parents: 138
diff changeset
957 }
1695a4b02b14 Members of coords are geos instead of shapes, now.
Thinker K.F. Li <thinker@branda.to>
parents: 138
diff changeset
958
1695a4b02b14 Members of coords are geos instead of shapes, now.
Thinker K.F. Li <thinker@branda.to>
parents: 138
diff changeset
959 coord = last->shape->coord;
1695a4b02b14 Members of coords are geos instead of shapes, now.
Thinker K.F. Li <thinker@branda.to>
parents: 138
diff changeset
960 next = STAILQ_NEXT(geo_t, coord_next, last);
1695a4b02b14 Members of coords are geos instead of shapes, now.
Thinker K.F. Li <thinker@branda.to>
parents: 138
diff changeset
961 while(next == NULL) {
1695a4b02b14 Members of coords are geos instead of shapes, now.
Thinker K.F. Li <thinker@branda.to>
parents: 138
diff changeset
962 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
963 if(coord == NULL)
1695a4b02b14 Members of coords are geos instead of shapes, now.
Thinker K.F. Li <thinker@branda.to>
parents: 138
diff changeset
964 return NULL;
1695a4b02b14 Members of coords are geos instead of shapes, now.
Thinker K.F. Li <thinker@branda.to>
parents: 138
diff changeset
965 next = STAILQ_HEAD(coord->members);
1695a4b02b14 Members of coords are geos instead of shapes, now.
Thinker K.F. Li <thinker@branda.to>
parents: 138
diff changeset
966 }
1695a4b02b14 Members of coords are geos instead of shapes, now.
Thinker K.F. Li <thinker@branda.to>
parents: 138
diff changeset
967 return next;
1695a4b02b14 Members of coords are geos instead of shapes, now.
Thinker K.F. Li <thinker@branda.to>
parents: 138
diff changeset
968 }
1695a4b02b14 Members of coords are geos instead of shapes, now.
Thinker K.F. Li <thinker@branda.to>
parents: 138
diff changeset
969
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
970 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
971 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
972
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
973 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
974
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
975 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
976 }
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
977
18
0f3baa488a62 Support solid color paint for fill.
Thinker K.F. Li <thinker@branda.to>
parents: 17
diff changeset
978 shnode_t *shnode_new(redraw_man_t *rdman, shape_t *shape) {
0f3baa488a62 Support solid color paint for fill.
Thinker K.F. Li <thinker@branda.to>
parents: 17
diff changeset
979 shnode_t *node;
0f3baa488a62 Support solid color paint for fill.
Thinker K.F. Li <thinker@branda.to>
parents: 17
diff changeset
980
0f3baa488a62 Support solid color paint for fill.
Thinker K.F. Li <thinker@branda.to>
parents: 17
diff changeset
981 node = (shnode_t *)elmpool_elm_alloc(rdman->shnode_pool);
0f3baa488a62 Support solid color paint for fill.
Thinker K.F. Li <thinker@branda.to>
parents: 17
diff changeset
982 if(node) {
0f3baa488a62 Support solid color paint for fill.
Thinker K.F. Li <thinker@branda.to>
parents: 17
diff changeset
983 node->shape = shape;
0f3baa488a62 Support solid color paint for fill.
Thinker K.F. Li <thinker@branda.to>
parents: 17
diff changeset
984 node->next = NULL;
0f3baa488a62 Support solid color paint for fill.
Thinker K.F. Li <thinker@branda.to>
parents: 17
diff changeset
985 }
0f3baa488a62 Support solid color paint for fill.
Thinker K.F. Li <thinker@branda.to>
parents: 17
diff changeset
986 return node;
0f3baa488a62 Support solid color paint for fill.
Thinker K.F. Li <thinker@branda.to>
parents: 17
diff changeset
987 }
0f3baa488a62 Support solid color paint for fill.
Thinker K.F. Li <thinker@branda.to>
parents: 17
diff changeset
988
135
Thinker K.F. Li <thinker@branda.to>
parents: 133
diff changeset
989 /*! \page dirty Dirty geo, coord, and area.
Thinker K.F. Li <thinker@branda.to>
parents: 133
diff changeset
990 *
Thinker K.F. Li <thinker@branda.to>
parents: 133
diff changeset
991 * \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
992 * 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
993 * 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
994 * 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
995 * 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
996 * size, and positions.
e17e12b112c4 A simple animation using rdman_redraw_changed().
Thinker K.F. Li <thinker@branda.to>
parents: 15
diff changeset
997 *
135
Thinker K.F. Li <thinker@branda.to>
parents: 133
diff changeset
998 * \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
999 * 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
1000 * 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
1001 * 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
1002 * 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
1003 * 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
1004 * 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
1005 * 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
1006 * 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
1007 * 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
1008 * 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
1009 * 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
1010 * 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
1011 * 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
1012 *
e17e12b112c4 A simple animation using rdman_redraw_changed().
Thinker K.F. Li <thinker@branda.to>
parents: 15
diff changeset
1013 * 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
1014 * 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
1015 *
e17e12b112c4 A simple animation using rdman_redraw_changed().
Thinker K.F. Li <thinker@branda.to>
parents: 15
diff changeset
1016 * 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
1017 * 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
1018 * 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
1019 *
e17e12b112c4 A simple animation using rdman_redraw_changed().
Thinker K.F. Li <thinker@branda.to>
parents: 15
diff changeset
1020 * 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
1021 * 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
1022 */
e17e12b112c4 A simple animation using rdman_redraw_changed().
Thinker K.F. Li <thinker@branda.to>
parents: 15
diff changeset
1023
e17e12b112c4 A simple animation using rdman_redraw_changed().
Thinker K.F. Li <thinker@branda.to>
parents: 15
diff changeset
1024 /*
12
79e9edf4c00a Add redraw manager
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
1025 * When redraw an area, the affected elements may also extend to
79e9edf4c00a Add redraw manager
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
1026 * outside of the area. Since the order of drawing will change
79e9edf4c00a Add redraw manager
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
1027 * the result, it will infect more and more elements to keep
79e9edf4c00a Add redraw manager
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
1028 * drawing order althrough they are overlaid directly with
79e9edf4c00a Add redraw manager
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
1029 * specified area.
79e9edf4c00a Add redraw manager
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
1030 *
79e9edf4c00a Add redraw manager
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
1031 * To fix the problem, we don't extend the set of redrawing to
79e9edf4c00a Add redraw manager
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
1032 * elements they are not overliad directly. The redrawing is
79e9edf4c00a Add redraw manager
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
1033 * performed on a temporary surface, clipped to fit the area, and
79e9edf4c00a Add redraw manager
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
1034 * update only specified area on the destinate surface.
79e9edf4c00a Add redraw manager
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
1035 */
79e9edf4c00a Add redraw manager
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
1036
79e9edf4c00a Add redraw manager
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
1037 /*
79e9edf4c00a Add redraw manager
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
1038 * To accelerate speed of transformation, when a matrix changed,
79e9edf4c00a Add redraw manager
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
1039 * transformation should be aggregated and computed in a loop.
79e9edf4c00a Add redraw manager
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
1040 * It can get intereset of higher hit rate of cache.
79e9edf4c00a Add redraw manager
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
1041 * - shapes prvoide list of positions needed to be transformed.
79e9edf4c00a Add redraw manager
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
1042 * - redraw_man transforms positions from shapes.
79e9edf4c00a Add redraw manager
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
1043 * - shapes drawing with result of transforms.
79e9edf4c00a Add redraw manager
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
1044 * - shapes should be called to give them a chance to update geometries.
79e9edf4c00a Add redraw manager
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
1045 */
79e9edf4c00a Add redraw manager
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
1046
13
ed55009d96d3 refactory for redrawing
Thinker K.F. Li <thinker@branda.to>
parents: 12
diff changeset
1047 /*
ed55009d96d3 refactory for redrawing
Thinker K.F. Li <thinker@branda.to>
parents: 12
diff changeset
1048 * functions:
ed55009d96d3 refactory for redrawing
Thinker K.F. Li <thinker@branda.to>
parents: 12
diff changeset
1049 * - redraw all
ed55009d96d3 refactory for redrawing
Thinker K.F. Li <thinker@branda.to>
parents: 12
diff changeset
1050 * - redraw changed
ed55009d96d3 refactory for redrawing
Thinker K.F. Li <thinker@branda.to>
parents: 12
diff changeset
1051 */
ed55009d96d3 refactory for redrawing
Thinker K.F. Li <thinker@branda.to>
parents: 12
diff changeset
1052
73
9ab15ebc9061 Observer for mouse events
Thinker K.F. Li <thinker@branda.to>
parents: 58
diff changeset
1053 /* 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
1054 */
9ab15ebc9061 Observer for mouse events
Thinker K.F. Li <thinker@branda.to>
parents: 58
diff changeset
1055 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
1056 redraw_man_t *rdman;
9ab15ebc9061 Observer for mouse events
Thinker K.F. Li <thinker@branda.to>
parents: 58
diff changeset
1057 subject_t *subject;
9ab15ebc9061 Observer for mouse events
Thinker K.F. Li <thinker@branda.to>
parents: 58
diff changeset
1058
9ab15ebc9061 Observer for mouse events
Thinker K.F. Li <thinker@branda.to>
parents: 58
diff changeset
1059 rdman = MEM2OBJ(factory, redraw_man_t, ob_factory);
9ab15ebc9061 Observer for mouse events
Thinker K.F. Li <thinker@branda.to>
parents: 58
diff changeset
1060 subject = elmpool_elm_alloc(rdman->subject_pool);
9ab15ebc9061 Observer for mouse events
Thinker K.F. Li <thinker@branda.to>
parents: 58
diff changeset
1061
9ab15ebc9061 Observer for mouse events
Thinker K.F. Li <thinker@branda.to>
parents: 58
diff changeset
1062 return subject;
9ab15ebc9061 Observer for mouse events
Thinker K.F. Li <thinker@branda.to>
parents: 58
diff changeset
1063 }
9ab15ebc9061 Observer for mouse events
Thinker K.F. Li <thinker@branda.to>
parents: 58
diff changeset
1064
9ab15ebc9061 Observer for mouse events
Thinker K.F. Li <thinker@branda.to>
parents: 58
diff changeset
1065 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
1066 redraw_man_t *rdman;
9ab15ebc9061 Observer for mouse events
Thinker K.F. Li <thinker@branda.to>
parents: 58
diff changeset
1067
9ab15ebc9061 Observer for mouse events
Thinker K.F. Li <thinker@branda.to>
parents: 58
diff changeset
1068 rdman = MEM2OBJ(factory, redraw_man_t, ob_factory);
9ab15ebc9061 Observer for mouse events
Thinker K.F. Li <thinker@branda.to>
parents: 58
diff changeset
1069 elmpool_elm_free(rdman->subject_pool, subject);
9ab15ebc9061 Observer for mouse events
Thinker K.F. Li <thinker@branda.to>
parents: 58
diff changeset
1070 }
9ab15ebc9061 Observer for mouse events
Thinker K.F. Li <thinker@branda.to>
parents: 58
diff changeset
1071
9ab15ebc9061 Observer for mouse events
Thinker K.F. Li <thinker@branda.to>
parents: 58
diff changeset
1072 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
1073 redraw_man_t *rdman;
9ab15ebc9061 Observer for mouse events
Thinker K.F. Li <thinker@branda.to>
parents: 58
diff changeset
1074 observer_t *observer;
9ab15ebc9061 Observer for mouse events
Thinker K.F. Li <thinker@branda.to>
parents: 58
diff changeset
1075
9ab15ebc9061 Observer for mouse events
Thinker K.F. Li <thinker@branda.to>
parents: 58
diff changeset
1076 rdman = MEM2OBJ(factory, redraw_man_t, ob_factory);
9ab15ebc9061 Observer for mouse events
Thinker K.F. Li <thinker@branda.to>
parents: 58
diff changeset
1077 observer = elmpool_elm_alloc(rdman->observer_pool);
9ab15ebc9061 Observer for mouse events
Thinker K.F. Li <thinker@branda.to>
parents: 58
diff changeset
1078
9ab15ebc9061 Observer for mouse events
Thinker K.F. Li <thinker@branda.to>
parents: 58
diff changeset
1079 return observer;
9ab15ebc9061 Observer for mouse events
Thinker K.F. Li <thinker@branda.to>
parents: 58
diff changeset
1080 }
9ab15ebc9061 Observer for mouse events
Thinker K.F. Li <thinker@branda.to>
parents: 58
diff changeset
1081
9ab15ebc9061 Observer for mouse events
Thinker K.F. Li <thinker@branda.to>
parents: 58
diff changeset
1082 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
1083 redraw_man_t *rdman;
9ab15ebc9061 Observer for mouse events
Thinker K.F. Li <thinker@branda.to>
parents: 58
diff changeset
1084
9ab15ebc9061 Observer for mouse events
Thinker K.F. Li <thinker@branda.to>
parents: 58
diff changeset
1085 rdman = MEM2OBJ(factory, redraw_man_t, ob_factory);
9ab15ebc9061 Observer for mouse events
Thinker K.F. Li <thinker@branda.to>
parents: 58
diff changeset
1086 elmpool_elm_free(rdman->observer_pool, observer);
9ab15ebc9061 Observer for mouse events
Thinker K.F. Li <thinker@branda.to>
parents: 58
diff changeset
1087 }
9ab15ebc9061 Observer for mouse events
Thinker K.F. Li <thinker@branda.to>
parents: 58
diff changeset
1088
9ab15ebc9061 Observer for mouse events
Thinker K.F. Li <thinker@branda.to>
parents: 58
diff changeset
1089 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
1090 subject_t *cur_subject) {
9ab15ebc9061 Observer for mouse events
Thinker K.F. Li <thinker@branda.to>
parents: 58
diff changeset
1091 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
1092 coord_t *coord, *parent_coord;
73
9ab15ebc9061 Observer for mouse events
Thinker K.F. Li <thinker@branda.to>
parents: 58
diff changeset
1093 geo_t *geo;
9ab15ebc9061 Observer for mouse events
Thinker K.F. Li <thinker@branda.to>
parents: 58
diff changeset
1094 subject_t *parent;
9ab15ebc9061 Observer for mouse events
Thinker K.F. Li <thinker@branda.to>
parents: 58
diff changeset
1095
9ab15ebc9061 Observer for mouse events
Thinker K.F. Li <thinker@branda.to>
parents: 58
diff changeset
1096 rdman = MEM2OBJ(factory, redraw_man_t, ob_factory);
9ab15ebc9061 Observer for mouse events
Thinker K.F. Li <thinker@branda.to>
parents: 58
diff changeset
1097 switch(cur_subject->obj_type) {
9ab15ebc9061 Observer for mouse events
Thinker K.F. Li <thinker@branda.to>
parents: 58
diff changeset
1098 case OBJT_GEO:
9ab15ebc9061 Observer for mouse events
Thinker K.F. Li <thinker@branda.to>
parents: 58
diff changeset
1099 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
1100 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
1101 parent = parent_coord->mouse_event;
73
9ab15ebc9061 Observer for mouse events
Thinker K.F. Li <thinker@branda.to>
parents: 58
diff changeset
1102 break;
9ab15ebc9061 Observer for mouse events
Thinker K.F. Li <thinker@branda.to>
parents: 58
diff changeset
1103 case OBJT_COORD:
9ab15ebc9061 Observer for mouse events
Thinker K.F. Li <thinker@branda.to>
parents: 58
diff changeset
1104 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
1105 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
1106 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
1107 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
1108 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
1109 }
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
1110 parent = parent_coord->mouse_event;
73
9ab15ebc9061 Observer for mouse events
Thinker K.F. Li <thinker@branda.to>
parents: 58
diff changeset
1111 break;
9ab15ebc9061 Observer for mouse events
Thinker K.F. Li <thinker@branda.to>
parents: 58
diff changeset
1112 default:
9ab15ebc9061 Observer for mouse events
Thinker K.F. Li <thinker@branda.to>
parents: 58
diff changeset
1113 parent = NULL;
9ab15ebc9061 Observer for mouse events
Thinker K.F. Li <thinker@branda.to>
parents: 58
diff changeset
1114 break;
9ab15ebc9061 Observer for mouse events
Thinker K.F. Li <thinker@branda.to>
parents: 58
diff changeset
1115 }
9ab15ebc9061 Observer for mouse events
Thinker K.F. Li <thinker@branda.to>
parents: 58
diff changeset
1116
9ab15ebc9061 Observer for mouse events
Thinker K.F. Li <thinker@branda.to>
parents: 58
diff changeset
1117 return parent;
9ab15ebc9061 Observer for mouse events
Thinker K.F. Li <thinker@branda.to>
parents: 58
diff changeset
1118 }
9ab15ebc9061 Observer for mouse events
Thinker K.F. Li <thinker@branda.to>
parents: 58
diff changeset
1119
12
79e9edf4c00a Add redraw manager
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
1120 #ifdef UNITTEST
73
9ab15ebc9061 Observer for mouse events
Thinker K.F. Li <thinker@branda.to>
parents: 58
diff changeset
1121 /* Test cases */
12
79e9edf4c00a Add redraw manager
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
1122
79e9edf4c00a Add redraw manager
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
1123 #include <CUnit/Basic.h>
19
cf6d65398619 More animation demo
Thinker K.F. Li <thinker@branda.to>
parents: 18
diff changeset
1124 #include "paint.h"
12
79e9edf4c00a Add redraw manager
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
1125
79e9edf4c00a Add redraw manager
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
1126 struct _sh_dummy {
79e9edf4c00a Add redraw manager
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
1127 shape_t shape;
79e9edf4c00a Add redraw manager
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
1128 co_aix x, y;
79e9edf4c00a Add redraw manager
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
1129 co_aix w, h;
119
257a1d314bcd Bug of insert sort
Thinker K.F. Li <thinker@branda.to>
parents: 115
diff changeset
1130 int trans_cnt;
17
41f0907b27ac Unittest for rdman_redraw_changed().
Thinker K.F. Li <thinker@branda.to>
parents: 16
diff changeset
1131 int draw_cnt;
12
79e9edf4c00a Add redraw manager
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
1132 };
79e9edf4c00a Add redraw manager
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
1133
79e9edf4c00a Add redraw manager
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
1134 shape_t *sh_dummy_new(co_aix x, co_aix y, co_aix w, co_aix h) {
79e9edf4c00a Add redraw manager
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
1135 sh_dummy_t *dummy;
79e9edf4c00a Add redraw manager
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
1136
79e9edf4c00a Add redraw manager
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
1137 dummy = (sh_dummy_t *)malloc(sizeof(sh_dummy_t));
79e9edf4c00a Add redraw manager
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
1138 if(dummy == NULL)
79e9edf4c00a Add redraw manager
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
1139 return NULL;
79e9edf4c00a Add redraw manager
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
1140
17
41f0907b27ac Unittest for rdman_redraw_changed().
Thinker K.F. Li <thinker@branda.to>
parents: 16
diff changeset
1141 memset(dummy, 0, sizeof(sh_dummy_t));
41f0907b27ac Unittest for rdman_redraw_changed().
Thinker K.F. Li <thinker@branda.to>
parents: 16
diff changeset
1142
12
79e9edf4c00a Add redraw manager
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
1143 dummy->x = x;
79e9edf4c00a Add redraw manager
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
1144 dummy->y = y;
79e9edf4c00a Add redraw manager
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
1145 dummy->w = w;
79e9edf4c00a Add redraw manager
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
1146 dummy->h = h;
119
257a1d314bcd Bug of insert sort
Thinker K.F. Li <thinker@branda.to>
parents: 115
diff changeset
1147 dummy->trans_cnt = 0;
17
41f0907b27ac Unittest for rdman_redraw_changed().
Thinker K.F. Li <thinker@branda.to>
parents: 16
diff changeset
1148 dummy->draw_cnt = 0;
12
79e9edf4c00a Add redraw manager
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
1149
79e9edf4c00a Add redraw manager
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
1150 return (shape_t *)dummy;
79e9edf4c00a Add redraw manager
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
1151 }
79e9edf4c00a Add redraw manager
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
1152
79e9edf4c00a Add redraw manager
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
1153 void sh_dummy_free(shape_t *sh) {
79e9edf4c00a Add redraw manager
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
1154 free(sh);
79e9edf4c00a Add redraw manager
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
1155 }
79e9edf4c00a Add redraw manager
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
1156
79e9edf4c00a Add redraw manager
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
1157 void sh_dummy_transform(shape_t *shape) {
79e9edf4c00a Add redraw manager
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
1158 sh_dummy_t *dummy = (sh_dummy_t *)shape;
79e9edf4c00a Add redraw manager
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
1159 co_aix poses[2][2];
79e9edf4c00a Add redraw manager
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
1160 co_aix x1, y1, x2, y2;
79e9edf4c00a Add redraw manager
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
1161
79e9edf4c00a Add redraw manager
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
1162 if(shape->geo && shape->coord) {
79e9edf4c00a Add redraw manager
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
1163 x1 = dummy->x;
79e9edf4c00a Add redraw manager
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
1164 y1 = dummy->y;
79e9edf4c00a Add redraw manager
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
1165 x2 = x1 + dummy->w;
79e9edf4c00a Add redraw manager
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
1166 y2 = y1 + dummy->h;
79e9edf4c00a Add redraw manager
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
1167
79e9edf4c00a Add redraw manager
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
1168 coord_trans_pos(shape->coord, &x1, &y1);
79e9edf4c00a Add redraw manager
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
1169 coord_trans_pos(shape->coord, &x2, &y2);
79e9edf4c00a Add redraw manager
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
1170 poses[0][0] = x1;
79e9edf4c00a Add redraw manager
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
1171 poses[0][1] = y1;
79e9edf4c00a Add redraw manager
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
1172 poses[1][0] = x2;
79e9edf4c00a Add redraw manager
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
1173 poses[1][1] = y2;
79e9edf4c00a Add redraw manager
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
1174
17
41f0907b27ac Unittest for rdman_redraw_changed().
Thinker K.F. Li <thinker@branda.to>
parents: 16
diff changeset
1175 if(shape->geo)
41f0907b27ac Unittest for rdman_redraw_changed().
Thinker K.F. Li <thinker@branda.to>
parents: 16
diff changeset
1176 geo_from_positions(shape->geo, 2, poses);
12
79e9edf4c00a Add redraw manager
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
1177 }
119
257a1d314bcd Bug of insert sort
Thinker K.F. Li <thinker@branda.to>
parents: 115
diff changeset
1178 dummy->trans_cnt++;
12
79e9edf4c00a Add redraw manager
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
1179 }
79e9edf4c00a Add redraw manager
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
1180
20
74d3d5dc9aaa rename XXX_draw() to XXX_fill()
Thinker K.F. Li <thinker@branda.to>
parents: 19
diff changeset
1181 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
1182 sh_dummy_t *dummy;
41f0907b27ac Unittest for rdman_redraw_changed().
Thinker K.F. Li <thinker@branda.to>
parents: 16
diff changeset
1183
41f0907b27ac Unittest for rdman_redraw_changed().
Thinker K.F. Li <thinker@branda.to>
parents: 16
diff changeset
1184 dummy = (sh_dummy_t *)shape;
41f0907b27ac Unittest for rdman_redraw_changed().
Thinker K.F. Li <thinker@branda.to>
parents: 16
diff changeset
1185 dummy->draw_cnt++;
41f0907b27ac Unittest for rdman_redraw_changed().
Thinker K.F. Li <thinker@branda.to>
parents: 16
diff changeset
1186 }
41f0907b27ac Unittest for rdman_redraw_changed().
Thinker K.F. Li <thinker@branda.to>
parents: 16
diff changeset
1187
19
cf6d65398619 More animation demo
Thinker K.F. Li <thinker@branda.to>
parents: 18
diff changeset
1188 static void dummy_paint_prepare(paint_t *paint, cairo_t *cr) {
cf6d65398619 More animation demo
Thinker K.F. Li <thinker@branda.to>
parents: 18
diff changeset
1189 }
cf6d65398619 More animation demo
Thinker K.F. Li <thinker@branda.to>
parents: 18
diff changeset
1190
cf6d65398619 More animation demo
Thinker K.F. Li <thinker@branda.to>
parents: 18
diff changeset
1191 static void dummy_paint_free(paint_t *paint) {
cf6d65398619 More animation demo
Thinker K.F. Li <thinker@branda.to>
parents: 18
diff changeset
1192 if(paint)
cf6d65398619 More animation demo
Thinker K.F. Li <thinker@branda.to>
parents: 18
diff changeset
1193 free(paint);
cf6d65398619 More animation demo
Thinker K.F. Li <thinker@branda.to>
parents: 18
diff changeset
1194 }
cf6d65398619 More animation demo
Thinker K.F. Li <thinker@branda.to>
parents: 18
diff changeset
1195
cf6d65398619 More animation demo
Thinker K.F. Li <thinker@branda.to>
parents: 18
diff changeset
1196 paint_t *dummy_paint_new(redraw_man_t *rdman) {
cf6d65398619 More animation demo
Thinker K.F. Li <thinker@branda.to>
parents: 18
diff changeset
1197 paint_t *paint;
cf6d65398619 More animation demo
Thinker K.F. Li <thinker@branda.to>
parents: 18
diff changeset
1198
cf6d65398619 More animation demo
Thinker K.F. Li <thinker@branda.to>
parents: 18
diff changeset
1199 paint = (paint_t *)malloc(sizeof(paint_t));
cf6d65398619 More animation demo
Thinker K.F. Li <thinker@branda.to>
parents: 18
diff changeset
1200 if(paint == NULL)
cf6d65398619 More animation demo
Thinker K.F. Li <thinker@branda.to>
parents: 18
diff changeset
1201 return NULL;
cf6d65398619 More animation demo
Thinker K.F. Li <thinker@branda.to>
parents: 18
diff changeset
1202
cf6d65398619 More animation demo
Thinker K.F. Li <thinker@branda.to>
parents: 18
diff changeset
1203 paint_init(paint, dummy_paint_prepare, dummy_paint_free);
cf6d65398619 More animation demo
Thinker K.F. Li <thinker@branda.to>
parents: 18
diff changeset
1204
cf6d65398619 More animation demo
Thinker K.F. Li <thinker@branda.to>
parents: 18
diff changeset
1205 return paint;
cf6d65398619 More animation demo
Thinker K.F. Li <thinker@branda.to>
parents: 18
diff changeset
1206 }
cf6d65398619 More animation demo
Thinker K.F. Li <thinker@branda.to>
parents: 18
diff changeset
1207
17
41f0907b27ac Unittest for rdman_redraw_changed().
Thinker K.F. Li <thinker@branda.to>
parents: 16
diff changeset
1208 void test_rdman_redraw_changed(void) {
41f0907b27ac Unittest for rdman_redraw_changed().
Thinker K.F. Li <thinker@branda.to>
parents: 16
diff changeset
1209 coord_t *coords[3];
41f0907b27ac Unittest for rdman_redraw_changed().
Thinker K.F. Li <thinker@branda.to>
parents: 16
diff changeset
1210 shape_t *shapes[3];
41f0907b27ac Unittest for rdman_redraw_changed().
Thinker K.F. Li <thinker@branda.to>
parents: 16
diff changeset
1211 sh_dummy_t **dummys;
19
cf6d65398619 More animation demo
Thinker K.F. Li <thinker@branda.to>
parents: 18
diff changeset
1212 paint_t *paint;
17
41f0907b27ac Unittest for rdman_redraw_changed().
Thinker K.F. Li <thinker@branda.to>
parents: 16
diff changeset
1213 redraw_man_t *rdman;
41f0907b27ac Unittest for rdman_redraw_changed().
Thinker K.F. Li <thinker@branda.to>
parents: 16
diff changeset
1214 redraw_man_t _rdman;
41f0907b27ac Unittest for rdman_redraw_changed().
Thinker K.F. Li <thinker@branda.to>
parents: 16
diff changeset
1215 int i;
41f0907b27ac Unittest for rdman_redraw_changed().
Thinker K.F. Li <thinker@branda.to>
parents: 16
diff changeset
1216
41f0907b27ac Unittest for rdman_redraw_changed().
Thinker K.F. Li <thinker@branda.to>
parents: 16
diff changeset
1217 dummys = (sh_dummy_t **)shapes;
41f0907b27ac Unittest for rdman_redraw_changed().
Thinker K.F. Li <thinker@branda.to>
parents: 16
diff changeset
1218
41f0907b27ac Unittest for rdman_redraw_changed().
Thinker K.F. Li <thinker@branda.to>
parents: 16
diff changeset
1219 rdman = &_rdman;
24
e598bc809c0f No more flash when animation.
Thinker K.F. Li <thinker@branda.to>
parents: 23
diff changeset
1220 redraw_man_init(rdman, NULL, NULL);
19
cf6d65398619 More animation demo
Thinker K.F. Li <thinker@branda.to>
parents: 18
diff changeset
1221 paint = dummy_paint_new(rdman);
17
41f0907b27ac Unittest for rdman_redraw_changed().
Thinker K.F. Li <thinker@branda.to>
parents: 16
diff changeset
1222 for(i = 0; i < 3; i++) {
41f0907b27ac Unittest for rdman_redraw_changed().
Thinker K.F. Li <thinker@branda.to>
parents: 16
diff changeset
1223 shapes[i] = sh_dummy_new(0, 0, 50, 50);
19
cf6d65398619 More animation demo
Thinker K.F. Li <thinker@branda.to>
parents: 18
diff changeset
1224 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
1225 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
1226 coords[i]->matrix[2] = 10 + i * 100;
41f0907b27ac Unittest for rdman_redraw_changed().
Thinker K.F. Li <thinker@branda.to>
parents: 16
diff changeset
1227 coords[i]->matrix[5] = 10 + i * 100;
41f0907b27ac Unittest for rdman_redraw_changed().
Thinker K.F. Li <thinker@branda.to>
parents: 16
diff changeset
1228 rdman_coord_changed(rdman, coords[i]);
41f0907b27ac Unittest for rdman_redraw_changed().
Thinker K.F. Li <thinker@branda.to>
parents: 16
diff changeset
1229 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
1230 }
41f0907b27ac Unittest for rdman_redraw_changed().
Thinker K.F. Li <thinker@branda.to>
parents: 16
diff changeset
1231 rdman_redraw_all(rdman);
119
257a1d314bcd Bug of insert sort
Thinker K.F. Li <thinker@branda.to>
parents: 115
diff changeset
1232 CU_ASSERT(dummys[0]->trans_cnt == 1);
257a1d314bcd Bug of insert sort
Thinker K.F. Li <thinker@branda.to>
parents: 115
diff changeset
1233 CU_ASSERT(dummys[1]->trans_cnt == 1);
257a1d314bcd Bug of insert sort
Thinker K.F. Li <thinker@branda.to>
parents: 115
diff changeset
1234 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
1235 CU_ASSERT(dummys[0]->draw_cnt == 1);
41f0907b27ac Unittest for rdman_redraw_changed().
Thinker K.F. Li <thinker@branda.to>
parents: 16
diff changeset
1236 CU_ASSERT(dummys[1]->draw_cnt == 1);
41f0907b27ac Unittest for rdman_redraw_changed().
Thinker K.F. Li <thinker@branda.to>
parents: 16
diff changeset
1237 CU_ASSERT(dummys[2]->draw_cnt == 1);
41f0907b27ac Unittest for rdman_redraw_changed().
Thinker K.F. Li <thinker@branda.to>
parents: 16
diff changeset
1238
41f0907b27ac Unittest for rdman_redraw_changed().
Thinker K.F. Li <thinker@branda.to>
parents: 16
diff changeset
1239 coords[2]->matrix[2] = 100;
41f0907b27ac Unittest for rdman_redraw_changed().
Thinker K.F. Li <thinker@branda.to>
parents: 16
diff changeset
1240 coords[2]->matrix[5] = 100;
119
257a1d314bcd Bug of insert sort
Thinker K.F. Li <thinker@branda.to>
parents: 115
diff changeset
1241 rdman_coord_changed(rdman, coords[0]);
17
41f0907b27ac Unittest for rdman_redraw_changed().
Thinker K.F. Li <thinker@branda.to>
parents: 16
diff changeset
1242 rdman_coord_changed(rdman, coords[2]);
41f0907b27ac Unittest for rdman_redraw_changed().
Thinker K.F. Li <thinker@branda.to>
parents: 16
diff changeset
1243 rdman_redraw_changed(rdman);
41f0907b27ac Unittest for rdman_redraw_changed().
Thinker K.F. Li <thinker@branda.to>
parents: 16
diff changeset
1244
119
257a1d314bcd Bug of insert sort
Thinker K.F. Li <thinker@branda.to>
parents: 115
diff changeset
1245 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
1246 CU_ASSERT(dummys[1]->draw_cnt == 2);
41f0907b27ac Unittest for rdman_redraw_changed().
Thinker K.F. Li <thinker@branda.to>
parents: 16
diff changeset
1247 CU_ASSERT(dummys[2]->draw_cnt == 2);
19
cf6d65398619 More animation demo
Thinker K.F. Li <thinker@branda.to>
parents: 18
diff changeset
1248
cf6d65398619 More animation demo
Thinker K.F. Li <thinker@branda.to>
parents: 18
diff changeset
1249 paint->free(paint);
cf6d65398619 More animation demo
Thinker K.F. Li <thinker@branda.to>
parents: 18
diff changeset
1250 redraw_man_destroy(rdman);
17
41f0907b27ac Unittest for rdman_redraw_changed().
Thinker K.F. Li <thinker@branda.to>
parents: 16
diff changeset
1251 }
41f0907b27ac Unittest for rdman_redraw_changed().
Thinker K.F. Li <thinker@branda.to>
parents: 16
diff changeset
1252
12
79e9edf4c00a Add redraw manager
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
1253 CU_pSuite get_redraw_man_suite(void) {
79e9edf4c00a Add redraw manager
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
1254 CU_pSuite suite;
79e9edf4c00a Add redraw manager
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
1255
79e9edf4c00a Add redraw manager
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
1256 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
1257 CU_ADD_TEST(suite, test_rdman_redraw_changed);
12
79e9edf4c00a Add redraw manager
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
1258
79e9edf4c00a Add redraw manager
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
1259 return suite;
79e9edf4c00a Add redraw manager
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
1260 }
79e9edf4c00a Add redraw manager
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
1261
79e9edf4c00a Add redraw manager
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
1262 #endif /* UNITTEST */