annotate src/coord.c @ 224:29e1b2bffe4c

X backend only sent EVT_MOUSE_MOVE_RAW to MadButterfly. - backend does not interpret mouse events (over/out/move), now. - redraw manager, now, interpret mouse events to make it backend independent. - The task (interpret mouse events) should be moved to somewhere in futhure. - backend only sent MotionNotify as EVT_MOUSE_MOVE_RAW. - EVT_MOUSE_MOVE_RAW is interpreted by backend independent code.
author Thinker K.F. Li <thinker@branda.to>
date Mon, 15 Dec 2008 10:13:03 +0800
parents c234ee745ceb
children 6c350fc92ae3
rev   line source
2
31402929c587 Transform position
Thinker K.F. Li <thinker@branda.to>
parents: 1
diff changeset
1 /*! \brief Implement coordination tranform mechanism.
31402929c587 Transform position
Thinker K.F. Li <thinker@branda.to>
parents: 1
diff changeset
2 * \file
31402929c587 Transform position
Thinker K.F. Li <thinker@branda.to>
parents: 1
diff changeset
3 * This file implements coordination transforming for containers.
31402929c587 Transform position
Thinker K.F. Li <thinker@branda.to>
parents: 1
diff changeset
4 */
1
b5c0162ccf69 Coordination tranforming
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
5 #include <stdio.h>
b5c0162ccf69 Coordination tranforming
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
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
b5c0162ccf69 Coordination tranforming
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
9
12
79e9edf4c00a Add redraw manager
Thinker K.F. Li <thinker@branda.to>
parents: 5
diff changeset
10
79e9edf4c00a Add redraw manager
Thinker K.F. Li <thinker@branda.to>
parents: 5
diff changeset
11 #define ASSERT(x)
79e9edf4c00a Add redraw manager
Thinker K.F. Li <thinker@branda.to>
parents: 5
diff changeset
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
31402929c587 Transform position
Thinker K.F. Li <thinker@branda.to>
parents: 1
diff changeset
14 #define MUL(a, b) ((a) * (b))
31402929c587 Transform position
Thinker K.F. Li <thinker@branda.to>
parents: 1
diff changeset
15 #define ADD(a, b) ((a) + (b))
31402929c587 Transform position
Thinker K.F. Li <thinker@branda.to>
parents: 1
diff changeset
16 #define DIV(a, b) ((a) / (b))
31402929c587 Transform position
Thinker K.F. Li <thinker@branda.to>
parents: 1
diff changeset
17 #define SUB(a, b) ((a) - (b))
31402929c587 Transform position
Thinker K.F. Li <thinker@branda.to>
parents: 1
diff changeset
18
31402929c587 Transform position
Thinker K.F. Li <thinker@branda.to>
parents: 1
diff changeset
19 static void mul_matrix(co_aix *m1, co_aix *m2, co_aix *dst) {
31402929c587 Transform position
Thinker K.F. Li <thinker@branda.to>
parents: 1
diff changeset
20 dst[0] = ADD(MUL(m1[0], m2[0]), MUL(m1[1], m2[3]));
31402929c587 Transform position
Thinker K.F. Li <thinker@branda.to>
parents: 1
diff changeset
21 dst[1] = ADD(MUL(m1[0], m2[1]), MUL(m1[1], m2[4]));
31402929c587 Transform position
Thinker K.F. Li <thinker@branda.to>
parents: 1
diff changeset
22 dst[2] = ADD(ADD(MUL(m1[0], m2[2]), MUL(m1[1], m2[5])), m1[2]);
31402929c587 Transform position
Thinker K.F. Li <thinker@branda.to>
parents: 1
diff changeset
23 dst[3] = ADD(MUL(m1[3], m2[0]), MUL(m1[4], m2[3]));
31402929c587 Transform position
Thinker K.F. Li <thinker@branda.to>
parents: 1
diff changeset
24 dst[4] = ADD(MUL(m1[3], m2[1]), MUL(m1[4], m2[4]));
31402929c587 Transform position
Thinker K.F. Li <thinker@branda.to>
parents: 1
diff changeset
25 dst[5] = ADD(ADD(MUL(m1[3], m2[2]), MUL(m1[4], m2[5])), m1[5]);
1
b5c0162ccf69 Coordination tranforming
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
26 }
b5c0162ccf69 Coordination tranforming
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
27
2
31402929c587 Transform position
Thinker K.F. Li <thinker@branda.to>
parents: 1
diff changeset
28 /*! \brief Compute agrregated transform function.
31402929c587 Transform position
Thinker K.F. Li <thinker@branda.to>
parents: 1
diff changeset
29 *
31402929c587 Transform position
Thinker K.F. Li <thinker@branda.to>
parents: 1
diff changeset
30 * Base on parent's aggregated matrix if it is existed, or use transform
31402929c587 Transform position
Thinker K.F. Li <thinker@branda.to>
parents: 1
diff changeset
31 * matrix as aggregated matrix.
31402929c587 Transform position
Thinker K.F. Li <thinker@branda.to>
parents: 1
diff changeset
32 */
1
b5c0162ccf69 Coordination tranforming
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
33 static void compute_transform_function(coord_t *visit) {
b5c0162ccf69 Coordination tranforming
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
34 if(visit->parent)
b5c0162ccf69 Coordination tranforming
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
35 mul_matrix(visit->parent->aggr_matrix,
b5c0162ccf69 Coordination tranforming
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
36 visit->matrix, visit->aggr_matrix);
b5c0162ccf69 Coordination tranforming
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
37 else
b5c0162ccf69 Coordination tranforming
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
38 memcpy(visit->aggr_matrix, visit->matrix, sizeof(visit->matrix));
b5c0162ccf69 Coordination tranforming
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
39 }
b5c0162ccf69 Coordination tranforming
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
40
16
e17e12b112c4 A simple animation using rdman_redraw_changed().
Thinker K.F. Li <thinker@branda.to>
parents: 15
diff changeset
41 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
42 compute_transform_function(coord);
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
1
b5c0162ccf69 Coordination tranforming
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
45 /*! \brief Update aggregate matrices of elements under a sub-tree.
b5c0162ccf69 Coordination tranforming
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
46 *
b5c0162ccf69 Coordination tranforming
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
47 * A subtree is specified by the root of it. All elements in the subtree
b5c0162ccf69 Coordination tranforming
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
48 * are effected by that changes of matrix of the subtree root.
b5c0162ccf69 Coordination tranforming
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
49 */
b5c0162ccf69 Coordination tranforming
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
50 void update_aggr_matrix(coord_t *start) {
b5c0162ccf69 Coordination tranforming
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
51 coord_t *visit, *child, *next;
b5c0162ccf69 Coordination tranforming
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
52
b5c0162ccf69 Coordination tranforming
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
53 compute_transform_function(start);
b5c0162ccf69 Coordination tranforming
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
54
b5c0162ccf69 Coordination tranforming
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
55 visit = start;
b5c0162ccf69 Coordination tranforming
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
56 while(visit) {
12
79e9edf4c00a Add redraw manager
Thinker K.F. Li <thinker@branda.to>
parents: 5
diff changeset
57 child = STAILQ_HEAD(visit->children);
1
b5c0162ccf69 Coordination tranforming
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
58 while(child) {
b5c0162ccf69 Coordination tranforming
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
59 compute_transform_function(child);
12
79e9edf4c00a Add redraw manager
Thinker K.F. Li <thinker@branda.to>
parents: 5
diff changeset
60 child = STAILQ_NEXT(coord_t, sibling, child);
1
b5c0162ccf69 Coordination tranforming
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
61 }
b5c0162ccf69 Coordination tranforming
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
62
12
79e9edf4c00a Add redraw manager
Thinker K.F. Li <thinker@branda.to>
parents: 5
diff changeset
63 if(STAILQ_HEAD(visit->children))
79e9edf4c00a Add redraw manager
Thinker K.F. Li <thinker@branda.to>
parents: 5
diff changeset
64 visit = STAILQ_HEAD(visit->children);
79e9edf4c00a Add redraw manager
Thinker K.F. Li <thinker@branda.to>
parents: 5
diff changeset
65 else if(STAILQ_NEXT(coord_t, sibling, visit))
79e9edf4c00a Add redraw manager
Thinker K.F. Li <thinker@branda.to>
parents: 5
diff changeset
66 visit = STAILQ_NEXT(coord_t, sibling, visit);
1
b5c0162ccf69 Coordination tranforming
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
67 else {
b5c0162ccf69 Coordination tranforming
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
68 next = NULL;
b5c0162ccf69 Coordination tranforming
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
69 while(visit->parent && visit->parent != start) {
b5c0162ccf69 Coordination tranforming
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
70 visit = visit->parent;
12
79e9edf4c00a Add redraw manager
Thinker K.F. Li <thinker@branda.to>
parents: 5
diff changeset
71 if(STAILQ_NEXT(coord_t, sibling, visit)) {
79e9edf4c00a Add redraw manager
Thinker K.F. Li <thinker@branda.to>
parents: 5
diff changeset
72 next = STAILQ_NEXT(coord_t, sibling, visit);
1
b5c0162ccf69 Coordination tranforming
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
73 break;
b5c0162ccf69 Coordination tranforming
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
74 }
b5c0162ccf69 Coordination tranforming
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
75 }
b5c0162ccf69 Coordination tranforming
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
76 visit = next;
b5c0162ccf69 Coordination tranforming
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
77 }
b5c0162ccf69 Coordination tranforming
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
78 }
b5c0162ccf69 Coordination tranforming
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
79 }
b5c0162ccf69 Coordination tranforming
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
80
12
79e9edf4c00a Add redraw manager
Thinker K.F. Li <thinker@branda.to>
parents: 5
diff changeset
81 /*! \brief Initialize a coord object.
79e9edf4c00a Add redraw manager
Thinker K.F. Li <thinker@branda.to>
parents: 5
diff changeset
82 *
79e9edf4c00a Add redraw manager
Thinker K.F. Li <thinker@branda.to>
parents: 5
diff changeset
83 * The object is cleared and matrix was initialized to ID.
79e9edf4c00a Add redraw manager
Thinker K.F. Li <thinker@branda.to>
parents: 5
diff changeset
84 * The object is be a children of specified parent.
79e9edf4c00a Add redraw manager
Thinker K.F. Li <thinker@branda.to>
parents: 5
diff changeset
85 */
1
b5c0162ccf69 Coordination tranforming
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
86 void coord_init(coord_t *co, coord_t *parent) {
b5c0162ccf69 Coordination tranforming
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
87 memset(co, 0, sizeof(coord_t));
b5c0162ccf69 Coordination tranforming
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
88 if(parent) {
12
79e9edf4c00a Add redraw manager
Thinker K.F. Li <thinker@branda.to>
parents: 5
diff changeset
89 /* insert at tail of children list. */
1
b5c0162ccf69 Coordination tranforming
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
90 co->parent = parent;
12
79e9edf4c00a Add redraw manager
Thinker K.F. Li <thinker@branda.to>
parents: 5
diff changeset
91 STAILQ_INS_TAIL(parent->children, coord_t, sibling, co);
1
b5c0162ccf69 Coordination tranforming
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
92 }
224
29e1b2bffe4c X backend only sent EVT_MOUSE_MOVE_RAW to MadButterfly.
Thinker K.F. Li <thinker@branda.to>
parents: 196
diff changeset
93 mb_obj_init(co, MBO_COORD);
1
b5c0162ccf69 Coordination tranforming
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
94 co->matrix[0] = 1;
b5c0162ccf69 Coordination tranforming
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
95 co->matrix[4] = 1;
17
41f0907b27ac Unittest for rdman_redraw_changed().
Thinker K.F. Li <thinker@branda.to>
parents: 16
diff changeset
96 co->aggr_matrix[0] = 1;
41f0907b27ac Unittest for rdman_redraw_changed().
Thinker K.F. Li <thinker@branda.to>
parents: 16
diff changeset
97 co->aggr_matrix[4] = 1;
15
c2ce186a5c37 X_main uses rdman_redraw_all()
Thinker K.F. Li <thinker@branda.to>
parents: 13
diff changeset
98 co->cur_area = &co->areas[0];
c2ce186a5c37 X_main uses rdman_redraw_all()
Thinker K.F. Li <thinker@branda.to>
parents: 13
diff changeset
99 co->last_area = &co->areas[1];
1
b5c0162ccf69 Coordination tranforming
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
100 }
b5c0162ccf69 Coordination tranforming
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
101
2
31402929c587 Transform position
Thinker K.F. Li <thinker@branda.to>
parents: 1
diff changeset
102 void coord_trans_pos(coord_t *co, co_aix *x, co_aix *y) {
31402929c587 Transform position
Thinker K.F. Li <thinker@branda.to>
parents: 1
diff changeset
103 co_aix nx, ny;
31402929c587 Transform position
Thinker K.F. Li <thinker@branda.to>
parents: 1
diff changeset
104
31402929c587 Transform position
Thinker K.F. Li <thinker@branda.to>
parents: 1
diff changeset
105 nx = ADD(ADD(MUL(co->aggr_matrix[0], *x),
31402929c587 Transform position
Thinker K.F. Li <thinker@branda.to>
parents: 1
diff changeset
106 MUL(co->aggr_matrix[1], *y)),
31402929c587 Transform position
Thinker K.F. Li <thinker@branda.to>
parents: 1
diff changeset
107 co->aggr_matrix[2]);
31402929c587 Transform position
Thinker K.F. Li <thinker@branda.to>
parents: 1
diff changeset
108 ny = ADD(ADD(MUL(co->aggr_matrix[3], *x),
31402929c587 Transform position
Thinker K.F. Li <thinker@branda.to>
parents: 1
diff changeset
109 MUL(co->aggr_matrix[4], *y)),
31402929c587 Transform position
Thinker K.F. Li <thinker@branda.to>
parents: 1
diff changeset
110 co->aggr_matrix[5]);
31402929c587 Transform position
Thinker K.F. Li <thinker@branda.to>
parents: 1
diff changeset
111 *x = nx;
31402929c587 Transform position
Thinker K.F. Li <thinker@branda.to>
parents: 1
diff changeset
112 *y = ny;
31402929c587 Transform position
Thinker K.F. Li <thinker@branda.to>
parents: 1
diff changeset
113 }
31402929c587 Transform position
Thinker K.F. Li <thinker@branda.to>
parents: 1
diff changeset
114
31
da770188a44d resize font size for changige of coord.
Thinker K.F. Li <thinker@branda.to>
parents: 17
diff changeset
115 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
116 co_aix x, y;
da770188a44d resize font size for changige of coord.
Thinker K.F. Li <thinker@branda.to>
parents: 17
diff changeset
117
da770188a44d resize font size for changige of coord.
Thinker K.F. Li <thinker@branda.to>
parents: 17
diff changeset
118 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
119 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
120
da770188a44d resize font size for changige of coord.
Thinker K.F. Li <thinker@branda.to>
parents: 17
diff changeset
121 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
122 }
da770188a44d resize font size for changige of coord.
Thinker K.F. Li <thinker@branda.to>
parents: 17
diff changeset
123
151
d11aa8fc06c7 Fix bug of tanks do not show at right places.
Thinker K.F. Li <thinker@branda.to>
parents: 140
diff changeset
124 /*!
d11aa8fc06c7 Fix bug of tanks do not show at right places.
Thinker K.F. Li <thinker@branda.to>
parents: 140
diff changeset
125 * \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
126 * 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
127 * 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
128 */
13
ed55009d96d3 refactory for redrawing
Thinker K.F. Li <thinker@branda.to>
parents: 12
diff changeset
129 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
130 coord_t *next = NULL;
12
79e9edf4c00a Add redraw manager
Thinker K.F. Li <thinker@branda.to>
parents: 5
diff changeset
131
138
9f4fc9ecfd1f Make shapes and coords drawed in post-order of tree.
Thinker K.F. Li <thinker@branda.to>
parents: 31
diff changeset
132 ASSERT(last != NULL);
12
79e9edf4c00a Add redraw manager
Thinker K.F. Li <thinker@branda.to>
parents: 5
diff changeset
133
151
d11aa8fc06c7 Fix bug of tanks do not show at right places.
Thinker K.F. Li <thinker@branda.to>
parents: 140
diff changeset
134 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
135 STAILQ_HEAD(last->children)) {
12
79e9edf4c00a Add redraw manager
Thinker K.F. Li <thinker@branda.to>
parents: 5
diff changeset
136 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
137 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
138 return next;
d11aa8fc06c7 Fix bug of tanks do not show at right places.
Thinker K.F. Li <thinker@branda.to>
parents: 140
diff changeset
139 } else {
12
79e9edf4c00a Add redraw manager
Thinker K.F. Li <thinker@branda.to>
parents: 5
diff changeset
140 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
141 }
d11aa8fc06c7 Fix bug of tanks do not show at right places.
Thinker K.F. Li <thinker@branda.to>
parents: 140
diff changeset
142
d11aa8fc06c7 Fix bug of tanks do not show at right places.
Thinker K.F. Li <thinker@branda.to>
parents: 140
diff changeset
143 do {
d11aa8fc06c7 Fix bug of tanks do not show at right places.
Thinker K.F. Li <thinker@branda.to>
parents: 140
diff changeset
144 next->flags &= ~COF_SKIP_TRIVAL;
13
ed55009d96d3 refactory for redrawing
Thinker K.F. Li <thinker@branda.to>
parents: 12
diff changeset
145 while(next != root && STAILQ_NEXT(coord_t, sibling, next) == NULL)
12
79e9edf4c00a Add redraw manager
Thinker K.F. Li <thinker@branda.to>
parents: 5
diff changeset
146 next = next->parent;
13
ed55009d96d3 refactory for redrawing
Thinker K.F. Li <thinker@branda.to>
parents: 12
diff changeset
147 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
148 return NULL;
d11aa8fc06c7 Fix bug of tanks do not show at right places.
Thinker K.F. Li <thinker@branda.to>
parents: 140
diff changeset
149 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
150 } while(next->flags & COF_SKIP_TRIVAL);
12
79e9edf4c00a Add redraw manager
Thinker K.F. Li <thinker@branda.to>
parents: 5
diff changeset
151
79e9edf4c00a Add redraw manager
Thinker K.F. Li <thinker@branda.to>
parents: 5
diff changeset
152 return next;
79e9edf4c00a Add redraw manager
Thinker K.F. Li <thinker@branda.to>
parents: 5
diff changeset
153 }
79e9edf4c00a Add redraw manager
Thinker K.F. Li <thinker@branda.to>
parents: 5
diff changeset
154
138
9f4fc9ecfd1f Make shapes and coords drawed in post-order of tree.
Thinker K.F. Li <thinker@branda.to>
parents: 31
diff changeset
155 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
156 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
157
9f4fc9ecfd1f Make shapes and coords drawed in post-order of tree.
Thinker K.F. Li <thinker@branda.to>
parents: 31
diff changeset
158 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
159 return NULL;
9f4fc9ecfd1f Make shapes and coords drawed in post-order of tree.
Thinker K.F. Li <thinker@branda.to>
parents: 31
diff changeset
160
9f4fc9ecfd1f Make shapes and coords drawed in post-order of tree.
Thinker K.F. Li <thinker@branda.to>
parents: 31
diff changeset
161 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
162 /* 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
163 next = root;
9f4fc9ecfd1f Make shapes and coords drawed in post-order of tree.
Thinker K.F. Li <thinker@branda.to>
parents: 31
diff changeset
164 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
165 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
166 return next;
9f4fc9ecfd1f Make shapes and coords drawed in post-order of tree.
Thinker K.F. Li <thinker@branda.to>
parents: 31
diff changeset
167 }
9f4fc9ecfd1f Make shapes and coords drawed in post-order of tree.
Thinker K.F. Li <thinker@branda.to>
parents: 31
diff changeset
168
9f4fc9ecfd1f Make shapes and coords drawed in post-order of tree.
Thinker K.F. Li <thinker@branda.to>
parents: 31
diff changeset
169 next = last;
9f4fc9ecfd1f Make shapes and coords drawed in post-order of tree.
Thinker K.F. Li <thinker@branda.to>
parents: 31
diff changeset
170 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
171 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
172
9f4fc9ecfd1f Make shapes and coords drawed in post-order of tree.
Thinker K.F. Li <thinker@branda.to>
parents: 31
diff changeset
173 /* 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
174 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
175 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
176 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
177
9f4fc9ecfd1f Make shapes and coords drawed in post-order of tree.
Thinker K.F. Li <thinker@branda.to>
parents: 31
diff changeset
178 return next;
9f4fc9ecfd1f Make shapes and coords drawed in post-order of tree.
Thinker K.F. Li <thinker@branda.to>
parents: 31
diff changeset
179 }
9f4fc9ecfd1f Make shapes and coords drawed in post-order of tree.
Thinker K.F. Li <thinker@branda.to>
parents: 31
diff changeset
180
1
b5c0162ccf69 Coordination tranforming
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
181 #ifdef UNITTEST
b5c0162ccf69 Coordination tranforming
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
182
b5c0162ccf69 Coordination tranforming
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
183 #include <CUnit/Basic.h>
b5c0162ccf69 Coordination tranforming
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
184
b5c0162ccf69 Coordination tranforming
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
185 void test_update_aggr_matrix(void) {
b5c0162ccf69 Coordination tranforming
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
186 coord_t elms[6];
2
31402929c587 Transform position
Thinker K.F. Li <thinker@branda.to>
parents: 1
diff changeset
187 co_aix x, y;
1
b5c0162ccf69 Coordination tranforming
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
188
b5c0162ccf69 Coordination tranforming
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
189 coord_init(elms, NULL);
b5c0162ccf69 Coordination tranforming
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
190 coord_init(elms + 1, elms);
b5c0162ccf69 Coordination tranforming
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
191 coord_init(elms + 2, elms);
b5c0162ccf69 Coordination tranforming
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
192 coord_init(elms + 3, elms + 1);
b5c0162ccf69 Coordination tranforming
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
193 coord_init(elms + 4, elms + 1);
b5c0162ccf69 Coordination tranforming
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
194 coord_init(elms + 5, elms + 2);
b5c0162ccf69 Coordination tranforming
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
195
b5c0162ccf69 Coordination tranforming
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
196 /* | 2 -1 0 |
b5c0162ccf69 Coordination tranforming
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
197 * | 0 1 0 |
b5c0162ccf69 Coordination tranforming
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
198 * | 0 0 1 |
b5c0162ccf69 Coordination tranforming
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
199 */
b5c0162ccf69 Coordination tranforming
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
200 elms[0].matrix[0] = 2;
b5c0162ccf69 Coordination tranforming
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
201 elms[0].matrix[1] = -1;
b5c0162ccf69 Coordination tranforming
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
202
b5c0162ccf69 Coordination tranforming
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
203 /* | 1 3 0 |
b5c0162ccf69 Coordination tranforming
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
204 * | 5 1 0 |
b5c0162ccf69 Coordination tranforming
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
205 * | 0 0 1 |
b5c0162ccf69 Coordination tranforming
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
206 */
b5c0162ccf69 Coordination tranforming
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
207 elms[1].matrix[1] = 3;
b5c0162ccf69 Coordination tranforming
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
208 elms[1].matrix[3] = 5;
b5c0162ccf69 Coordination tranforming
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
209
b5c0162ccf69 Coordination tranforming
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
210 update_aggr_matrix(elms);
b5c0162ccf69 Coordination tranforming
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
211
b5c0162ccf69 Coordination tranforming
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
212 /* | -3 5 0 |
b5c0162ccf69 Coordination tranforming
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
213 * | 5 1 0 |
b5c0162ccf69 Coordination tranforming
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
214 * | 0 0 1 |
b5c0162ccf69 Coordination tranforming
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
215 */
b5c0162ccf69 Coordination tranforming
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
216 CU_ASSERT(elms[3].aggr_matrix[0] == -3);
b5c0162ccf69 Coordination tranforming
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
217 CU_ASSERT(elms[3].aggr_matrix[1] == 5);
b5c0162ccf69 Coordination tranforming
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
218 CU_ASSERT(elms[3].aggr_matrix[2] == 0);
b5c0162ccf69 Coordination tranforming
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
219 CU_ASSERT(elms[3].aggr_matrix[3] == 5);
b5c0162ccf69 Coordination tranforming
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
220 CU_ASSERT(elms[3].aggr_matrix[4] == 1);
b5c0162ccf69 Coordination tranforming
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
221 CU_ASSERT(elms[3].aggr_matrix[5] == 0);
b5c0162ccf69 Coordination tranforming
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
222
b5c0162ccf69 Coordination tranforming
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
223 CU_ASSERT(elms[4].aggr_matrix[0] == -3);
b5c0162ccf69 Coordination tranforming
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
224 CU_ASSERT(elms[4].aggr_matrix[1] == 5);
b5c0162ccf69 Coordination tranforming
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
225 CU_ASSERT(elms[4].aggr_matrix[2] == 0);
b5c0162ccf69 Coordination tranforming
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
226 CU_ASSERT(elms[4].aggr_matrix[3] == 5);
b5c0162ccf69 Coordination tranforming
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
227 CU_ASSERT(elms[4].aggr_matrix[4] == 1);
b5c0162ccf69 Coordination tranforming
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
228 CU_ASSERT(elms[4].aggr_matrix[5] == 0);
b5c0162ccf69 Coordination tranforming
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
229
b5c0162ccf69 Coordination tranforming
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
230 CU_ASSERT(elms[5].aggr_matrix[0] == 2);
b5c0162ccf69 Coordination tranforming
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
231 CU_ASSERT(elms[5].aggr_matrix[1] == -1);
b5c0162ccf69 Coordination tranforming
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
232 CU_ASSERT(elms[5].aggr_matrix[2] == 0);
b5c0162ccf69 Coordination tranforming
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
233 CU_ASSERT(elms[5].aggr_matrix[3] == 0);
b5c0162ccf69 Coordination tranforming
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
234 CU_ASSERT(elms[5].aggr_matrix[4] == 1);
b5c0162ccf69 Coordination tranforming
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
235 CU_ASSERT(elms[5].aggr_matrix[5] == 0);
2
31402929c587 Transform position
Thinker K.F. Li <thinker@branda.to>
parents: 1
diff changeset
236
31402929c587 Transform position
Thinker K.F. Li <thinker@branda.to>
parents: 1
diff changeset
237 x = 50;
31402929c587 Transform position
Thinker K.F. Li <thinker@branda.to>
parents: 1
diff changeset
238 y = 99;
31402929c587 Transform position
Thinker K.F. Li <thinker@branda.to>
parents: 1
diff changeset
239 coord_trans_pos(elms + 5, &x, &y);
31402929c587 Transform position
Thinker K.F. Li <thinker@branda.to>
parents: 1
diff changeset
240 CU_ASSERT(x == 1);
31402929c587 Transform position
Thinker K.F. Li <thinker@branda.to>
parents: 1
diff changeset
241 CU_ASSERT(y == 99);
1
b5c0162ccf69 Coordination tranforming
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
242 }
b5c0162ccf69 Coordination tranforming
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
243
13
ed55009d96d3 refactory for redrawing
Thinker K.F. Li <thinker@branda.to>
parents: 12
diff changeset
244 void test_preorder_coord_subtree(void) {
12
79e9edf4c00a Add redraw manager
Thinker K.F. Li <thinker@branda.to>
parents: 5
diff changeset
245 coord_t elms[6];
79e9edf4c00a Add redraw manager
Thinker K.F. Li <thinker@branda.to>
parents: 5
diff changeset
246 coord_t *last;
79e9edf4c00a Add redraw manager
Thinker K.F. Li <thinker@branda.to>
parents: 5
diff changeset
247
79e9edf4c00a Add redraw manager
Thinker K.F. Li <thinker@branda.to>
parents: 5
diff changeset
248 coord_init(elms, NULL);
79e9edf4c00a Add redraw manager
Thinker K.F. Li <thinker@branda.to>
parents: 5
diff changeset
249 coord_init(elms + 1, elms);
79e9edf4c00a Add redraw manager
Thinker K.F. Li <thinker@branda.to>
parents: 5
diff changeset
250 coord_init(elms + 2, elms);
79e9edf4c00a Add redraw manager
Thinker K.F. Li <thinker@branda.to>
parents: 5
diff changeset
251 coord_init(elms + 3, elms + 1);
79e9edf4c00a Add redraw manager
Thinker K.F. Li <thinker@branda.to>
parents: 5
diff changeset
252 coord_init(elms + 4, elms + 1);
79e9edf4c00a Add redraw manager
Thinker K.F. Li <thinker@branda.to>
parents: 5
diff changeset
253 coord_init(elms + 5, elms + 2);
79e9edf4c00a Add redraw manager
Thinker K.F. Li <thinker@branda.to>
parents: 5
diff changeset
254
79e9edf4c00a Add redraw manager
Thinker K.F. Li <thinker@branda.to>
parents: 5
diff changeset
255 last = elms;
13
ed55009d96d3 refactory for redrawing
Thinker K.F. Li <thinker@branda.to>
parents: 12
diff changeset
256 last = preorder_coord_subtree(elms, last);
12
79e9edf4c00a Add redraw manager
Thinker K.F. Li <thinker@branda.to>
parents: 5
diff changeset
257 CU_ASSERT(last == elms + 1);
13
ed55009d96d3 refactory for redrawing
Thinker K.F. Li <thinker@branda.to>
parents: 12
diff changeset
258 last = preorder_coord_subtree(elms, last);
12
79e9edf4c00a Add redraw manager
Thinker K.F. Li <thinker@branda.to>
parents: 5
diff changeset
259 CU_ASSERT(last == elms + 3);
13
ed55009d96d3 refactory for redrawing
Thinker K.F. Li <thinker@branda.to>
parents: 12
diff changeset
260 last = preorder_coord_subtree(elms, last);
12
79e9edf4c00a Add redraw manager
Thinker K.F. Li <thinker@branda.to>
parents: 5
diff changeset
261 CU_ASSERT(last == elms + 4);
13
ed55009d96d3 refactory for redrawing
Thinker K.F. Li <thinker@branda.to>
parents: 12
diff changeset
262 last = preorder_coord_subtree(elms, last);
12
79e9edf4c00a Add redraw manager
Thinker K.F. Li <thinker@branda.to>
parents: 5
diff changeset
263 CU_ASSERT(last == elms + 2);
13
ed55009d96d3 refactory for redrawing
Thinker K.F. Li <thinker@branda.to>
parents: 12
diff changeset
264 last = preorder_coord_subtree(elms, last);
12
79e9edf4c00a Add redraw manager
Thinker K.F. Li <thinker@branda.to>
parents: 5
diff changeset
265 CU_ASSERT(last == elms + 5);
13
ed55009d96d3 refactory for redrawing
Thinker K.F. Li <thinker@branda.to>
parents: 12
diff changeset
266 last = preorder_coord_subtree(elms, last);
12
79e9edf4c00a Add redraw manager
Thinker K.F. Li <thinker@branda.to>
parents: 5
diff changeset
267 CU_ASSERT(last == NULL);
79e9edf4c00a Add redraw manager
Thinker K.F. Li <thinker@branda.to>
parents: 5
diff changeset
268 }
79e9edf4c00a Add redraw manager
Thinker K.F. Li <thinker@branda.to>
parents: 5
diff changeset
269
1
b5c0162ccf69 Coordination tranforming
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
270 CU_pSuite get_coord_suite(void) {
b5c0162ccf69 Coordination tranforming
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
271 CU_pSuite suite;
b5c0162ccf69 Coordination tranforming
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
272
b5c0162ccf69 Coordination tranforming
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
273 suite = CU_add_suite("Suite_coord", NULL, NULL);
b5c0162ccf69 Coordination tranforming
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
274 CU_ADD_TEST(suite, test_update_aggr_matrix);
13
ed55009d96d3 refactory for redrawing
Thinker K.F. Li <thinker@branda.to>
parents: 12
diff changeset
275 CU_ADD_TEST(suite, test_preorder_coord_subtree);
1
b5c0162ccf69 Coordination tranforming
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
276
b5c0162ccf69 Coordination tranforming
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
277 return suite;
b5c0162ccf69 Coordination tranforming
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
278 }
b5c0162ccf69 Coordination tranforming
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
279
b5c0162ccf69 Coordination tranforming
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
280 #endif