]> err.no Git - mapper/blob - src/map.h
Include settings.h so the banner macro hildon version works.
[mapper] / src / map.h
1 #include <config.h>
2
3 #ifndef _MAPPER_MAP_H
4 #define _MAPPER_MAP_H
5
6 #include <unistd.h>
7 #include <stdlib.h>
8 #include <string.h>
9 #include <strings.h>
10 #include <stddef.h>
11 #include <locale.h>
12 #include <math.h>
13 #include <errno.h>
14 #include <sys/wait.h>
15 #include <glib/gstdio.h>
16 #include <gtk/gtk.h>
17 #include <dbus/dbus-glib.h>
18
19 #include "utils.h"
20 #include "mapper-types.h"
21 #include "osm.h"
22
23 /** MAX_ZOOM defines the largest map zoom level we will download.
24  * (MAX_ZOOM - 1) is the largest map zoom level that the user can zoom to.
25  */
26 #define MAX_ZOOM 16
27
28 #define TILE_SIZE_PIXELS (256)
29 #define TILE_SIZE_P2 (8)
30
31 #define WORLD_SIZE_UNITS (2 << (MAX_ZOOM + TILE_SIZE_P2))
32
33 #define tile2grid(tile) ((tile) << 3)
34 #define grid2tile(grid) ((grid) >> 3)
35 #define tile2pixel(tile) ((tile) << 8)
36 #define pixel2tile(pixel) ((pixel) >> 8)
37 #define tile2unit(tile) ((tile) << (8 + _zoom))
38 #define unit2tile(unit) ((unit) >> (8 + _zoom))
39 #define tile2zunit(tile, zoom) ((tile) << (8 + zoom))
40 #define unit2ztile(unit, zoom) ((unit) >> (8 + zoom))
41
42 #define grid2pixel(grid) ((grid) << 5)
43 #define pixel2grid(pixel) ((pixel) >> 5)
44 #define grid2unit(grid) ((grid) << (5 + _zoom))
45 #define unit2grid(unit) ((unit) >> (5 + _zoom))
46
47 #define pixel2unit(pixel) ((pixel) << _zoom)
48 #define unit2pixel(pixel) ((pixel) >> _zoom)
49 #define pixel2zunit(pixel, zoom) ((pixel) << (zoom))
50
51 #define unit2bufx(unit) (unit2pixel(unit) - tile2pixel(_base_tilex))
52 #define bufx2unit(x) (pixel2unit(x) + tile2unit(_base_tilex))
53 #define unit2bufy(unit) (unit2pixel(unit) - tile2pixel(_base_tiley))
54 #define bufy2unit(y) (pixel2unit(y) + tile2unit(_base_tiley))
55
56 #define unit2x(unit) (unit2pixel(unit) - tile2pixel(_base_tilex) - _offsetx)
57 #define x2unit(x) (pixel2unit(x + _offsetx) + tile2unit(_base_tilex))
58 #define unit2y(unit) (unit2pixel(unit) - tile2pixel(_base_tiley) - _offsety)
59 #define y2unit(y) (pixel2unit(y + _offsety) + tile2unit(_base_tiley))
60
61 #define leadx2unit(mgps) (mgps.unitx + (_lead_ratio) * pixel2unit(mgps.vel_offsetx))
62 #define leady2unit(mgps) (mgps.unity + (0.6f*_lead_ratio)*pixel2unit(mgps.vel_offsety))
63
64 /* Pans are done two "grids" at a time, or 64 pixels. */
65 #define PAN_UNITS (grid2unit(2))
66
67 #define MACRO_RECALC_CENTER(mgps, center_unitx, center_unity) { \
68     switch(_center_mode) \
69     { \
70         case CENTER_LEAD: \
71             center_unitx = leadx2unit(mgps); \
72             center_unity = leady2unit(mgps); \
73             break; \
74         case CENTER_LATLON: \
75             center_unitx = mgps.unitx; \
76             center_unity = mgps.unity; \
77             break; \
78         default: \
79              center_unitx = _center.unitx; \
80              center_unity = _center.unity; \
81             ; \
82     } \
83 };
84
85 #define MACRO_RECALC_OFFSET() { \
86     _offsetx = grid2pixel(unit2grid(_center.unitx) - _screen_grids_halfwidth - tile2grid(_base_tilex)); \
87     _offsety = grid2pixel(unit2grid(_center.unity) - _screen_grids_halfheight - tile2grid(_base_tiley)); \
88 }
89
90 #define MACRO_RECALC_FOCUS_BASE() { \
91     _focus.unitx = x2unit(_screen_width_pixels * _center_ratio / 20); \
92     _focus.unity = y2unit(_screen_height_pixels * _center_ratio / 20); \
93 }
94
95 #define MACRO_QUEUE_DRAW_AREA() \
96     gtk_widget_queue_draw_area(_map_widget, 0, 0, _screen_width_pixels, _screen_height_pixels)
97
98 /* Render all on-map metadata an annotations, including POI and paths. */
99 #define MACRO_MAP_RENDER_DATA() { \
100     if(_show_poi) \
101         map_render_poi(); \
102     if(_show_tracks > 0) \
103         map_render_paths(); \
104 }
105
106 #define MACRO_RECALC_FOCUS_SIZE() { \
107     _focus_unitwidth = pixel2unit((10 - _center_ratio) * _screen_width_pixels / 10); \
108     _focus_unitheight = pixel2unit((10 - _center_ratio) * _screen_height_pixels / 10); \
109 }
110
111 #define MACRO_RECALC_CENTER_BOUNDS() { \
112   _min_center.unitx = pixel2unit(grid2pixel(_screen_grids_halfwidth)); \
113   _min_center.unity = pixel2unit(grid2pixel(_screen_grids_halfheight)); \
114   _max_center.unitx = WORLD_SIZE_UNITS-grid2unit(_screen_grids_halfwidth) - 1;\
115   _max_center.unity = WORLD_SIZE_UNITS-grid2unit(_screen_grids_halfheight)- 1;\
116 }
117
118 typedef enum {
119         MAP_MODE_NORMAL=0,
120         MAP_MODE_DRAW_TRACK,
121         MAP_MODE_DRAW_ROUTE,
122         MAP_MODE_SET_ROUTE_FROM,
123         MAP_MODE_SET_ROUTE_POINT,
124         MAP_MODE_SET_ROUTE_TO,
125         MAP_MODES
126 } MapMode;
127
128 /** Possible center modes.  The "WAS" modes imply no current center mode;
129  * they only hint at what the last center mode was, so that it can be
130  * recalled. */
131 typedef enum {
132         CENTER_WAS_LATLON = -2,
133         CENTER_WAS_LEAD = -1,
134         CENTER_MANUAL =0,
135         CENTER_LEAD = 1,
136         CENTER_LATLON = 2
137 } CenterMode;
138
139 /** VARIABLES FOR MAINTAINING STATE OF THE CURRENT VIEW. */
140
141 /** The "zoom" level defines the resolution of a pixel, from 0 to MAX_ZOOM.
142  * Each pixel in the current view is exactly (1 << _zoom) "units" wide. */
143
144 Point _min_center;
145 Point _max_center;
146 Point _focus;
147
148 /** The "base tile" is the upper-left tile in the pixmap. */
149 guint _base_tilex;
150 guint _base_tiley;
151
152 guint _zoom;                    /* zoom level, from 0 to MAX_ZOOM. */
153 Point _center;                  /* current center location, X. */
154
155 /** The "offset" defines the upper-left corner of the visible portion of the
156  * 1024x768 pixmap. */
157 guint _offsetx;
158 guint _offsety;
159
160 /** CACHED SCREEN INFORMATION THAT IS DEPENDENT ON THE CURRENT VIEW. */
161 guint _screen_grids_halfwidth;
162 guint _screen_grids_halfheight;
163 guint _screen_width_pixels;
164 guint _screen_height_pixels;
165
166 guint _focus_unitwidth;
167 guint _focus_unitheight;
168 guint _world_size_tiles;
169
170 gint _show_tracks;
171 gboolean _show_scale;
172 gboolean _show_velvec;
173 gboolean _show_poi;
174
175 guint _lead_ratio;
176 guint _center_ratio;
177 guint _draw_width;
178
179 guint _key_zoom_new;
180 guint _key_zoom_timeout_sid;
181
182 osm_location map_loc;
183
184 CenterMode _center_mode;
185
186 /** The widget that provides the visual display of the map. */
187 GtkWidget *_map_widget;
188
189 /** The backing pixmap of _map_widget. */
190 GdkPixmap *_map_pixmap;
191
192 GtkWidget *map_new(void);
193
194 gboolean map_key_zoom_timeout();
195
196 int map_zoom(gint zdir);
197 gboolean map_zoom_in(void);
198 gboolean map_zoom_out(void);
199 void map_set_autozoom(gboolean az, gfloat speed);
200 void map_render_path(Path * path, GdkGC ** gc);
201 void map_pan(gint delta_unitx, gint delta_unity);
202 void map_move_mark(void);
203 void map_set_mark(GpsData *gps);
204 void map_render_data(void);
205 gboolean map_render_tile(guint tilex, guint tiley, guint destx, guint desty, gboolean fast_fail);
206
207 void map_render_waypoint(guint x1, guint y1, GdkGC *gc);
208
209 void map_center_unit(guint new_center_unitx, guint new_center_unity);
210 void map_center_latlon(gdouble lat, gdouble lon);
211
212 gboolean map_goto_position(Position *pos);
213 gboolean map_update_location_from_center(void);
214
215 #endif