Contents of /trunk/src/map.h

Parent Directory Parent Directory | Revision Log Revision Log


Revision 108 - (hide annotations)
Wed Mar 4 13:10:16 2009 UTC (15 years, 2 months ago) by harbaum
File MIME type: text/plain
File size: 6277 byte(s)
Tried to layer ways more nicely
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     #ifndef MAP_H
21     #define MAP_H
22    
23     #include "osm.h"
24    
25     #define MAP_LAYER_ALL (0xffff)
26 harbaum 108 #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_WAYS_INT) | (1<<CANVAS_GROUP_NODES_HL) | (1<<CANVAS_GROUP_NODES) | (1<<CANVAS_GROUP_WAYS_DIR))
27 harbaum 1
28     /* -------- all sizes are in meters ---------- */
29     #define MAP_COLOR_NONE 0x0
30     #define NO_COLOR CANVAS_COLOR(0x00,0x00,0x00,0x00)
31    
32 harbaum 22 #define RGBA_COMBINE(a,b) (((a)&~0xff) | ((b)&0xff))
33 harbaum 1
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     map_item_t selected; // the currently selected item (node or way)
106    
107     canvas_item_t *cursor; // the cursor visible on the draw layer
108     canvas_item_t *touchnode; // the blue "touch node" on the draw layer
109    
110     tag_t *last_node_tags; // used to "repeat" tagging
111     tag_t *last_way_tags;
112    
113     /* background image related stuff */
114     struct {
115     GdkPixbuf *pix;
116     canvas_item_t *item;
117     struct { float x, y; } offset;
118     struct { float x, y; } scale;
119     } bg;
120    
121     struct {
122     map_action_t type; // current action type in progress
123    
124     struct { // action related variables/states
125     way_t *way;
126     way_t *extending, *ends_on; // ways touched by first and last node
127     };
128     } action;
129    
130     /* variables required for pen/mouse handling */
131     struct {
132     gboolean is;
133     gboolean drag;
134     map_item_t *on_item;
135     struct { gint x,y; } at; // point mouse button was last pressed
136     struct { gint x,y; } so; // initial scroll offset
137     gboolean on_selected_node; // the currently clicked node
138     // (may be part of a selected way)
139     } pen_down;
140    
141     struct style_s *style;
142    
143     } map_t;
144    
145     GtkWidget *map_new(appdata_t *appdata);
146     void map_state_free(map_state_t *state);
147     void map_init(appdata_t *appdata);
148     gboolean map_key_press_event(appdata_t *appdata, GdkEventKey *event);
149     void map_item_set_flags(map_item_t *map_item, int set, int clr);
150     void map_show_node(map_t *map, node_t *node);
151     void map_cmenu_show(map_t *map);
152     void map_highlight_refresh(appdata_t *appdata);
153    
154     void map_item_redraw(appdata_t *appdata, map_item_t *map_item);
155    
156     void map_clear(appdata_t *appdata, gint layer_mask);
157     void map_paint(appdata_t *appdata);
158    
159     void map_action_set(appdata_t *appdata, map_action_t action);
160     void map_action_cancel(appdata_t *appdata);
161     void map_action_ok(appdata_t *appdata);
162    
163     void map_delete_selected(appdata_t *appdata);
164    
165     /* track stuff */
166     void map_track_draw(map_t *map, struct track_s *track);
167     struct track_seg_s;
168     void map_track_draw_seg(map_t *map, struct track_seg_s *seg);
169     void map_track_update_seg(map_t *map, struct track_seg_s *seg);
170     void map_track_remove(appdata_t *appdata);
171     void map_track_pos(appdata_t *appdata, lpos_t *lpos);
172    
173     /* background stuff */
174     void map_set_bg_image(map_t *map, char *filename);
175     void map_remove_bg_image(map_t *map);
176    
177     void map_hide_selected(appdata_t *appdata);
178     void map_show_all(appdata_t *appdata);
179    
180     void map_set_zoom(map_t *map, double zoom, gboolean update_scroll_offsets);
181    
182 achadwick 12 #ifdef USE_GOOCANVAS
183     void map_scroll_to_if_offscreen(map_t *map, lpos_t *lpos);
184     #endif
185    
186 harbaum 1 /* various functions required by map_edit */
187     gboolean map_item_is_selected_node(map_t *map, map_item_t *map_item);
188     gboolean map_item_is_selected_way(map_t *map, map_item_t *map_item);
189     void map_item_chain_destroy(map_item_chain_t **chainP);
190     map_item_t *map_item_at(map_t *map, gint x, gint y);
191 harbaum 15 map_item_t *map_real_item_at(map_t *map, gint x, gint y);
192 harbaum 1 void map_item_deselect(appdata_t *appdata);
193     void map_way_delete(appdata_t *appdata, way_t *way);
194     void map_way_draw(map_t *map, way_t *way);
195     void map_way_select(appdata_t *appdata, way_t *way);
196     void map_outside_error(appdata_t *appdata);
197     void map_node_draw(map_t *map, node_t *node);
198    
199     #endif // MAP_H