Contents of /trunk/src/map.h

Parent Directory Parent Directory | Revision Log Revision Log


Revision 15 - (show annotations)
Tue Dec 16 17:00:20 2008 UTC (15 years, 4 months ago) by harbaum
File MIME type: text/plain
File size: 6292 byte(s)
initial line mod support and some small fixes
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 #ifndef MAP_H
21 #define MAP_H
22
23 #include "osm.h"
24
25 #define MAP_LAYER_ALL (0xffff)
26 #define MAP_LAYER_OBJECTS_ONLY ((1<<CANVAS_GROUP_POLYGONS) | (1<<CANVAS_GROUP_WAYS_HL) | (1<<CANVAS_GROUP_WAYS_OL) | (1<<CANVAS_GROUP_WAYS) | (1<<CANVAS_GROUP_NODES_HL) | (1<<CANVAS_GROUP_NODES))
27
28 /* -------- all sizes are in meters ---------- */
29 #define MAP_COLOR_NONE 0x0
30 #define NO_COLOR CANVAS_COLOR(0x00,0x00,0x00,0x00)
31
32 #define RGB2CANVAS(a) (((a)<<8) | 0xff)
33 #define RGBA2CANVAS(a,b) (((a)<<8) | (b))
34
35 #define ZOOM_FACTOR_MENU (1.5)
36 #define ZOOM_FACTOR_WHEEL (1.1)
37 #define ZOOM_FACTOR_BUTTON (1.5)
38
39 /* the "drag limit" is the number of pixels the mouse/pen has to */
40 /* be moved so the action is actually considered dragging. This is */
41 /* to prevent accidential dragging when the user only intended to click */
42 /* something. This is especially useful when using a touchscreen. */
43 #ifndef USE_HILDON
44 #define MAP_DRAG_LIMIT 4
45 #else
46 #define MAP_DRAG_LIMIT 16
47 #endif
48
49 typedef enum {
50 MAP_TYPE_ILLEGAL=0,
51 MAP_TYPE_NODE,
52 MAP_TYPE_WAY
53 } map_type_t;
54
55 /* don't reorder these as some things in map.c */
56 /* rely on a certain order */
57 typedef enum {
58 MAP_ACTION_IDLE=0,
59 MAP_ACTION_NODE_ADD,
60 MAP_ACTION_BG_ADJUST,
61 MAP_ACTION_WAY_ADD,
62 MAP_ACTION_WAY_NODE_ADD,
63 MAP_ACTION_WAY_CUT,
64 MAP_ACTION_NUM
65 } map_action_t;
66
67 typedef struct map_highlight_s {
68 canvas_item_t *item;
69 struct map_highlight_s *next;
70 } map_highlight_t;
71
72 typedef struct map_item_s {
73 map_type_t type;
74 gboolean highlight;
75 union {
76 node_t *node;
77 way_t *way;
78 void *ptr;
79 };
80 canvas_item_t *item;
81 } map_item_t;
82
83 /* this is a chain of map_items which is attached to all entries */
84 /* in the osm tree (node_t, way_t, ...) to be able to get a link */
85 /* to the screen representation of a give node/way/etc */
86 typedef struct map_item_chain_s {
87 map_item_t *map_item;
88 struct map_item_chain_s *next;
89 } map_item_chain_t;
90
91 typedef struct {
92 gint refcount;
93 float zoom; // zoom level (1.0 = 1m/pixel
94 struct { gint x,y; } scroll_offset; // initial scroll offset
95 } map_state_t;
96
97 typedef struct map_s {
98 appdata_t *appdata;
99
100 canvas_t *canvas;
101
102 map_state_t *state;
103
104 map_highlight_t *highlight; // list of elements used for highlighting
105
106 canvas_item_t *group[CANVAS_GROUPS];
107
108 map_item_t selected; // the currently selected item (node or way)
109
110 canvas_item_t *cursor; // the cursor visible on the draw layer
111 canvas_item_t *touchnode; // the blue "touch node" on the draw layer
112
113 tag_t *last_node_tags; // used to "repeat" tagging
114 tag_t *last_way_tags;
115
116 /* background image related stuff */
117 struct {
118 GdkPixbuf *pix;
119 canvas_item_t *item;
120 struct { float x, y; } offset;
121 struct { float x, y; } scale;
122 } bg;
123
124 struct {
125 map_action_t type; // current action type in progress
126
127 struct { // action related variables/states
128 way_t *way;
129 way_t *extending, *ends_on; // ways touched by first and last node
130 };
131 } action;
132
133 /* variables required for pen/mouse handling */
134 struct {
135 gboolean is;
136 gboolean drag;
137 map_item_t *on_item;
138 struct { gint x,y; } at; // point mouse button was last pressed
139 struct { gint x,y; } so; // initial scroll offset
140 gboolean on_selected_node; // the currently clicked node
141 // (may be part of a selected way)
142 } pen_down;
143
144 struct style_s *style;
145
146 } map_t;
147
148 GtkWidget *map_new(appdata_t *appdata);
149 void map_state_free(map_state_t *state);
150 void map_init(appdata_t *appdata);
151 gboolean map_key_press_event(appdata_t *appdata, GdkEventKey *event);
152 void map_item_set_flags(map_item_t *map_item, int set, int clr);
153 void map_show_node(map_t *map, node_t *node);
154 void map_cmenu_show(map_t *map);
155 void map_highlight_refresh(appdata_t *appdata);
156
157 void map_item_redraw(appdata_t *appdata, map_item_t *map_item);
158
159 void map_clear(appdata_t *appdata, gint layer_mask);
160 void map_paint(appdata_t *appdata);
161
162 void map_action_set(appdata_t *appdata, map_action_t action);
163 void map_action_cancel(appdata_t *appdata);
164 void map_action_ok(appdata_t *appdata);
165
166 void map_delete_selected(appdata_t *appdata);
167
168 /* track stuff */
169 void map_track_draw(map_t *map, struct track_s *track);
170 struct track_seg_s;
171 void map_track_draw_seg(map_t *map, struct track_seg_s *seg);
172 void map_track_update_seg(map_t *map, struct track_seg_s *seg);
173 void map_track_remove(appdata_t *appdata);
174 void map_track_pos(appdata_t *appdata, lpos_t *lpos);
175
176 /* background stuff */
177 void map_set_bg_image(map_t *map, char *filename);
178 void map_remove_bg_image(map_t *map);
179
180 void map_hide_selected(appdata_t *appdata);
181 void map_show_all(appdata_t *appdata);
182
183 void map_set_zoom(map_t *map, double zoom, gboolean update_scroll_offsets);
184
185 #ifdef USE_GOOCANVAS
186 void map_scroll_to_if_offscreen(map_t *map, lpos_t *lpos);
187 #endif
188
189 /* various functions required by map_edit */
190 gboolean map_item_is_selected_node(map_t *map, map_item_t *map_item);
191 gboolean map_item_is_selected_way(map_t *map, map_item_t *map_item);
192 void map_item_chain_destroy(map_item_chain_t **chainP);
193 map_item_t *map_item_at(map_t *map, gint x, gint y);
194 map_item_t *map_real_item_at(map_t *map, gint x, gint y);
195 void map_item_deselect(appdata_t *appdata);
196 void map_way_delete(appdata_t *appdata, way_t *way);
197 void map_way_draw(map_t *map, way_t *way);
198 void map_way_select(appdata_t *appdata, way_t *way);
199 void map_outside_error(appdata_t *appdata);
200 void map_node_draw(map_t *map, node_t *node);
201
202 #endif // MAP_H