Mercurial > MadButterfly
annotate src/coord.c @ 446:2437047b8bb8
Fix bug of propertional shifting of sh_stext_t.
Original
- sh_stext_t does not apply shifting of text himself to scaled font face, but
- apply aggreagated matrix to font face.
- shifting in parent parent coord_t would applied to scaled font.
- amount of shifting is also multiplied by aggreagated matrix.
- It means shiftings of parent coord_ts are applied two times.
Now,
- remove x, y shifting from aggreagated matrices before applying
to scaled fonts.
author | Thinker K.F. Li <thinker@branda.to> |
---|---|
date | Sun, 02 Aug 2009 10:59:59 +0800 |
parents | 6c350fc92ae3 |
children | b51ae415f459 |
rev | line source |
---|---|
2 | 1 /*! \brief Implement coordination tranform mechanism. |
2 * \file | |
3 * This file implements coordination transforming for containers. | |
4 */ | |
1 | 5 #include <stdio.h> |
6 #include <string.h> | |
31
da770188a44d
resize font size for changige of coord.
Thinker K.F. Li <thinker@branda.to>
parents:
17
diff
changeset
|
7 #include <math.h> |
186
530bb7728546
Move header files to $(top_srcdir)/include/ and prefixed with 'mb_'.
Thinker K.F. Li <thinker@branda.to>
parents:
185
diff
changeset
|
8 #include "mb_types.h" |
1 | 9 |
12 | 10 |
11 #define ASSERT(x) | |
12 | |
3
164162781a7a
Test cairo with Xlib surface
Thinker K.F. Li <thinker@branda.to>
parents:
2
diff
changeset
|
13 /* To keep possibility of changing type of aix */ |
2 | 14 #define MUL(a, b) ((a) * (b)) |
15 #define ADD(a, b) ((a) + (b)) | |
16 #define DIV(a, b) ((a) / (b)) | |
17 #define SUB(a, b) ((a) - (b)) | |
18 | |
19 static void mul_matrix(co_aix *m1, co_aix *m2, co_aix *dst) { | |
20 dst[0] = ADD(MUL(m1[0], m2[0]), MUL(m1[1], m2[3])); | |
21 dst[1] = ADD(MUL(m1[0], m2[1]), MUL(m1[1], m2[4])); | |
22 dst[2] = ADD(ADD(MUL(m1[0], m2[2]), MUL(m1[1], m2[5])), m1[2]); | |
23 dst[3] = ADD(MUL(m1[3], m2[0]), MUL(m1[4], m2[3])); | |
24 dst[4] = ADD(MUL(m1[3], m2[1]), MUL(m1[4], m2[4])); | |
25 dst[5] = ADD(ADD(MUL(m1[3], m2[2]), MUL(m1[4], m2[5])), m1[5]); | |
1 | 26 } |
27 | |
314
6c350fc92ae3
Cache rednering result is now workable.
Thinker K.F. Li <thinker@branda.to>
parents:
224
diff
changeset
|
28 void matrix_mul(co_aix *m1, co_aix *m2, co_aix *dst) { |
6c350fc92ae3
Cache rednering result is now workable.
Thinker K.F. Li <thinker@branda.to>
parents:
224
diff
changeset
|
29 co_aix *_dst = dst; |
6c350fc92ae3
Cache rednering result is now workable.
Thinker K.F. Li <thinker@branda.to>
parents:
224
diff
changeset
|
30 co_aix fake_dst[6]; |
6c350fc92ae3
Cache rednering result is now workable.
Thinker K.F. Li <thinker@branda.to>
parents:
224
diff
changeset
|
31 |
6c350fc92ae3
Cache rednering result is now workable.
Thinker K.F. Li <thinker@branda.to>
parents:
224
diff
changeset
|
32 if(m1 == dst || m2 == dst) |
6c350fc92ae3
Cache rednering result is now workable.
Thinker K.F. Li <thinker@branda.to>
parents:
224
diff
changeset
|
33 _dst = fake_dst; |
6c350fc92ae3
Cache rednering result is now workable.
Thinker K.F. Li <thinker@branda.to>
parents:
224
diff
changeset
|
34 |
6c350fc92ae3
Cache rednering result is now workable.
Thinker K.F. Li <thinker@branda.to>
parents:
224
diff
changeset
|
35 mul_matrix(m1, m2, _dst); |
6c350fc92ae3
Cache rednering result is now workable.
Thinker K.F. Li <thinker@branda.to>
parents:
224
diff
changeset
|
36 |
6c350fc92ae3
Cache rednering result is now workable.
Thinker K.F. Li <thinker@branda.to>
parents:
224
diff
changeset
|
37 if(m1 == dst || m2 == dst) { |
6c350fc92ae3
Cache rednering result is now workable.
Thinker K.F. Li <thinker@branda.to>
parents:
224
diff
changeset
|
38 dst[0] = fake_dst[0]; |
6c350fc92ae3
Cache rednering result is now workable.
Thinker K.F. Li <thinker@branda.to>
parents:
224
diff
changeset
|
39 dst[1] = fake_dst[1]; |
6c350fc92ae3
Cache rednering result is now workable.
Thinker K.F. Li <thinker@branda.to>
parents:
224
diff
changeset
|
40 dst[2] = fake_dst[2]; |
6c350fc92ae3
Cache rednering result is now workable.
Thinker K.F. Li <thinker@branda.to>
parents:
224
diff
changeset
|
41 dst[3] = fake_dst[3]; |
6c350fc92ae3
Cache rednering result is now workable.
Thinker K.F. Li <thinker@branda.to>
parents:
224
diff
changeset
|
42 dst[4] = fake_dst[4]; |
6c350fc92ae3
Cache rednering result is now workable.
Thinker K.F. Li <thinker@branda.to>
parents:
224
diff
changeset
|
43 dst[5] = fake_dst[5]; |
6c350fc92ae3
Cache rednering result is now workable.
Thinker K.F. Li <thinker@branda.to>
parents:
224
diff
changeset
|
44 } |
6c350fc92ae3
Cache rednering result is now workable.
Thinker K.F. Li <thinker@branda.to>
parents:
224
diff
changeset
|
45 } |
6c350fc92ae3
Cache rednering result is now workable.
Thinker K.F. Li <thinker@branda.to>
parents:
224
diff
changeset
|
46 |
6c350fc92ae3
Cache rednering result is now workable.
Thinker K.F. Li <thinker@branda.to>
parents:
224
diff
changeset
|
47 void matrix_trans_pos(co_aix *matrix, co_aix *x, co_aix *y) { |
6c350fc92ae3
Cache rednering result is now workable.
Thinker K.F. Li <thinker@branda.to>
parents:
224
diff
changeset
|
48 co_aix nx, ny; |
6c350fc92ae3
Cache rednering result is now workable.
Thinker K.F. Li <thinker@branda.to>
parents:
224
diff
changeset
|
49 |
6c350fc92ae3
Cache rednering result is now workable.
Thinker K.F. Li <thinker@branda.to>
parents:
224
diff
changeset
|
50 nx = ADD(ADD(MUL(matrix[0], *x), |
6c350fc92ae3
Cache rednering result is now workable.
Thinker K.F. Li <thinker@branda.to>
parents:
224
diff
changeset
|
51 MUL(matrix[1], *y)), |
6c350fc92ae3
Cache rednering result is now workable.
Thinker K.F. Li <thinker@branda.to>
parents:
224
diff
changeset
|
52 matrix[2]); |
6c350fc92ae3
Cache rednering result is now workable.
Thinker K.F. Li <thinker@branda.to>
parents:
224
diff
changeset
|
53 ny = ADD(ADD(MUL(matrix[3], *x), |
6c350fc92ae3
Cache rednering result is now workable.
Thinker K.F. Li <thinker@branda.to>
parents:
224
diff
changeset
|
54 MUL(matrix[4], *y)), |
6c350fc92ae3
Cache rednering result is now workable.
Thinker K.F. Li <thinker@branda.to>
parents:
224
diff
changeset
|
55 matrix[5]); |
6c350fc92ae3
Cache rednering result is now workable.
Thinker K.F. Li <thinker@branda.to>
parents:
224
diff
changeset
|
56 *x = nx; |
6c350fc92ae3
Cache rednering result is now workable.
Thinker K.F. Li <thinker@branda.to>
parents:
224
diff
changeset
|
57 *y = ny; |
6c350fc92ae3
Cache rednering result is now workable.
Thinker K.F. Li <thinker@branda.to>
parents:
224
diff
changeset
|
58 } |
6c350fc92ae3
Cache rednering result is now workable.
Thinker K.F. Li <thinker@branda.to>
parents:
224
diff
changeset
|
59 |
6c350fc92ae3
Cache rednering result is now workable.
Thinker K.F. Li <thinker@branda.to>
parents:
224
diff
changeset
|
60 /*! \brief Compute aggregated transform matrix. |
2 | 61 * |
62 * Base on parent's aggregated matrix if it is existed, or use transform | |
63 * matrix as aggregated matrix. | |
64 */ | |
1 | 65 static void compute_transform_function(coord_t *visit) { |
66 if(visit->parent) | |
67 mul_matrix(visit->parent->aggr_matrix, | |
68 visit->matrix, visit->aggr_matrix); | |
69 else | |
70 memcpy(visit->aggr_matrix, visit->matrix, sizeof(visit->matrix)); | |
71 } | |
72 | |
16
e17e12b112c4
A simple animation using rdman_redraw_changed().
Thinker K.F. Li <thinker@branda.to>
parents:
15
diff
changeset
|
73 void compute_aggr_of_coord(coord_t *coord) { |
e17e12b112c4
A simple animation using rdman_redraw_changed().
Thinker K.F. Li <thinker@branda.to>
parents:
15
diff
changeset
|
74 compute_transform_function(coord); |
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 |
314
6c350fc92ae3
Cache rednering result is now workable.
Thinker K.F. Li <thinker@branda.to>
parents:
224
diff
changeset
|
77 /*! \brief Compute aggregated transform matrix for cached coord. |
6c350fc92ae3
Cache rednering result is now workable.
Thinker K.F. Li <thinker@branda.to>
parents:
224
diff
changeset
|
78 * |
6c350fc92ae3
Cache rednering result is now workable.
Thinker K.F. Li <thinker@branda.to>
parents:
224
diff
changeset
|
79 * \sa \ref img_cache |
6c350fc92ae3
Cache rednering result is now workable.
Thinker K.F. Li <thinker@branda.to>
parents:
224
diff
changeset
|
80 */ |
6c350fc92ae3
Cache rednering result is now workable.
Thinker K.F. Li <thinker@branda.to>
parents:
224
diff
changeset
|
81 static void compute_transform_function_cached(coord_t *visit) { |
6c350fc92ae3
Cache rednering result is now workable.
Thinker K.F. Li <thinker@branda.to>
parents:
224
diff
changeset
|
82 co_aix *p_matrix; |
6c350fc92ae3
Cache rednering result is now workable.
Thinker K.F. Li <thinker@branda.to>
parents:
224
diff
changeset
|
83 co_aix cache_p_matrix[6]; |
6c350fc92ae3
Cache rednering result is now workable.
Thinker K.F. Li <thinker@branda.to>
parents:
224
diff
changeset
|
84 co_aix cache_scale_x, cache_scale_y; |
6c350fc92ae3
Cache rednering result is now workable.
Thinker K.F. Li <thinker@branda.to>
parents:
224
diff
changeset
|
85 |
6c350fc92ae3
Cache rednering result is now workable.
Thinker K.F. Li <thinker@branda.to>
parents:
224
diff
changeset
|
86 if(visit->parent) { |
6c350fc92ae3
Cache rednering result is now workable.
Thinker K.F. Li <thinker@branda.to>
parents:
224
diff
changeset
|
87 p_matrix = coord_get_aggr_matrix(visit->parent); |
6c350fc92ae3
Cache rednering result is now workable.
Thinker K.F. Li <thinker@branda.to>
parents:
224
diff
changeset
|
88 cache_scale_x = |
6c350fc92ae3
Cache rednering result is now workable.
Thinker K.F. Li <thinker@branda.to>
parents:
224
diff
changeset
|
89 sqrtf(p_matrix[0] * p_matrix[0] + p_matrix[3] * p_matrix[3]); |
6c350fc92ae3
Cache rednering result is now workable.
Thinker K.F. Li <thinker@branda.to>
parents:
224
diff
changeset
|
90 cache_scale_y = |
6c350fc92ae3
Cache rednering result is now workable.
Thinker K.F. Li <thinker@branda.to>
parents:
224
diff
changeset
|
91 sqrtf(p_matrix[1] * p_matrix[1] + p_matrix[4] * p_matrix[4]); |
6c350fc92ae3
Cache rednering result is now workable.
Thinker K.F. Li <thinker@branda.to>
parents:
224
diff
changeset
|
92 cache_p_matrix[0] = cache_scale_x; |
6c350fc92ae3
Cache rednering result is now workable.
Thinker K.F. Li <thinker@branda.to>
parents:
224
diff
changeset
|
93 cache_p_matrix[1] = 0; |
6c350fc92ae3
Cache rednering result is now workable.
Thinker K.F. Li <thinker@branda.to>
parents:
224
diff
changeset
|
94 cache_p_matrix[2] = 0; |
6c350fc92ae3
Cache rednering result is now workable.
Thinker K.F. Li <thinker@branda.to>
parents:
224
diff
changeset
|
95 cache_p_matrix[3] = 0; |
6c350fc92ae3
Cache rednering result is now workable.
Thinker K.F. Li <thinker@branda.to>
parents:
224
diff
changeset
|
96 cache_p_matrix[4] = cache_scale_y; |
6c350fc92ae3
Cache rednering result is now workable.
Thinker K.F. Li <thinker@branda.to>
parents:
224
diff
changeset
|
97 cache_p_matrix[5] = 0; |
6c350fc92ae3
Cache rednering result is now workable.
Thinker K.F. Li <thinker@branda.to>
parents:
224
diff
changeset
|
98 mul_matrix(cache_p_matrix, visit->matrix, visit->aggr_matrix); |
6c350fc92ae3
Cache rednering result is now workable.
Thinker K.F. Li <thinker@branda.to>
parents:
224
diff
changeset
|
99 } else { |
6c350fc92ae3
Cache rednering result is now workable.
Thinker K.F. Li <thinker@branda.to>
parents:
224
diff
changeset
|
100 memcpy(visit->aggr_matrix, visit->matrix, sizeof(visit->matrix)); |
6c350fc92ae3
Cache rednering result is now workable.
Thinker K.F. Li <thinker@branda.to>
parents:
224
diff
changeset
|
101 } |
6c350fc92ae3
Cache rednering result is now workable.
Thinker K.F. Li <thinker@branda.to>
parents:
224
diff
changeset
|
102 } |
6c350fc92ae3
Cache rednering result is now workable.
Thinker K.F. Li <thinker@branda.to>
parents:
224
diff
changeset
|
103 |
6c350fc92ae3
Cache rednering result is now workable.
Thinker K.F. Li <thinker@branda.to>
parents:
224
diff
changeset
|
104 void compute_aggr_of_cached_coord(coord_t *coord) { |
6c350fc92ae3
Cache rednering result is now workable.
Thinker K.F. Li <thinker@branda.to>
parents:
224
diff
changeset
|
105 compute_transform_function_cached(coord); |
6c350fc92ae3
Cache rednering result is now workable.
Thinker K.F. Li <thinker@branda.to>
parents:
224
diff
changeset
|
106 } |
6c350fc92ae3
Cache rednering result is now workable.
Thinker K.F. Li <thinker@branda.to>
parents:
224
diff
changeset
|
107 |
6c350fc92ae3
Cache rednering result is now workable.
Thinker K.F. Li <thinker@branda.to>
parents:
224
diff
changeset
|
108 void compute_reverse(co_aix *orig, co_aix *reverse) { |
6c350fc92ae3
Cache rednering result is now workable.
Thinker K.F. Li <thinker@branda.to>
parents:
224
diff
changeset
|
109 co_aix working[6]; |
6c350fc92ae3
Cache rednering result is now workable.
Thinker K.F. Li <thinker@branda.to>
parents:
224
diff
changeset
|
110 co_aix factor; |
6c350fc92ae3
Cache rednering result is now workable.
Thinker K.F. Li <thinker@branda.to>
parents:
224
diff
changeset
|
111 |
6c350fc92ae3
Cache rednering result is now workable.
Thinker K.F. Li <thinker@branda.to>
parents:
224
diff
changeset
|
112 #define VEC_MAC(src, factor, dst) \ |
6c350fc92ae3
Cache rednering result is now workable.
Thinker K.F. Li <thinker@branda.to>
parents:
224
diff
changeset
|
113 do { \ |
6c350fc92ae3
Cache rednering result is now workable.
Thinker K.F. Li <thinker@branda.to>
parents:
224
diff
changeset
|
114 (dst)[0] += (src)[0] * (factor); \ |
6c350fc92ae3
Cache rednering result is now workable.
Thinker K.F. Li <thinker@branda.to>
parents:
224
diff
changeset
|
115 (dst)[1] += (src)[1] * (factor); \ |
6c350fc92ae3
Cache rednering result is now workable.
Thinker K.F. Li <thinker@branda.to>
parents:
224
diff
changeset
|
116 (dst)[2] += (src)[2] * (factor); \ |
6c350fc92ae3
Cache rednering result is now workable.
Thinker K.F. Li <thinker@branda.to>
parents:
224
diff
changeset
|
117 } while(0) |
6c350fc92ae3
Cache rednering result is now workable.
Thinker K.F. Li <thinker@branda.to>
parents:
224
diff
changeset
|
118 |
6c350fc92ae3
Cache rednering result is now workable.
Thinker K.F. Li <thinker@branda.to>
parents:
224
diff
changeset
|
119 reverse[0] = 1; |
6c350fc92ae3
Cache rednering result is now workable.
Thinker K.F. Li <thinker@branda.to>
parents:
224
diff
changeset
|
120 reverse[1] = 0; |
6c350fc92ae3
Cache rednering result is now workable.
Thinker K.F. Li <thinker@branda.to>
parents:
224
diff
changeset
|
121 reverse[2] = 0; |
6c350fc92ae3
Cache rednering result is now workable.
Thinker K.F. Li <thinker@branda.to>
parents:
224
diff
changeset
|
122 reverse[3] = 0; |
6c350fc92ae3
Cache rednering result is now workable.
Thinker K.F. Li <thinker@branda.to>
parents:
224
diff
changeset
|
123 reverse[4] = 1; |
6c350fc92ae3
Cache rednering result is now workable.
Thinker K.F. Li <thinker@branda.to>
parents:
224
diff
changeset
|
124 reverse[5] = 0; |
6c350fc92ae3
Cache rednering result is now workable.
Thinker K.F. Li <thinker@branda.to>
parents:
224
diff
changeset
|
125 |
6c350fc92ae3
Cache rednering result is now workable.
Thinker K.F. Li <thinker@branda.to>
parents:
224
diff
changeset
|
126 memcpy(working, orig, sizeof(co_aix) * 6); |
6c350fc92ae3
Cache rednering result is now workable.
Thinker K.F. Li <thinker@branda.to>
parents:
224
diff
changeset
|
127 |
6c350fc92ae3
Cache rednering result is now workable.
Thinker K.F. Li <thinker@branda.to>
parents:
224
diff
changeset
|
128 factor = -working[3] / working[0]; |
6c350fc92ae3
Cache rednering result is now workable.
Thinker K.F. Li <thinker@branda.to>
parents:
224
diff
changeset
|
129 VEC_MAC(working, factor, working + 3); |
6c350fc92ae3
Cache rednering result is now workable.
Thinker K.F. Li <thinker@branda.to>
parents:
224
diff
changeset
|
130 VEC_MAC(reverse, factor, reverse + 3); |
6c350fc92ae3
Cache rednering result is now workable.
Thinker K.F. Li <thinker@branda.to>
parents:
224
diff
changeset
|
131 |
6c350fc92ae3
Cache rednering result is now workable.
Thinker K.F. Li <thinker@branda.to>
parents:
224
diff
changeset
|
132 factor = -working[1] / working[4]; |
6c350fc92ae3
Cache rednering result is now workable.
Thinker K.F. Li <thinker@branda.to>
parents:
224
diff
changeset
|
133 VEC_MAC(working + 3, factor, working); |
6c350fc92ae3
Cache rednering result is now workable.
Thinker K.F. Li <thinker@branda.to>
parents:
224
diff
changeset
|
134 VEC_MAC(reverse + 3, factor, reverse); |
6c350fc92ae3
Cache rednering result is now workable.
Thinker K.F. Li <thinker@branda.to>
parents:
224
diff
changeset
|
135 |
6c350fc92ae3
Cache rednering result is now workable.
Thinker K.F. Li <thinker@branda.to>
parents:
224
diff
changeset
|
136 reverse[2] = -working[2]; |
6c350fc92ae3
Cache rednering result is now workable.
Thinker K.F. Li <thinker@branda.to>
parents:
224
diff
changeset
|
137 reverse[5] = -working[5]; |
6c350fc92ae3
Cache rednering result is now workable.
Thinker K.F. Li <thinker@branda.to>
parents:
224
diff
changeset
|
138 |
6c350fc92ae3
Cache rednering result is now workable.
Thinker K.F. Li <thinker@branda.to>
parents:
224
diff
changeset
|
139 reverse[0] /= working[0]; |
6c350fc92ae3
Cache rednering result is now workable.
Thinker K.F. Li <thinker@branda.to>
parents:
224
diff
changeset
|
140 reverse[1] /= working[0]; |
6c350fc92ae3
Cache rednering result is now workable.
Thinker K.F. Li <thinker@branda.to>
parents:
224
diff
changeset
|
141 reverse[2] /= working[0]; |
6c350fc92ae3
Cache rednering result is now workable.
Thinker K.F. Li <thinker@branda.to>
parents:
224
diff
changeset
|
142 reverse[3] /= working[4]; |
6c350fc92ae3
Cache rednering result is now workable.
Thinker K.F. Li <thinker@branda.to>
parents:
224
diff
changeset
|
143 reverse[4] /= working[4]; |
6c350fc92ae3
Cache rednering result is now workable.
Thinker K.F. Li <thinker@branda.to>
parents:
224
diff
changeset
|
144 reverse[5] /= working[4]; |
6c350fc92ae3
Cache rednering result is now workable.
Thinker K.F. Li <thinker@branda.to>
parents:
224
diff
changeset
|
145 } |
6c350fc92ae3
Cache rednering result is now workable.
Thinker K.F. Li <thinker@branda.to>
parents:
224
diff
changeset
|
146 |
1 | 147 /*! \brief Update aggregate matrices of elements under a sub-tree. |
148 * | |
149 * A subtree is specified by the root of it. All elements in the subtree | |
150 * are effected by that changes of matrix of the subtree root. | |
314
6c350fc92ae3
Cache rednering result is now workable.
Thinker K.F. Li <thinker@branda.to>
parents:
224
diff
changeset
|
151 * |
6c350fc92ae3
Cache rednering result is now workable.
Thinker K.F. Li <thinker@branda.to>
parents:
224
diff
changeset
|
152 * \todo Remove update_aggr_matrix() since it is out of date and |
6c350fc92ae3
Cache rednering result is now workable.
Thinker K.F. Li <thinker@branda.to>
parents:
224
diff
changeset
|
153 * no one use it. |
1 | 154 */ |
155 void update_aggr_matrix(coord_t *start) { | |
156 coord_t *visit, *child, *next; | |
157 | |
158 compute_transform_function(start); | |
159 | |
160 visit = start; | |
161 while(visit) { | |
12 | 162 child = STAILQ_HEAD(visit->children); |
1 | 163 while(child) { |
164 compute_transform_function(child); | |
12 | 165 child = STAILQ_NEXT(coord_t, sibling, child); |
1 | 166 } |
167 | |
12 | 168 if(STAILQ_HEAD(visit->children)) |
169 visit = STAILQ_HEAD(visit->children); | |
170 else if(STAILQ_NEXT(coord_t, sibling, visit)) | |
171 visit = STAILQ_NEXT(coord_t, sibling, visit); | |
1 | 172 else { |
173 next = NULL; | |
174 while(visit->parent && visit->parent != start) { | |
175 visit = visit->parent; | |
12 | 176 if(STAILQ_NEXT(coord_t, sibling, visit)) { |
177 next = STAILQ_NEXT(coord_t, sibling, visit); | |
1 | 178 break; |
179 } | |
180 } | |
181 visit = next; | |
182 } | |
183 } | |
184 } | |
185 | |
12 | 186 /*! \brief Initialize a coord object. |
187 * | |
188 * The object is cleared and matrix was initialized to ID. | |
189 * The object is be a children of specified parent. | |
190 */ | |
1 | 191 void coord_init(coord_t *co, coord_t *parent) { |
192 memset(co, 0, sizeof(coord_t)); | |
193 if(parent) { | |
12 | 194 /* insert at tail of children list. */ |
1 | 195 co->parent = parent; |
12 | 196 STAILQ_INS_TAIL(parent->children, coord_t, sibling, co); |
1 | 197 } |
224
29e1b2bffe4c
X backend only sent EVT_MOUSE_MOVE_RAW to MadButterfly.
Thinker K.F. Li <thinker@branda.to>
parents:
196
diff
changeset
|
198 mb_obj_init(co, MBO_COORD); |
1 | 199 co->matrix[0] = 1; |
200 co->matrix[4] = 1; | |
17
41f0907b27ac
Unittest for rdman_redraw_changed().
Thinker K.F. Li <thinker@branda.to>
parents:
16
diff
changeset
|
201 co->aggr_matrix[0] = 1; |
41f0907b27ac
Unittest for rdman_redraw_changed().
Thinker K.F. Li <thinker@branda.to>
parents:
16
diff
changeset
|
202 co->aggr_matrix[4] = 1; |
15
c2ce186a5c37
X_main uses rdman_redraw_all()
Thinker K.F. Li <thinker@branda.to>
parents:
13
diff
changeset
|
203 co->cur_area = &co->areas[0]; |
c2ce186a5c37
X_main uses rdman_redraw_all()
Thinker K.F. Li <thinker@branda.to>
parents:
13
diff
changeset
|
204 co->last_area = &co->areas[1]; |
1 | 205 } |
206 | |
2 | 207 void coord_trans_pos(coord_t *co, co_aix *x, co_aix *y) { |
208 co_aix nx, ny; | |
209 | |
210 nx = ADD(ADD(MUL(co->aggr_matrix[0], *x), | |
211 MUL(co->aggr_matrix[1], *y)), | |
212 co->aggr_matrix[2]); | |
213 ny = ADD(ADD(MUL(co->aggr_matrix[3], *x), | |
214 MUL(co->aggr_matrix[4], *y)), | |
215 co->aggr_matrix[5]); | |
216 *x = nx; | |
217 *y = ny; | |
218 } | |
219 | |
31
da770188a44d
resize font size for changige of coord.
Thinker K.F. Li <thinker@branda.to>
parents:
17
diff
changeset
|
220 co_aix coord_trans_size(coord_t *co, co_aix sz) { |
da770188a44d
resize font size for changige of coord.
Thinker K.F. Li <thinker@branda.to>
parents:
17
diff
changeset
|
221 co_aix x, y; |
da770188a44d
resize font size for changige of coord.
Thinker K.F. Li <thinker@branda.to>
parents:
17
diff
changeset
|
222 |
da770188a44d
resize font size for changige of coord.
Thinker K.F. Li <thinker@branda.to>
parents:
17
diff
changeset
|
223 x = MUL(co->aggr_matrix[0], sz); |
da770188a44d
resize font size for changige of coord.
Thinker K.F. Li <thinker@branda.to>
parents:
17
diff
changeset
|
224 y = MUL(co->aggr_matrix[3], sz); |
da770188a44d
resize font size for changige of coord.
Thinker K.F. Li <thinker@branda.to>
parents:
17
diff
changeset
|
225 |
da770188a44d
resize font size for changige of coord.
Thinker K.F. Li <thinker@branda.to>
parents:
17
diff
changeset
|
226 return sqrt(x * x + y * y); |
da770188a44d
resize font size for changige of coord.
Thinker K.F. Li <thinker@branda.to>
parents:
17
diff
changeset
|
227 } |
da770188a44d
resize font size for changige of coord.
Thinker K.F. Li <thinker@branda.to>
parents:
17
diff
changeset
|
228 |
151
d11aa8fc06c7
Fix bug of tanks do not show at right places.
Thinker K.F. Li <thinker@branda.to>
parents:
140
diff
changeset
|
229 /*! |
d11aa8fc06c7
Fix bug of tanks do not show at right places.
Thinker K.F. Li <thinker@branda.to>
parents:
140
diff
changeset
|
230 * \note Coords, marked with COF_SKIP_TRIVAL (for temporary), and |
d11aa8fc06c7
Fix bug of tanks do not show at right places.
Thinker K.F. Li <thinker@branda.to>
parents:
140
diff
changeset
|
231 * descendants of them will not be trivaled and the flag with be removed |
d11aa8fc06c7
Fix bug of tanks do not show at right places.
Thinker K.F. Li <thinker@branda.to>
parents:
140
diff
changeset
|
232 * after skipping them. |
d11aa8fc06c7
Fix bug of tanks do not show at right places.
Thinker K.F. Li <thinker@branda.to>
parents:
140
diff
changeset
|
233 */ |
13 | 234 coord_t *preorder_coord_subtree(coord_t *root, coord_t *last) { |
151
d11aa8fc06c7
Fix bug of tanks do not show at right places.
Thinker K.F. Li <thinker@branda.to>
parents:
140
diff
changeset
|
235 coord_t *next = NULL; |
12 | 236 |
138
9f4fc9ecfd1f
Make shapes and coords drawed in post-order of tree.
Thinker K.F. Li <thinker@branda.to>
parents:
31
diff
changeset
|
237 ASSERT(last != NULL); |
12 | 238 |
151
d11aa8fc06c7
Fix bug of tanks do not show at right places.
Thinker K.F. Li <thinker@branda.to>
parents:
140
diff
changeset
|
239 if((!(last->flags & COF_SKIP_TRIVAL)) && |
d11aa8fc06c7
Fix bug of tanks do not show at right places.
Thinker K.F. Li <thinker@branda.to>
parents:
140
diff
changeset
|
240 STAILQ_HEAD(last->children)) { |
12 | 241 next = STAILQ_HEAD(last->children); |
151
d11aa8fc06c7
Fix bug of tanks do not show at right places.
Thinker K.F. Li <thinker@branda.to>
parents:
140
diff
changeset
|
242 if(!(next->flags & COF_SKIP_TRIVAL)) |
d11aa8fc06c7
Fix bug of tanks do not show at right places.
Thinker K.F. Li <thinker@branda.to>
parents:
140
diff
changeset
|
243 return next; |
d11aa8fc06c7
Fix bug of tanks do not show at right places.
Thinker K.F. Li <thinker@branda.to>
parents:
140
diff
changeset
|
244 } else { |
12 | 245 next = last; |
151
d11aa8fc06c7
Fix bug of tanks do not show at right places.
Thinker K.F. Li <thinker@branda.to>
parents:
140
diff
changeset
|
246 } |
d11aa8fc06c7
Fix bug of tanks do not show at right places.
Thinker K.F. Li <thinker@branda.to>
parents:
140
diff
changeset
|
247 |
d11aa8fc06c7
Fix bug of tanks do not show at right places.
Thinker K.F. Li <thinker@branda.to>
parents:
140
diff
changeset
|
248 do { |
d11aa8fc06c7
Fix bug of tanks do not show at right places.
Thinker K.F. Li <thinker@branda.to>
parents:
140
diff
changeset
|
249 next->flags &= ~COF_SKIP_TRIVAL; |
13 | 250 while(next != root && STAILQ_NEXT(coord_t, sibling, next) == NULL) |
12 | 251 next = next->parent; |
13 | 252 if(next == root) |
151
d11aa8fc06c7
Fix bug of tanks do not show at right places.
Thinker K.F. Li <thinker@branda.to>
parents:
140
diff
changeset
|
253 return NULL; |
d11aa8fc06c7
Fix bug of tanks do not show at right places.
Thinker K.F. Li <thinker@branda.to>
parents:
140
diff
changeset
|
254 next = STAILQ_NEXT(coord_t, sibling, next); |
d11aa8fc06c7
Fix bug of tanks do not show at right places.
Thinker K.F. Li <thinker@branda.to>
parents:
140
diff
changeset
|
255 } while(next->flags & COF_SKIP_TRIVAL); |
12 | 256 |
257 return next; | |
258 } | |
259 | |
138
9f4fc9ecfd1f
Make shapes and coords drawed in post-order of tree.
Thinker K.F. Li <thinker@branda.to>
parents:
31
diff
changeset
|
260 coord_t *postorder_coord_subtree(coord_t *root, coord_t *last) { |
9f4fc9ecfd1f
Make shapes and coords drawed in post-order of tree.
Thinker K.F. Li <thinker@branda.to>
parents:
31
diff
changeset
|
261 coord_t *next; |
9f4fc9ecfd1f
Make shapes and coords drawed in post-order of tree.
Thinker K.F. Li <thinker@branda.to>
parents:
31
diff
changeset
|
262 |
9f4fc9ecfd1f
Make shapes and coords drawed in post-order of tree.
Thinker K.F. Li <thinker@branda.to>
parents:
31
diff
changeset
|
263 if(root == last) |
9f4fc9ecfd1f
Make shapes and coords drawed in post-order of tree.
Thinker K.F. Li <thinker@branda.to>
parents:
31
diff
changeset
|
264 return NULL; |
9f4fc9ecfd1f
Make shapes and coords drawed in post-order of tree.
Thinker K.F. Li <thinker@branda.to>
parents:
31
diff
changeset
|
265 |
9f4fc9ecfd1f
Make shapes and coords drawed in post-order of tree.
Thinker K.F. Li <thinker@branda.to>
parents:
31
diff
changeset
|
266 if(last == NULL) { |
9f4fc9ecfd1f
Make shapes and coords drawed in post-order of tree.
Thinker K.F. Li <thinker@branda.to>
parents:
31
diff
changeset
|
267 /* Go most left leaf. */ |
9f4fc9ecfd1f
Make shapes and coords drawed in post-order of tree.
Thinker K.F. Li <thinker@branda.to>
parents:
31
diff
changeset
|
268 next = root; |
9f4fc9ecfd1f
Make shapes and coords drawed in post-order of tree.
Thinker K.F. Li <thinker@branda.to>
parents:
31
diff
changeset
|
269 while(STAILQ_HEAD(next->children)) |
9f4fc9ecfd1f
Make shapes and coords drawed in post-order of tree.
Thinker K.F. Li <thinker@branda.to>
parents:
31
diff
changeset
|
270 next = STAILQ_HEAD(next->children); |
9f4fc9ecfd1f
Make shapes and coords drawed in post-order of tree.
Thinker K.F. Li <thinker@branda.to>
parents:
31
diff
changeset
|
271 return next; |
9f4fc9ecfd1f
Make shapes and coords drawed in post-order of tree.
Thinker K.F. Li <thinker@branda.to>
parents:
31
diff
changeset
|
272 } |
9f4fc9ecfd1f
Make shapes and coords drawed in post-order of tree.
Thinker K.F. Li <thinker@branda.to>
parents:
31
diff
changeset
|
273 |
9f4fc9ecfd1f
Make shapes and coords drawed in post-order of tree.
Thinker K.F. Li <thinker@branda.to>
parents:
31
diff
changeset
|
274 next = last; |
9f4fc9ecfd1f
Make shapes and coords drawed in post-order of tree.
Thinker K.F. Li <thinker@branda.to>
parents:
31
diff
changeset
|
275 if(STAILQ_NEXT(coord_t, sibling, next) == NULL) /* most right */ |
9f4fc9ecfd1f
Make shapes and coords drawed in post-order of tree.
Thinker K.F. Li <thinker@branda.to>
parents:
31
diff
changeset
|
276 return next->parent; |
9f4fc9ecfd1f
Make shapes and coords drawed in post-order of tree.
Thinker K.F. Li <thinker@branda.to>
parents:
31
diff
changeset
|
277 |
9f4fc9ecfd1f
Make shapes and coords drawed in post-order of tree.
Thinker K.F. Li <thinker@branda.to>
parents:
31
diff
changeset
|
278 /* Go most left leaf of right sibling sub-tree. */ |
9f4fc9ecfd1f
Make shapes and coords drawed in post-order of tree.
Thinker K.F. Li <thinker@branda.to>
parents:
31
diff
changeset
|
279 next = STAILQ_NEXT(coord_t, sibling, next); |
9f4fc9ecfd1f
Make shapes and coords drawed in post-order of tree.
Thinker K.F. Li <thinker@branda.to>
parents:
31
diff
changeset
|
280 while(STAILQ_HEAD(next->children)) |
9f4fc9ecfd1f
Make shapes and coords drawed in post-order of tree.
Thinker K.F. Li <thinker@branda.to>
parents:
31
diff
changeset
|
281 next = STAILQ_HEAD(next->children); |
9f4fc9ecfd1f
Make shapes and coords drawed in post-order of tree.
Thinker K.F. Li <thinker@branda.to>
parents:
31
diff
changeset
|
282 |
9f4fc9ecfd1f
Make shapes and coords drawed in post-order of tree.
Thinker K.F. Li <thinker@branda.to>
parents:
31
diff
changeset
|
283 return next; |
9f4fc9ecfd1f
Make shapes and coords drawed in post-order of tree.
Thinker K.F. Li <thinker@branda.to>
parents:
31
diff
changeset
|
284 } |
9f4fc9ecfd1f
Make shapes and coords drawed in post-order of tree.
Thinker K.F. Li <thinker@branda.to>
parents:
31
diff
changeset
|
285 |
1 | 286 #ifdef UNITTEST |
287 | |
288 #include <CUnit/Basic.h> | |
289 | |
290 void test_update_aggr_matrix(void) { | |
291 coord_t elms[6]; | |
2 | 292 co_aix x, y; |
1 | 293 |
294 coord_init(elms, NULL); | |
295 coord_init(elms + 1, elms); | |
296 coord_init(elms + 2, elms); | |
297 coord_init(elms + 3, elms + 1); | |
298 coord_init(elms + 4, elms + 1); | |
299 coord_init(elms + 5, elms + 2); | |
300 | |
301 /* | 2 -1 0 | | |
302 * | 0 1 0 | | |
303 * | 0 0 1 | | |
304 */ | |
305 elms[0].matrix[0] = 2; | |
306 elms[0].matrix[1] = -1; | |
307 | |
308 /* | 1 3 0 | | |
309 * | 5 1 0 | | |
310 * | 0 0 1 | | |
311 */ | |
312 elms[1].matrix[1] = 3; | |
313 elms[1].matrix[3] = 5; | |
314 | |
315 update_aggr_matrix(elms); | |
316 | |
317 /* | -3 5 0 | | |
318 * | 5 1 0 | | |
319 * | 0 0 1 | | |
320 */ | |
321 CU_ASSERT(elms[3].aggr_matrix[0] == -3); | |
322 CU_ASSERT(elms[3].aggr_matrix[1] == 5); | |
323 CU_ASSERT(elms[3].aggr_matrix[2] == 0); | |
324 CU_ASSERT(elms[3].aggr_matrix[3] == 5); | |
325 CU_ASSERT(elms[3].aggr_matrix[4] == 1); | |
326 CU_ASSERT(elms[3].aggr_matrix[5] == 0); | |
327 | |
328 CU_ASSERT(elms[4].aggr_matrix[0] == -3); | |
329 CU_ASSERT(elms[4].aggr_matrix[1] == 5); | |
330 CU_ASSERT(elms[4].aggr_matrix[2] == 0); | |
331 CU_ASSERT(elms[4].aggr_matrix[3] == 5); | |
332 CU_ASSERT(elms[4].aggr_matrix[4] == 1); | |
333 CU_ASSERT(elms[4].aggr_matrix[5] == 0); | |
334 | |
335 CU_ASSERT(elms[5].aggr_matrix[0] == 2); | |
336 CU_ASSERT(elms[5].aggr_matrix[1] == -1); | |
337 CU_ASSERT(elms[5].aggr_matrix[2] == 0); | |
338 CU_ASSERT(elms[5].aggr_matrix[3] == 0); | |
339 CU_ASSERT(elms[5].aggr_matrix[4] == 1); | |
340 CU_ASSERT(elms[5].aggr_matrix[5] == 0); | |
2 | 341 |
342 x = 50; | |
343 y = 99; | |
344 coord_trans_pos(elms + 5, &x, &y); | |
345 CU_ASSERT(x == 1); | |
346 CU_ASSERT(y == 99); | |
1 | 347 } |
348 | |
13 | 349 void test_preorder_coord_subtree(void) { |
12 | 350 coord_t elms[6]; |
351 coord_t *last; | |
352 | |
353 coord_init(elms, NULL); | |
354 coord_init(elms + 1, elms); | |
355 coord_init(elms + 2, elms); | |
356 coord_init(elms + 3, elms + 1); | |
357 coord_init(elms + 4, elms + 1); | |
358 coord_init(elms + 5, elms + 2); | |
359 | |
360 last = elms; | |
13 | 361 last = preorder_coord_subtree(elms, last); |
12 | 362 CU_ASSERT(last == elms + 1); |
13 | 363 last = preorder_coord_subtree(elms, last); |
12 | 364 CU_ASSERT(last == elms + 3); |
13 | 365 last = preorder_coord_subtree(elms, last); |
12 | 366 CU_ASSERT(last == elms + 4); |
13 | 367 last = preorder_coord_subtree(elms, last); |
12 | 368 CU_ASSERT(last == elms + 2); |
13 | 369 last = preorder_coord_subtree(elms, last); |
12 | 370 CU_ASSERT(last == elms + 5); |
13 | 371 last = preorder_coord_subtree(elms, last); |
12 | 372 CU_ASSERT(last == NULL); |
373 } | |
374 | |
1 | 375 CU_pSuite get_coord_suite(void) { |
376 CU_pSuite suite; | |
377 | |
378 suite = CU_add_suite("Suite_coord", NULL, NULL); | |
379 CU_ADD_TEST(suite, test_update_aggr_matrix); | |
13 | 380 CU_ADD_TEST(suite, test_preorder_coord_subtree); |
1 | 381 |
382 return suite; | |
383 } | |
384 | |
385 #endif |