1 |
/* |
/* |
2 |
* Copyright (C) 2008 Till Harbaum <till@harbaum.org>. |
* Copyright (C) 2008-2009 Till Harbaum <till@harbaum.org>. |
3 |
* |
* |
4 |
* This file is part of GPXView. |
* This file is part of GPXView. |
5 |
* |
* |
17 |
* along with GPXView. If not, see <http://www.gnu.org/licenses/>. |
* along with GPXView. If not, see <http://www.gnu.org/licenses/>. |
18 |
*/ |
*/ |
19 |
|
|
20 |
|
/* |
21 |
|
* http://topo.geofabrik.de/relief/${z}/${x}/${y}.png 8-15 |
22 |
|
* http://topo.geofabrik.de/trail/${z}/${x}/${y}.png 8-15 |
23 |
|
*/ |
24 |
|
|
25 |
|
/* |
26 |
|
* TODO: |
27 |
|
* - make semi-transparent caches selectable |
28 |
|
*/ |
29 |
|
|
30 |
#include "gpxview.h" |
#include "gpxview.h" |
31 |
|
#include "converter.h" |
32 |
#include <math.h> // for isnan |
#include <math.h> // for isnan |
33 |
|
|
34 |
#ifdef ENABLE_OSM_GPS_MAP |
#ifdef ENABLE_OSM_GPS_MAP |
35 |
#include "osm-gps-map.h" |
#include "osm-gps-map.h" |
36 |
|
#include "osm-gps-map-osd-classic.h" |
37 |
#endif |
#endif |
38 |
|
|
39 |
#define GPS_DEFAULT_ZOOM 13 |
#if defined(USE_MAEMO) && (MAEMO_VERSION_MAJOR == 5) |
40 |
|
#include <gdk/gdkx.h> |
41 |
/* equatorial radius in meters */ |
#include <X11/Xatom.h> |
42 |
#define EQ_RADIUS (6378137.0) |
#endif |
|
|
|
|
#define RAD2DEG(a) (((a)*180.0)/M_PI) |
|
|
#define DEG2RAD(a) (((a)*M_PI)/180.0) |
|
43 |
|
|
44 |
typedef struct { |
/* any defined key enables key support */ |
45 |
appdata_t *appdata; |
#if (defined(MAP_KEY_FULLSCREEN) || \ |
46 |
GtkWidget *widget; |
defined(MAP_KEY_ZOOMIN) || \ |
47 |
GtkWidget *zoomin, *zoomout, *gps; |
defined(MAP_KEY_ZOOMOUT) || \ |
48 |
gint handler_id; |
defined(MAP_KEY_UP) || \ |
49 |
cache_t *press_on; |
defined(MAP_KEY_DOWN) || \ |
50 |
#if MAEMO_VERSION_MAJOR == 5 |
defined(MAP_KEY_LEFT) || \ |
51 |
GtkWidget *old_view; |
defined(MAP_KEY_RIGHT)) |
52 |
|
#include <gdk/gdkkeysyms.h> |
53 |
#endif |
#endif |
54 |
} map_context_t; |
|
55 |
|
/* default values */ |
56 |
|
#define MAP_SOURCE OSM_GPS_MAP_SOURCE_OPENCYCLEMAP |
57 |
|
#define GPS_DEFAULT_ZOOM 13 |
58 |
|
|
59 |
#define PROXY_KEY "/system/http_proxy/" |
#define PROXY_KEY "/system/http_proxy/" |
60 |
|
|
64 |
/* use environment settings if preset */ |
/* use environment settings if preset */ |
65 |
const char *proxy = g_getenv("http_proxy"); |
const char *proxy = g_getenv("http_proxy"); |
66 |
if(proxy) { |
if(proxy) { |
67 |
printf("http_proxy: %s\n", proxy); |
printf("map http proxy from env: %s\n", proxy); |
68 |
return proxy; |
return proxy; |
69 |
} |
} |
70 |
|
|
85 |
|
|
86 |
snprintf(proxy_buffer, sizeof(proxy_buffer), |
snprintf(proxy_buffer, sizeof(proxy_buffer), |
87 |
"http://%s:%u", host, port); |
"http://%s:%u", host, port); |
88 |
|
printf("map http proxy from gconf: %s\n ", proxy_buffer); |
89 |
|
|
90 |
g_free(host); |
g_free(host); |
91 |
} |
} |
95 |
return NULL; |
return NULL; |
96 |
} |
} |
97 |
|
|
|
static void map_zoom(map_context_t *context, int step) { |
|
|
gint zoom; |
|
|
OsmGpsMap *map = OSM_GPS_MAP(context->widget); |
|
|
g_object_get(map, "zoom", &zoom, NULL); |
|
|
zoom = osm_gps_map_set_zoom(map, zoom+step); |
|
98 |
|
|
99 |
/* enable/disable zoom buttons as required */ |
pos_t *map_gps_get_pos(map_context_t *context) { |
100 |
gtk_widget_set_sensitive(context->zoomin, zoom<17); |
static pos_t pos; |
|
gtk_widget_set_sensitive(context->zoomout, zoom>1); |
|
101 |
|
|
102 |
/* save new zoom */ |
if(context->gps.set & FIX_LATLON_SET) { |
103 |
context->appdata->map.zoom = zoom; |
pos.lat = context->gps.fix.latitude; |
104 |
|
pos.lon = context->gps.fix.longitude; |
105 |
|
return &pos; |
106 |
|
} |
107 |
|
|
108 |
|
return NULL; |
109 |
} |
} |
110 |
|
|
111 |
static gboolean |
pos_t *map_get_pos(map_context_t *context) { |
112 |
cb_map_zoomin(GtkButton *button, map_context_t *context) { |
pos_t *pos = &context->appdata->home; |
113 |
map_zoom(context, +1); |
|
114 |
return FALSE; |
if(context->appdata->active_location) { |
115 |
|
int i = context->appdata->active_location-1; |
116 |
|
location_t *loc = context->appdata->location; |
117 |
|
while(i--) loc = loc->next; |
118 |
|
pos = &loc->pos; |
119 |
|
} |
120 |
|
|
121 |
|
if(context->appdata->use_gps) |
122 |
|
pos = map_gps_get_pos(context); |
123 |
|
|
124 |
|
return pos; |
125 |
} |
} |
126 |
|
|
127 |
static gboolean |
float map_gps_get_heading(map_context_t *context) { |
128 |
cb_map_zoomout(GtkButton *button, map_context_t *context) { |
if(context->gps.set & FIX_TRACK_SET) |
129 |
map_zoom(context, -1); |
return context->gps.fix.track; |
130 |
return FALSE; |
|
131 |
|
return NAN; |
132 |
} |
} |
133 |
|
|
134 |
static gboolean |
float map_gps_get_eph(map_context_t *context) { |
135 |
cb_map_gps(GtkButton *button, map_context_t *context) { |
if(context->gps.set & FIX_HERR_SET) |
136 |
pos_t *refpos = get_pos(context->appdata); |
return context->gps.fix.eph; |
|
if(refpos && !isnan(refpos->lat) && !isnan(refpos->lon)) { |
|
|
osm_gps_map_set_mapcenter(OSM_GPS_MAP(context->widget), |
|
|
refpos->lat, refpos->lon, GPS_DEFAULT_ZOOM); |
|
|
} else { |
|
|
/* no coordinates given: display the entire world */ |
|
|
osm_gps_map_set_mapcenter(OSM_GPS_MAP(context->widget), |
|
|
0.0, 0.0, 1); |
|
|
} |
|
137 |
|
|
138 |
return FALSE; |
return NAN; |
139 |
} |
} |
140 |
|
|
141 |
static GtkWidget |
/* callback called by the gps layer whenever gps state changes */ |
142 |
*map_add_button(int icon, GCallback cb, gpointer data, |
static void |
143 |
char *tooltip) { |
gps_callback(gps_mask_t set, struct gps_t *fix, void *data) { |
144 |
GtkWidget *button = gtk_button_new(); |
map_context_t *context = (map_context_t*)data; |
145 |
gtk_button_set_image(GTK_BUTTON(button), icon_get_widget(ICON_MISC, icon)); |
|
146 |
g_signal_connect(button, "clicked", cb, data); |
printf("map: gps callback\n"); |
147 |
#ifndef USE_MAEMO |
|
148 |
gtk_widget_set_tooltip_text(button, tooltip); |
context->gps.set = set; |
149 |
#endif |
memcpy(&context->gps.fix, fix, sizeof(struct gps_t)); |
150 |
return button; |
} |
151 |
|
|
152 |
|
static void |
153 |
|
cb_map_gps(osd_button_t but, map_context_t *context) { |
154 |
|
|
155 |
|
if(but == OSD_GPS) { |
156 |
|
pos_t *refpos = get_pos(context->appdata); |
157 |
|
if(refpos && !isnan(refpos->lat) && !isnan(refpos->lon)) { |
158 |
|
gint zoom; |
159 |
|
g_object_get(OSM_GPS_MAP(context->widget), "zoom", &zoom, NULL); |
160 |
|
if(zoom < 10) |
161 |
|
osm_gps_map_set_mapcenter(OSM_GPS_MAP(context->widget), |
162 |
|
refpos->lat, refpos->lon, GPS_DEFAULT_ZOOM); |
163 |
|
else |
164 |
|
osm_gps_map_set_center(OSM_GPS_MAP(context->widget), |
165 |
|
refpos->lat, refpos->lon); |
166 |
|
|
167 |
|
/* re-enable centering */ |
168 |
|
g_object_set(context->widget, "auto-center", TRUE, NULL); |
169 |
|
} else { |
170 |
|
/* no coordinates given: display the entire world */ |
171 |
|
osm_gps_map_set_mapcenter(OSM_GPS_MAP(context->widget), |
172 |
|
0.0, 0.0, 1); |
173 |
|
} |
174 |
|
} |
175 |
|
} |
176 |
|
|
177 |
|
static int dist2pixel(map_context_t *context, float km, float lat) { |
178 |
|
return 1000.0*km/osm_gps_map_get_scale(OSM_GPS_MAP(context->widget)); |
179 |
} |
} |
180 |
|
|
181 |
static gboolean map_gps_update(gpointer data) { |
static gboolean map_gps_update(gpointer data) { |
182 |
map_context_t *context = (map_context_t*)data; |
map_context_t *context = (map_context_t*)data; |
183 |
|
|
184 |
|
#ifdef USE_MAEMO |
185 |
|
if(context->appdata->goto_disable_screensaver) |
186 |
|
if(osso_display_blanking_pause(context->appdata->osso_context) != OSSO_OK) |
187 |
|
fprintf(stderr, "error with display blank\n"); |
188 |
|
#endif |
189 |
|
|
190 |
/* get reference position ... */ |
/* get reference position ... */ |
191 |
pos_t *refpos = get_pos(context->appdata); |
pos_t *refpos = map_get_pos(context); |
192 |
gboolean ok = (refpos!= NULL) && !isnan(refpos->lat) && !isnan(refpos->lon); |
gboolean ok = (refpos!= NULL) && !isnan(refpos->lat) && !isnan(refpos->lon); |
193 |
|
|
194 |
/* ... and enable "goto" button if it's valid */ |
/* ... and enable "goto" button if it's valid */ |
195 |
gtk_widget_set_sensitive(context->gps, ok); |
if(ok != context->goto_is_enabled) { |
196 |
|
osm_gps_map_osd_enable_gps (OSM_GPS_MAP(context->widget), |
197 |
|
OSM_GPS_MAP_OSD_CALLBACK(ok?cb_map_gps:NULL), context); |
198 |
|
context->goto_is_enabled = ok; |
199 |
|
} |
200 |
|
|
201 |
if(ok) { |
if(ok) { |
202 |
float heading = NAN; |
float heading = NAN; |
203 |
int radius = 0; |
int radius = 0; |
204 |
|
|
205 |
if(context->appdata->use_gps) { |
if(context->appdata->use_gps) { |
206 |
heading = gps_get_heading(context->appdata); |
heading = map_gps_get_heading(context); |
207 |
|
|
208 |
/* get error */ |
/* get error */ |
209 |
float eph = gps_get_eph(context->appdata); |
float eph = map_gps_get_eph(context); |
210 |
if(!isnan(eph)) { |
if(!isnan(eph)) |
211 |
|
radius = dist2pixel(context, eph/1000, refpos->lat); |
|
/* world at zoom 1 == 512 pixels */ |
|
|
gint zoom; |
|
|
g_object_get(OSM_GPS_MAP(context->widget), "zoom", &zoom, NULL); |
|
|
float m_per_pix = |
|
|
cos(DEG2RAD(refpos->lat))*2*M_PI*EQ_RADIUS/(1<<(8+zoom)); |
|
|
|
|
|
radius = eph/m_per_pix; |
|
|
} |
|
212 |
} |
} |
213 |
|
|
214 |
|
/* TODO: in order to save energy: only draw if state actually changed */ |
215 |
|
|
216 |
g_object_set(context->widget, "gps-track-highlight-radius", radius, NULL); |
g_object_set(context->widget, "gps-track-highlight-radius", radius, NULL); |
217 |
osm_gps_map_draw_gps(OSM_GPS_MAP(context->widget), |
osm_gps_map_draw_gps(OSM_GPS_MAP(context->widget), |
218 |
refpos->lat, refpos->lon, heading); |
refpos->lat, refpos->lon, heading); |
222 |
return TRUE; |
return TRUE; |
223 |
} |
} |
224 |
|
|
225 |
static gboolean on_map_configure(GtkWidget *widget, |
static void map_draw_cache(GtkWidget *map, cache_t *cache, gboolean semi) { |
226 |
GdkEventConfigure *event, |
int type = semi?ICON_CACHE_TYPE_SEMI:ICON_CACHE_TYPE; |
|
map_context_t *context) { |
|
227 |
|
|
228 |
/* set default values if they are invalid */ |
GdkPixbuf *icon = icon_get(type, cache->type); |
229 |
if(!context->appdata->map.zoom || |
GdkPixbuf *over = NULL; |
230 |
isnan(context->appdata->map.pos.lat) || |
|
231 |
isnan(context->appdata->map.pos.lon)) { |
if(cache->mine) over = icon_get(type, 14); |
232 |
printf("no valid map position found\n"); |
else if(cache->found) over = icon_get(type, 12); |
233 |
|
else if(cache->notes) { |
234 |
pos_t *refpos = get_pos(context->appdata); |
if(cache->notes->found) over = icon_get(type, 12); |
235 |
if(refpos && !isnan(refpos->lat) && !isnan(refpos->lon)) { |
else if(cache->notes->override) over = icon_get(type, 11); |
236 |
/* use gps position if present */ |
else over = icon_get(type, 13); |
|
context->appdata->map.pos = *refpos; |
|
|
context->appdata->map.zoom = GPS_DEFAULT_ZOOM; |
|
|
} else { |
|
|
/* use world map otherwise */ |
|
|
context->appdata->map.pos.lat = 0.0; |
|
|
context->appdata->map.pos.lon = 0.0; |
|
|
context->appdata->map.zoom = 1; |
|
|
} |
|
237 |
} |
} |
238 |
|
|
239 |
/* jump to initial position */ |
pos_t *pos = &cache->pos; |
240 |
osm_gps_map_set_mapcenter(OSM_GPS_MAP(context->widget), |
/* check if there's also an overwritten coordinate */ |
241 |
context->appdata->map.pos.lat, |
if(cache->notes && cache->notes->override) |
242 |
context->appdata->map.pos.lon, |
pos = &cache->notes->pos; |
|
context->appdata->map.zoom); |
|
|
|
|
|
return FALSE; |
|
|
} |
|
243 |
|
|
244 |
static void map_draw_cachelist(GtkWidget *map, cache_t *cache) { |
if(!isnan(pos->lat) && !isnan(pos->lon)) { |
|
while(cache) { |
|
|
GdkPixbuf *icon = icon_get(ICON_CACHE_TYPE, cache->type); |
|
|
|
|
245 |
osm_gps_map_add_image(OSM_GPS_MAP(map), |
osm_gps_map_add_image(OSM_GPS_MAP(map), |
246 |
cache->pos.lat, cache->pos.lon, icon); |
pos->lat, pos->lon, icon); |
247 |
|
if(over) |
248 |
cache = cache->next; |
osm_gps_map_add_image(OSM_GPS_MAP(map), |
249 |
|
pos->lat, pos->lon, over); |
250 |
} |
} |
251 |
} |
} |
252 |
|
|
253 |
/* draw a nice popup */ |
static void map_draw_wpt(GtkWidget *map, cache_t *cache, wpt_t *wpt) { |
254 |
typedef struct { |
/* only draw wpts that don't equal the main point */ |
255 |
appdata_t *appdata; |
if(pos_differ(&cache->pos, &wpt->pos)) { |
256 |
GtkWidget *window; |
if(!isnan(wpt->pos.lat) && !isnan(wpt->pos.lon)) { |
257 |
GMainLoop *loop; |
GdkPixbuf *icon = |
258 |
} popup_context_t; |
icon_get(ICON_WPT, (wpt->sym!=WPT_SYM_UNKNOWN)? |
259 |
|
wpt->sym:WPT_SYM_REFPOINT); |
260 |
/* draw shape */ |
|
261 |
#define ARROW_BORDER 20 |
osm_gps_map_add_image(OSM_GPS_MAP(map), |
262 |
#define CORNER_RADIUS 10 |
wpt->pos.lat, wpt->pos.lon, icon); |
263 |
|
} |
|
#ifndef USE_MAEMO |
|
|
#define POPUP_WIDTH 300 |
|
|
#define POPUP_HEIGHT 100 |
|
|
#else |
|
|
#define POPUP_WIDTH 350 |
|
|
#define POPUP_HEIGHT 120 |
|
|
#endif |
|
|
|
|
|
static gboolean |
|
|
pointer_in_window(GtkWidget *widget, gint x_root, gint y_root) { |
|
|
if(GTK_WIDGET_MAPPED(gtk_widget_get_toplevel(widget))) { |
|
|
gint window_x, window_y; |
|
|
|
|
|
gdk_window_get_position(gtk_widget_get_toplevel(widget)->window, |
|
|
&window_x, &window_y); |
|
|
|
|
|
if(x_root >= window_x && x_root < window_x + widget->allocation.width && |
|
|
y_root >= window_y && y_root < window_y + widget->allocation.height) |
|
|
return TRUE; |
|
264 |
} |
} |
|
|
|
|
return FALSE; |
|
|
} |
|
|
|
|
|
static gboolean |
|
|
on_button_press_event(GtkWidget *widget, |
|
|
GdkEventButton *event, popup_context_t *context) { |
|
|
gboolean in = pointer_in_window(widget, event->x_root, event->y_root); |
|
|
|
|
|
printf("overlay button press (in = %d)\n", in); |
|
|
return !in; |
|
265 |
} |
} |
266 |
|
|
267 |
static gboolean |
static void map_draw_gpx(appdata_t *appdata, cache_display_t *caches, |
268 |
on_button_release_event(GtkWidget *widget, |
GtkWidget *map, gpx_t *gpx, |
269 |
GdkEventButton *event, popup_context_t *context) { |
cache_t *nav, gboolean semi) { |
270 |
gboolean in = pointer_in_window(widget, event->x_root, event->y_root); |
if(!gpx->notes_loaded) { |
271 |
|
notes_load_all(appdata, gpx); |
272 |
printf("overlay button release (in = %d)\n", in); |
gpx->notes_loaded = TRUE; |
|
|
|
|
if(!in) { |
|
|
printf("destroying popup\n"); |
|
|
gtk_widget_destroy(gtk_widget_get_toplevel(widget)); |
|
273 |
} |
} |
274 |
|
|
275 |
return !in; |
cache_t *cache = gpx->cache; |
276 |
} |
while(cache) { |
277 |
|
/* search if we have that cache already in our list/displayed */ |
278 |
static void |
int i=0; |
279 |
shutdown_loop(popup_context_t *context) { |
while(caches[i].id && (strcmp(caches[i].id, cache->id) != 0)) |
280 |
if(g_main_loop_is_running(context->loop)) |
i++; |
281 |
g_main_loop_quit(context->loop); |
|
282 |
} |
if(!caches[i].id) { |
283 |
|
/* if nav is given draw all other caches semitransparent. */ |
284 |
|
/* if nav is not given do what semi sais */ |
285 |
|
map_draw_cache(map, cache, nav?(cache != nav):semi); |
286 |
|
caches[i].id = cache->id; |
287 |
|
|
288 |
|
/* also draw waypoints of nav cache */ |
289 |
|
if(nav && cache == nav) { |
290 |
|
wpt_t *wpt = cache->wpt; |
291 |
|
while(wpt) { |
292 |
|
map_draw_wpt(map, cache, wpt); |
293 |
|
wpt = wpt->next; |
294 |
|
} |
295 |
|
} |
296 |
|
} |
297 |
|
|
298 |
static gint |
cache = cache->next; |
299 |
run_delete_handler(GtkWindow *window, GdkEventAny *event, |
} |
|
popup_context_t *context) { |
|
|
shutdown_loop(context); |
|
|
return TRUE; /* Do not destroy */ |
|
300 |
} |
} |
301 |
|
|
302 |
static void |
static cache_t *cache_search_first(gpx_t *gpx, cache_t *cache) { |
303 |
run_destroy_handler(GtkWindow *window, popup_context_t *context) { |
while(gpx) { |
304 |
/* shutdown_loop will be called by run_unmap_handler */ |
cache_t *cur = gpx->cache; |
305 |
printf("popup destroyed\n"); |
while(cur) { |
306 |
} |
/* we do a string comparision to make sure that if copies */ |
307 |
|
/* exist, we get the original one */ |
308 |
|
if(!strcmp(cache->id, cur->id)) |
309 |
|
return cur; |
310 |
|
|
311 |
static void |
cur = cur->next; |
312 |
run_unmap_handler(GtkWindow *window, popup_context_t *context) { |
} |
313 |
shutdown_loop(context); |
gpx = gpx->next; |
314 |
|
} |
315 |
|
g_assert(FALSE); |
316 |
|
return NULL; |
317 |
} |
} |
318 |
|
|
319 |
static void popup_window_shape(GtkWidget *window, int tip_x, int tip_y) { |
/* draw geocaches and set window title */ |
320 |
GdkBitmap *mask = gdk_pixmap_new(NULL, POPUP_WIDTH, POPUP_HEIGHT, 1); |
static void map_setup(map_context_t *context) { |
321 |
|
char *name = NULL; |
|
GdkGC *gc = gdk_gc_new(mask); |
|
|
GdkColormap *colormap; |
|
|
GdkColor black; |
|
|
GdkColor white; |
|
|
|
|
|
/* get black/white color values */ |
|
|
colormap = gdk_colormap_get_system(); |
|
|
gdk_color_black(colormap, &black); |
|
|
gdk_color_white(colormap, &white); |
|
|
|
|
|
/* erase */ |
|
|
gdk_gc_set_foreground(gc, &black); |
|
|
gdk_gc_set_background(gc, &white); |
|
|
|
|
|
/* erase background */ |
|
|
gdk_draw_rectangle(mask, gc, TRUE, 0, 0, POPUP_WIDTH, POPUP_HEIGHT); |
|
|
|
|
|
gdk_gc_set_foreground(gc, &white); |
|
|
gdk_gc_set_background(gc, &black); |
|
|
|
|
|
/* the tip is always above or below the "bubble" but never at its side */ |
|
|
guint tip_offset = (tip_y == 0)?ARROW_BORDER:0; |
|
|
|
|
|
gdk_draw_rectangle(mask, gc, TRUE, |
|
|
0, tip_offset + CORNER_RADIUS, |
|
|
POPUP_WIDTH, |
|
|
POPUP_HEIGHT - 2*CORNER_RADIUS - ARROW_BORDER); |
|
322 |
|
|
323 |
gdk_draw_rectangle(mask, gc, TRUE, |
int cache_num = gpx_total_caches_global(context->appdata->gpx); |
|
CORNER_RADIUS, tip_offset, |
|
|
POPUP_WIDTH - 2*CORNER_RADIUS, |
|
|
POPUP_HEIGHT - ARROW_BORDER); |
|
|
|
|
|
int off[][2] = { |
|
|
{ CORNER_RADIUS, tip_offset + CORNER_RADIUS }, |
|
|
{ POPUP_WIDTH - CORNER_RADIUS, tip_offset + CORNER_RADIUS }, |
|
|
{ POPUP_WIDTH - CORNER_RADIUS, |
|
|
POPUP_HEIGHT - CORNER_RADIUS - ARROW_BORDER + tip_offset}, |
|
|
{ CORNER_RADIUS, |
|
|
POPUP_HEIGHT - CORNER_RADIUS - ARROW_BORDER + tip_offset}}; |
|
324 |
|
|
325 |
int i; |
if(context->caches_displayed && (cache_num != context->cache_list_len)) { |
326 |
for(i=0;i<4;i++) { |
// printf("re-alloc because %p %d/%d\n", context->caches_displayed, |
327 |
gdk_draw_arc(mask, gc, TRUE, |
// cache_num, context->cache_list_len); |
328 |
off[i][0]-CORNER_RADIUS, off[i][1]-CORNER_RADIUS, |
g_free(context->caches_displayed); |
329 |
2*CORNER_RADIUS, 2*CORNER_RADIUS, |
context->caches_displayed = NULL; |
330 |
0, 360*64); |
context->cache_list_len = 0; |
331 |
} |
} |
332 |
|
|
333 |
GdkPoint points[3] = { {POPUP_WIDTH*1/3, POPUP_HEIGHT/2}, |
/* allocate buffer */ |
334 |
{POPUP_WIDTH*2/3, POPUP_HEIGHT/2}, |
if(cache_num && !context->caches_displayed) { |
335 |
{tip_x,tip_y} }; |
context->cache_list_len = cache_num; |
336 |
gdk_draw_polygon(mask, gc, TRUE, points, 3); |
context->caches_displayed = g_new0(cache_display_t, cache_num+1); |
337 |
|
printf("allocated space to handle %d map icons\n", cache_num); |
338 |
|
} |
|
gdk_window_shape_combine_mask(window->window, mask, 0, 0); |
|
|
} |
|
|
|
|
|
/* create a left aligned label (normal ones are centered) */ |
|
|
static GtkWidget *gtk_label_left_new(char *str) { |
|
|
GtkWidget *label = gtk_label_new(str); |
|
|
gtk_misc_set_alignment(GTK_MISC(label), 0.f, .5f); |
|
|
return label; |
|
|
} |
|
339 |
|
|
340 |
/* the small labels are actually only on maemo small */ |
if(context->appdata->search_results && !context->appdata->cur_cache) { |
341 |
#ifdef USE_MAEMO |
if(context->state != MAP_SEARCH) { |
342 |
#define MARKUP_SMALL "<span size='small'>%s</span>" |
printf("map_setup(SEARCH)\n"); |
343 |
GtkWidget *gtk_label_small_left_new(char *str) { |
|
344 |
GtkWidget *label = gtk_label_new(""); |
/* clear any pending balloon */ |
345 |
char *markup = g_markup_printf_escaped(MARKUP_SMALL, str); |
context->balloon = NULL; |
346 |
gtk_label_set_markup(GTK_LABEL(label), markup); |
osm_gps_map_osd_clear_balloon (OSM_GPS_MAP(context->widget)); |
347 |
g_free(markup); |
|
348 |
gtk_misc_set_alignment(GTK_MISC(label), 0.f, .5f); |
#ifdef OSD_NAV |
349 |
return label; |
/* no navigation in this mode */ |
350 |
} |
osm_gps_map_osd_clear_nav (OSM_GPS_MAP(context->widget)); |
|
#define gtk_label_big_left_new(a) gtk_label_left_new(a) |
|
|
#else |
|
|
#define gtk_label_small_left_new(a) gtk_label_left_new(a) |
|
|
#define MARKUP_BIG "<span size='x-large'>%s</span>" |
|
|
GtkWidget *gtk_label_big_left_new(char *str) { |
|
|
GtkWidget *label = gtk_label_new(""); |
|
|
char *markup = g_markup_printf_escaped(MARKUP_BIG, str); |
|
|
gtk_label_set_markup(GTK_LABEL(label), markup); |
|
|
g_free(markup); |
|
|
gtk_misc_set_alignment(GTK_MISC(label), 0.f, .5f); |
|
|
return label; |
|
|
} |
|
351 |
#endif |
#endif |
352 |
|
|
353 |
void cache_popup(map_context_t *mcontext, cache_t *cache) { |
/* clear all existing cache images */ |
354 |
popup_context_t pcontext; |
osm_gps_map_clear_images (OSM_GPS_MAP(context->widget)); |
|
pcontext.appdata = mcontext->appdata; |
|
|
|
|
|
pcontext.window = gtk_window_new(GTK_WINDOW_POPUP); |
|
|
gtk_widget_realize(pcontext.window); |
|
|
gtk_window_set_default_size(GTK_WINDOW(pcontext.window), |
|
|
POPUP_WIDTH, POPUP_HEIGHT); |
|
|
gtk_window_resize(GTK_WINDOW(pcontext.window), POPUP_WIDTH, POPUP_HEIGHT); |
|
|
// gtk_window_set_resizable(GTK_WINDOW(pcontext.window), FALSE); |
|
|
gtk_window_set_transient_for(GTK_WINDOW(pcontext.window), |
|
|
GTK_WINDOW(mcontext->appdata->window)); |
|
|
gtk_window_set_keep_above(GTK_WINDOW(pcontext.window), TRUE); |
|
|
gtk_window_set_destroy_with_parent(GTK_WINDOW(pcontext.window), TRUE); |
|
|
gtk_window_set_gravity(GTK_WINDOW(pcontext.window), GDK_GRAVITY_STATIC); |
|
|
gtk_window_set_modal(GTK_WINDOW(pcontext.window), TRUE); |
|
|
|
|
|
/* connect events */ |
|
|
g_signal_connect(G_OBJECT(pcontext.window), "button-press-event", |
|
|
G_CALLBACK(on_button_press_event), &pcontext); |
|
|
g_signal_connect(G_OBJECT(pcontext.window), "button-release-event", |
|
|
G_CALLBACK(on_button_release_event), &pcontext); |
|
|
g_signal_connect(G_OBJECT(pcontext.window), "delete-event", |
|
|
G_CALLBACK(run_delete_handler), &pcontext); |
|
|
g_signal_connect(G_OBJECT(pcontext.window), "destroy", |
|
|
G_CALLBACK(run_destroy_handler), &pcontext); |
|
|
g_signal_connect(G_OBJECT(pcontext.window), "unmap", |
|
|
G_CALLBACK(run_unmap_handler), &pcontext); |
|
|
|
|
|
gdk_pointer_grab(pcontext.window->window, TRUE, |
|
|
GDK_BUTTON_PRESS_MASK | GDK_BUTTON_RELEASE_MASK | GDK_BUTTON_MOTION_MASK, |
|
|
NULL, NULL, GDK_CURRENT_TIME); |
|
|
gtk_grab_add(pcontext.window); |
|
|
|
|
|
/* check whether cache is in upper or lower half of window */ |
|
|
gint x, y, sx, sy; |
|
|
osm_gps_map_geographic_to_screen(OSM_GPS_MAP(mcontext->widget), |
|
|
cache->pos.lat, cache->pos.lon, |
|
|
&sx, &sy); |
|
|
|
|
|
gdk_window_get_origin(mcontext->widget->window, &x, &y); |
|
|
|
|
|
gint ax = 0, ay = 0; |
|
|
if(sx > mcontext->widget->allocation.width/2) |
|
|
ax = POPUP_WIDTH; |
|
355 |
|
|
356 |
if(sy > mcontext->widget->allocation.height/2) |
if(context->caches_displayed) { |
357 |
ay = POPUP_HEIGHT; |
memset(context->caches_displayed, 0, |
358 |
|
(cache_num+1) * sizeof(cache_display_t)); |
359 |
|
|
360 |
|
/* draw search results and all other gpx files are semi-transparent */ |
361 |
|
map_draw_gpx(context->appdata, context->caches_displayed, |
362 |
|
context->widget, context->appdata->search_results, |
363 |
|
NULL, FALSE); |
364 |
|
|
365 |
|
gpx_t *gpx = context->appdata->gpx; |
366 |
|
while(gpx) { |
367 |
|
map_draw_gpx(context->appdata, context->caches_displayed, |
368 |
|
context->widget, gpx, NULL, TRUE); |
369 |
|
|
370 |
#if !defined(USE_MAEMO) || (MAEMO_VERSION_MAJOR < 5) |
gpx = gpx->next; |
371 |
GdkColor color; |
} |
372 |
gdk_color_parse("darkgray", &color); |
} |
373 |
gtk_widget_modify_bg(GTK_WIDGET(pcontext.window), GTK_STATE_NORMAL, &color); |
name = g_strdup(_("Search results")); |
374 |
|
context->state = MAP_SEARCH; |
375 |
|
} |
376 |
|
} else if(!context->appdata->cur_gpx && !context->appdata->cur_cache) { |
377 |
|
if(context->state != MAP_ALL) { |
378 |
|
printf("map_setup(ALL)\n"); |
379 |
|
|
380 |
|
/* clear any pending balloon */ |
381 |
|
context->balloon = NULL; |
382 |
|
osm_gps_map_osd_clear_balloon (OSM_GPS_MAP(context->widget)); |
383 |
|
|
384 |
|
#ifdef OSD_NAV |
385 |
|
/* no navigation in this mode */ |
386 |
|
osm_gps_map_osd_clear_nav (OSM_GPS_MAP(context->widget)); |
387 |
#endif |
#endif |
388 |
|
|
389 |
gtk_window_move(GTK_WINDOW(pcontext.window), |
/* clear all existing cache images */ |
390 |
x + mcontext->widget->allocation.x + sx - ax, |
osm_gps_map_clear_images (OSM_GPS_MAP(context->widget)); |
391 |
y + mcontext->widget->allocation.y + sy - ay); |
if(context->caches_displayed) { |
392 |
|
memset(context->caches_displayed, 0, |
393 |
|
(cache_num+1) * sizeof(cache_display_t)); |
394 |
GtkWidget *alignment = gtk_alignment_new(0.5, 0.5, 1.0, 1.0); |
|
395 |
gtk_alignment_set_padding(GTK_ALIGNMENT(alignment), |
/* draw all geocaches and none is semi-transparent */ |
396 |
CORNER_RADIUS/2 + (ay?0:ARROW_BORDER), |
gpx_t *gpx = context->appdata->gpx; |
397 |
CORNER_RADIUS/2 + (ay?ARROW_BORDER:0), |
while(gpx) { |
398 |
CORNER_RADIUS, CORNER_RADIUS); |
map_draw_gpx(context->appdata, context->caches_displayed, |
399 |
|
context->widget, gpx, NULL, FALSE); |
400 |
/* --- actual content ---- */ |
gpx = gpx->next; |
401 |
GtkWidget *vbox = gtk_vbox_new(FALSE, 0); |
} |
402 |
|
|
403 |
if(cache->id) { |
{ |
404 |
GtkWidget *ihbox = gtk_hbox_new(FALSE, 0); |
int i=0; |
405 |
|
while(context->caches_displayed[i].id) i++; |
406 |
gtk_box_pack_start(GTK_BOX(ihbox), |
printf("number of caches actually displayed: %d\n", i); |
407 |
icon_get_widget(ICON_CACHE_TYPE, cache->type), |
} |
408 |
FALSE, FALSE, 5); |
} |
409 |
|
name = g_strdup(_("all")); |
410 |
gtk_box_pack_start_defaults(GTK_BOX(ihbox), |
context->state = MAP_ALL; |
411 |
gtk_label_big_left_new(cache->id)); |
} |
412 |
|
} else if(!context->appdata->cur_cache) { |
413 |
|
if(context->state != MAP_GPX) { |
414 |
|
printf("map_setup(GPX)\n"); |
415 |
|
|
416 |
|
/* clear any pending balloon */ |
417 |
|
context->balloon = NULL; |
418 |
|
osm_gps_map_osd_clear_balloon (OSM_GPS_MAP(context->widget)); |
419 |
|
|
420 |
|
#ifdef OSD_NAV |
421 |
|
/* no navigation in this mode */ |
422 |
|
osm_gps_map_osd_clear_nav (OSM_GPS_MAP(context->widget)); |
423 |
|
#endif |
424 |
|
|
425 |
gtk_box_pack_start_defaults(GTK_BOX(vbox), ihbox); |
/* clear all existing cache images */ |
426 |
} |
osm_gps_map_clear_images (OSM_GPS_MAP(context->widget)); |
427 |
|
if(context->caches_displayed) { |
428 |
|
memset(context->caches_displayed, 0, |
429 |
|
(cache_num+1) * sizeof(cache_display_t)); |
430 |
|
|
431 |
|
/* draw all geocaches and all other gpx files are semi-transparent */ |
432 |
|
map_draw_gpx(context->appdata, context->caches_displayed, |
433 |
|
context->widget, context->appdata->cur_gpx, NULL, FALSE); |
434 |
|
|
435 |
|
gpx_t *gpx = context->appdata->gpx; |
436 |
|
while(gpx) { |
437 |
|
if(gpx != context->appdata->cur_gpx) |
438 |
|
map_draw_gpx(context->appdata, context->caches_displayed, |
439 |
|
context->widget, gpx, NULL, TRUE); |
440 |
|
|
441 |
|
gpx = gpx->next; |
442 |
|
} |
443 |
|
} |
444 |
|
|
445 |
if(cache->name) { |
name = g_strdup(context->appdata->cur_gpx->name); |
446 |
GtkWidget *label = gtk_label_small_left_new(cache->name); |
context->state = MAP_GPX; |
447 |
gtk_label_set_ellipsize(GTK_LABEL(label), PANGO_ELLIPSIZE_END); |
} |
448 |
gtk_box_pack_start_defaults(GTK_BOX(vbox), label); |
} else { |
449 |
} |
cache_t *cache = context->appdata->cur_cache; |
450 |
|
|
451 |
|
printf("map_setup(CACHE)\n"); |
452 |
|
|
453 |
|
/* clear any pending balloon */ |
454 |
|
context->balloon = NULL; |
455 |
|
osm_gps_map_osd_clear_balloon (OSM_GPS_MAP(context->widget)); |
456 |
|
|
457 |
|
/* clear all existing ccahe images */ |
458 |
|
osm_gps_map_clear_images (OSM_GPS_MAP(context->widget)); |
459 |
|
if(context->caches_displayed) { |
460 |
|
memset(context->caches_displayed, 0, |
461 |
|
(cache_num+1) * sizeof(cache_display_t)); |
462 |
|
|
463 |
|
/* Make sure we really work on the first copy in the list as */ |
464 |
|
/* only this is being used if duplicates exist */ |
465 |
|
cache = cache_search_first(context->appdata->gpx, cache); |
466 |
|
|
467 |
|
/* draw all geocaches and all but selected one are semi-transparent */ |
468 |
|
gpx_t *gpx = context->appdata->gpx; |
469 |
|
while(gpx) { |
470 |
|
map_draw_gpx(context->appdata, context->caches_displayed, |
471 |
|
context->widget, gpx, cache, FALSE); |
472 |
|
gpx = gpx->next; |
473 |
|
} |
474 |
|
} |
475 |
|
|
476 |
GtkWidget *hbox = gtk_hbox_new(FALSE, 0); |
name = g_strdup(cache->name); |
477 |
if(cache->terrain) { |
context->state = MAP_CACHE; |
478 |
GtkWidget *ihbox = gtk_hbox_new(FALSE, 0); |
|
479 |
gtk_box_pack_start(GTK_BOX(ihbox), |
/* navigation in this mode! */ |
480 |
gtk_label_small_left_new(_("Terrain:")), FALSE, FALSE, 0); |
pos_t cpos = gpx_cache_pos(cache); |
|
gtk_box_pack_start(GTK_BOX(ihbox), |
|
|
icon_get_widget(ICON_STARS, (int)(cache->terrain*2-2)), |
|
|
FALSE, FALSE, 5); |
|
|
gtk_box_pack_start_defaults(GTK_BOX(hbox), ihbox); |
|
|
} |
|
481 |
|
|
482 |
if(cache->difficulty) { |
#ifdef OSD_NAV |
483 |
GtkWidget *ihbox = gtk_hbox_new(FALSE, 0); |
osm_gps_map_osd_draw_nav (OSM_GPS_MAP(context->widget), |
484 |
gtk_box_pack_start(GTK_BOX(ihbox), |
context->appdata->imperial, |
485 |
gtk_label_small_left_new(_("Difficulty:")), FALSE, FALSE, 0); |
cpos.lat, cpos.lon, cache->name); |
486 |
gtk_box_pack_start(GTK_BOX(ihbox), |
#else |
487 |
icon_get_widget(ICON_STARS, (int)(cache->difficulty*2-2)), |
#warning OSD_NAV not defined! |
488 |
FALSE, FALSE, 5); |
#endif |
|
gtk_box_pack_start_defaults(GTK_BOX(hbox), ihbox); |
|
489 |
} |
} |
490 |
|
|
491 |
gtk_box_pack_start(GTK_BOX(vbox), hbox, FALSE, FALSE, 0); |
/* also mark geomath position */ |
492 |
|
|
493 |
gtk_container_add(GTK_CONTAINER(alignment), vbox); |
/* remove all existing appearances of this icon first */ |
494 |
/* ----------------------- */ |
osm_gps_map_remove_image(OSM_GPS_MAP(context->widget), |
495 |
|
icon_get(ICON_MISC, 4)); |
|
|
|
|
gtk_container_add(GTK_CONTAINER(pcontext.window), alignment); |
|
|
|
|
|
/* give window its shape */ |
|
|
popup_window_shape(pcontext.window, ax, ay); |
|
|
|
|
|
gtk_widget_show_all(pcontext.window); |
|
|
|
|
|
/* handle this popup until it's gone */ |
|
496 |
|
|
497 |
pcontext.loop = g_main_loop_new(NULL, FALSE); |
if(!isnan(context->appdata->geomath.lat) && |
498 |
|
!isnan(context->appdata->geomath.lon)) { |
|
GDK_THREADS_LEAVE(); |
|
|
g_main_loop_run(pcontext.loop); |
|
|
GDK_THREADS_ENTER(); |
|
499 |
|
|
500 |
g_main_loop_unref(pcontext.loop); |
osm_gps_map_add_image(OSM_GPS_MAP(context->widget), |
501 |
|
context->appdata->geomath.lat, |
502 |
|
context->appdata->geomath.lon, |
503 |
|
icon_get(ICON_MISC, 4)); |
504 |
|
} |
505 |
|
|
506 |
printf("cache popup removed\n"); |
if(name) { |
507 |
|
gtk_window_set_title(GTK_WINDOW(context->window), name); |
508 |
|
g_free(name); |
509 |
|
} else |
510 |
|
printf("map_setup(keep)\n"); |
511 |
} |
} |
512 |
|
|
513 |
static void |
static void |
514 |
map_cachelist_nearest(cache_t *cache, pos_t *pos, |
map_cachelist_nearest(cache_t *cache, pos_t *pos, |
515 |
cache_t **result, float *distance) { |
cache_t **result, float *distance) { |
516 |
|
|
517 |
while(cache) { |
while(cache) { |
518 |
|
pos_t cpos = gpx_cache_pos(cache); |
519 |
|
|
520 |
float dist = |
float dist = |
521 |
pow(cache->pos.lat - pos->lat, 2) + |
pow(cpos.lat - pos->lat, 2) + |
522 |
pow(cache->pos.lon - pos->lon, 2); |
pow(cpos.lon - pos->lon, 2); |
523 |
|
|
524 |
if(!(dist > *distance)) { |
if(!(dist > *distance)) { |
525 |
*result = cache; |
*result = cache; |
533 |
static cache_t *map_closest(map_context_t *context, pos_t *pos) { |
static cache_t *map_closest(map_context_t *context, pos_t *pos) { |
534 |
cache_t *result = NULL; |
cache_t *result = NULL; |
535 |
float distance = NAN; |
float distance = NAN; |
536 |
|
|
537 |
#ifdef USE_MAEMO |
if(context->appdata->search_results && !context->appdata->cur_cache) { |
538 |
if(!context->appdata->cur_gpx) { |
/* search search results */ |
539 |
#endif |
map_cachelist_nearest(context->appdata->search_results->cache, |
540 |
|
pos, &result, &distance); |
541 |
|
} else if(!context->appdata->cur_gpx && !context->appdata->cur_cache) { |
542 |
/* search all geocaches */ |
/* search all geocaches */ |
543 |
gpx_t *gpx = context->appdata->gpx; |
gpx_t *gpx = context->appdata->gpx; |
544 |
while(gpx) { |
while(gpx) { |
545 |
map_cachelist_nearest(gpx->cache, pos, &result, &distance); |
map_cachelist_nearest(gpx->cache, pos, &result, &distance); |
546 |
gpx = gpx->next; |
gpx = gpx->next; |
547 |
} |
} |
548 |
#ifdef USE_MAEMO |
} else if(context->appdata->cur_gpx) { |
549 |
} else { |
/* search in current gpx file */ |
550 |
map_cachelist_nearest(context->appdata->cur_gpx->cache, |
map_cachelist_nearest(context->appdata->cur_gpx->cache, |
551 |
pos, &result, &distance); |
pos, &result, &distance); |
552 |
} |
} else |
553 |
#endif |
result = context->appdata->cur_cache; |
554 |
|
|
555 |
|
/* make sure this is the first hit */ |
556 |
|
if(context->caches_displayed) |
557 |
|
result = cache_search_first(context->appdata->gpx, result); |
558 |
|
|
559 |
return result; |
return result; |
560 |
} |
} |
562 |
/* translate between osm-gps-map positions and gpxview ones */ |
/* translate between osm-gps-map positions and gpxview ones */ |
563 |
pos_t coord2pos(coord_t coo) { |
pos_t coord2pos(coord_t coo) { |
564 |
pos_t pos; |
pos_t pos; |
565 |
pos.lat = RAD2DEG(coo.rlat); |
pos.lat = rad2deg(coo.rlat); |
566 |
pos.lon = RAD2DEG(coo.rlon); |
pos.lon = rad2deg(coo.rlon); |
567 |
return pos; |
return pos; |
568 |
} |
} |
569 |
|
|
|
static int dist2pixel(map_context_t *context, float km, float lat) { |
|
|
gint zoom; |
|
|
g_object_get(OSM_GPS_MAP(context->widget), "zoom", &zoom, NULL); |
|
|
|
|
|
/* world at zoom 1 == 512 pixels */ |
|
|
float m_per_pix = |
|
|
cos(DEG2RAD(lat))*2*M_PI*EQ_RADIUS/(1<<(8+zoom)); |
|
|
|
|
|
return 1000.0*km/m_per_pix; |
|
|
} |
|
|
|
|
570 |
#define CLICK_FUZZ (24) |
#define CLICK_FUZZ (24) |
571 |
|
|
572 |
static gboolean |
static gboolean |
573 |
on_map_button_press_event(GtkWidget *widget, |
on_map_button_press_event(GtkWidget *widget, |
574 |
GdkEventButton *event, map_context_t *context) { |
GdkEventButton *event, map_context_t *context) { |
575 |
|
|
576 |
OsmGpsMap *map = OSM_GPS_MAP(context->widget); |
OsmGpsMap *map = OSM_GPS_MAP(context->widget); |
577 |
|
|
578 |
|
/* check if we actually clicked parts of the OSD */ |
579 |
|
if(osm_gps_map_osd_check(map, event->x, event->y) != OSD_NONE) |
580 |
|
return FALSE; |
581 |
|
|
582 |
/* got a press event without release event? eat it! */ |
/* got a press event without release event? eat it! */ |
583 |
if(context->press_on != NULL) { |
if(context->press_on != NULL) { |
584 |
printf("PRESS: already\n"); |
printf("PRESS: already\n"); |
585 |
return TRUE; |
return FALSE; |
586 |
} |
} |
587 |
|
|
588 |
pos_t pos = |
pos_t pos = |
590 |
|
|
591 |
cache_t *nearest = map_closest(context, &pos); |
cache_t *nearest = map_closest(context, &pos); |
592 |
if(nearest) { |
if(nearest) { |
593 |
float dist = gpx_pos_get_distance(pos, nearest->pos, FALSE); |
pos_t cpos = gpx_cache_pos(nearest); |
594 |
if(dist2pixel(context, dist, nearest->pos.lat) < CLICK_FUZZ) |
|
595 |
|
float dist = gpx_pos_get_distance(pos, cpos, FALSE); |
596 |
|
if(dist2pixel(context, dist, cpos.lat) < CLICK_FUZZ) |
597 |
context->press_on = nearest; |
context->press_on = nearest; |
598 |
} |
} |
599 |
|
|
600 |
return FALSE; |
return FALSE; |
601 |
} |
} |
602 |
|
|
603 |
|
static void |
604 |
|
cairo_draw_pixbuf(cairo_t *cr, GdkPixbuf *buf, gint x, gint y) { |
605 |
|
/* convert the pixbuf into something cairo can handle */ |
606 |
|
|
607 |
|
// Create a new ImageSurface |
608 |
|
cairo_surface_t *image_surface = |
609 |
|
cairo_image_surface_create(CAIRO_FORMAT_ARGB32, |
610 |
|
gdk_pixbuf_get_width(buf), |
611 |
|
gdk_pixbuf_get_height(buf)); |
612 |
|
|
613 |
|
// Create the new Context for the ImageSurface |
614 |
|
g_assert(image_surface); |
615 |
|
cairo_t *context = cairo_create(image_surface); |
616 |
|
|
617 |
|
// Draw the image on the new Context |
618 |
|
gdk_cairo_set_source_pixbuf(context, buf, 0.0, 0.0); |
619 |
|
cairo_paint(context); |
620 |
|
|
621 |
|
// now draw this onto the original context |
622 |
|
cairo_set_source_surface(cr, image_surface, x, y); |
623 |
|
|
624 |
|
cairo_paint(cr); |
625 |
|
} |
626 |
|
|
627 |
|
#ifndef BIG_BALLOONS |
628 |
|
#define ICON_SIZE ICON_CACHE_TYPE |
629 |
|
#else |
630 |
|
#define ICON_SIZE ICON_CACHE_TYPE_1_5X |
631 |
|
#endif |
632 |
|
|
633 |
|
#ifndef BIG_BALLOONS |
634 |
|
#define FONT_SIZE 14.0 |
635 |
|
#else |
636 |
|
#define FONT_SIZE 22.0 |
637 |
|
#endif |
638 |
|
#define LINE_SKIP (FONT_SIZE/4) |
639 |
|
|
640 |
|
|
641 |
|
static void |
642 |
|
balloon_cb(osm_gps_map_balloon_event_t *event, gpointer data) { |
643 |
|
printf("balloon event: "); |
644 |
|
|
645 |
|
map_context_t *context = (map_context_t*)data; |
646 |
|
cache_t *cache = context->balloon; |
647 |
|
|
648 |
|
if(event->type == OSM_GPS_MAP_BALLOON_EVENT_TYPE_DRAW) { |
649 |
|
printf("draw\n"); |
650 |
|
|
651 |
|
#if 0 |
652 |
|
/* draw pink background to check clipping */ |
653 |
|
cairo_rectangle (event->data.draw.cr, |
654 |
|
event->data.draw.rect->x-20, event->data.draw.rect->y-20, |
655 |
|
event->data.draw.rect->w+40, event->data.draw.rect->h+40); |
656 |
|
cairo_set_source_rgba (event->data.draw.cr, 1, 0, 0, 0.3); |
657 |
|
cairo_fill_preserve (event->data.draw.cr); |
658 |
|
cairo_set_line_width (event->data.draw.cr, 0); |
659 |
|
cairo_stroke (event->data.draw.cr); |
660 |
|
#endif |
661 |
|
|
662 |
|
/* leave a little border top and left */ |
663 |
|
gint x = event->data.draw.rect->x, y = event->data.draw.rect->y; |
664 |
|
|
665 |
|
/* draw the cache type icon ... */ |
666 |
|
GdkPixbuf *icon = icon_get(ICON_SIZE, cache->type); |
667 |
|
cairo_draw_pixbuf(event->data.draw.cr, icon, x, y); |
668 |
|
|
669 |
|
if(cache->notes && cache->notes->override) { |
670 |
|
GdkPixbuf *over = icon_get(ICON_SIZE, 11); |
671 |
|
cairo_draw_pixbuf(event->data.draw.cr, over, x, y); |
672 |
|
} |
673 |
|
|
674 |
|
/* ... and right of it the waypoint id */ |
675 |
|
cairo_text_extents_t extents; |
676 |
|
|
677 |
|
if(cache->id) { |
678 |
|
cairo_select_font_face (event->data.draw.cr, "Sans", |
679 |
|
CAIRO_FONT_SLANT_NORMAL, |
680 |
|
CAIRO_FONT_WEIGHT_BOLD); |
681 |
|
|
682 |
|
#ifndef BIG_BALLOONS |
683 |
|
cairo_set_font_size (event->data.draw.cr, 20.0); |
684 |
|
#else |
685 |
|
cairo_set_font_size (event->data.draw.cr, 36.0); |
686 |
|
#endif |
687 |
|
|
688 |
|
cairo_text_extents (event->data.draw.cr, cache->id, &extents); |
689 |
|
|
690 |
|
/* display id right of icon vertically centered */ |
691 |
|
x += gdk_pixbuf_get_width(icon) + 5; |
692 |
|
y += (gdk_pixbuf_get_height(icon) + extents.height)/2; |
693 |
|
cairo_move_to (event->data.draw.cr, x, y); |
694 |
|
cairo_set_source_rgba (event->data.draw.cr, 0, 0, 0, 1); |
695 |
|
cairo_show_text (event->data.draw.cr, cache->id); |
696 |
|
cairo_stroke (event->data.draw.cr); |
697 |
|
|
698 |
|
y += (gdk_pixbuf_get_height(icon) - extents.height)/2 + LINE_SKIP; |
699 |
|
} else |
700 |
|
y += gdk_pixbuf_get_height(icon); |
701 |
|
|
702 |
|
/* return to the left border and below icon/text */ |
703 |
|
x = event->data.draw.rect->x; |
704 |
|
|
705 |
|
/* everything from here uses the same font */ |
706 |
|
cairo_select_font_face (event->data.draw.cr, "Sans", |
707 |
|
CAIRO_FONT_SLANT_NORMAL, |
708 |
|
CAIRO_FONT_WEIGHT_NORMAL); |
709 |
|
|
710 |
|
cairo_set_font_size (event->data.draw.cr, FONT_SIZE); |
711 |
|
|
712 |
|
if(cache->name) { |
713 |
|
/* draw cache name */ |
714 |
|
cairo_text_extents (event->data.draw.cr, cache->name, &extents); |
715 |
|
cairo_move_to (event->data.draw.cr, x, y - extents.y_bearing); |
716 |
|
cairo_set_source_rgba (event->data.draw.cr, 0, 0, 0, 1); |
717 |
|
cairo_show_text (event->data.draw.cr, cache->name); |
718 |
|
cairo_stroke (event->data.draw.cr); |
719 |
|
|
720 |
|
/* return to the left border and below text */ |
721 |
|
y += LINE_SKIP + FONT_SIZE; |
722 |
|
x = event->data.draw.rect->x; |
723 |
|
} |
724 |
|
|
725 |
|
if(cache->terrain) { |
726 |
|
int text_y = 0, icon_y = 0; |
727 |
|
|
728 |
|
/* draw cache rating */ |
729 |
|
const char *terrain = "Terrain:"; |
730 |
|
icon = icon_get(ICON_STARS, (int)(cache->terrain*2-2)); |
731 |
|
cairo_text_extents (event->data.draw.cr, _(terrain), &extents); |
732 |
|
|
733 |
|
if(gdk_pixbuf_get_height(icon) > FONT_SIZE) |
734 |
|
text_y = (gdk_pixbuf_get_height(icon) - FONT_SIZE)/2; |
735 |
|
else |
736 |
|
icon_y = (FONT_SIZE - gdk_pixbuf_get_height(icon))/2; |
737 |
|
|
738 |
|
/* draw "Terrain:" string */ |
739 |
|
cairo_move_to (event->data.draw.cr, x, y - extents.y_bearing + text_y); |
740 |
|
cairo_set_source_rgba (event->data.draw.cr, 0, 0, 0, 1); |
741 |
|
cairo_show_text (event->data.draw.cr, _(terrain)); |
742 |
|
cairo_stroke (event->data.draw.cr); |
743 |
|
x += extents.width + 2; |
744 |
|
|
745 |
|
/* draw terrain stars */ |
746 |
|
cairo_draw_pixbuf(event->data.draw.cr, icon, x, y + icon_y); |
747 |
|
|
748 |
|
x += gdk_pixbuf_get_width(icon) + FONT_SIZE/2; |
749 |
|
} |
750 |
|
|
751 |
|
if(cache->difficulty) { |
752 |
|
int text_y = 0, icon_y = 0; |
753 |
|
|
754 |
|
const char *difficulty = "Difficulty:"; |
755 |
|
icon = icon_get(ICON_STARS, (int)(cache->difficulty*2-2)); |
756 |
|
cairo_text_extents (event->data.draw.cr, _(difficulty), &extents); |
757 |
|
|
758 |
|
if(gdk_pixbuf_get_height(icon) > FONT_SIZE) |
759 |
|
text_y = (gdk_pixbuf_get_height(icon) - FONT_SIZE)/2; |
760 |
|
else |
761 |
|
icon_y = (FONT_SIZE - gdk_pixbuf_get_height(icon))/2; |
762 |
|
|
763 |
|
/* draw "Difficulty:" string */ |
764 |
|
cairo_move_to (event->data.draw.cr, x, y - extents.y_bearing + text_y); |
765 |
|
cairo_set_source_rgba (event->data.draw.cr, 0, 0, 0, 1); |
766 |
|
cairo_show_text (event->data.draw.cr, _(difficulty)); |
767 |
|
cairo_stroke (event->data.draw.cr); |
768 |
|
x += extents.width + 2; |
769 |
|
|
770 |
|
cairo_draw_pixbuf(event->data.draw.cr, icon, x, y + icon_y); |
771 |
|
} |
772 |
|
|
773 |
|
/* draw container info */ |
774 |
|
/* TODO ... */ |
775 |
|
|
776 |
|
|
777 |
|
} else if(event->type == OSM_GPS_MAP_BALLOON_EVENT_TYPE_CLICK) { |
778 |
|
printf("click %s event at %d %d\n", |
779 |
|
event->data.click.down?"down":"up", |
780 |
|
event->data.click.x, event->data.click.y); |
781 |
|
|
782 |
|
/* make the main screen jump to that cache */ |
783 |
|
if(!event->data.click.down) { |
784 |
|
if(context->appdata->cur_cache) { |
785 |
|
printf("ERROR: no current cache should be visible!\n"); |
786 |
|
} else { |
787 |
|
gpx_t *is_in = NULL; |
788 |
|
|
789 |
|
if(context->appdata->search_results) { |
790 |
|
printf("click while in \"search results\" view\n"); |
791 |
|
|
792 |
|
is_in = context->appdata->search_results; |
793 |
|
} else if(!context->appdata->cur_gpx) { |
794 |
|
printf("click while in \"all\" view\n"); |
795 |
|
|
796 |
|
/* we first need to figure out which gpx file this cache */ |
797 |
|
/* is in so we can open it first */ |
798 |
|
gpx_t *gpx = context->appdata->gpx; |
799 |
|
while(gpx && !is_in) { |
800 |
|
cache_t *cur = gpx->cache; |
801 |
|
while(cur && !is_in) { |
802 |
|
if(cur == cache) |
803 |
|
is_in = gpx; |
804 |
|
cur = cur->next; |
805 |
|
} |
806 |
|
gpx = gpx->next; |
807 |
|
} |
808 |
|
|
809 |
|
if(is_in) |
810 |
|
gpxlist_goto_cachelist(context->appdata, is_in); |
811 |
|
|
812 |
|
} else { |
813 |
|
printf("click while in \"cachelist\" view\n"); |
814 |
|
|
815 |
|
/* the simple case: there already is an open gpx file and */ |
816 |
|
/* we just jump into the "cache" view */ |
817 |
|
is_in = context->appdata->cur_gpx; |
818 |
|
} |
819 |
|
|
820 |
|
if(is_in) { |
821 |
|
printf("selecting %s in %s\n", |
822 |
|
cache->id, |
823 |
|
context->appdata->search_results? |
824 |
|
context->appdata->search_results->name: |
825 |
|
context->appdata->cur_gpx->name); |
826 |
|
|
827 |
|
cachelist_goto_cache(context->appdata, cache); |
828 |
|
|
829 |
|
/* give focus to main screen (important for maemo) */ |
830 |
|
printf("raising main window\n"); |
831 |
|
gtk_window_present(GTK_WINDOW(context->appdata->window)); |
832 |
|
} |
833 |
|
} |
834 |
|
} |
835 |
|
} else if(event->type == OSM_GPS_MAP_BALLOON_EVENT_TYPE_REMOVED) { |
836 |
|
printf("removed\n"); |
837 |
|
context->balloon = NULL; |
838 |
|
} |
839 |
|
} |
840 |
|
|
841 |
static gboolean |
static gboolean |
842 |
on_map_button_release_event(GtkWidget *widget, |
on_map_button_release_event(GtkWidget *widget, |
843 |
GdkEventButton *event, map_context_t *context) { |
GdkEventButton *event, map_context_t *context) { |
844 |
OsmGpsMap *map = OSM_GPS_MAP(context->widget); |
OsmGpsMap *map = OSM_GPS_MAP(context->widget); |
845 |
|
|
846 |
|
/* in "MAP_CACHE" state only one cache is visible */ |
847 |
|
/* and the map is in navigation mode. the balloon is */ |
848 |
|
/* pretty useless there */ |
849 |
if(context->press_on) { |
if(context->press_on) { |
850 |
|
|
851 |
|
coord_t coo; |
852 |
|
coo = osm_gps_map_get_co_ordinates(map, event->x, event->y); |
853 |
|
|
854 |
pos_t pos = |
pos_t pos = |
855 |
coord2pos(osm_gps_map_get_co_ordinates(map, event->x, event->y)); |
coord2pos(osm_gps_map_get_co_ordinates(map, event->x, event->y)); |
856 |
|
|
857 |
cache_t *nearest = map_closest(context, &pos); |
cache_t *nearest = map_closest(context, &pos); |
858 |
if(nearest && nearest == context->press_on) { |
if(nearest && nearest == context->press_on) { |
859 |
float dist = gpx_pos_get_distance(pos, nearest->pos, FALSE); |
pos_t cpos = gpx_cache_pos(nearest); |
860 |
if(dist2pixel(context, dist, nearest->pos.lat) < CLICK_FUZZ) |
|
861 |
cache_popup(context, nearest); |
float dist = gpx_pos_get_distance(pos, cpos, FALSE); |
862 |
|
if(dist2pixel(context, dist, cpos.lat) < CLICK_FUZZ) { |
863 |
|
|
864 |
|
context->balloon = nearest; |
865 |
|
osm_gps_map_osd_draw_balloon(map, cpos.lat, cpos.lon, |
866 |
|
balloon_cb, context); |
867 |
|
} |
868 |
} |
} |
869 |
context->press_on = NULL; |
context->press_on = NULL; |
870 |
} else { |
} else { |
878 |
return FALSE; |
return FALSE; |
879 |
} |
} |
880 |
|
|
881 |
static void save_map_state(map_context_t *context) { |
static void on_window_destroy(GtkWidget *widget, map_context_t *context) { |
882 |
|
appdata_t *appdata = context->appdata; |
883 |
|
|
884 |
/* save map parameters */ |
/* save map parameters */ |
885 |
OsmGpsMap *map = OSM_GPS_MAP(context->widget); |
OsmGpsMap *map = OSM_GPS_MAP(context->widget); |
886 |
gint zoom; |
gint zoom; |
887 |
g_object_get(map, "zoom", &zoom, NULL); |
g_object_get(map, "zoom", &zoom, NULL); |
888 |
context->appdata->map.zoom = zoom; |
context->appdata->map.zoom = zoom; |
889 |
|
|
890 |
|
gboolean dpix; |
891 |
|
g_object_get(map, "double-pixel", &dpix, NULL); |
892 |
|
context->appdata->map.dpix = dpix; |
893 |
|
|
894 |
gfloat lat, lon; |
gfloat lat, lon; |
895 |
g_object_get(map, "latitude", &lat, "longitude", &lon, NULL); |
g_object_get(map, "latitude", &lat, "longitude", &lon, NULL); |
896 |
context->appdata->map.pos.lat = lat; |
context->appdata->map.pos.lat = lat; |
897 |
context->appdata->map.pos.lon = lon; |
context->appdata->map.pos.lon = lon; |
|
} |
|
|
|
|
|
#if MAEMO_VERSION_MAJOR == 5 |
|
|
static void on_window_destroy(GtkWidget *widget, map_context_t *context) { |
|
|
printf("destroy map view\n"); |
|
898 |
|
|
899 |
save_map_state(context); |
gint source; |
900 |
|
g_object_get(map, "map-source", &source, NULL); |
901 |
|
context->appdata->map.source = source; |
902 |
|
|
903 |
|
#if MAEMO_VERSION_MAJOR == 5 |
904 |
/* restore cur_view */ |
/* restore cur_view */ |
905 |
context->appdata->cur_view = context->old_view; |
context->appdata->cur_view = context->old_view; |
906 |
|
#endif |
907 |
|
|
908 |
gtk_timeout_remove(context->handler_id); |
gtk_timeout_remove(context->handler_id); |
909 |
|
|
910 |
|
if(context->caches_displayed) { |
911 |
|
g_free(context->caches_displayed); |
912 |
|
context->caches_displayed = NULL; |
913 |
|
} |
914 |
|
|
915 |
|
printf("destroy map context\n"); |
916 |
g_free(context); |
g_free(context); |
917 |
|
appdata->map.context = NULL; |
918 |
|
} |
919 |
|
|
920 |
|
#if (MAEMO_VERSION_MAJOR == 5) && !defined(__i386__) |
921 |
|
/* get access to zoom buttons */ |
922 |
|
static void |
923 |
|
on_window_realize(GtkWidget *widget, gpointer data) { |
924 |
|
if (widget->window) { |
925 |
|
unsigned char value = 1; |
926 |
|
Atom hildon_zoom_key_atom = |
927 |
|
gdk_x11_get_xatom_by_name("_HILDON_ZOOM_KEY_ATOM"), |
928 |
|
integer_atom = gdk_x11_get_xatom_by_name("INTEGER"); |
929 |
|
Display *dpy = |
930 |
|
GDK_DISPLAY_XDISPLAY(gdk_drawable_get_display(widget->window)); |
931 |
|
Window w = GDK_WINDOW_XID(widget->window); |
932 |
|
|
933 |
|
XChangeProperty(dpy, w, hildon_zoom_key_atom, |
934 |
|
integer_atom, 8, PropModeReplace, &value, 1); |
935 |
|
} |
936 |
} |
} |
937 |
#endif |
#endif |
938 |
|
|
939 |
|
/* on maemo a window is either on top or completely invisible. this */ |
940 |
|
/* means that we only need to update the map window if its raised. */ |
941 |
|
/* on ordinary desktops this is different and we always update */ |
942 |
|
|
943 |
|
static gboolean on_focus_in(GtkWidget *widget, GdkEventFocus *event, |
944 |
|
gpointer data) { |
945 |
|
map_context_t *context = (map_context_t*)data; |
946 |
|
|
947 |
|
printf("map got focus\n"); |
948 |
|
|
949 |
|
#ifdef USE_MAEMO |
950 |
|
/* re-enable refresh of map */ |
951 |
|
if(!context->handler_id) |
952 |
|
context->handler_id = gtk_timeout_add(1000, map_gps_update, context); |
953 |
|
#endif |
954 |
|
|
955 |
|
gps_register_callback(context->appdata->gps_state, |
956 |
|
LATLON_CHANGED | HERR_CHANGED | TRACK_CHANGED, |
957 |
|
gps_callback, context); |
958 |
|
|
959 |
|
map_setup(context); |
960 |
|
return FALSE; |
961 |
|
} |
962 |
|
|
963 |
|
static gboolean on_focus_out(GtkWidget *widget, GdkEventFocus *event, |
964 |
|
gpointer data) { |
965 |
|
map_context_t *context = (map_context_t*)data; |
966 |
|
|
967 |
|
printf("map lost focus\n"); |
968 |
|
|
969 |
|
/* save new map position */ |
970 |
|
gfloat lat, lon; |
971 |
|
g_object_get(widget, "latitude", &lat, "longitude", &lon, NULL); |
972 |
|
|
973 |
|
context->appdata->map.pos.lat = lat; |
974 |
|
context->appdata->map.pos.lon = lon; |
975 |
|
|
976 |
|
#ifdef USE_MAEMO |
977 |
|
gtk_timeout_remove(context->handler_id); |
978 |
|
context->handler_id = 0; |
979 |
|
#endif |
980 |
|
|
981 |
|
gps_unregister_callback(context->appdata->gps_state, gps_callback); |
982 |
|
|
983 |
|
return FALSE; |
984 |
|
} |
985 |
|
|
986 |
|
void map_update(appdata_t *appdata) { |
987 |
|
printf("map_update\n"); |
988 |
|
#ifndef USE_MAEMO |
989 |
|
if(appdata->map.context) |
990 |
|
map_setup(appdata->map.context); |
991 |
|
#endif |
992 |
|
} |
993 |
|
|
994 |
|
static gboolean |
995 |
|
on_map_window_key_press(GtkWidget *window, GdkEventKey *event, GtkWidget *map) { |
996 |
|
#ifdef USE_MAEMO |
997 |
|
if((event->keyval == HILDON_HARDKEY_FULLSCREEN) || |
998 |
|
(event->keyval == HILDON_HARDKEY_INCREASE) || |
999 |
|
(event->keyval == HILDON_HARDKEY_DECREASE)) |
1000 |
|
#else |
1001 |
|
if(event->keyval == GDK_F11) |
1002 |
|
#endif |
1003 |
|
{ |
1004 |
|
gboolean return_val; |
1005 |
|
g_signal_emit_by_name(GTK_OBJECT(map), "key_press_event", |
1006 |
|
event, &return_val); |
1007 |
|
return return_val; |
1008 |
|
} |
1009 |
|
|
1010 |
|
return FALSE; |
1011 |
|
} |
1012 |
|
|
1013 |
void map(appdata_t *appdata) { |
void map(appdata_t *appdata) { |
1014 |
map_context_t *context = g_new0(map_context_t, 1); |
map_context_t *context = NULL; |
1015 |
|
|
1016 |
|
/* if the map window already exists, just raise it */ |
1017 |
|
if(appdata->map.context) { |
1018 |
|
printf("using existing map!\n"); |
1019 |
|
gtk_window_present(GTK_WINDOW(appdata->map.context->window)); |
1020 |
|
map_setup(appdata->map.context); |
1021 |
|
return; |
1022 |
|
} |
1023 |
|
|
1024 |
|
context = appdata->map.context = g_new0(map_context_t, 1); |
1025 |
|
printf("allocated new context at %p\n", context); |
1026 |
|
|
1027 |
context->appdata = appdata; |
context->appdata = appdata; |
1028 |
|
context->state = MAP_NONE; |
1029 |
|
|
1030 |
|
/* cleanup old (pre 0.8.7) path if it exists */ |
1031 |
|
char *old_path = g_strdup_printf("%s/map/", appdata->image_path); |
1032 |
|
if(g_file_test(old_path, G_FILE_TEST_IS_DIR)) { |
1033 |
|
printf("old file path %s exists\n", old_path); |
1034 |
|
rmdir_recursive(old_path); |
1035 |
|
} |
1036 |
|
|
1037 |
GtkWidget *hbox = gtk_hbox_new(FALSE, 0); |
/* It is recommanded that all applications share these same */ |
1038 |
|
/* map path, so data is only cached once. The path should be: */ |
1039 |
|
/* ~/.osm-gps-map on standard PC (users home) */ |
1040 |
|
/* /home/user/.osm-gps-map on Maemo5 (ext3 on internal card) */ |
1041 |
|
/* /media/mmc2/osm-gps-map on Maemo4 (vfat on internal card) */ |
1042 |
|
#if !defined(USE_MAEMO) |
1043 |
|
char *p = getenv("HOME"); |
1044 |
|
if(!p) p = "/tmp"; |
1045 |
|
char *path = g_strdup_printf("%s/.osm-gps-map", p); |
1046 |
|
#else |
1047 |
|
#if MAEMO_VERSION_MAJOR == 5 |
1048 |
|
char *path = g_strdup("/home/user/.osm-gps-map"); |
1049 |
|
#else |
1050 |
|
char *path = g_strdup("/media/mmc2/osm-gps-map"); |
1051 |
|
#endif |
1052 |
|
#endif |
1053 |
|
|
|
char *path = g_strdup_printf("%s/map/", appdata->image_path); |
|
1054 |
const char *proxy = get_proxy_uri(appdata); |
const char *proxy = get_proxy_uri(appdata); |
1055 |
|
|
1056 |
|
gint source = context->appdata->map.source; |
1057 |
|
if(!source) source = MAP_SOURCE; |
1058 |
|
|
1059 |
context->widget = g_object_new(OSM_TYPE_GPS_MAP, |
context->widget = g_object_new(OSM_TYPE_GPS_MAP, |
1060 |
"repo-uri", MAP_SOURCE_OPENSTREETMAP, |
"map-source", source, |
1061 |
"tile-cache", path, |
"tile-cache", OSM_GPS_MAP_CACHE_FRIENDLY, |
1062 |
"auto-center", FALSE, |
"tile-cache-base", path, |
1063 |
"record-trip-history", FALSE, |
"auto-center", FALSE, |
1064 |
"show-trip-history", FALSE, |
"record-trip-history", FALSE, |
1065 |
|
"show-trip-history", FALSE, |
1066 |
|
"double-pixel", context->appdata->map.dpix, |
1067 |
|
proxy?"proxy-uri":NULL, proxy, |
1068 |
NULL); |
NULL); |
1069 |
|
|
|
if(proxy) |
|
|
g_object_set(OSM_GPS_MAP(context->widget), "proxy-uri", proxy, NULL); |
|
|
|
|
1070 |
g_free(path); |
g_free(path); |
1071 |
|
|
1072 |
char *name = NULL; |
osm_gps_map_osd_classic_init(OSM_GPS_MAP(context->widget)); |
1073 |
#ifdef USE_MAEMO |
|
1074 |
if(!appdata->cur_gpx) { |
/* set default values if they are invalid */ |
1075 |
#endif |
if(!context->appdata->map.zoom || |
1076 |
/* draw all geocaches */ |
isnan(context->appdata->map.pos.lat) || |
1077 |
gpx_t *gpx = appdata->gpx; |
isnan(context->appdata->map.pos.lon)) { |
1078 |
while(gpx) { |
printf("no valid map position found\n"); |
1079 |
map_draw_cachelist(context->widget, gpx->cache); |
|
1080 |
gpx = gpx->next; |
pos_t *refpos = get_pos(context->appdata); |
1081 |
|
if(refpos && !isnan(refpos->lat) && !isnan(refpos->lon)) { |
1082 |
|
printf("use refpos\n"); |
1083 |
|
|
1084 |
|
/* use gps position if present */ |
1085 |
|
context->appdata->map.pos = *refpos; |
1086 |
|
context->appdata->map.zoom = GPS_DEFAULT_ZOOM; |
1087 |
|
} else { |
1088 |
|
printf("use zero pos\n"); |
1089 |
|
|
1090 |
|
/* use world map otherwise */ |
1091 |
|
context->appdata->map.pos.lat = 0.0; |
1092 |
|
context->appdata->map.pos.lon = 0.0; |
1093 |
|
context->appdata->map.zoom = 1; |
1094 |
} |
} |
|
name = g_strdup(_("all geocaches")); |
|
|
#ifdef USE_MAEMO |
|
|
} else { |
|
|
map_draw_cachelist(context->widget, appdata->cur_gpx->cache); |
|
|
name = g_strdup(appdata->cur_gpx->name); |
|
1095 |
} |
} |
|
#endif |
|
1096 |
|
|
1097 |
char *title = g_strdup_printf(_("Map - %s"), name); |
int key_maps[][2] = { |
1098 |
g_free(name); |
{ OSM_GPS_MAP_KEY_FULLSCREEN, MAP_KEY_FULLSCREEN }, |
1099 |
|
{ OSM_GPS_MAP_KEY_ZOOMIN, MAP_KEY_ZOOMIN }, |
1100 |
|
{ OSM_GPS_MAP_KEY_ZOOMOUT, MAP_KEY_ZOOMOUT }, |
1101 |
|
{ OSM_GPS_MAP_KEY_UP, MAP_KEY_UP }, |
1102 |
|
{ OSM_GPS_MAP_KEY_DOWN, MAP_KEY_DOWN }, |
1103 |
|
{ OSM_GPS_MAP_KEY_LEFT, MAP_KEY_LEFT }, |
1104 |
|
{ OSM_GPS_MAP_KEY_RIGHT, MAP_KEY_RIGHT }, |
1105 |
|
{ OSM_GPS_MAP_KEY_MAX, 0 } }; |
1106 |
|
|
1107 |
|
int i; |
1108 |
|
for(i=0;key_maps[i][0] != OSM_GPS_MAP_KEY_MAX;i++) |
1109 |
|
osm_gps_map_set_keyboard_shortcut(OSM_GPS_MAP(context->widget), |
1110 |
|
key_maps[i][0], key_maps[i][1]); |
1111 |
|
|
1112 |
#if MAEMO_VERSION_MAJOR == 5 |
osm_gps_map_set_mapcenter(OSM_GPS_MAP(context->widget), |
1113 |
GtkWidget *window = hildon_stackable_window_new(); |
context->appdata->map.pos.lat, |
1114 |
gtk_window_set_title(GTK_WINDOW(window), title); |
context->appdata->map.pos.lon, |
1115 |
|
context->appdata->map.zoom); |
1116 |
|
|
1117 |
|
#ifdef USE_MAEMO |
1118 |
|
/* we don't use a stackable window here on fremantle, since */ |
1119 |
|
/* this leaves the main window independent from the map and */ |
1120 |
|
/* the user can e.g. still navigate the main menu */ |
1121 |
|
context->window = hildon_window_new(); |
1122 |
|
|
1123 |
|
#if (MAEMO_VERSION_MAJOR == 5) && !defined(__i386__) |
1124 |
|
g_signal_connect(G_OBJECT(context->window), "realize", |
1125 |
|
G_CALLBACK(on_window_realize), NULL); |
1126 |
|
#endif // MAEMO_VERSION |
1127 |
#else |
#else |
1128 |
GtkWidget *dialog = gtk_dialog_new_with_buttons(title, |
context->window = gtk_window_new(GTK_WINDOW_TOPLEVEL); |
1129 |
GTK_WINDOW(appdata->window), |
#endif |
|
GTK_DIALOG_MODAL | GTK_DIALOG_DESTROY_WITH_PARENT, |
|
|
GTK_STOCK_CLOSE, GTK_RESPONSE_CLOSE, |
|
|
NULL); |
|
1130 |
|
|
1131 |
#ifndef USE_MAEMO |
#ifndef USE_MAEMO |
1132 |
gtk_window_set_default_size(GTK_WINDOW(dialog), 640, 480); |
gtk_window_set_default_size(GTK_WINDOW(context->window), 640, 480); |
|
#else |
|
|
gtk_window_set_default_size(GTK_WINDOW(dialog), 800, 480); |
|
|
#endif |
|
1133 |
#endif |
#endif |
1134 |
|
|
1135 |
g_free(title); |
g_signal_connect(G_OBJECT(context->widget), "focus-in-event", |
1136 |
|
G_CALLBACK(on_focus_in), context); |
1137 |
|
|
1138 |
g_signal_connect(G_OBJECT(context->widget), "configure-event", |
g_signal_connect(G_OBJECT(context->widget), "focus-out-event", |
1139 |
G_CALLBACK(on_map_configure), context); |
G_CALLBACK(on_focus_out), context); |
1140 |
|
|
1141 |
g_signal_connect(G_OBJECT(context->widget), "button-press-event", |
g_signal_connect(G_OBJECT(context->widget), "button-press-event", |
1142 |
G_CALLBACK(on_map_button_press_event), context); |
G_CALLBACK(on_map_button_press_event), context); |
1144 |
g_signal_connect(G_OBJECT(context->widget), "button-release-event", |
g_signal_connect(G_OBJECT(context->widget), "button-release-event", |
1145 |
G_CALLBACK(on_map_button_release_event), context); |
G_CALLBACK(on_map_button_release_event), context); |
1146 |
|
|
|
gtk_box_pack_start_defaults(GTK_BOX(hbox), context->widget); |
|
|
/* zoom button box */ |
|
|
GtkWidget *vbox = gtk_vbox_new(FALSE,0); |
|
|
|
|
|
context->zoomin = |
|
|
map_add_button(10, G_CALLBACK(cb_map_zoomin), |
|
|
context, _("Zoom in")); |
|
|
gtk_box_pack_start(GTK_BOX(vbox), context->zoomin, FALSE, FALSE, 0); |
|
|
|
|
|
context->zoomout = |
|
|
map_add_button(11, G_CALLBACK(cb_map_zoomout), |
|
|
context, _("Zoom out")); |
|
|
gtk_box_pack_start(GTK_BOX(vbox), context->zoomout, FALSE, FALSE, 0); |
|
|
|
|
|
context->gps = |
|
|
map_add_button(9, G_CALLBACK(cb_map_gps), |
|
|
context, _("Jump to GPS position")); |
|
|
gtk_widget_set_sensitive(context->gps, FALSE); |
|
1147 |
/* install handler for timed updates of the gps button */ |
/* install handler for timed updates of the gps button */ |
1148 |
context->handler_id = gtk_timeout_add(1000, map_gps_update, context); |
context->handler_id = gtk_timeout_add(1000, map_gps_update, context); |
|
gtk_box_pack_start(GTK_BOX(vbox), context->gps, FALSE, FALSE, 0); |
|
|
|
|
|
gtk_box_pack_start(GTK_BOX(hbox), vbox, FALSE, FALSE, 0); |
|
1149 |
|
|
1150 |
#if MAEMO_VERSION_MAJOR == 5 |
#if MAEMO_VERSION_MAJOR == 5 |
1151 |
/* prevent some of the main screen things */ |
/* prevent some of the main screen things */ |
1152 |
context->old_view = appdata->cur_view; |
context->old_view = appdata->cur_view; |
1153 |
appdata->cur_view = NULL; |
appdata->cur_view = NULL; |
1154 |
|
#endif |
1155 |
|
|
1156 |
g_signal_connect(G_OBJECT(window), "destroy", |
g_signal_connect(G_OBJECT(context->window), "destroy", |
1157 |
G_CALLBACK(on_window_destroy), context); |
G_CALLBACK(on_window_destroy), context); |
1158 |
|
|
1159 |
gtk_container_add(GTK_CONTAINER(window), hbox); |
/* connect a key handler to forward global shortcuts (function keys) */ |
1160 |
gtk_widget_show_all(GTK_WIDGET(window)); |
/* to the ap widget */ |
1161 |
|
g_signal_connect(G_OBJECT(context->window), "key_press_event", |
1162 |
#else |
G_CALLBACK(on_map_window_key_press), context->widget); |
1163 |
gtk_box_pack_start_defaults(GTK_BOX(GTK_DIALOG(dialog)->vbox), hbox); |
|
1164 |
gtk_dialog_set_default_response(GTK_DIALOG(dialog), GTK_RESPONSE_CLOSE); |
gtk_container_add(GTK_CONTAINER(context->window), context->widget); |
1165 |
gtk_widget_show_all(dialog); |
gtk_widget_show_all(GTK_WIDGET(context->window)); |
1166 |
gtk_dialog_run(GTK_DIALOG(dialog)); |
|
1167 |
save_map_state(context); |
/* setup cache state */ |
1168 |
gtk_timeout_remove(context->handler_id); |
map_setup(context); |
|
gtk_widget_destroy(dialog); |
|
|
g_free(context); |
|
|
#endif |
|
1169 |
} |
} |