Contents of /trunk/src/map.h

Parent Directory Parent Directory | Revision Log Revision Log


Revision 153 - (hide annotations)
Mon Mar 30 11:14:20 2009 UTC (15 years, 2 months ago) by harbaum
File MIME type: text/plain
File size: 6421 byte(s)
Relation highlighting
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 153 #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_IHL) | (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 harbaum 153 MAP_TYPE_WAY,
52     MAP_TYPE_RELATION
53 harbaum 1 } 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 harbaum 153 relation_t *relation;
79 harbaum 1 void *ptr;
80     };
81     canvas_item_t *item;
82     } map_item_t;
83    
84     /* this is a chain of map_items which is attached to all entries */
85     /* in the osm tree (node_t, way_t, ...) to be able to get a link */
86     /* to the screen representation of a give node/way/etc */
87     typedef struct map_item_chain_s {
88     map_item_t *map_item;
89     struct map_item_chain_s *next;
90     } map_item_chain_t;
91    
92     typedef struct {
93     gint refcount;
94     float zoom; // zoom level (1.0 = 1m/pixel
95     struct { gint x,y; } scroll_offset; // initial scroll offset
96     } map_state_t;
97    
98     typedef struct map_s {
99     appdata_t *appdata;
100    
101     canvas_t *canvas;
102    
103     map_state_t *state;
104    
105     map_highlight_t *highlight; // list of elements used for highlighting
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 achadwick 12 #ifdef USE_GOOCANVAS
185     void map_scroll_to_if_offscreen(map_t *map, lpos_t *lpos);
186     #endif
187    
188 harbaum 1 /* 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 harbaum 15 map_item_t *map_real_item_at(map_t *map, gint x, gint y);
194 harbaum 1 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 harbaum 153 void map_relation_select(appdata_t *appdata, relation_t *relation);
201 harbaum 1
202     #endif // MAP_H