annotate src/geo.c @ 58:1ca417f741f1

-
author Thinker K.F. Li <thinker@branda.to>
date Sun, 10 Aug 2008 21:32:42 +0800
parents 0f3baa488a62
children 21db69d46835
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>
18
0f3baa488a62 Support solid color paint for fill.
Thinker K.F. Li <thinker@branda.to>
parents: 17
diff changeset
8 #include <string.h>
5
9c331ec9e210 SVG path is partially supported
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
9 #include "mb_types.h"
9c331ec9e210 SVG path is partially supported
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
10
9c331ec9e210 SVG path is partially supported
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
11 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
12 if(x1 > x2) {
9c331ec9e210 SVG path is partially supported
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
13 if((x1 - x2) >= w2)
9c331ec9e210 SVG path is partially supported
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
14 return 0;
9c331ec9e210 SVG path is partially supported
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
15 } else {
9c331ec9e210 SVG path is partially supported
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
16 if((x2 - x1) >= w1)
9c331ec9e210 SVG path is partially supported
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
17 return 0;
9c331ec9e210 SVG path is partially supported
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
18 }
9c331ec9e210 SVG path is partially supported
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
19 return 1;
9c331ec9e210 SVG path is partially supported
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
20 }
9c331ec9e210 SVG path is partially supported
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
21
13
ed55009d96d3 refactory for redrawing
Thinker K.F. Li <thinker@branda.to>
parents: 12
diff changeset
22 static int _is_overlay(area_t *r1, area_t *r2) {
5
9c331ec9e210 SVG path is partially supported
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
23 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
24 return 0;
9c331ec9e210 SVG path is partially supported
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
25 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
26 return 0;
9c331ec9e210 SVG path is partially supported
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
27
9c331ec9e210 SVG path is partially supported
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
28 return 1;
9c331ec9e210 SVG path is partially supported
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
29 }
9c331ec9e210 SVG path is partially supported
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
30
13
ed55009d96d3 refactory for redrawing
Thinker K.F. Li <thinker@branda.to>
parents: 12
diff changeset
31 int is_overlay(area_t *r1, area_t *r2) {
12
79e9edf4c00a Add redraw manager
Thinker K.F. Li <thinker@branda.to>
parents: 10
diff changeset
32 return _is_overlay(r1, r2);
79e9edf4c00a Add redraw manager
Thinker K.F. Li <thinker@branda.to>
parents: 10
diff changeset
33 }
79e9edf4c00a Add redraw manager
Thinker K.F. Li <thinker@branda.to>
parents: 10
diff changeset
34
15
c2ce186a5c37 X_main uses rdman_redraw_all()
Thinker K.F. Li <thinker@branda.to>
parents: 13
diff changeset
35 void area_init(area_t *area, int n_pos, co_aix pos[][2]) {
5
9c331ec9e210 SVG path is partially supported
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
36 co_aix min_x, max_x;
9c331ec9e210 SVG path is partially supported
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
37 co_aix min_y, max_y;
9c331ec9e210 SVG path is partially supported
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
38 co_aix x, y;
9c331ec9e210 SVG path is partially supported
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
39 int i;
15
c2ce186a5c37 X_main uses rdman_redraw_all()
Thinker K.F. Li <thinker@branda.to>
parents: 13
diff changeset
40
5
9c331ec9e210 SVG path is partially supported
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
41 min_x = max_x = pos[0][0];
9c331ec9e210 SVG path is partially supported
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
42 min_y = max_y = pos[0][1];
9c331ec9e210 SVG path is partially supported
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
43 for(i = 1; i < n_pos; i++) {
9c331ec9e210 SVG path is partially supported
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
44 x = pos[i][0];
9c331ec9e210 SVG path is partially supported
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
45 if(x < min_x)
9c331ec9e210 SVG path is partially supported
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
46 min_x = x;
9c331ec9e210 SVG path is partially supported
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
47 else if(x > max_x)
9c331ec9e210 SVG path is partially supported
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
48 max_x = x;
9c331ec9e210 SVG path is partially supported
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
49 y = pos[i][1];
9c331ec9e210 SVG path is partially supported
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
50 if(y < min_y)
9c331ec9e210 SVG path is partially supported
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
51 min_y = y;
9c331ec9e210 SVG path is partially supported
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
52 else if(y > max_y)
9c331ec9e210 SVG path is partially supported
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
53 max_y = y;
9c331ec9e210 SVG path is partially supported
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
54 }
13
ed55009d96d3 refactory for redrawing
Thinker K.F. Li <thinker@branda.to>
parents: 12
diff changeset
55
15
c2ce186a5c37 X_main uses rdman_redraw_all()
Thinker K.F. Li <thinker@branda.to>
parents: 13
diff changeset
56 area->x = min_x;
17
41f0907b27ac Unittest for rdman_redraw_changed().
Thinker K.F. Li <thinker@branda.to>
parents: 15
diff changeset
57 area->w = max_x - min_x + 1;
15
c2ce186a5c37 X_main uses rdman_redraw_all()
Thinker K.F. Li <thinker@branda.to>
parents: 13
diff changeset
58 area->y = min_y;
17
41f0907b27ac Unittest for rdman_redraw_changed().
Thinker K.F. Li <thinker@branda.to>
parents: 15
diff changeset
59 area->h = max_y - min_y + 1;
15
c2ce186a5c37 X_main uses rdman_redraw_all()
Thinker K.F. Li <thinker@branda.to>
parents: 13
diff changeset
60 }
c2ce186a5c37 X_main uses rdman_redraw_all()
Thinker K.F. Li <thinker@branda.to>
parents: 13
diff changeset
61
17
41f0907b27ac Unittest for rdman_redraw_changed().
Thinker K.F. Li <thinker@branda.to>
parents: 15
diff changeset
62 void geo_init(geo_t *g) {
41f0907b27ac Unittest for rdman_redraw_changed().
Thinker K.F. Li <thinker@branda.to>
parents: 15
diff changeset
63 memset(g, 0, sizeof(geo_t));
13
ed55009d96d3 refactory for redrawing
Thinker K.F. Li <thinker@branda.to>
parents: 12
diff changeset
64 g->cur_area = g->areas;
ed55009d96d3 refactory for redrawing
Thinker K.F. Li <thinker@branda.to>
parents: 12
diff changeset
65 g->last_area = g->areas + 1;
17
41f0907b27ac Unittest for rdman_redraw_changed().
Thinker K.F. Li <thinker@branda.to>
parents: 15
diff changeset
66 }
41f0907b27ac Unittest for rdman_redraw_changed().
Thinker K.F. Li <thinker@branda.to>
parents: 15
diff changeset
67
41f0907b27ac Unittest for rdman_redraw_changed().
Thinker K.F. Li <thinker@branda.to>
parents: 15
diff changeset
68 void geo_from_positions(geo_t *g, int n_pos, co_aix pos[][2]) {
15
c2ce186a5c37 X_main uses rdman_redraw_all()
Thinker K.F. Li <thinker@branda.to>
parents: 13
diff changeset
69 area_init(g->cur_area, n_pos, pos);
5
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 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
73 int *n_overlays, geo_t **overlays) {
9c331ec9e210 SVG path is partially supported
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
74 int i, ov_idx;
9c331ec9e210 SVG path is partially supported
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
75
9c331ec9e210 SVG path is partially supported
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
76 ov_idx = 0;
9c331ec9e210 SVG path is partially supported
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
77 for(i = 0; i < n_others; i++) {
13
ed55009d96d3 refactory for redrawing
Thinker K.F. Li <thinker@branda.to>
parents: 12
diff changeset
78 if(_is_overlay(g->cur_area, others[i]->cur_area))
5
9c331ec9e210 SVG path is partially supported
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
79 overlays[ov_idx++] = others[i];
9c331ec9e210 SVG path is partially supported
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
80 }
9c331ec9e210 SVG path is partially supported
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
81 *n_overlays = ov_idx;
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
9c331ec9e210 SVG path is partially supported
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
84
9c331ec9e210 SVG path is partially supported
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
85 #ifdef UNITTEST
9c331ec9e210 SVG path is partially supported
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
86
9c331ec9e210 SVG path is partially supported
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
87 #include <CUnit/Basic.h>
9c331ec9e210 SVG path is partially supported
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
88
17
41f0907b27ac Unittest for rdman_redraw_changed().
Thinker K.F. Li <thinker@branda.to>
parents: 15
diff changeset
89 void test_geo_from_positions(void) {
5
9c331ec9e210 SVG path is partially supported
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
90 co_aix data[][2] = {
9c331ec9e210 SVG path is partially supported
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
91 {33, 25}, {49, 12},
9c331ec9e210 SVG path is partially supported
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
92 {14, 28}, {39, 56}};
9c331ec9e210 SVG path is partially supported
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
93 geo_t g;
9c331ec9e210 SVG path is partially supported
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
94
17
41f0907b27ac Unittest for rdman_redraw_changed().
Thinker K.F. Li <thinker@branda.to>
parents: 15
diff changeset
95 geo_init(&g);
41f0907b27ac Unittest for rdman_redraw_changed().
Thinker K.F. Li <thinker@branda.to>
parents: 15
diff changeset
96 geo_from_positions(&g, 4, data);
13
ed55009d96d3 refactory for redrawing
Thinker K.F. Li <thinker@branda.to>
parents: 12
diff changeset
97 CU_ASSERT(g.cur_area->x == 14);
17
41f0907b27ac Unittest for rdman_redraw_changed().
Thinker K.F. Li <thinker@branda.to>
parents: 15
diff changeset
98 CU_ASSERT(g.cur_area->w == 36);
13
ed55009d96d3 refactory for redrawing
Thinker K.F. Li <thinker@branda.to>
parents: 12
diff changeset
99 CU_ASSERT(g.cur_area->y == 12);
17
41f0907b27ac Unittest for rdman_redraw_changed().
Thinker K.F. Li <thinker@branda.to>
parents: 15
diff changeset
100 CU_ASSERT(g.cur_area->h == 45);
5
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
9c331ec9e210 SVG path is partially supported
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
103 void test_geo_mark_overlay(void) {
9c331ec9e210 SVG path is partially supported
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
104 geo_t _geos[3], *geos[3], *overlays[3];
9c331ec9e210 SVG path is partially supported
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
105 geo_t g;
13
ed55009d96d3 refactory for redrawing
Thinker K.F. Li <thinker@branda.to>
parents: 12
diff changeset
106 co_aix pos[2][2];
5
9c331ec9e210 SVG path is partially supported
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
107 int i, n_ov;
9c331ec9e210 SVG path is partially supported
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
108
9c331ec9e210 SVG path is partially supported
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
109 for(i = 0; i < 3; i++) {
13
ed55009d96d3 refactory for redrawing
Thinker K.F. Li <thinker@branda.to>
parents: 12
diff changeset
110 pos[0][0] = i * 50;
ed55009d96d3 refactory for redrawing
Thinker K.F. Li <thinker@branda.to>
parents: 12
diff changeset
111 pos[0][1] = i * 50;
ed55009d96d3 refactory for redrawing
Thinker K.F. Li <thinker@branda.to>
parents: 12
diff changeset
112 pos[1][0] = i * 50 + 55;
ed55009d96d3 refactory for redrawing
Thinker K.F. Li <thinker@branda.to>
parents: 12
diff changeset
113 pos[1][1] = i * 50 + 66;
17
41f0907b27ac Unittest for rdman_redraw_changed().
Thinker K.F. Li <thinker@branda.to>
parents: 15
diff changeset
114 geo_init(_geos + i);
41f0907b27ac Unittest for rdman_redraw_changed().
Thinker K.F. Li <thinker@branda.to>
parents: 15
diff changeset
115 geo_from_positions(_geos + i, 2, pos);
5
9c331ec9e210 SVG path is partially supported
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
116 geos[i] = _geos + i;
9c331ec9e210 SVG path is partially supported
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
117 }
13
ed55009d96d3 refactory for redrawing
Thinker K.F. Li <thinker@branda.to>
parents: 12
diff changeset
118 pos[0][0] = 88;
ed55009d96d3 refactory for redrawing
Thinker K.F. Li <thinker@branda.to>
parents: 12
diff changeset
119 pos[0][1] = 79;
ed55009d96d3 refactory for redrawing
Thinker K.F. Li <thinker@branda.to>
parents: 12
diff changeset
120 pos[1][0] = 88 + 70;
ed55009d96d3 refactory for redrawing
Thinker K.F. Li <thinker@branda.to>
parents: 12
diff changeset
121 pos[1][1] = 79 + 70;
17
41f0907b27ac Unittest for rdman_redraw_changed().
Thinker K.F. Li <thinker@branda.to>
parents: 15
diff changeset
122 geo_init(&g);
41f0907b27ac Unittest for rdman_redraw_changed().
Thinker K.F. Li <thinker@branda.to>
parents: 15
diff changeset
123 geo_from_positions(&g, 2, pos);
5
9c331ec9e210 SVG path is partially supported
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
124
9c331ec9e210 SVG path is partially supported
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
125 /* overlay with geos[1] and geos[2] */
9c331ec9e210 SVG path is partially supported
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
126 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
127 CU_ASSERT(n_ov == 2);
9c331ec9e210 SVG path is partially supported
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
128 CU_ASSERT(overlays[0] == geos[1]);
9c331ec9e210 SVG path is partially supported
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
129 CU_ASSERT(overlays[1] == geos[2]);
9c331ec9e210 SVG path is partially supported
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
130
9c331ec9e210 SVG path is partially supported
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
131 /* right side of geos[1], and up side of geos[2] */
17
41f0907b27ac Unittest for rdman_redraw_changed().
Thinker K.F. Li <thinker@branda.to>
parents: 15
diff changeset
132 pos[0][0] = 106;
41f0907b27ac Unittest for rdman_redraw_changed().
Thinker K.F. Li <thinker@branda.to>
parents: 15
diff changeset
133 pos[0][1] = 51;
41f0907b27ac Unittest for rdman_redraw_changed().
Thinker K.F. Li <thinker@branda.to>
parents: 15
diff changeset
134 pos[1][0] = 106 + 49;
41f0907b27ac Unittest for rdman_redraw_changed().
Thinker K.F. Li <thinker@branda.to>
parents: 15
diff changeset
135 pos[1][1] = 51 + 49;
41f0907b27ac Unittest for rdman_redraw_changed().
Thinker K.F. Li <thinker@branda.to>
parents: 15
diff changeset
136 geo_from_positions(&g, 2, pos);
5
9c331ec9e210 SVG path is partially supported
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
137 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
138 CU_ASSERT(n_ov == 1);
9c331ec9e210 SVG path is partially supported
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
139 CU_ASSERT(overlays[0] == geos[2]);
9c331ec9e210 SVG path is partially supported
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
140 }
9c331ec9e210 SVG path is partially supported
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
141
9c331ec9e210 SVG path is partially supported
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
142 CU_pSuite get_geo_suite(void) {
9c331ec9e210 SVG path is partially supported
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
143 CU_pSuite suite;
9c331ec9e210 SVG path is partially supported
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
144
9c331ec9e210 SVG path is partially supported
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
145 suite = CU_add_suite("Suite_geo", NULL, NULL);
17
41f0907b27ac Unittest for rdman_redraw_changed().
Thinker K.F. Li <thinker@branda.to>
parents: 15
diff changeset
146 CU_ADD_TEST(suite, test_geo_from_positions);
5
9c331ec9e210 SVG path is partially supported
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
147 CU_ADD_TEST(suite, test_geo_mark_overlay);
9c331ec9e210 SVG path is partially supported
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
148
9c331ec9e210 SVG path is partially supported
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
149 return suite;
9c331ec9e210 SVG path is partially supported
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
150 }
9c331ec9e210 SVG path is partially supported
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
151
9c331ec9e210 SVG path is partially supported
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
152 #endif