Contents of /src/map_hl.c

Parent Directory Parent Directory | Revision Log Revision Log


Revision 1 - (hide annotations)
Tue Dec 9 20:06:06 2008 UTC (15 years, 6 months ago) by harbaum
File MIME type: text/plain
File size: 5118 byte(s)
Initial import
1 harbaum 1 /*
2     * Copyright (C) 2008 Till Harbaum <till@harbaum.org>.
3     *
4     * This file is part of OSM2Go.
5     *
6     * OSM2Go is free software: you can redistribute it and/or modify
7     * it under the terms of the GNU General Public License as published by
8     * the Free Software Foundation, either version 3 of the License, or
9     * (at your option) any later version.
10     *
11     * OSM2Go is distributed in the hope that it will be useful,
12     * but WITHOUT ANY WARRANTY; without even the implied warranty of
13     * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14     * GNU General Public License for more details.
15     *
16     * You should have received a copy of the GNU General Public License
17     * along with OSM2Go. If not, see <http://www.gnu.org/licenses/>.
18     */
19    
20     #include "appdata.h"
21    
22     /* create a new item for the cursor */
23     void map_hl_cursor_draw(map_t *map, gint x, gint y, gboolean is_world,
24     gint radius) {
25     if(map->cursor)
26     canvas_item_destroy(map->cursor);
27    
28     gint wx, wy;
29     if(!is_world) canvas_window2world(map->canvas, x, y, &wx, &wy);
30     else { wx = x; wy = y; }
31    
32     map->cursor = canvas_circle_new(map, CANVAS_GROUP_DRAW, wx, wy,
33     radius, 0, map->style->highlight.node_color, NO_COLOR);
34     }
35    
36     /* special highlight for segments. use when cutting ways */
37     void map_hl_segment_draw(map_t *map, gint width,
38     gint x0, gint y0, gint x1, gint y1) {
39     canvas_points_t *points = canvas_points_new(2);
40    
41     points->coords[0] = x0; points->coords[1] = y0;
42     points->coords[2] = x1; points->coords[3] = y1;
43    
44     map->cursor = canvas_polyline_new(map, CANVAS_GROUP_DRAW,
45     points, width, map->style->highlight.node_color);
46     canvas_points_free(points);
47     }
48    
49     void map_hl_cursor_clear(map_t *map) {
50     if(map->cursor) {
51     canvas_item_destroy(map->cursor);
52     map->cursor = NULL;
53     }
54     }
55    
56     /* create a new item used for touched node */
57     void map_hl_touchnode_draw(map_t *map, node_t *node) {
58     if(map->touchnode)
59     canvas_item_destroy(map->touchnode);
60    
61     map->touchnode =
62     canvas_circle_new(map, CANVAS_GROUP_DRAW, node->lpos.x, node->lpos.y,
63     2*map->style->node.radius, 0,
64     map->style->highlight.touch_color, NO_COLOR);
65    
66     canvas_item_set_user_data(map->touchnode, node);
67     }
68    
69     node_t *map_hl_touchnode_get_node(map_t *map) {
70     if(!map->touchnode) return NULL;
71     return (node_t*)canvas_item_get_user_data(map->touchnode);
72     }
73    
74     void map_hl_touchnode_clear(map_t *map) {
75     if(map->touchnode) {
76     canvas_item_destroy(map->touchnode);
77     map->touchnode = NULL;
78     }
79     }
80    
81     /* called whenever a highlight item is to be destroyed */
82     gint map_hl_item_destroy_event(GtkWidget *widget, gpointer data) {
83     map_item_t *map_item = (map_item_t*)data;
84    
85     // printf("destroying highlight map_item @ %p\n", map_item);
86     g_free(map_item);
87     return FALSE;
88     }
89    
90     void map_hl_remove(appdata_t *appdata) {
91     map_t *map = appdata->map;
92    
93     if(!map->highlight) return;
94    
95     printf("removing highlight\n");
96    
97     map_highlight_t *hl = map->highlight;
98     while(hl) {
99     map_highlight_t *next = hl->next;
100     canvas_item_destroy(hl->item);
101     g_free(hl);
102    
103     hl = next;
104     }
105    
106     map->highlight = NULL;
107     }
108    
109     gboolean map_hl_item_is_highlighted(map_t *map, map_item_t *item) {
110     map_highlight_t *hl = map->highlight;
111     while(hl) {
112     map_item_t *hl_item = canvas_item_get_user_data(hl->item);
113    
114     if(hl_item) {
115     if((hl_item->type == item->type) &&
116     (hl_item->ptr == item->ptr))
117     return TRUE;
118     }
119    
120     hl = hl->next;
121     }
122    
123     return FALSE;
124     }
125    
126     canvas_item_t *map_hl_circle_new(map_t *map, canvas_group_t group,
127     map_item_t *map_item,
128     gint x, gint y, gint radius, canvas_color_t color) {
129    
130     /* attach highlight object */
131     map_highlight_t **hl = &map->highlight;
132     while(*hl) hl = &((*hl)->next);
133     *hl = g_new0(map_highlight_t, 1);
134    
135     map_item->item = (*hl)->item =
136     canvas_circle_new(map, group, x, y, radius, 0, color, NO_COLOR);
137    
138     canvas_item_set_user_data((*hl)->item, map_item);
139    
140     canvas_item_destroy_connect((*hl)->item,
141     G_CALLBACK(map_hl_item_destroy_event), map_item);
142    
143     return (*hl)->item;
144     }
145    
146     canvas_item_t *map_hl_polygon_new(map_t *map, canvas_group_t group, map_item_t *map_item,
147     canvas_points_t *points, canvas_color_t color) {
148    
149     /* attach highlight object */
150     map_highlight_t **hl = &map->highlight;
151     while(*hl) hl = &((*hl)->next);
152     *hl = g_new0(map_highlight_t, 1);
153    
154     map_item->item = (*hl)->item =
155     canvas_polygon_new(map, group, points, 0, 0, color);
156    
157     canvas_item_set_user_data((*hl)->item, map_item);
158    
159     canvas_item_destroy_connect((*hl)->item,
160     G_CALLBACK(map_hl_item_destroy_event), map_item);
161    
162     return (*hl)->item;
163     }
164    
165     canvas_item_t *map_hl_polyline_new(map_t *map, canvas_group_t group, map_item_t *map_item,
166     canvas_points_t *points, gint width, canvas_color_t color) {
167    
168     /* attach highlight object */
169     map_highlight_t **hl = &map->highlight;
170     while(*hl) hl = &((*hl)->next);
171     *hl = g_new0(map_highlight_t, 1);
172    
173     map_item->item = (*hl)->item =
174     canvas_polyline_new(map, group, points, width, color);
175    
176     canvas_item_set_user_data((*hl)->item, map_item);
177    
178     canvas_item_destroy_connect((*hl)->item,
179     G_CALLBACK(map_hl_item_destroy_event), map_item);
180    
181     return (*hl)->item;
182     }