annotate src/geo.c @ 12:79e9edf4c00a

Add redraw manager
author Thinker K.F. Li <thinker@branda.to>
date Mon, 28 Jul 2008 17:45:36 +0800
parents 7cfecdce94cc
children ed55009d96d3
rev   line source
5
9c331ec9e210 SVG path is partially supported
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
1 /*! \brief Determine who should be re-drawed.
9c331ec9e210 SVG path is partially supported
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
2 * \file
9c331ec9e210 SVG path is partially supported
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
3 * When part of graphic are chagned, not mater size, shape, or position,
9c331ec9e210 SVG path is partially supported
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
4 * the components effected or overlaid should be re-drawed. This module
9c331ec9e210 SVG path is partially supported
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
5 * figures out components that should be re-drawed.
9c331ec9e210 SVG path is partially supported
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
6 */
9c331ec9e210 SVG path is partially supported
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
7 #include <stdio.h>
9c331ec9e210 SVG path is partially supported
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
8 #include "mb_types.h"
9c331ec9e210 SVG path is partially supported
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
9
9c331ec9e210 SVG path is partially supported
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
10 static int is_scale_overlay(co_aix x1, co_aix w1, co_aix x2, co_aix w2) {
9c331ec9e210 SVG path is partially supported
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
11 if(x1 > x2) {
9c331ec9e210 SVG path is partially supported
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
12 if((x1 - x2) >= w2)
9c331ec9e210 SVG path is partially supported
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
13 return 0;
9c331ec9e210 SVG path is partially supported
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
14 } else {
9c331ec9e210 SVG path is partially supported
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
15 if((x2 - x1) >= w1)
9c331ec9e210 SVG path is partially supported
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
16 return 0;
9c331ec9e210 SVG path is partially supported
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
17 }
9c331ec9e210 SVG path is partially supported
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
18 return 1;
9c331ec9e210 SVG path is partially supported
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
19 }
9c331ec9e210 SVG path is partially supported
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
20
12
79e9edf4c00a Add redraw manager
Thinker K.F. Li <thinker@branda.to>
parents: 10
diff changeset
21 static int _is_overlay(geo_t *r1, geo_t *r2) {
5
9c331ec9e210 SVG path is partially supported
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
22 if(!is_scale_overlay(r1->x, r1->w, r2->x, r2->w))
9c331ec9e210 SVG path is partially supported
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
23 return 0;
9c331ec9e210 SVG path is partially supported
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
24 if(!is_scale_overlay(r1->y, r1->h, r2->y, r2->h))
9c331ec9e210 SVG path is partially supported
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
25 return 0;
9c331ec9e210 SVG path is partially supported
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
26
9c331ec9e210 SVG path is partially supported
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
27 return 1;
9c331ec9e210 SVG path is partially supported
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
28 }
9c331ec9e210 SVG path is partially supported
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
29
12
79e9edf4c00a Add redraw manager
Thinker K.F. Li <thinker@branda.to>
parents: 10
diff changeset
30 int is_overlay(geo_t *r1, geo_t *r2) {
79e9edf4c00a Add redraw manager
Thinker K.F. Li <thinker@branda.to>
parents: 10
diff changeset
31 return _is_overlay(r1, r2);
79e9edf4c00a Add redraw manager
Thinker K.F. Li <thinker@branda.to>
parents: 10
diff changeset
32 }
79e9edf4c00a Add redraw manager
Thinker K.F. Li <thinker@branda.to>
parents: 10
diff changeset
33
5
9c331ec9e210 SVG path is partially supported
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
34 void geo_init(geo_t *g, int n_pos, co_aix pos[][2]) {
9c331ec9e210 SVG path is partially supported
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
35 co_aix min_x, max_x;
9c331ec9e210 SVG path is partially supported
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
36 co_aix min_y, max_y;
9c331ec9e210 SVG path is partially supported
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
37 co_aix x, y;
9c331ec9e210 SVG path is partially supported
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
38 int i;
9c331ec9e210 SVG path is partially supported
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
39
9c331ec9e210 SVG path is partially supported
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
40 min_x = max_x = pos[0][0];
9c331ec9e210 SVG path is partially supported
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
41 min_y = max_y = pos[0][1];
9c331ec9e210 SVG path is partially supported
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
42 for(i = 1; i < n_pos; i++) {
9c331ec9e210 SVG path is partially supported
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
43 x = pos[i][0];
9c331ec9e210 SVG path is partially supported
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
44 if(x < min_x)
9c331ec9e210 SVG path is partially supported
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
45 min_x = x;
9c331ec9e210 SVG path is partially supported
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
46 else if(x > max_x)
9c331ec9e210 SVG path is partially supported
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
47 max_x = x;
9c331ec9e210 SVG path is partially supported
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
48 y = pos[i][1];
9c331ec9e210 SVG path is partially supported
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
49 if(y < min_y)
9c331ec9e210 SVG path is partially supported
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
50 min_y = y;
9c331ec9e210 SVG path is partially supported
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
51 else if(y > max_y)
9c331ec9e210 SVG path is partially supported
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
52 max_y = y;
9c331ec9e210 SVG path is partially supported
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
53 }
9c331ec9e210 SVG path is partially supported
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
54 g->x = min_x;
9c331ec9e210 SVG path is partially supported
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
55 g->w = max_x - min_x;
9c331ec9e210 SVG path is partially supported
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
56 g->y = min_y;
9c331ec9e210 SVG path is partially supported
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
57 g->h = max_y - min_y;
9c331ec9e210 SVG path is partially supported
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
58 }
9c331ec9e210 SVG path is partially supported
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
59
9c331ec9e210 SVG path is partially supported
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
60 void geo_mark_overlay(geo_t *g, int n_others, geo_t **others,
9c331ec9e210 SVG path is partially supported
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
61 int *n_overlays, geo_t **overlays) {
9c331ec9e210 SVG path is partially supported
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
62 int i, ov_idx;
9c331ec9e210 SVG path is partially supported
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
63
9c331ec9e210 SVG path is partially supported
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
64 ov_idx = 0;
9c331ec9e210 SVG path is partially supported
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
65 for(i = 0; i < n_others; i++) {
12
79e9edf4c00a Add redraw manager
Thinker K.F. Li <thinker@branda.to>
parents: 10
diff changeset
66 if(_is_overlay(g, others[i]))
5
9c331ec9e210 SVG path is partially supported
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
67 overlays[ov_idx++] = others[i];
9c331ec9e210 SVG path is partially supported
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
68 }
9c331ec9e210 SVG path is partially supported
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
69 *n_overlays = ov_idx;
9c331ec9e210 SVG path is partially supported
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
70 }
9c331ec9e210 SVG path is partially supported
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
71
9c331ec9e210 SVG path is partially supported
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
72
9c331ec9e210 SVG path is partially supported
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
73 #ifdef UNITTEST
9c331ec9e210 SVG path is partially supported
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
74
9c331ec9e210 SVG path is partially supported
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
75 #include <CUnit/Basic.h>
9c331ec9e210 SVG path is partially supported
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
76
9c331ec9e210 SVG path is partially supported
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
77 void test_geo_init(void) {
9c331ec9e210 SVG path is partially supported
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
78 co_aix data[][2] = {
9c331ec9e210 SVG path is partially supported
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
79 {33, 25}, {49, 12},
9c331ec9e210 SVG path is partially supported
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
80 {14, 28}, {39, 56}};
9c331ec9e210 SVG path is partially supported
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
81 geo_t g;
9c331ec9e210 SVG path is partially supported
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
82
9c331ec9e210 SVG path is partially supported
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
83 geo_init(&g, 4, data);
9c331ec9e210 SVG path is partially supported
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
84 CU_ASSERT(g.x == 14);
9c331ec9e210 SVG path is partially supported
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
85 CU_ASSERT(g.w == 35);
9c331ec9e210 SVG path is partially supported
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
86 CU_ASSERT(g.y == 12);
9c331ec9e210 SVG path is partially supported
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
87 CU_ASSERT(g.h == 44);
9c331ec9e210 SVG path is partially supported
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
88 }
9c331ec9e210 SVG path is partially supported
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
89
9c331ec9e210 SVG path is partially supported
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
90 void test_geo_mark_overlay(void) {
9c331ec9e210 SVG path is partially supported
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
91 geo_t _geos[3], *geos[3], *overlays[3];
9c331ec9e210 SVG path is partially supported
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
92 geo_t g;
9c331ec9e210 SVG path is partially supported
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
93 int i, n_ov;
9c331ec9e210 SVG path is partially supported
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
94
9c331ec9e210 SVG path is partially supported
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
95 for(i = 0; i < 3; i++) {
9c331ec9e210 SVG path is partially supported
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
96 _geos[i].x = i * 50;
9c331ec9e210 SVG path is partially supported
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
97 _geos[i].y = i * 50;
9c331ec9e210 SVG path is partially supported
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
98 _geos[i].w = 55;
9c331ec9e210 SVG path is partially supported
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
99 _geos[i].h = 66;
9c331ec9e210 SVG path is partially supported
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
100 geos[i] = _geos + i;
9c331ec9e210 SVG path is partially supported
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
101 }
9c331ec9e210 SVG path is partially supported
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
102 g.x = 88;
9c331ec9e210 SVG path is partially supported
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
103 g.y = 79;
9c331ec9e210 SVG path is partially supported
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
104 g.w = 70;
9c331ec9e210 SVG path is partially supported
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
105 g.h = 70;
9c331ec9e210 SVG path is partially supported
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
106
9c331ec9e210 SVG path is partially supported
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
107 /* overlay with geos[1] and geos[2] */
9c331ec9e210 SVG path is partially supported
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
108 geo_mark_overlay(&g, 3, geos, &n_ov, overlays);
9c331ec9e210 SVG path is partially supported
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
109 CU_ASSERT(n_ov == 2);
9c331ec9e210 SVG path is partially supported
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
110 CU_ASSERT(overlays[0] == geos[1]);
9c331ec9e210 SVG path is partially supported
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
111 CU_ASSERT(overlays[1] == geos[2]);
9c331ec9e210 SVG path is partially supported
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
112
9c331ec9e210 SVG path is partially supported
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
113 /* right side of geos[1], and up side of geos[2] */
9c331ec9e210 SVG path is partially supported
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
114 g.x = 105;
9c331ec9e210 SVG path is partially supported
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
115 g.y = 50;
9c331ec9e210 SVG path is partially supported
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
116 g.w = 50;
9c331ec9e210 SVG path is partially supported
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
117 g.h = 51;
9c331ec9e210 SVG path is partially supported
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
118 geo_mark_overlay(&g, 3, geos, &n_ov, overlays);
9c331ec9e210 SVG path is partially supported
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
119 CU_ASSERT(n_ov == 1);
9c331ec9e210 SVG path is partially supported
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
120 CU_ASSERT(overlays[0] == geos[2]);
9c331ec9e210 SVG path is partially supported
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
121 }
9c331ec9e210 SVG path is partially supported
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
122
9c331ec9e210 SVG path is partially supported
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
123 CU_pSuite get_geo_suite(void) {
9c331ec9e210 SVG path is partially supported
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
124 CU_pSuite suite;
9c331ec9e210 SVG path is partially supported
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
125
9c331ec9e210 SVG path is partially supported
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
126 suite = CU_add_suite("Suite_geo", NULL, NULL);
9c331ec9e210 SVG path is partially supported
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
127 CU_ADD_TEST(suite, test_geo_init);
9c331ec9e210 SVG path is partially supported
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
128 CU_ADD_TEST(suite, test_geo_mark_overlay);
9c331ec9e210 SVG path is partially supported
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
129
9c331ec9e210 SVG path is partially supported
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
130 return suite;
9c331ec9e210 SVG path is partially supported
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
131 }
9c331ec9e210 SVG path is partially supported
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
132
9c331ec9e210 SVG path is partially supported
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
133 #endif