Mercurial > MadButterfly
annotate src/redraw_man.c @ 27:19c603dd6ff9
Add text shape.
author | Thinker K.F. Li <thinker@branda.to> |
---|---|
date | Mon, 04 Aug 2008 10:10:47 +0800 |
parents | d50f33040de6 |
children | 604bc90d509d |
rev | line source |
---|---|
12 | 1 #include <stdio.h> |
2 #include <stdlib.h> | |
3 #include <string.h> | |
15
c2ce186a5c37
X_main uses rdman_redraw_all()
Thinker K.F. Li <thinker@branda.to>
parents:
14
diff
changeset
|
4 #include <cairo.h> |
12 | 5 #include "mb_types.h" |
6 #include "shapes.h" | |
7 #include "tools.h" | |
8 #include "redraw_man.h" | |
9 | |
26
d50f33040de6
Set line width for path.
Thinker K.F. Li <thinker@branda.to>
parents:
25
diff
changeset
|
10 /* 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
|
11 */ |
d50f33040de6
Set line width for path.
Thinker K.F. Li <thinker@branda.to>
parents:
25
diff
changeset
|
12 |
12 | 13 #define OK 0 |
14 #define ERR -1 | |
15 | |
13 | 16 #define OFFSET(type, field) ((void *)&((type *)NULL)->field - (void *)NULL) |
17 #define SWAP(a, b, t) do { t c; c = a; a = b; b = c; } while(0) | |
18 | |
17
41f0907b27ac
Unittest for rdman_redraw_changed().
Thinker K.F. Li <thinker@branda.to>
parents:
16
diff
changeset
|
19 #ifdef UNITTEST |
41f0907b27ac
Unittest for rdman_redraw_changed().
Thinker K.F. Li <thinker@branda.to>
parents:
16
diff
changeset
|
20 typedef struct _sh_dummy sh_dummy_t; |
41f0907b27ac
Unittest for rdman_redraw_changed().
Thinker K.F. Li <thinker@branda.to>
parents:
16
diff
changeset
|
21 |
41f0907b27ac
Unittest for rdman_redraw_changed().
Thinker K.F. Li <thinker@branda.to>
parents:
16
diff
changeset
|
22 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
|
23 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
|
24 #endif /* UNITTEST */ |
41f0907b27ac
Unittest for rdman_redraw_changed().
Thinker K.F. Li <thinker@branda.to>
parents:
16
diff
changeset
|
25 |
16
e17e12b112c4
A simple animation using rdman_redraw_changed().
Thinker K.F. Li <thinker@branda.to>
parents:
15
diff
changeset
|
26 /*! \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
|
27 * |
e17e12b112c4
A simple animation using rdman_redraw_changed().
Thinker K.F. Li <thinker@branda.to>
parents:
15
diff
changeset
|
28 * 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
|
29 * 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
|
30 */ |
e17e12b112c4
A simple animation using rdman_redraw_changed().
Thinker K.F. Li <thinker@branda.to>
parents:
15
diff
changeset
|
31 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
|
32 int i, j; |
e17e12b112c4
A simple animation using rdman_redraw_changed().
Thinker K.F. Li <thinker@branda.to>
parents:
15
diff
changeset
|
33 unsigned int val; |
e17e12b112c4
A simple animation using rdman_redraw_changed().
Thinker K.F. Li <thinker@branda.to>
parents:
15
diff
changeset
|
34 |
e17e12b112c4
A simple animation using rdman_redraw_changed().
Thinker K.F. Li <thinker@branda.to>
parents:
15
diff
changeset
|
35 for(i = 1; i < num; i++) { |
e17e12b112c4
A simple animation using rdman_redraw_changed().
Thinker K.F. Li <thinker@branda.to>
parents:
15
diff
changeset
|
36 val = *(unsigned int *)(elms[i] + off); |
e17e12b112c4
A simple animation using rdman_redraw_changed().
Thinker K.F. Li <thinker@branda.to>
parents:
15
diff
changeset
|
37 for(j = i; j > 0; j--) { |
e17e12b112c4
A simple animation using rdman_redraw_changed().
Thinker K.F. Li <thinker@branda.to>
parents:
15
diff
changeset
|
38 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
|
39 break; |
e17e12b112c4
A simple animation using rdman_redraw_changed().
Thinker K.F. Li <thinker@branda.to>
parents:
15
diff
changeset
|
40 elms[j] = elms[j - 1]; |
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 elms[j] = elms[i]; |
e17e12b112c4
A simple animation using rdman_redraw_changed().
Thinker K.F. Li <thinker@branda.to>
parents:
15
diff
changeset
|
43 } |
e17e12b112c4
A simple animation using rdman_redraw_changed().
Thinker K.F. Li <thinker@branda.to>
parents:
15
diff
changeset
|
44 } |
e17e12b112c4
A simple animation using rdman_redraw_changed().
Thinker K.F. Li <thinker@branda.to>
parents:
15
diff
changeset
|
45 |
e17e12b112c4
A simple animation using rdman_redraw_changed().
Thinker K.F. Li <thinker@branda.to>
parents:
15
diff
changeset
|
46 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
|
47 void *new_buf; |
e17e12b112c4
A simple animation using rdman_redraw_changed().
Thinker K.F. Li <thinker@branda.to>
parents:
15
diff
changeset
|
48 |
e17e12b112c4
A simple animation using rdman_redraw_changed().
Thinker K.F. Li <thinker@branda.to>
parents:
15
diff
changeset
|
49 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
|
50 if(new_buf == NULL) |
e17e12b112c4
A simple animation using rdman_redraw_changed().
Thinker K.F. Li <thinker@branda.to>
parents:
15
diff
changeset
|
51 return ERR; |
e17e12b112c4
A simple animation using rdman_redraw_changed().
Thinker K.F. Li <thinker@branda.to>
parents:
15
diff
changeset
|
52 |
e17e12b112c4
A simple animation using rdman_redraw_changed().
Thinker K.F. Li <thinker@branda.to>
parents:
15
diff
changeset
|
53 if(new_buf != *buf) |
e17e12b112c4
A simple animation using rdman_redraw_changed().
Thinker K.F. Li <thinker@branda.to>
parents:
15
diff
changeset
|
54 *buf = new_buf; |
e17e12b112c4
A simple animation using rdman_redraw_changed().
Thinker K.F. Li <thinker@branda.to>
parents:
15
diff
changeset
|
55 |
e17e12b112c4
A simple animation using rdman_redraw_changed().
Thinker K.F. Li <thinker@branda.to>
parents:
15
diff
changeset
|
56 return OK; |
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 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
|
60 int max_dirty_geos; |
e17e12b112c4
A simple animation using rdman_redraw_changed().
Thinker K.F. Li <thinker@branda.to>
parents:
15
diff
changeset
|
61 int r; |
e17e12b112c4
A simple animation using rdman_redraw_changed().
Thinker K.F. Li <thinker@branda.to>
parents:
15
diff
changeset
|
62 |
e17e12b112c4
A simple animation using rdman_redraw_changed().
Thinker K.F. Li <thinker@branda.to>
parents:
15
diff
changeset
|
63 if(rdman->n_dirty_geos >= rdman->max_dirty_geos) { |
e17e12b112c4
A simple animation using rdman_redraw_changed().
Thinker K.F. Li <thinker@branda.to>
parents:
15
diff
changeset
|
64 max_dirty_geos = rdman->n_geos; |
e17e12b112c4
A simple animation using rdman_redraw_changed().
Thinker K.F. Li <thinker@branda.to>
parents:
15
diff
changeset
|
65 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
|
66 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
|
67 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
|
68 if(r != OK) |
e17e12b112c4
A simple animation using rdman_redraw_changed().
Thinker K.F. Li <thinker@branda.to>
parents:
15
diff
changeset
|
69 return ERR; |
e17e12b112c4
A simple animation using rdman_redraw_changed().
Thinker K.F. Li <thinker@branda.to>
parents:
15
diff
changeset
|
70 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
|
71 } |
e17e12b112c4
A simple animation using rdman_redraw_changed().
Thinker K.F. Li <thinker@branda.to>
parents:
15
diff
changeset
|
72 |
e17e12b112c4
A simple animation using rdman_redraw_changed().
Thinker K.F. Li <thinker@branda.to>
parents:
15
diff
changeset
|
73 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
|
74 return OK; |
e17e12b112c4
A simple animation using rdman_redraw_changed().
Thinker K.F. Li <thinker@branda.to>
parents:
15
diff
changeset
|
75 } |
e17e12b112c4
A simple animation using rdman_redraw_changed().
Thinker K.F. Li <thinker@branda.to>
parents:
15
diff
changeset
|
76 |
e17e12b112c4
A simple animation using rdman_redraw_changed().
Thinker K.F. Li <thinker@branda.to>
parents:
15
diff
changeset
|
77 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
|
78 int max_dirty_areas; |
e17e12b112c4
A simple animation using rdman_redraw_changed().
Thinker K.F. Li <thinker@branda.to>
parents:
15
diff
changeset
|
79 int r; |
e17e12b112c4
A simple animation using rdman_redraw_changed().
Thinker K.F. Li <thinker@branda.to>
parents:
15
diff
changeset
|
80 |
e17e12b112c4
A simple animation using rdman_redraw_changed().
Thinker K.F. Li <thinker@branda.to>
parents:
15
diff
changeset
|
81 if(rdman->n_dirty_areas >= rdman->max_dirty_areas) { |
e17e12b112c4
A simple animation using rdman_redraw_changed().
Thinker K.F. Li <thinker@branda.to>
parents:
15
diff
changeset
|
82 /* every geo object and coord object can contribute 2 areas. */ |
e17e12b112c4
A simple animation using rdman_redraw_changed().
Thinker K.F. Li <thinker@branda.to>
parents:
15
diff
changeset
|
83 max_dirty_areas = (rdman->n_geos + rdman->n_coords) * 2; |
e17e12b112c4
A simple animation using rdman_redraw_changed().
Thinker K.F. Li <thinker@branda.to>
parents:
15
diff
changeset
|
84 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
|
85 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
|
86 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
|
87 if(r != OK) |
e17e12b112c4
A simple animation using rdman_redraw_changed().
Thinker K.F. Li <thinker@branda.to>
parents:
15
diff
changeset
|
88 return ERR; |
e17e12b112c4
A simple animation using rdman_redraw_changed().
Thinker K.F. Li <thinker@branda.to>
parents:
15
diff
changeset
|
89 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
|
90 } |
e17e12b112c4
A simple animation using rdman_redraw_changed().
Thinker K.F. Li <thinker@branda.to>
parents:
15
diff
changeset
|
91 |
e17e12b112c4
A simple animation using rdman_redraw_changed().
Thinker K.F. Li <thinker@branda.to>
parents:
15
diff
changeset
|
92 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
|
93 return OK; |
e17e12b112c4
A simple animation using rdman_redraw_changed().
Thinker K.F. Li <thinker@branda.to>
parents:
15
diff
changeset
|
94 } |
e17e12b112c4
A simple animation using rdman_redraw_changed().
Thinker K.F. Li <thinker@branda.to>
parents:
15
diff
changeset
|
95 |
17
41f0907b27ac
Unittest for rdman_redraw_changed().
Thinker K.F. Li <thinker@branda.to>
parents:
16
diff
changeset
|
96 static void clean_shape(shape_t *shape) { |
41f0907b27ac
Unittest for rdman_redraw_changed().
Thinker K.F. Li <thinker@branda.to>
parents:
16
diff
changeset
|
97 switch(shape->sh_type) { |
41f0907b27ac
Unittest for rdman_redraw_changed().
Thinker K.F. Li <thinker@branda.to>
parents:
16
diff
changeset
|
98 case SHT_PATH: |
41f0907b27ac
Unittest for rdman_redraw_changed().
Thinker K.F. Li <thinker@branda.to>
parents:
16
diff
changeset
|
99 sh_path_transform(shape); |
41f0907b27ac
Unittest for rdman_redraw_changed().
Thinker K.F. Li <thinker@branda.to>
parents:
16
diff
changeset
|
100 break; |
27 | 101 case SHT_TEXT: |
102 sh_text_transform(shape); | |
103 break; | |
17
41f0907b27ac
Unittest for rdman_redraw_changed().
Thinker K.F. Li <thinker@branda.to>
parents:
16
diff
changeset
|
104 #ifdef UNITTEST |
41f0907b27ac
Unittest for rdman_redraw_changed().
Thinker K.F. Li <thinker@branda.to>
parents:
16
diff
changeset
|
105 default: |
41f0907b27ac
Unittest for rdman_redraw_changed().
Thinker K.F. Li <thinker@branda.to>
parents:
16
diff
changeset
|
106 sh_dummy_transform(shape); |
41f0907b27ac
Unittest for rdman_redraw_changed().
Thinker K.F. Li <thinker@branda.to>
parents:
16
diff
changeset
|
107 break; |
41f0907b27ac
Unittest for rdman_redraw_changed().
Thinker K.F. Li <thinker@branda.to>
parents:
16
diff
changeset
|
108 #endif /* UNITTEST */ |
41f0907b27ac
Unittest for rdman_redraw_changed().
Thinker K.F. Li <thinker@branda.to>
parents:
16
diff
changeset
|
109 } |
41f0907b27ac
Unittest for rdman_redraw_changed().
Thinker K.F. Li <thinker@branda.to>
parents:
16
diff
changeset
|
110 shape->geo->flags &= ~GEF_DIRTY; |
41f0907b27ac
Unittest for rdman_redraw_changed().
Thinker K.F. Li <thinker@branda.to>
parents:
16
diff
changeset
|
111 } |
41f0907b27ac
Unittest for rdman_redraw_changed().
Thinker K.F. Li <thinker@branda.to>
parents:
16
diff
changeset
|
112 |
41f0907b27ac
Unittest for rdman_redraw_changed().
Thinker K.F. Li <thinker@branda.to>
parents:
16
diff
changeset
|
113 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
|
114 poses[0][0] = area->x; |
41f0907b27ac
Unittest for rdman_redraw_changed().
Thinker K.F. Li <thinker@branda.to>
parents:
16
diff
changeset
|
115 poses[0][1] = area->y; |
41f0907b27ac
Unittest for rdman_redraw_changed().
Thinker K.F. Li <thinker@branda.to>
parents:
16
diff
changeset
|
116 poses[1][0] = area->x + area->w; |
41f0907b27ac
Unittest for rdman_redraw_changed().
Thinker K.F. Li <thinker@branda.to>
parents:
16
diff
changeset
|
117 poses[1][1] = area->y + area->h;; |
41f0907b27ac
Unittest for rdman_redraw_changed().
Thinker K.F. Li <thinker@branda.to>
parents:
16
diff
changeset
|
118 } |
41f0907b27ac
Unittest for rdman_redraw_changed().
Thinker K.F. Li <thinker@branda.to>
parents:
16
diff
changeset
|
119 |
41f0907b27ac
Unittest for rdman_redraw_changed().
Thinker K.F. Li <thinker@branda.to>
parents:
16
diff
changeset
|
120 static int clean_coord(coord_t *coord) { |
41f0907b27ac
Unittest for rdman_redraw_changed().
Thinker K.F. Li <thinker@branda.to>
parents:
16
diff
changeset
|
121 shape_t *shape; |
41f0907b27ac
Unittest for rdman_redraw_changed().
Thinker K.F. Li <thinker@branda.to>
parents:
16
diff
changeset
|
122 geo_t *geo; |
41f0907b27ac
Unittest for rdman_redraw_changed().
Thinker K.F. Li <thinker@branda.to>
parents:
16
diff
changeset
|
123 co_aix (*poses)[2]; |
41f0907b27ac
Unittest for rdman_redraw_changed().
Thinker K.F. Li <thinker@branda.to>
parents:
16
diff
changeset
|
124 int cnt, pos_cnt; |
41f0907b27ac
Unittest for rdman_redraw_changed().
Thinker K.F. Li <thinker@branda.to>
parents:
16
diff
changeset
|
125 |
41f0907b27ac
Unittest for rdman_redraw_changed().
Thinker K.F. Li <thinker@branda.to>
parents:
16
diff
changeset
|
126 compute_aggr_of_coord(coord); |
41f0907b27ac
Unittest for rdman_redraw_changed().
Thinker K.F. Li <thinker@branda.to>
parents:
16
diff
changeset
|
127 |
41f0907b27ac
Unittest for rdman_redraw_changed().
Thinker K.F. Li <thinker@branda.to>
parents:
16
diff
changeset
|
128 /* Clean member shapes. */ |
41f0907b27ac
Unittest for rdman_redraw_changed().
Thinker K.F. Li <thinker@branda.to>
parents:
16
diff
changeset
|
129 cnt = 0; |
41f0907b27ac
Unittest for rdman_redraw_changed().
Thinker K.F. Li <thinker@branda.to>
parents:
16
diff
changeset
|
130 for(shape = STAILQ_HEAD(coord->members); |
41f0907b27ac
Unittest for rdman_redraw_changed().
Thinker K.F. Li <thinker@branda.to>
parents:
16
diff
changeset
|
131 shape != NULL; |
41f0907b27ac
Unittest for rdman_redraw_changed().
Thinker K.F. Li <thinker@branda.to>
parents:
16
diff
changeset
|
132 shape = STAILQ_NEXT(shape_t, coord_mem_next, shape)) { |
41f0907b27ac
Unittest for rdman_redraw_changed().
Thinker K.F. Li <thinker@branda.to>
parents:
16
diff
changeset
|
133 geo = shape->geo; |
41f0907b27ac
Unittest for rdman_redraw_changed().
Thinker K.F. Li <thinker@branda.to>
parents:
16
diff
changeset
|
134 SWAP(geo->cur_area, geo->last_area, area_t *); |
41f0907b27ac
Unittest for rdman_redraw_changed().
Thinker K.F. Li <thinker@branda.to>
parents:
16
diff
changeset
|
135 clean_shape(shape); |
41f0907b27ac
Unittest for rdman_redraw_changed().
Thinker K.F. Li <thinker@branda.to>
parents:
16
diff
changeset
|
136 cnt++; |
41f0907b27ac
Unittest for rdman_redraw_changed().
Thinker K.F. Li <thinker@branda.to>
parents:
16
diff
changeset
|
137 } |
41f0907b27ac
Unittest for rdman_redraw_changed().
Thinker K.F. Li <thinker@branda.to>
parents:
16
diff
changeset
|
138 |
41f0907b27ac
Unittest for rdman_redraw_changed().
Thinker K.F. Li <thinker@branda.to>
parents:
16
diff
changeset
|
139 /* Compute area of the coord. */ |
41f0907b27ac
Unittest for rdman_redraw_changed().
Thinker K.F. Li <thinker@branda.to>
parents:
16
diff
changeset
|
140 poses = (co_aix (*)[2])malloc(sizeof(co_aix [2]) * 2 * cnt); |
41f0907b27ac
Unittest for rdman_redraw_changed().
Thinker K.F. Li <thinker@branda.to>
parents:
16
diff
changeset
|
141 if(poses == NULL) |
41f0907b27ac
Unittest for rdman_redraw_changed().
Thinker K.F. Li <thinker@branda.to>
parents:
16
diff
changeset
|
142 return ERR; |
41f0907b27ac
Unittest for rdman_redraw_changed().
Thinker K.F. Li <thinker@branda.to>
parents:
16
diff
changeset
|
143 |
41f0907b27ac
Unittest for rdman_redraw_changed().
Thinker K.F. Li <thinker@branda.to>
parents:
16
diff
changeset
|
144 pos_cnt = 0; |
41f0907b27ac
Unittest for rdman_redraw_changed().
Thinker K.F. Li <thinker@branda.to>
parents:
16
diff
changeset
|
145 for(shape = STAILQ_HEAD(coord->members); |
41f0907b27ac
Unittest for rdman_redraw_changed().
Thinker K.F. Li <thinker@branda.to>
parents:
16
diff
changeset
|
146 shape != NULL; |
41f0907b27ac
Unittest for rdman_redraw_changed().
Thinker K.F. Li <thinker@branda.to>
parents:
16
diff
changeset
|
147 shape = STAILQ_NEXT(shape_t, coord_mem_next, shape)) { |
41f0907b27ac
Unittest for rdman_redraw_changed().
Thinker K.F. Li <thinker@branda.to>
parents:
16
diff
changeset
|
148 geo = shape->geo; |
41f0907b27ac
Unittest for rdman_redraw_changed().
Thinker K.F. Li <thinker@branda.to>
parents:
16
diff
changeset
|
149 |
41f0907b27ac
Unittest for rdman_redraw_changed().
Thinker K.F. Li <thinker@branda.to>
parents:
16
diff
changeset
|
150 area_to_positions(geo->cur_area, poses + pos_cnt); |
41f0907b27ac
Unittest for rdman_redraw_changed().
Thinker K.F. Li <thinker@branda.to>
parents:
16
diff
changeset
|
151 pos_cnt += 2; |
41f0907b27ac
Unittest for rdman_redraw_changed().
Thinker K.F. Li <thinker@branda.to>
parents:
16
diff
changeset
|
152 } |
41f0907b27ac
Unittest for rdman_redraw_changed().
Thinker K.F. Li <thinker@branda.to>
parents:
16
diff
changeset
|
153 |
41f0907b27ac
Unittest for rdman_redraw_changed().
Thinker K.F. Li <thinker@branda.to>
parents:
16
diff
changeset
|
154 SWAP(coord->cur_area, coord->last_area, area_t *); |
41f0907b27ac
Unittest for rdman_redraw_changed().
Thinker K.F. Li <thinker@branda.to>
parents:
16
diff
changeset
|
155 area_init(coord->cur_area, pos_cnt, poses); |
41f0907b27ac
Unittest for rdman_redraw_changed().
Thinker K.F. Li <thinker@branda.to>
parents:
16
diff
changeset
|
156 free(poses); |
41f0907b27ac
Unittest for rdman_redraw_changed().
Thinker K.F. Li <thinker@branda.to>
parents:
16
diff
changeset
|
157 |
41f0907b27ac
Unittest for rdman_redraw_changed().
Thinker K.F. Li <thinker@branda.to>
parents:
16
diff
changeset
|
158 coord->flags &= ~COF_DIRTY; |
41f0907b27ac
Unittest for rdman_redraw_changed().
Thinker K.F. Li <thinker@branda.to>
parents:
16
diff
changeset
|
159 |
41f0907b27ac
Unittest for rdman_redraw_changed().
Thinker K.F. Li <thinker@branda.to>
parents:
16
diff
changeset
|
160 return OK; |
41f0907b27ac
Unittest for rdman_redraw_changed().
Thinker K.F. Li <thinker@branda.to>
parents:
16
diff
changeset
|
161 } |
41f0907b27ac
Unittest for rdman_redraw_changed().
Thinker K.F. Li <thinker@branda.to>
parents:
16
diff
changeset
|
162 |
41f0907b27ac
Unittest for rdman_redraw_changed().
Thinker K.F. Li <thinker@branda.to>
parents:
16
diff
changeset
|
163 static int clean_rdman_coords(redraw_man_t *rdman) { |
41f0907b27ac
Unittest for rdman_redraw_changed().
Thinker K.F. Li <thinker@branda.to>
parents:
16
diff
changeset
|
164 coord_t *coord; |
41f0907b27ac
Unittest for rdman_redraw_changed().
Thinker K.F. Li <thinker@branda.to>
parents:
16
diff
changeset
|
165 coord_t **dirty_coords; |
41f0907b27ac
Unittest for rdman_redraw_changed().
Thinker K.F. Li <thinker@branda.to>
parents:
16
diff
changeset
|
166 int n_dirty_coords; |
41f0907b27ac
Unittest for rdman_redraw_changed().
Thinker K.F. Li <thinker@branda.to>
parents:
16
diff
changeset
|
167 int i, r; |
41f0907b27ac
Unittest for rdman_redraw_changed().
Thinker K.F. Li <thinker@branda.to>
parents:
16
diff
changeset
|
168 |
41f0907b27ac
Unittest for rdman_redraw_changed().
Thinker K.F. Li <thinker@branda.to>
parents:
16
diff
changeset
|
169 n_dirty_coords = rdman->n_dirty_coords; |
41f0907b27ac
Unittest for rdman_redraw_changed().
Thinker K.F. Li <thinker@branda.to>
parents:
16
diff
changeset
|
170 if(n_dirty_coords > 0) { |
41f0907b27ac
Unittest for rdman_redraw_changed().
Thinker K.F. Li <thinker@branda.to>
parents:
16
diff
changeset
|
171 dirty_coords = rdman->dirty_coords; |
41f0907b27ac
Unittest for rdman_redraw_changed().
Thinker K.F. Li <thinker@branda.to>
parents:
16
diff
changeset
|
172 _insert_sort((void **)dirty_coords, n_dirty_coords, |
41f0907b27ac
Unittest for rdman_redraw_changed().
Thinker K.F. Li <thinker@branda.to>
parents:
16
diff
changeset
|
173 OFFSET(coord_t, order)); |
41f0907b27ac
Unittest for rdman_redraw_changed().
Thinker K.F. Li <thinker@branda.to>
parents:
16
diff
changeset
|
174 for(i = 0; i < n_dirty_coords; i++) { |
41f0907b27ac
Unittest for rdman_redraw_changed().
Thinker K.F. Li <thinker@branda.to>
parents:
16
diff
changeset
|
175 coord = dirty_coords[i]; |
41f0907b27ac
Unittest for rdman_redraw_changed().
Thinker K.F. Li <thinker@branda.to>
parents:
16
diff
changeset
|
176 if(!(coord->flags & COF_DIRTY)) |
41f0907b27ac
Unittest for rdman_redraw_changed().
Thinker K.F. Li <thinker@branda.to>
parents:
16
diff
changeset
|
177 continue; |
41f0907b27ac
Unittest for rdman_redraw_changed().
Thinker K.F. Li <thinker@branda.to>
parents:
16
diff
changeset
|
178 r = clean_coord(coord); |
41f0907b27ac
Unittest for rdman_redraw_changed().
Thinker K.F. Li <thinker@branda.to>
parents:
16
diff
changeset
|
179 if(r != OK) |
41f0907b27ac
Unittest for rdman_redraw_changed().
Thinker K.F. Li <thinker@branda.to>
parents:
16
diff
changeset
|
180 return ERR; |
41f0907b27ac
Unittest for rdman_redraw_changed().
Thinker K.F. Li <thinker@branda.to>
parents:
16
diff
changeset
|
181 /* These two steps can be avoided for drawing all. */ |
41f0907b27ac
Unittest for rdman_redraw_changed().
Thinker K.F. Li <thinker@branda.to>
parents:
16
diff
changeset
|
182 add_dirty_area(rdman, &coord->areas[0]); |
41f0907b27ac
Unittest for rdman_redraw_changed().
Thinker K.F. Li <thinker@branda.to>
parents:
16
diff
changeset
|
183 add_dirty_area(rdman, &coord->areas[1]); |
41f0907b27ac
Unittest for rdman_redraw_changed().
Thinker K.F. Li <thinker@branda.to>
parents:
16
diff
changeset
|
184 } |
41f0907b27ac
Unittest for rdman_redraw_changed().
Thinker K.F. Li <thinker@branda.to>
parents:
16
diff
changeset
|
185 rdman->n_dirty_coords = 0; |
41f0907b27ac
Unittest for rdman_redraw_changed().
Thinker K.F. Li <thinker@branda.to>
parents:
16
diff
changeset
|
186 } |
41f0907b27ac
Unittest for rdman_redraw_changed().
Thinker K.F. Li <thinker@branda.to>
parents:
16
diff
changeset
|
187 return OK; |
41f0907b27ac
Unittest for rdman_redraw_changed().
Thinker K.F. Li <thinker@branda.to>
parents:
16
diff
changeset
|
188 } |
41f0907b27ac
Unittest for rdman_redraw_changed().
Thinker K.F. Li <thinker@branda.to>
parents:
16
diff
changeset
|
189 |
24
e598bc809c0f
No more flash when animation.
Thinker K.F. Li <thinker@branda.to>
parents:
23
diff
changeset
|
190 int redraw_man_init(redraw_man_t *rdman, cairo_t *cr, cairo_t *backend) { |
12 | 191 extern void redraw_man_destroy(redraw_man_t *rdman); |
192 | |
193 memset(rdman, 0, sizeof(redraw_man_t)); | |
194 | |
195 rdman->geo_pool = elmpool_new(sizeof(geo_t), 128); | |
196 if(rdman->geo_pool == NULL) | |
197 return ERR; | |
198 | |
199 rdman->coord_pool = elmpool_new(sizeof(coord_t), 16); | |
200 if(rdman->coord_pool == NULL) { | |
201 elmpool_free(rdman->geo_pool); | |
202 return ERR; | |
203 } | |
204 | |
18
0f3baa488a62
Support solid color paint for fill.
Thinker K.F. Li <thinker@branda.to>
parents:
17
diff
changeset
|
205 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
|
206 if(rdman->shnode_pool == NULL) { |
0f3baa488a62
Support solid color paint for fill.
Thinker K.F. Li <thinker@branda.to>
parents:
17
diff
changeset
|
207 elmpool_free(rdman->geo_pool); |
0f3baa488a62
Support solid color paint for fill.
Thinker K.F. Li <thinker@branda.to>
parents:
17
diff
changeset
|
208 elmpool_free(rdman->coord_pool); |
0f3baa488a62
Support solid color paint for fill.
Thinker K.F. Li <thinker@branda.to>
parents:
17
diff
changeset
|
209 return ERR; |
0f3baa488a62
Support solid color paint for fill.
Thinker K.F. Li <thinker@branda.to>
parents:
17
diff
changeset
|
210 } |
0f3baa488a62
Support solid color paint for fill.
Thinker K.F. Li <thinker@branda.to>
parents:
17
diff
changeset
|
211 |
12 | 212 rdman->root_coord = elmpool_elm_alloc(rdman->coord_pool); |
213 if(rdman->root_coord == NULL) | |
214 redraw_man_destroy(rdman); | |
13 | 215 rdman->n_coords = 1; |
12 | 216 coord_init(rdman->root_coord, NULL); |
217 | |
15
c2ce186a5c37
X_main uses rdman_redraw_all()
Thinker K.F. Li <thinker@branda.to>
parents:
14
diff
changeset
|
218 rdman->cr = cr; |
24
e598bc809c0f
No more flash when animation.
Thinker K.F. Li <thinker@branda.to>
parents:
23
diff
changeset
|
219 rdman->backend = backend; |
15
c2ce186a5c37
X_main uses rdman_redraw_all()
Thinker K.F. Li <thinker@branda.to>
parents:
14
diff
changeset
|
220 |
12 | 221 return OK; |
222 } | |
223 | |
224 void redraw_man_destroy(redraw_man_t *rdman) { | |
225 elmpool_free(rdman->coord_pool); | |
226 elmpool_free(rdman->geo_pool); | |
18
0f3baa488a62
Support solid color paint for fill.
Thinker K.F. Li <thinker@branda.to>
parents:
17
diff
changeset
|
227 elmpool_free(rdman->shnode_pool); |
13 | 228 if(rdman->dirty_coords) |
229 free(rdman->dirty_coords); | |
14 | 230 if(rdman->dirty_geos) |
231 free(rdman->dirty_geos); | |
12 | 232 } |
233 | |
234 | |
235 #define ASSERT(x) | |
236 /* | |
237 * Change transformation matrix | |
238 * - update aggregated transformation matrix | |
239 * - of coord_t object been changed. | |
240 * - of children coord_t objects. | |
241 * - redraw members of coord_t objects. | |
242 * - redraw shape objects they are overlaid with members. | |
243 * - find out overlaid shape objects. | |
244 * - geo_t of a coord_t object | |
245 * - can make finding more efficiency. | |
246 * - fill overlay geo_t objects of members. | |
247 * | |
248 * Change a shape object | |
249 * - redraw changed object. | |
250 * - redraw shape objects they are overlaid with changed object. | |
251 * - find out overlaid shape objects. | |
252 * | |
253 * That coord and geo of shape objects are setted by user code | |
254 * give user code a chance to collect coord and geo objects together | |
255 * and gain interest of higher cache hit rate. | |
256 */ | |
257 | |
258 /*! \brief Find out all affected shape objects. | |
259 * | |
260 * Find out all shape objects that are overalid with geo_t of | |
261 * a geometry changed object. | |
262 * | |
263 * Linear scan geo_t objects of all shape objects in all_shapes | |
264 * list of a redraw_man_t object. | |
265 */ | |
266 int rdman_find_overlaid_shapes(redraw_man_t *rdman, geo_t *geo, | |
267 geo_t ***overlays) { | |
268 int n_geos; | |
269 geo_t **geos; | |
270 geo_t *geo_cur; | |
271 int n_overlays; | |
272 geo_t **_overlays; | |
273 int i; | |
274 | |
275 n_geos = rdman->n_geos; | |
276 | |
277 geos = (geo_t **)malloc(sizeof(geo_t *) * n_geos); | |
278 if(geos == NULL) | |
279 return -1; | |
280 | |
281 _overlays = (geo_t **)malloc(sizeof(geo_t *) * n_geos); | |
282 if(geos == NULL) { | |
283 free(geos); | |
284 return -1; | |
285 } | |
286 | |
287 geo_cur = STAILQ_HEAD(rdman->all_geos); | |
288 for(i = 0; i < n_geos; i++) { | |
289 geos[i] = geo_cur; | |
290 geo_cur = STAILQ_NEXT(geo_t, next, geo_cur); | |
291 } | |
292 geo_mark_overlay(geo, n_geos, geos, &n_overlays, _overlays); | |
293 | |
294 free(geos); | |
295 *overlays = _overlays; | |
296 | |
297 return n_overlays; | |
298 } | |
299 | |
300 int rdman_add_shape(redraw_man_t *rdman, shape_t *shape, coord_t *coord) { | |
301 geo_t *geo; | |
16
e17e12b112c4
A simple animation using rdman_redraw_changed().
Thinker K.F. Li <thinker@branda.to>
parents:
15
diff
changeset
|
302 #ifdef GEO_ORDER |
13 | 303 geo_t *visit; |
304 unsigned int next_order; | |
16
e17e12b112c4
A simple animation using rdman_redraw_changed().
Thinker K.F. Li <thinker@branda.to>
parents:
15
diff
changeset
|
305 #endif |
e17e12b112c4
A simple animation using rdman_redraw_changed().
Thinker K.F. Li <thinker@branda.to>
parents:
15
diff
changeset
|
306 int r; |
12 | 307 |
308 geo = elmpool_elm_alloc(rdman->geo_pool); | |
309 if(geo == NULL) | |
310 return ERR; | |
17
41f0907b27ac
Unittest for rdman_redraw_changed().
Thinker K.F. Li <thinker@branda.to>
parents:
16
diff
changeset
|
311 |
41f0907b27ac
Unittest for rdman_redraw_changed().
Thinker K.F. Li <thinker@branda.to>
parents:
16
diff
changeset
|
312 geo_init(geo); |
41f0907b27ac
Unittest for rdman_redraw_changed().
Thinker K.F. Li <thinker@branda.to>
parents:
16
diff
changeset
|
313 |
12 | 314 sh_attach_geo(shape, geo); |
315 STAILQ_INS_TAIL(rdman->all_geos, geo_t, next, geo); | |
316 rdman->n_geos++; | |
13 | 317 |
16
e17e12b112c4
A simple animation using rdman_redraw_changed().
Thinker K.F. Li <thinker@branda.to>
parents:
15
diff
changeset
|
318 #ifdef GEO_ORDER |
e17e12b112c4
A simple animation using rdman_redraw_changed().
Thinker K.F. Li <thinker@branda.to>
parents:
15
diff
changeset
|
319 /* TODO: remove order number. */ |
13 | 320 geo->order = ++rdman->next_geo_order; |
321 if(geo->order == 0) { | |
322 next_order = 0; | |
323 for(visit = STAILQ_HEAD(rdman->all_geos); | |
324 visit != NULL; | |
325 visit = STAILQ_NEXT(geo_t, next, visit)) | |
326 visit->order = ++next_order; | |
327 rdman->next_geo_order = next_order; | |
328 } | |
16
e17e12b112c4
A simple animation using rdman_redraw_changed().
Thinker K.F. Li <thinker@branda.to>
parents:
15
diff
changeset
|
329 #endif |
e17e12b112c4
A simple animation using rdman_redraw_changed().
Thinker K.F. Li <thinker@branda.to>
parents:
15
diff
changeset
|
330 |
e17e12b112c4
A simple animation using rdman_redraw_changed().
Thinker K.F. Li <thinker@branda.to>
parents:
15
diff
changeset
|
331 /* 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
|
332 geo->flags |= GEF_DIRTY; |
16
e17e12b112c4
A simple animation using rdman_redraw_changed().
Thinker K.F. Li <thinker@branda.to>
parents:
15
diff
changeset
|
333 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
|
334 if(r != OK) |
e17e12b112c4
A simple animation using rdman_redraw_changed().
Thinker K.F. Li <thinker@branda.to>
parents:
15
diff
changeset
|
335 return ERR; |
13 | 336 |
12 | 337 sh_attach_coord(shape, coord); |
338 | |
339 return OK; | |
340 } | |
341 | |
17
41f0907b27ac
Unittest for rdman_redraw_changed().
Thinker K.F. Li <thinker@branda.to>
parents:
16
diff
changeset
|
342 /*! \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
|
343 * |
41f0907b27ac
Unittest for rdman_redraw_changed().
Thinker K.F. Li <thinker@branda.to>
parents:
16
diff
changeset
|
344 * TODO: redraw shape objects that overlaid with removed one. |
41f0907b27ac
Unittest for rdman_redraw_changed().
Thinker K.F. Li <thinker@branda.to>
parents:
16
diff
changeset
|
345 */ |
12 | 346 int rdman_remove_shape(redraw_man_t *rdman, shape_t *shape) { |
347 STAILQ_REMOVE(rdman->all_geos, geo_t, next, shape->geo); | |
348 elmpool_elm_free(rdman->geo_pool, shape->geo); | |
349 sh_detach_geo(shape); | |
350 rdman->n_geos--; | |
351 sh_detach_coord(shape); | |
352 return OK; | |
353 } | |
354 | |
355 coord_t *rdman_coord_new(redraw_man_t *rdman, coord_t *parent) { | |
13 | 356 coord_t *coord, *root_coord; |
357 coord_t *visit; | |
12 | 358 |
359 coord = elmpool_elm_alloc(rdman->coord_pool); | |
360 if(coord == NULL) | |
361 return NULL; | |
362 | |
363 coord_init(coord, parent); | |
13 | 364 rdman->n_coords++; |
365 | |
366 coord->order = ++rdman->next_coord_order; | |
367 if(coord->order == 0) { | |
368 rdman->next_coord_order = 0; | |
369 root_coord = visit = rdman->root_coord; | |
370 /* skip root coord. */ | |
371 visit = preorder_coord_subtree(root_coord, visit); | |
372 while(visit) { | |
373 visit->order = ++rdman->next_coord_order; | |
374 visit = preorder_coord_subtree(root_coord, visit); | |
375 } | |
376 } | |
12 | 377 |
378 return coord; | |
379 } | |
380 | |
381 /*! \brief Free a coord of a redraw_man_t object. | |
382 * | |
383 * \param coord is a coord_t without children and members. | |
384 * \return 0 for successful, -1 for error. | |
385 */ | |
386 int rdman_coord_free(redraw_man_t *rdman, coord_t *coord) { | |
387 coord_t *parent; | |
388 | |
389 parent = coord->parent; | |
390 if(parent == NULL) | |
391 return ERR; | |
392 | |
393 if(STAILQ_HEAD(coord->members) != NULL) | |
394 return ERR; | |
395 | |
396 if(STAILQ_HEAD(coord->children) != NULL) | |
397 return ERR; | |
398 | |
399 STAILQ_REMOVE(parent->children, coord_t, sibling, coord); | |
400 elmpool_elm_free(rdman->coord_pool, coord); | |
13 | 401 rdman->n_coords--; |
402 | |
403 return OK; | |
404 } | |
405 | |
406 /*! \brief Mark a coord is changed. | |
407 * | |
408 * A changed coord_t object is marked as dirty and put | |
409 * into dirty_coords list. | |
410 */ | |
411 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
|
412 coord_t *child; |
13 | 413 int max_dirty_coords; |
414 int r; | |
415 | |
416 if(coord->flags & COF_DIRTY) | |
417 return OK; | |
418 | |
419 if(rdman->n_dirty_coords >= rdman->max_dirty_coords) { | |
420 /* Max of dirty_coords is not big enough. */ | |
421 max_dirty_coords = rdman->max_dirty_coords + 16; | |
422 | |
423 r = extend_memblk((void **)&rdman->dirty_coords, | |
424 sizeof(coord_t *) * rdman->n_dirty_coords, | |
425 sizeof(coord_t *) * max_dirty_coords); | |
426 rdman->max_dirty_coords = max_dirty_coords; | |
427 } | |
428 | |
16
e17e12b112c4
A simple animation using rdman_redraw_changed().
Thinker K.F. Li <thinker@branda.to>
parents:
15
diff
changeset
|
429 /* 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
|
430 for(child = coord; |
e17e12b112c4
A simple animation using rdman_redraw_changed().
Thinker K.F. Li <thinker@branda.to>
parents:
15
diff
changeset
|
431 child != NULL; |
e17e12b112c4
A simple animation using rdman_redraw_changed().
Thinker K.F. Li <thinker@branda.to>
parents:
15
diff
changeset
|
432 child = preorder_coord_subtree(coord, child)) { |
e17e12b112c4
A simple animation using rdman_redraw_changed().
Thinker K.F. Li <thinker@branda.to>
parents:
15
diff
changeset
|
433 rdman->dirty_coords[rdman->n_dirty_coords++] = coord; |
e17e12b112c4
A simple animation using rdman_redraw_changed().
Thinker K.F. Li <thinker@branda.to>
parents:
15
diff
changeset
|
434 coord->flags |= COF_DIRTY; |
e17e12b112c4
A simple animation using rdman_redraw_changed().
Thinker K.F. Li <thinker@branda.to>
parents:
15
diff
changeset
|
435 } |
13 | 436 |
437 return OK; | |
438 } | |
439 | |
18
0f3baa488a62
Support solid color paint for fill.
Thinker K.F. Li <thinker@branda.to>
parents:
17
diff
changeset
|
440 static int _rdman_shape_changed(redraw_man_t *rdman, shape_t *shape) { |
13 | 441 geo_t *geo; |
442 int r; | |
443 | |
444 geo = shape->geo; | |
445 | |
446 if(geo->flags & GEF_DIRTY) | |
447 return OK; | |
448 | |
449 r = add_dirty_geo(rdman, geo); | |
450 if(r == ERR) | |
451 return ERR; | |
452 geo->flags |= GEF_DIRTY; | |
12 | 453 |
454 return OK; | |
455 } | |
456 | |
18
0f3baa488a62
Support solid color paint for fill.
Thinker K.F. Li <thinker@branda.to>
parents:
17
diff
changeset
|
457 /*! \brief Mark a shape is changed. |
0f3baa488a62
Support solid color paint for fill.
Thinker K.F. Li <thinker@branda.to>
parents:
17
diff
changeset
|
458 * |
0f3baa488a62
Support solid color paint for fill.
Thinker K.F. Li <thinker@branda.to>
parents:
17
diff
changeset
|
459 * 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
|
460 * put into dirty_geos list. |
0f3baa488a62
Support solid color paint for fill.
Thinker K.F. Li <thinker@branda.to>
parents:
17
diff
changeset
|
461 */ |
0f3baa488a62
Support solid color paint for fill.
Thinker K.F. Li <thinker@branda.to>
parents:
17
diff
changeset
|
462 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
|
463 return _rdman_shape_changed(rdman, shape); |
0f3baa488a62
Support solid color paint for fill.
Thinker K.F. Li <thinker@branda.to>
parents:
17
diff
changeset
|
464 } |
0f3baa488a62
Support solid color paint for fill.
Thinker K.F. Li <thinker@branda.to>
parents:
17
diff
changeset
|
465 |
17
41f0907b27ac
Unittest for rdman_redraw_changed().
Thinker K.F. Li <thinker@branda.to>
parents:
16
diff
changeset
|
466 /* Drawing and Redrawing |
41f0907b27ac
Unittest for rdman_redraw_changed().
Thinker K.F. Li <thinker@branda.to>
parents:
16
diff
changeset
|
467 * ============================================================ |
41f0907b27ac
Unittest for rdman_redraw_changed().
Thinker K.F. Li <thinker@branda.to>
parents:
16
diff
changeset
|
468 */ |
16
e17e12b112c4
A simple animation using rdman_redraw_changed().
Thinker K.F. Li <thinker@branda.to>
parents:
15
diff
changeset
|
469 |
26
d50f33040de6
Set line width for path.
Thinker K.F. Li <thinker@branda.to>
parents:
25
diff
changeset
|
470 #ifndef UNITTEST |
d50f33040de6
Set line width for path.
Thinker K.F. Li <thinker@branda.to>
parents:
25
diff
changeset
|
471 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
|
472 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
|
473 } |
d50f33040de6
Set line width for path.
Thinker K.F. Li <thinker@branda.to>
parents:
25
diff
changeset
|
474 #else |
d50f33040de6
Set line width for path.
Thinker K.F. Li <thinker@branda.to>
parents:
25
diff
changeset
|
475 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
|
476 } |
d50f33040de6
Set line width for path.
Thinker K.F. Li <thinker@branda.to>
parents:
25
diff
changeset
|
477 #endif |
d50f33040de6
Set line width for path.
Thinker K.F. Li <thinker@branda.to>
parents:
25
diff
changeset
|
478 |
22 | 479 static void draw_shape(redraw_man_t *rdman, shape_t *shape) { |
480 paint_t *fill, *stroke; | |
18
0f3baa488a62
Support solid color paint for fill.
Thinker K.F. Li <thinker@branda.to>
parents:
17
diff
changeset
|
481 |
0f3baa488a62
Support solid color paint for fill.
Thinker K.F. Li <thinker@branda.to>
parents:
17
diff
changeset
|
482 fill = shape->fill; |
19 | 483 if(fill) { |
18
0f3baa488a62
Support solid color paint for fill.
Thinker K.F. Li <thinker@branda.to>
parents:
17
diff
changeset
|
484 fill->prepare(fill, rdman->cr); |
19 | 485 switch(shape->sh_type) { |
486 case SHT_PATH: | |
20
74d3d5dc9aaa
rename XXX_draw() to XXX_fill()
Thinker K.F. Li <thinker@branda.to>
parents:
19
diff
changeset
|
487 sh_path_fill(shape, rdman->cr); |
19 | 488 break; |
27 | 489 case SHT_TEXT: |
490 sh_text_fill(shape, rdman->cr); | |
491 break; | |
17
41f0907b27ac
Unittest for rdman_redraw_changed().
Thinker K.F. Li <thinker@branda.to>
parents:
16
diff
changeset
|
492 #ifdef UNITTEST |
19 | 493 default: |
20
74d3d5dc9aaa
rename XXX_draw() to XXX_fill()
Thinker K.F. Li <thinker@branda.to>
parents:
19
diff
changeset
|
494 sh_dummy_fill(shape, rdman->cr); |
19 | 495 break; |
17
41f0907b27ac
Unittest for rdman_redraw_changed().
Thinker K.F. Li <thinker@branda.to>
parents:
16
diff
changeset
|
496 #endif /* UNITTEST */ |
19 | 497 } |
15
c2ce186a5c37
X_main uses rdman_redraw_all()
Thinker K.F. Li <thinker@branda.to>
parents:
14
diff
changeset
|
498 } |
22 | 499 stroke = shape->stroke; |
500 if(stroke) { | |
501 stroke->prepare(stroke, rdman->cr); | |
26
d50f33040de6
Set line width for path.
Thinker K.F. Li <thinker@branda.to>
parents:
25
diff
changeset
|
502 set_shape_stroke_param(shape, rdman->cr); |
22 | 503 switch(shape->sh_type) { |
504 case SHT_PATH: | |
505 sh_path_stroke(shape, rdman->cr); | |
506 break; | |
27 | 507 case SHT_TEXT: |
508 sh_text_stroke(shape, rdman->cr); | |
509 break; | |
22 | 510 #ifdef UNITTEST |
511 default: | |
512 /* sh_dummy_fill(shape, rdman->cr); */ | |
513 break; | |
514 #endif /* UNITTEST */ | |
515 } | |
516 } | |
13 | 517 } |
518 | |
17
41f0907b27ac
Unittest for rdman_redraw_changed().
Thinker K.F. Li <thinker@branda.to>
parents:
16
diff
changeset
|
519 #ifndef UNITTEST |
25
29937c26bb01
Fix bug of a dark line appear when animating.
Thinker K.F. Li <thinker@branda.to>
parents:
24
diff
changeset
|
520 static void clean_canvas(cairo_t *cr) { |
16
e17e12b112c4
A simple animation using rdman_redraw_changed().
Thinker K.F. Li <thinker@branda.to>
parents:
15
diff
changeset
|
521 /* TODO: clean to background color. */ |
e17e12b112c4
A simple animation using rdman_redraw_changed().
Thinker K.F. Li <thinker@branda.to>
parents:
15
diff
changeset
|
522 cairo_set_source_rgb(cr, 0, 0, 0); |
24
e598bc809c0f
No more flash when animation.
Thinker K.F. Li <thinker@branda.to>
parents:
23
diff
changeset
|
523 cairo_paint(cr); |
16
e17e12b112c4
A simple animation using rdman_redraw_changed().
Thinker K.F. Li <thinker@branda.to>
parents:
15
diff
changeset
|
524 } |
e17e12b112c4
A simple animation using rdman_redraw_changed().
Thinker K.F. Li <thinker@branda.to>
parents:
15
diff
changeset
|
525 |
24
e598bc809c0f
No more flash when animation.
Thinker K.F. Li <thinker@branda.to>
parents:
23
diff
changeset
|
526 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
|
527 area_t **dirty_areas) { |
c2ce186a5c37
X_main uses rdman_redraw_all()
Thinker K.F. Li <thinker@branda.to>
parents:
14
diff
changeset
|
528 int i; |
c2ce186a5c37
X_main uses rdman_redraw_all()
Thinker K.F. Li <thinker@branda.to>
parents:
14
diff
changeset
|
529 area_t *area; |
c2ce186a5c37
X_main uses rdman_redraw_all()
Thinker K.F. Li <thinker@branda.to>
parents:
14
diff
changeset
|
530 |
c2ce186a5c37
X_main uses rdman_redraw_all()
Thinker K.F. Li <thinker@branda.to>
parents:
14
diff
changeset
|
531 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
|
532 area = dirty_areas[i]; |
c2ce186a5c37
X_main uses rdman_redraw_all()
Thinker K.F. Li <thinker@branda.to>
parents:
14
diff
changeset
|
533 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
|
534 } |
c2ce186a5c37
X_main uses rdman_redraw_all()
Thinker K.F. Li <thinker@branda.to>
parents:
14
diff
changeset
|
535 cairo_clip(cr); |
c2ce186a5c37
X_main uses rdman_redraw_all()
Thinker K.F. Li <thinker@branda.to>
parents:
14
diff
changeset
|
536 } |
c2ce186a5c37
X_main uses rdman_redraw_all()
Thinker K.F. Li <thinker@branda.to>
parents:
14
diff
changeset
|
537 |
17
41f0907b27ac
Unittest for rdman_redraw_changed().
Thinker K.F. Li <thinker@branda.to>
parents:
16
diff
changeset
|
538 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
|
539 cairo_reset_clip(rdman->cr); |
24
e598bc809c0f
No more flash when animation.
Thinker K.F. Li <thinker@branda.to>
parents:
23
diff
changeset
|
540 cairo_reset_clip(rdman->backend); |
e598bc809c0f
No more flash when animation.
Thinker K.F. Li <thinker@branda.to>
parents:
23
diff
changeset
|
541 } |
e598bc809c0f
No more flash when animation.
Thinker K.F. Li <thinker@branda.to>
parents:
23
diff
changeset
|
542 |
e598bc809c0f
No more flash when animation.
Thinker K.F. Li <thinker@branda.to>
parents:
23
diff
changeset
|
543 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
|
544 area_t **dirty_areas) { |
e598bc809c0f
No more flash when animation.
Thinker K.F. Li <thinker@branda.to>
parents:
23
diff
changeset
|
545 if(n_dirty_areas) |
e598bc809c0f
No more flash when animation.
Thinker K.F. Li <thinker@branda.to>
parents:
23
diff
changeset
|
546 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
|
547 |
e598bc809c0f
No more flash when animation.
Thinker K.F. Li <thinker@branda.to>
parents:
23
diff
changeset
|
548 cairo_paint(rdman->backend); |
17
41f0907b27ac
Unittest for rdman_redraw_changed().
Thinker K.F. Li <thinker@branda.to>
parents:
16
diff
changeset
|
549 } |
41f0907b27ac
Unittest for rdman_redraw_changed().
Thinker K.F. Li <thinker@branda.to>
parents:
16
diff
changeset
|
550 #else /* UNITTEST */ |
25
29937c26bb01
Fix bug of a dark line appear when animating.
Thinker K.F. Li <thinker@branda.to>
parents:
24
diff
changeset
|
551 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
|
552 } |
e598bc809c0f
No more flash when animation.
Thinker K.F. Li <thinker@branda.to>
parents:
23
diff
changeset
|
553 |
e598bc809c0f
No more flash when animation.
Thinker K.F. Li <thinker@branda.to>
parents:
23
diff
changeset
|
554 static void make_clip(cairo_t *cr, int n_dirty_areas, |
17
41f0907b27ac
Unittest for rdman_redraw_changed().
Thinker K.F. Li <thinker@branda.to>
parents:
16
diff
changeset
|
555 area_t **dirty_areas) { |
41f0907b27ac
Unittest for rdman_redraw_changed().
Thinker K.F. Li <thinker@branda.to>
parents:
16
diff
changeset
|
556 } |
41f0907b27ac
Unittest for rdman_redraw_changed().
Thinker K.F. Li <thinker@branda.to>
parents:
16
diff
changeset
|
557 |
41f0907b27ac
Unittest for rdman_redraw_changed().
Thinker K.F. Li <thinker@branda.to>
parents:
16
diff
changeset
|
558 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
|
559 } |
24
e598bc809c0f
No more flash when animation.
Thinker K.F. Li <thinker@branda.to>
parents:
23
diff
changeset
|
560 |
e598bc809c0f
No more flash when animation.
Thinker K.F. Li <thinker@branda.to>
parents:
23
diff
changeset
|
561 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
|
562 area_t **dirty_areas) { |
e598bc809c0f
No more flash when animation.
Thinker K.F. Li <thinker@branda.to>
parents:
23
diff
changeset
|
563 } |
17
41f0907b27ac
Unittest for rdman_redraw_changed().
Thinker K.F. Li <thinker@branda.to>
parents:
16
diff
changeset
|
564 #endif /* UNITTEST */ |
41f0907b27ac
Unittest for rdman_redraw_changed().
Thinker K.F. Li <thinker@branda.to>
parents:
16
diff
changeset
|
565 |
22 | 566 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
|
567 int n_areas, |
c2ce186a5c37
X_main uses rdman_redraw_all()
Thinker K.F. Li <thinker@branda.to>
parents:
14
diff
changeset
|
568 area_t **areas) { |
c2ce186a5c37
X_main uses rdman_redraw_all()
Thinker K.F. Li <thinker@branda.to>
parents:
14
diff
changeset
|
569 geo_t *visit_geo; |
c2ce186a5c37
X_main uses rdman_redraw_all()
Thinker K.F. Li <thinker@branda.to>
parents:
14
diff
changeset
|
570 int i; |
c2ce186a5c37
X_main uses rdman_redraw_all()
Thinker K.F. Li <thinker@branda.to>
parents:
14
diff
changeset
|
571 |
c2ce186a5c37
X_main uses rdman_redraw_all()
Thinker K.F. Li <thinker@branda.to>
parents:
14
diff
changeset
|
572 for(visit_geo = STAILQ_HEAD(rdman->all_geos); |
c2ce186a5c37
X_main uses rdman_redraw_all()
Thinker K.F. Li <thinker@branda.to>
parents:
14
diff
changeset
|
573 visit_geo != NULL; |
c2ce186a5c37
X_main uses rdman_redraw_all()
Thinker K.F. Li <thinker@branda.to>
parents:
14
diff
changeset
|
574 visit_geo = STAILQ_NEXT(geo_t, next, visit_geo)) { |
16
e17e12b112c4
A simple animation using rdman_redraw_changed().
Thinker K.F. Li <thinker@branda.to>
parents:
15
diff
changeset
|
575 if(visit_geo->flags & GEF_DIRTY) |
e17e12b112c4
A simple animation using rdman_redraw_changed().
Thinker K.F. Li <thinker@branda.to>
parents:
15
diff
changeset
|
576 clean_shape(visit_geo->shape); |
15
c2ce186a5c37
X_main uses rdman_redraw_all()
Thinker K.F. Li <thinker@branda.to>
parents:
14
diff
changeset
|
577 for(i = 0; i < n_areas; i++) { |
c2ce186a5c37
X_main uses rdman_redraw_all()
Thinker K.F. Li <thinker@branda.to>
parents:
14
diff
changeset
|
578 if(is_overlay(visit_geo->cur_area, areas[i])) { |
22 | 579 draw_shape(rdman, visit_geo->shape); |
15
c2ce186a5c37
X_main uses rdman_redraw_all()
Thinker K.F. Li <thinker@branda.to>
parents:
14
diff
changeset
|
580 break; |
c2ce186a5c37
X_main uses rdman_redraw_all()
Thinker K.F. Li <thinker@branda.to>
parents:
14
diff
changeset
|
581 } |
c2ce186a5c37
X_main uses rdman_redraw_all()
Thinker K.F. Li <thinker@branda.to>
parents:
14
diff
changeset
|
582 } |
c2ce186a5c37
X_main uses rdman_redraw_all()
Thinker K.F. Li <thinker@branda.to>
parents:
14
diff
changeset
|
583 } |
13 | 584 } |
585 | |
24
e598bc809c0f
No more flash when animation.
Thinker K.F. Li <thinker@branda.to>
parents:
23
diff
changeset
|
586 |
13 | 587 /*! \brief Re-draw all changed shapes or shapes affected by changed coords. |
588 * | |
589 * A coord object has a geo to keep track the range that it's members will | |
590 * draw on. Geo of a coord should be recomputed when the coord is changed. | |
591 * Geo of a coord used to accelerate finding overlay shape objects of | |
592 * a specified geo. A coord object also must be recomputed when one of | |
593 * it's members is changed. | |
594 * | |
595 * New and old geo values of a coord object that is recomputed for | |
596 * changing of it-self must be used to find overlay shape objects. | |
597 * New and old geo values of a shape should also be used to find | |
598 * overlay shape objects, too. If a shape's coord is changed, shape's | |
599 * geo object is not used to find overlay shape objects any more. | |
600 * | |
601 * steps: | |
602 * - update chagned coord objects | |
14 | 603 * - recompute area for changed coord objects |
13 | 604 * - recompute geo for members shape objects |
14 | 605 * - clear dirty of geo for members to prevent from |
606 * recomputing for change of shape objects. | |
607 * - add old and new area value to list of dirty areas. | |
13 | 608 * - recompute geo for changed shape objects |
14 | 609 * - only if a shape object is dirty. |
610 * - put new and old value of area of geo to list of dirty areas. | |
611 * - Scan all shapes and redraw shapes overlaid with dirty areas. | |
13 | 612 * |
14 | 613 * 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
|
614 * 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
|
615 * 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
|
616 * corod objects. |
14 | 617 * |
13 | 618 */ |
619 int rdman_redraw_changed(redraw_man_t *rdman) { | |
15
c2ce186a5c37
X_main uses rdman_redraw_all()
Thinker K.F. Li <thinker@branda.to>
parents:
14
diff
changeset
|
620 int i, r; |
14 | 621 geo_t *visit_geo, **dirty_geos; |
622 int n_dirty_geos; | |
13 | 623 int n_dirty_areas; |
14 | 624 area_t **dirty_areas; |
13 | 625 |
16
e17e12b112c4
A simple animation using rdman_redraw_changed().
Thinker K.F. Li <thinker@branda.to>
parents:
15
diff
changeset
|
626 r = clean_rdman_coords(rdman); |
e17e12b112c4
A simple animation using rdman_redraw_changed().
Thinker K.F. Li <thinker@branda.to>
parents:
15
diff
changeset
|
627 if(r != OK) |
e17e12b112c4
A simple animation using rdman_redraw_changed().
Thinker K.F. Li <thinker@branda.to>
parents:
15
diff
changeset
|
628 return ERR; |
13 | 629 |
14 | 630 n_dirty_geos = rdman->n_dirty_geos; |
631 if(n_dirty_geos > 0) { | |
632 dirty_geos = rdman->dirty_geos; | |
633 for(i = 0; i < n_dirty_geos; i++) { | |
634 visit_geo = dirty_geos[i]; | |
13 | 635 if(!(visit_geo->flags & GEF_DIRTY)) |
636 continue; | |
637 | |
638 SWAP(visit_geo->cur_area, visit_geo->last_area, area_t *); | |
16
e17e12b112c4
A simple animation using rdman_redraw_changed().
Thinker K.F. Li <thinker@branda.to>
parents:
15
diff
changeset
|
639 clean_shape(visit_geo->shape); |
13 | 640 add_dirty_area(rdman, visit_geo->cur_area); |
641 add_dirty_area(rdman, visit_geo->last_area); | |
642 } | |
15
c2ce186a5c37
X_main uses rdman_redraw_all()
Thinker K.F. Li <thinker@branda.to>
parents:
14
diff
changeset
|
643 rdman->n_dirty_geos = 0; |
c2ce186a5c37
X_main uses rdman_redraw_all()
Thinker K.F. Li <thinker@branda.to>
parents:
14
diff
changeset
|
644 } |
13 | 645 |
15
c2ce186a5c37
X_main uses rdman_redraw_all()
Thinker K.F. Li <thinker@branda.to>
parents:
14
diff
changeset
|
646 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
|
647 dirty_areas = rdman->dirty_areas; |
c2ce186a5c37
X_main uses rdman_redraw_all()
Thinker K.F. Li <thinker@branda.to>
parents:
14
diff
changeset
|
648 if(n_dirty_areas > 0) { |
25
29937c26bb01
Fix bug of a dark line appear when animating.
Thinker K.F. Li <thinker@branda.to>
parents:
24
diff
changeset
|
649 clean_canvas(rdman->cr); |
22 | 650 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
|
651 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
|
652 rdman->n_dirty_areas = 0; |
17
41f0907b27ac
Unittest for rdman_redraw_changed().
Thinker K.F. Li <thinker@branda.to>
parents:
16
diff
changeset
|
653 reset_clip(rdman); |
15
c2ce186a5c37
X_main uses rdman_redraw_all()
Thinker K.F. Li <thinker@branda.to>
parents:
14
diff
changeset
|
654 } |
16
e17e12b112c4
A simple animation using rdman_redraw_changed().
Thinker K.F. Li <thinker@branda.to>
parents:
15
diff
changeset
|
655 rdman->n_dirty_areas = 0; |
e17e12b112c4
A simple animation using rdman_redraw_changed().
Thinker K.F. Li <thinker@branda.to>
parents:
15
diff
changeset
|
656 |
15
c2ce186a5c37
X_main uses rdman_redraw_all()
Thinker K.F. Li <thinker@branda.to>
parents:
14
diff
changeset
|
657 return OK; |
c2ce186a5c37
X_main uses rdman_redraw_all()
Thinker K.F. Li <thinker@branda.to>
parents:
14
diff
changeset
|
658 } |
c2ce186a5c37
X_main uses rdman_redraw_all()
Thinker K.F. Li <thinker@branda.to>
parents:
14
diff
changeset
|
659 |
c2ce186a5c37
X_main uses rdman_redraw_all()
Thinker K.F. Li <thinker@branda.to>
parents:
14
diff
changeset
|
660 int rdman_redraw_all(redraw_man_t *rdman) { |
c2ce186a5c37
X_main uses rdman_redraw_all()
Thinker K.F. Li <thinker@branda.to>
parents:
14
diff
changeset
|
661 geo_t *geo; |
c2ce186a5c37
X_main uses rdman_redraw_all()
Thinker K.F. Li <thinker@branda.to>
parents:
14
diff
changeset
|
662 |
16
e17e12b112c4
A simple animation using rdman_redraw_changed().
Thinker K.F. Li <thinker@branda.to>
parents:
15
diff
changeset
|
663 clean_rdman_coords(rdman); |
e17e12b112c4
A simple animation using rdman_redraw_changed().
Thinker K.F. Li <thinker@branda.to>
parents:
15
diff
changeset
|
664 rdman->n_dirty_areas = 0; |
e17e12b112c4
A simple animation using rdman_redraw_changed().
Thinker K.F. Li <thinker@branda.to>
parents:
15
diff
changeset
|
665 |
15
c2ce186a5c37
X_main uses rdman_redraw_all()
Thinker K.F. Li <thinker@branda.to>
parents:
14
diff
changeset
|
666 for(geo = STAILQ_HEAD(rdman->all_geos); |
c2ce186a5c37
X_main uses rdman_redraw_all()
Thinker K.F. Li <thinker@branda.to>
parents:
14
diff
changeset
|
667 geo != NULL; |
c2ce186a5c37
X_main uses rdman_redraw_all()
Thinker K.F. Li <thinker@branda.to>
parents:
14
diff
changeset
|
668 geo = STAILQ_NEXT(geo_t, next, geo)) { |
16
e17e12b112c4
A simple animation using rdman_redraw_changed().
Thinker K.F. Li <thinker@branda.to>
parents:
15
diff
changeset
|
669 if(geo->flags & GEF_DIRTY) |
e17e12b112c4
A simple animation using rdman_redraw_changed().
Thinker K.F. Li <thinker@branda.to>
parents:
15
diff
changeset
|
670 clean_shape(geo->shape); |
22 | 671 draw_shape(rdman, geo->shape); |
13 | 672 } |
24
e598bc809c0f
No more flash when animation.
Thinker K.F. Li <thinker@branda.to>
parents:
23
diff
changeset
|
673 copy_cr_2_backend(rdman, 0, NULL); |
23
56f592f56ff7
Fix bug and add linear gradient paint.
Thinker K.F. Li <thinker@branda.to>
parents:
22
diff
changeset
|
674 rdman->n_dirty_geos = 0; |
13 | 675 |
676 return OK; | |
12 | 677 } |
678 | |
18
0f3baa488a62
Support solid color paint for fill.
Thinker K.F. Li <thinker@branda.to>
parents:
17
diff
changeset
|
679 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
|
680 shnode_t *node; |
0f3baa488a62
Support solid color paint for fill.
Thinker K.F. Li <thinker@branda.to>
parents:
17
diff
changeset
|
681 |
0f3baa488a62
Support solid color paint for fill.
Thinker K.F. Li <thinker@branda.to>
parents:
17
diff
changeset
|
682 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
|
683 if(node) { |
0f3baa488a62
Support solid color paint for fill.
Thinker K.F. Li <thinker@branda.to>
parents:
17
diff
changeset
|
684 node->shape = shape; |
0f3baa488a62
Support solid color paint for fill.
Thinker K.F. Li <thinker@branda.to>
parents:
17
diff
changeset
|
685 node->next = NULL; |
0f3baa488a62
Support solid color paint for fill.
Thinker K.F. Li <thinker@branda.to>
parents:
17
diff
changeset
|
686 } |
0f3baa488a62
Support solid color paint for fill.
Thinker K.F. Li <thinker@branda.to>
parents:
17
diff
changeset
|
687 return node; |
0f3baa488a62
Support solid color paint for fill.
Thinker K.F. Li <thinker@branda.to>
parents:
17
diff
changeset
|
688 } |
0f3baa488a62
Support solid color paint for fill.
Thinker K.F. Li <thinker@branda.to>
parents:
17
diff
changeset
|
689 |
0f3baa488a62
Support solid color paint for fill.
Thinker K.F. Li <thinker@branda.to>
parents:
17
diff
changeset
|
690 int rdman_paint_changed(redraw_man_t *rdman, paint_t *paint) { |
0f3baa488a62
Support solid color paint for fill.
Thinker K.F. Li <thinker@branda.to>
parents:
17
diff
changeset
|
691 shnode_t *node; |
0f3baa488a62
Support solid color paint for fill.
Thinker K.F. Li <thinker@branda.to>
parents:
17
diff
changeset
|
692 int r; |
0f3baa488a62
Support solid color paint for fill.
Thinker K.F. Li <thinker@branda.to>
parents:
17
diff
changeset
|
693 |
0f3baa488a62
Support solid color paint for fill.
Thinker K.F. Li <thinker@branda.to>
parents:
17
diff
changeset
|
694 for(node = STAILQ_HEAD(paint->members); |
0f3baa488a62
Support solid color paint for fill.
Thinker K.F. Li <thinker@branda.to>
parents:
17
diff
changeset
|
695 node != NULL; |
0f3baa488a62
Support solid color paint for fill.
Thinker K.F. Li <thinker@branda.to>
parents:
17
diff
changeset
|
696 node = STAILQ_NEXT(shnode_t, next, node)) { |
0f3baa488a62
Support solid color paint for fill.
Thinker K.F. Li <thinker@branda.to>
parents:
17
diff
changeset
|
697 r = _rdman_shape_changed(rdman, node->shape); |
0f3baa488a62
Support solid color paint for fill.
Thinker K.F. Li <thinker@branda.to>
parents:
17
diff
changeset
|
698 if(r != OK) |
0f3baa488a62
Support solid color paint for fill.
Thinker K.F. Li <thinker@branda.to>
parents:
17
diff
changeset
|
699 return ERR; |
0f3baa488a62
Support solid color paint for fill.
Thinker K.F. Li <thinker@branda.to>
parents:
17
diff
changeset
|
700 } |
0f3baa488a62
Support solid color paint for fill.
Thinker K.F. Li <thinker@branda.to>
parents:
17
diff
changeset
|
701 return OK; |
0f3baa488a62
Support solid color paint for fill.
Thinker K.F. Li <thinker@branda.to>
parents:
17
diff
changeset
|
702 } |
0f3baa488a62
Support solid color paint for fill.
Thinker K.F. Li <thinker@branda.to>
parents:
17
diff
changeset
|
703 |
12 | 704 /* |
16
e17e12b112c4
A simple animation using rdman_redraw_changed().
Thinker K.F. Li <thinker@branda.to>
parents:
15
diff
changeset
|
705 * Dirty of geo |
e17e12b112c4
A simple animation using rdman_redraw_changed().
Thinker K.F. Li <thinker@branda.to>
parents:
15
diff
changeset
|
706 * 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
|
707 * 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
|
708 * 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
|
709 * 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
|
710 * size, and positions. |
e17e12b112c4
A simple animation using rdman_redraw_changed().
Thinker K.F. Li <thinker@branda.to>
parents:
15
diff
changeset
|
711 * |
e17e12b112c4
A simple animation using rdman_redraw_changed().
Thinker K.F. Li <thinker@branda.to>
parents:
15
diff
changeset
|
712 * Dirty of coord |
e17e12b112c4
A simple animation using rdman_redraw_changed().
Thinker K.F. Li <thinker@branda.to>
parents:
15
diff
changeset
|
713 * 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
|
714 * 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
|
715 * 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
|
716 * 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
|
717 * 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
|
718 * 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
|
719 * 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
|
720 * 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
|
721 * 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
|
722 * 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
|
723 * 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
|
724 * 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
|
725 * 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
|
726 * |
e17e12b112c4
A simple animation using rdman_redraw_changed().
Thinker K.F. Li <thinker@branda.to>
parents:
15
diff
changeset
|
727 * 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
|
728 * 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
|
729 * |
e17e12b112c4
A simple animation using rdman_redraw_changed().
Thinker K.F. Li <thinker@branda.to>
parents:
15
diff
changeset
|
730 * 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
|
731 * 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
|
732 * 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
|
733 * |
e17e12b112c4
A simple animation using rdman_redraw_changed().
Thinker K.F. Li <thinker@branda.to>
parents:
15
diff
changeset
|
734 * 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
|
735 * 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
|
736 */ |
e17e12b112c4
A simple animation using rdman_redraw_changed().
Thinker K.F. Li <thinker@branda.to>
parents:
15
diff
changeset
|
737 |
e17e12b112c4
A simple animation using rdman_redraw_changed().
Thinker K.F. Li <thinker@branda.to>
parents:
15
diff
changeset
|
738 /* |
12 | 739 * When redraw an area, the affected elements may also extend to |
740 * outside of the area. Since the order of drawing will change | |
741 * the result, it will infect more and more elements to keep | |
742 * drawing order althrough they are overlaid directly with | |
743 * specified area. | |
744 * | |
745 * To fix the problem, we don't extend the set of redrawing to | |
746 * elements they are not overliad directly. The redrawing is | |
747 * performed on a temporary surface, clipped to fit the area, and | |
748 * update only specified area on the destinate surface. | |
749 */ | |
750 | |
751 /* | |
752 * To accelerate speed of transformation, when a matrix changed, | |
753 * transformation should be aggregated and computed in a loop. | |
754 * It can get intereset of higher hit rate of cache. | |
755 * - shapes prvoide list of positions needed to be transformed. | |
756 * - redraw_man transforms positions from shapes. | |
757 * - shapes drawing with result of transforms. | |
758 * - shapes should be called to give them a chance to update geometries. | |
759 */ | |
760 | |
13 | 761 /* |
762 * functions: | |
763 * - redraw all | |
764 * - redraw changed | |
765 */ | |
766 | |
12 | 767 #ifdef UNITTEST |
768 | |
769 #include <CUnit/Basic.h> | |
19 | 770 #include "paint.h" |
12 | 771 |
772 struct _sh_dummy { | |
773 shape_t shape; | |
774 co_aix x, y; | |
775 co_aix w, h; | |
17
41f0907b27ac
Unittest for rdman_redraw_changed().
Thinker K.F. Li <thinker@branda.to>
parents:
16
diff
changeset
|
776 int draw_cnt; |
12 | 777 }; |
778 | |
779 shape_t *sh_dummy_new(co_aix x, co_aix y, co_aix w, co_aix h) { | |
780 sh_dummy_t *dummy; | |
781 | |
782 dummy = (sh_dummy_t *)malloc(sizeof(sh_dummy_t)); | |
783 if(dummy == NULL) | |
784 return NULL; | |
785 | |
17
41f0907b27ac
Unittest for rdman_redraw_changed().
Thinker K.F. Li <thinker@branda.to>
parents:
16
diff
changeset
|
786 memset(dummy, 0, sizeof(sh_dummy_t)); |
41f0907b27ac
Unittest for rdman_redraw_changed().
Thinker K.F. Li <thinker@branda.to>
parents:
16
diff
changeset
|
787 |
12 | 788 dummy->x = x; |
789 dummy->y = y; | |
790 dummy->w = w; | |
791 dummy->h = h; | |
17
41f0907b27ac
Unittest for rdman_redraw_changed().
Thinker K.F. Li <thinker@branda.to>
parents:
16
diff
changeset
|
792 dummy->draw_cnt = 0; |
12 | 793 |
794 return (shape_t *)dummy; | |
795 } | |
796 | |
797 void sh_dummy_free(shape_t *sh) { | |
798 free(sh); | |
799 } | |
800 | |
801 void sh_dummy_transform(shape_t *shape) { | |
802 sh_dummy_t *dummy = (sh_dummy_t *)shape; | |
803 co_aix poses[2][2]; | |
804 co_aix x1, y1, x2, y2; | |
805 | |
806 if(shape->geo && shape->coord) { | |
807 x1 = dummy->x; | |
808 y1 = dummy->y; | |
809 x2 = x1 + dummy->w; | |
810 y2 = y1 + dummy->h; | |
811 | |
812 coord_trans_pos(shape->coord, &x1, &y1); | |
813 coord_trans_pos(shape->coord, &x2, &y2); | |
814 poses[0][0] = x1; | |
815 poses[0][1] = y1; | |
816 poses[1][0] = x2; | |
817 poses[1][1] = y2; | |
818 | |
17
41f0907b27ac
Unittest for rdman_redraw_changed().
Thinker K.F. Li <thinker@branda.to>
parents:
16
diff
changeset
|
819 if(shape->geo) |
41f0907b27ac
Unittest for rdman_redraw_changed().
Thinker K.F. Li <thinker@branda.to>
parents:
16
diff
changeset
|
820 geo_from_positions(shape->geo, 2, poses); |
12 | 821 } |
822 } | |
823 | |
20
74d3d5dc9aaa
rename XXX_draw() to XXX_fill()
Thinker K.F. Li <thinker@branda.to>
parents:
19
diff
changeset
|
824 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
|
825 sh_dummy_t *dummy; |
41f0907b27ac
Unittest for rdman_redraw_changed().
Thinker K.F. Li <thinker@branda.to>
parents:
16
diff
changeset
|
826 |
41f0907b27ac
Unittest for rdman_redraw_changed().
Thinker K.F. Li <thinker@branda.to>
parents:
16
diff
changeset
|
827 dummy = (sh_dummy_t *)shape; |
41f0907b27ac
Unittest for rdman_redraw_changed().
Thinker K.F. Li <thinker@branda.to>
parents:
16
diff
changeset
|
828 dummy->draw_cnt++; |
41f0907b27ac
Unittest for rdman_redraw_changed().
Thinker K.F. Li <thinker@branda.to>
parents:
16
diff
changeset
|
829 } |
41f0907b27ac
Unittest for rdman_redraw_changed().
Thinker K.F. Li <thinker@branda.to>
parents:
16
diff
changeset
|
830 |
19 | 831 static void dummy_paint_prepare(paint_t *paint, cairo_t *cr) { |
832 } | |
833 | |
834 static void dummy_paint_free(paint_t *paint) { | |
835 if(paint) | |
836 free(paint); | |
837 } | |
838 | |
839 paint_t *dummy_paint_new(redraw_man_t *rdman) { | |
840 paint_t *paint; | |
841 | |
842 paint = (paint_t *)malloc(sizeof(paint_t)); | |
843 if(paint == NULL) | |
844 return NULL; | |
845 | |
846 paint_init(paint, dummy_paint_prepare, dummy_paint_free); | |
847 | |
848 return paint; | |
849 } | |
850 | |
12 | 851 void test_rdman_find_overlaid_shapes(void) { |
852 redraw_man_t rdman; | |
853 geo_t geo; | |
854 coord_t *coords[3]; | |
855 shape_t *shapes[5]; | |
856 geo_t **overlays; | |
13 | 857 co_aix pos[2][2]; |
12 | 858 int n; |
859 int i; | |
860 | |
24
e598bc809c0f
No more flash when animation.
Thinker K.F. Li <thinker@branda.to>
parents:
23
diff
changeset
|
861 redraw_man_init(&rdman, NULL, NULL); |
12 | 862 coords[0] = rdman.root_coord; |
863 for(i = 1; i < 3; i++) { | |
864 coords[i] = rdman_coord_new(&rdman, rdman.root_coord); | |
865 } | |
866 for(i = 0; i < 5; i++) { | |
867 shapes[i] = sh_dummy_new(10 + i * 30, 10 + i * 20, 25, 15); | |
868 CU_ASSERT(shapes[i] != NULL); | |
869 } | |
870 for(i = 0; i < 3; i++) | |
871 rdman_add_shape(&rdman, shapes[i], coords[1]); | |
872 for(i = 3; i < 5; i++) | |
873 rdman_add_shape(&rdman, shapes[i], coords[2]); | |
874 | |
875 coords[1]->matrix[0] = 2; | |
876 coords[0]->matrix[4] = 2; | |
877 | |
878 update_aggr_matrix(coords[0]); | |
879 for(i = 0; i < 5; i++) | |
880 sh_dummy_transform(shapes[i]); | |
881 | |
13 | 882 pos[0][0] = 100; |
883 pos[0][1] = 120; | |
884 pos[1][0] = 100 + 140; | |
885 pos[1][1] = 120 + 40; | |
17
41f0907b27ac
Unittest for rdman_redraw_changed().
Thinker K.F. Li <thinker@branda.to>
parents:
16
diff
changeset
|
886 geo_init(&geo); |
41f0907b27ac
Unittest for rdman_redraw_changed().
Thinker K.F. Li <thinker@branda.to>
parents:
16
diff
changeset
|
887 geo_from_positions(&geo, 2, pos); |
12 | 888 |
889 n = rdman_find_overlaid_shapes(&rdman, &geo, &overlays); | |
890 CU_ASSERT(n == 2); | |
891 CU_ASSERT(overlays != NULL); | |
892 CU_ASSERT(overlays[0] == shapes[2]->geo); | |
893 CU_ASSERT(overlays[1] == shapes[3]->geo); | |
894 | |
895 free(overlays); | |
896 for(i = 0; i < 5; i++) | |
897 sh_dummy_free(shapes[i]); | |
898 | |
899 redraw_man_destroy(&rdman); | |
900 } | |
901 | |
17
41f0907b27ac
Unittest for rdman_redraw_changed().
Thinker K.F. Li <thinker@branda.to>
parents:
16
diff
changeset
|
902 void test_rdman_redraw_changed(void) { |
41f0907b27ac
Unittest for rdman_redraw_changed().
Thinker K.F. Li <thinker@branda.to>
parents:
16
diff
changeset
|
903 coord_t *coords[3]; |
41f0907b27ac
Unittest for rdman_redraw_changed().
Thinker K.F. Li <thinker@branda.to>
parents:
16
diff
changeset
|
904 shape_t *shapes[3]; |
41f0907b27ac
Unittest for rdman_redraw_changed().
Thinker K.F. Li <thinker@branda.to>
parents:
16
diff
changeset
|
905 sh_dummy_t **dummys; |
19 | 906 paint_t *paint; |
17
41f0907b27ac
Unittest for rdman_redraw_changed().
Thinker K.F. Li <thinker@branda.to>
parents:
16
diff
changeset
|
907 redraw_man_t *rdman; |
41f0907b27ac
Unittest for rdman_redraw_changed().
Thinker K.F. Li <thinker@branda.to>
parents:
16
diff
changeset
|
908 redraw_man_t _rdman; |
41f0907b27ac
Unittest for rdman_redraw_changed().
Thinker K.F. Li <thinker@branda.to>
parents:
16
diff
changeset
|
909 int i; |
41f0907b27ac
Unittest for rdman_redraw_changed().
Thinker K.F. Li <thinker@branda.to>
parents:
16
diff
changeset
|
910 |
41f0907b27ac
Unittest for rdman_redraw_changed().
Thinker K.F. Li <thinker@branda.to>
parents:
16
diff
changeset
|
911 dummys = (sh_dummy_t **)shapes; |
41f0907b27ac
Unittest for rdman_redraw_changed().
Thinker K.F. Li <thinker@branda.to>
parents:
16
diff
changeset
|
912 |
41f0907b27ac
Unittest for rdman_redraw_changed().
Thinker K.F. Li <thinker@branda.to>
parents:
16
diff
changeset
|
913 rdman = &_rdman; |
24
e598bc809c0f
No more flash when animation.
Thinker K.F. Li <thinker@branda.to>
parents:
23
diff
changeset
|
914 redraw_man_init(rdman, NULL, NULL); |
19 | 915 paint = dummy_paint_new(rdman); |
17
41f0907b27ac
Unittest for rdman_redraw_changed().
Thinker K.F. Li <thinker@branda.to>
parents:
16
diff
changeset
|
916 for(i = 0; i < 3; i++) { |
41f0907b27ac
Unittest for rdman_redraw_changed().
Thinker K.F. Li <thinker@branda.to>
parents:
16
diff
changeset
|
917 shapes[i] = sh_dummy_new(0, 0, 50, 50); |
19 | 918 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
|
919 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
|
920 coords[i]->matrix[2] = 10 + i * 100; |
41f0907b27ac
Unittest for rdman_redraw_changed().
Thinker K.F. Li <thinker@branda.to>
parents:
16
diff
changeset
|
921 coords[i]->matrix[5] = 10 + i * 100; |
41f0907b27ac
Unittest for rdman_redraw_changed().
Thinker K.F. Li <thinker@branda.to>
parents:
16
diff
changeset
|
922 rdman_coord_changed(rdman, coords[i]); |
41f0907b27ac
Unittest for rdman_redraw_changed().
Thinker K.F. Li <thinker@branda.to>
parents:
16
diff
changeset
|
923 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
|
924 } |
41f0907b27ac
Unittest for rdman_redraw_changed().
Thinker K.F. Li <thinker@branda.to>
parents:
16
diff
changeset
|
925 rdman_redraw_all(rdman); |
41f0907b27ac
Unittest for rdman_redraw_changed().
Thinker K.F. Li <thinker@branda.to>
parents:
16
diff
changeset
|
926 CU_ASSERT(dummys[0]->draw_cnt == 1); |
41f0907b27ac
Unittest for rdman_redraw_changed().
Thinker K.F. Li <thinker@branda.to>
parents:
16
diff
changeset
|
927 CU_ASSERT(dummys[1]->draw_cnt == 1); |
41f0907b27ac
Unittest for rdman_redraw_changed().
Thinker K.F. Li <thinker@branda.to>
parents:
16
diff
changeset
|
928 CU_ASSERT(dummys[2]->draw_cnt == 1); |
41f0907b27ac
Unittest for rdman_redraw_changed().
Thinker K.F. Li <thinker@branda.to>
parents:
16
diff
changeset
|
929 |
41f0907b27ac
Unittest for rdman_redraw_changed().
Thinker K.F. Li <thinker@branda.to>
parents:
16
diff
changeset
|
930 coords[2]->matrix[2] = 100; |
41f0907b27ac
Unittest for rdman_redraw_changed().
Thinker K.F. Li <thinker@branda.to>
parents:
16
diff
changeset
|
931 coords[2]->matrix[5] = 100; |
41f0907b27ac
Unittest for rdman_redraw_changed().
Thinker K.F. Li <thinker@branda.to>
parents:
16
diff
changeset
|
932 rdman_coord_changed(rdman, coords[2]); |
41f0907b27ac
Unittest for rdman_redraw_changed().
Thinker K.F. Li <thinker@branda.to>
parents:
16
diff
changeset
|
933 rdman_redraw_changed(rdman); |
41f0907b27ac
Unittest for rdman_redraw_changed().
Thinker K.F. Li <thinker@branda.to>
parents:
16
diff
changeset
|
934 |
41f0907b27ac
Unittest for rdman_redraw_changed().
Thinker K.F. Li <thinker@branda.to>
parents:
16
diff
changeset
|
935 CU_ASSERT(dummys[0]->draw_cnt == 1); |
41f0907b27ac
Unittest for rdman_redraw_changed().
Thinker K.F. Li <thinker@branda.to>
parents:
16
diff
changeset
|
936 CU_ASSERT(dummys[1]->draw_cnt == 2); |
41f0907b27ac
Unittest for rdman_redraw_changed().
Thinker K.F. Li <thinker@branda.to>
parents:
16
diff
changeset
|
937 CU_ASSERT(dummys[2]->draw_cnt == 2); |
19 | 938 |
939 paint->free(paint); | |
940 redraw_man_destroy(rdman); | |
17
41f0907b27ac
Unittest for rdman_redraw_changed().
Thinker K.F. Li <thinker@branda.to>
parents:
16
diff
changeset
|
941 } |
41f0907b27ac
Unittest for rdman_redraw_changed().
Thinker K.F. Li <thinker@branda.to>
parents:
16
diff
changeset
|
942 |
12 | 943 CU_pSuite get_redraw_man_suite(void) { |
944 CU_pSuite suite; | |
945 | |
946 suite = CU_add_suite("Suite_redraw_man", NULL, NULL); | |
947 CU_ADD_TEST(suite, test_rdman_find_overlaid_shapes); | |
17
41f0907b27ac
Unittest for rdman_redraw_changed().
Thinker K.F. Li <thinker@branda.to>
parents:
16
diff
changeset
|
948 CU_ADD_TEST(suite, test_rdman_redraw_changed); |
12 | 949 |
950 return suite; | |
951 } | |
952 | |
953 #endif /* UNITTEST */ |