Contents of /trunk/src/map.h

Parent Directory Parent Directory | Revision Log Revision Log


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