24 |
#include "osm-gps-map.h" |
#include "osm-gps-map.h" |
25 |
#endif |
#endif |
26 |
|
|
27 |
|
#define GPS_DEFAULT_ZOOM 13 |
28 |
|
|
29 |
|
/* equatorial radius in meters */ |
30 |
|
#define EQ_RADIUS (6378137.0) |
31 |
|
|
32 |
|
#define RAD2DEG(a) (((a)*180.0)/M_PI) |
33 |
|
#define DEG2RAD(a) (((a)*M_PI)/180.0) |
34 |
|
|
35 |
typedef struct { |
typedef struct { |
36 |
appdata_t *appdata; |
appdata_t *appdata; |
37 |
GtkWidget *widget; |
GtkWidget *widget; |
38 |
GtkWidget *zoomin, *zoomout, *gps; |
GtkWidget *zoomin, *zoomout, *gps; |
39 |
gint handler_id; |
gint handler_id; |
40 |
|
cache_t *press_on; |
41 |
#if MAEMO_VERSION_MAJOR == 5 |
#if MAEMO_VERSION_MAJOR == 5 |
42 |
GtkWidget *old_view; |
GtkWidget *old_view; |
43 |
#endif |
#endif |
82 |
} |
} |
83 |
|
|
84 |
static void map_zoom(map_context_t *context, int step) { |
static void map_zoom(map_context_t *context, int step) { |
85 |
int zoom; |
gint zoom; |
86 |
OsmGpsMap *map = OSM_GPS_MAP(context->widget); |
OsmGpsMap *map = OSM_GPS_MAP(context->widget); |
87 |
g_object_get(map, "zoom", &zoom, NULL); |
g_object_get(map, "zoom", &zoom, NULL); |
88 |
zoom = osm_gps_map_set_zoom(map, zoom+step); |
zoom = osm_gps_map_set_zoom(map, zoom+step); |
90 |
/* enable/disable zoom buttons as required */ |
/* enable/disable zoom buttons as required */ |
91 |
gtk_widget_set_sensitive(context->zoomin, zoom<17); |
gtk_widget_set_sensitive(context->zoomin, zoom<17); |
92 |
gtk_widget_set_sensitive(context->zoomout, zoom>1); |
gtk_widget_set_sensitive(context->zoomout, zoom>1); |
93 |
|
|
94 |
|
/* save new zoom */ |
95 |
|
context->appdata->map.zoom = zoom; |
96 |
} |
} |
97 |
|
|
98 |
static gboolean |
static gboolean |
112 |
pos_t *refpos = get_pos(context->appdata); |
pos_t *refpos = get_pos(context->appdata); |
113 |
if(refpos && !isnan(refpos->lat) && !isnan(refpos->lon)) { |
if(refpos && !isnan(refpos->lat) && !isnan(refpos->lon)) { |
114 |
osm_gps_map_set_mapcenter(OSM_GPS_MAP(context->widget), |
osm_gps_map_set_mapcenter(OSM_GPS_MAP(context->widget), |
115 |
refpos->lat, refpos->lon, 14); |
refpos->lat, refpos->lon, GPS_DEFAULT_ZOOM); |
116 |
} else { |
} else { |
117 |
/* no coordinates given: display the entire world */ |
/* no coordinates given: display the entire world */ |
118 |
osm_gps_map_set_mapcenter(OSM_GPS_MAP(context->widget), |
osm_gps_map_set_mapcenter(OSM_GPS_MAP(context->widget), |
123 |
} |
} |
124 |
|
|
125 |
static GtkWidget |
static GtkWidget |
126 |
*map_add_button(const gchar *icon, GCallback cb, gpointer data, |
*map_add_button(int icon, GCallback cb, gpointer data, |
127 |
char *tooltip) { |
char *tooltip) { |
128 |
GtkWidget *button = gtk_button_new(); |
GtkWidget *button = gtk_button_new(); |
129 |
gtk_button_set_image(GTK_BUTTON(button), |
gtk_button_set_image(GTK_BUTTON(button), icon_get_widget(ICON_MISC, icon)); |
|
gtk_image_new_from_stock(icon, GTK_ICON_SIZE_MENU)); |
|
130 |
g_signal_connect(button, "clicked", cb, data); |
g_signal_connect(button, "clicked", cb, data); |
131 |
#ifndef USE_MAEMO |
#ifndef USE_MAEMO |
132 |
gtk_widget_set_tooltip_text(button, tooltip); |
gtk_widget_set_tooltip_text(button, tooltip); |
137 |
static gboolean map_gps_update(gpointer data) { |
static gboolean map_gps_update(gpointer data) { |
138 |
map_context_t *context = (map_context_t*)data; |
map_context_t *context = (map_context_t*)data; |
139 |
|
|
140 |
|
/* get reference position ... */ |
141 |
pos_t *refpos = get_pos(context->appdata); |
pos_t *refpos = get_pos(context->appdata); |
142 |
gboolean ok = (refpos!= NULL) && !isnan(refpos->lat) && !isnan(refpos->lon); |
gboolean ok = (refpos!= NULL) && !isnan(refpos->lat) && !isnan(refpos->lon); |
143 |
|
|
144 |
/* get reference position and go there */ |
/* ... and enable "goto" button if it's valid */ |
145 |
gtk_widget_set_sensitive(context->gps, ok); |
gtk_widget_set_sensitive(context->gps, ok); |
146 |
|
|
147 |
|
if(ok) { |
148 |
|
float heading = NAN; |
149 |
|
int radius = 0; |
150 |
|
|
151 |
|
if(context->appdata->use_gps) { |
152 |
|
heading = gps_get_heading(context->appdata); |
153 |
|
|
154 |
|
/* get error */ |
155 |
|
float eph = gps_get_eph(context->appdata); |
156 |
|
if(!isnan(eph)) { |
157 |
|
|
158 |
|
/* world at zoom 1 == 512 pixels */ |
159 |
|
gint zoom; |
160 |
|
g_object_get(OSM_GPS_MAP(context->widget), "zoom", &zoom, NULL); |
161 |
|
float m_per_pix = |
162 |
|
cos(DEG2RAD(refpos->lat))*2*M_PI*EQ_RADIUS/(1<<(8+zoom)); |
163 |
|
|
164 |
|
radius = eph/m_per_pix; |
165 |
|
} |
166 |
|
} |
167 |
|
|
168 |
|
g_object_set(context->widget, "gps-track-highlight-radius", radius, NULL); |
169 |
|
osm_gps_map_draw_gps(OSM_GPS_MAP(context->widget), |
170 |
|
refpos->lat, refpos->lon, heading); |
171 |
|
} else |
172 |
|
osm_gps_map_clear_gps(OSM_GPS_MAP(context->widget)); |
173 |
|
|
174 |
return TRUE; |
return TRUE; |
175 |
} |
} |
176 |
|
|
178 |
GdkEventConfigure *event, |
GdkEventConfigure *event, |
179 |
map_context_t *context) { |
map_context_t *context) { |
180 |
|
|
181 |
cb_map_gps(NULL, context); |
/* set default values if they are invalid */ |
182 |
|
if(!context->appdata->map.zoom || |
183 |
|
isnan(context->appdata->map.pos.lat) || |
184 |
|
isnan(context->appdata->map.pos.lon)) { |
185 |
|
printf("no valid map position found\n"); |
186 |
|
|
187 |
|
pos_t *refpos = get_pos(context->appdata); |
188 |
|
if(refpos && !isnan(refpos->lat) && !isnan(refpos->lon)) { |
189 |
|
/* use gps position if present */ |
190 |
|
context->appdata->map.pos = *refpos; |
191 |
|
context->appdata->map.zoom = GPS_DEFAULT_ZOOM; |
192 |
|
} else { |
193 |
|
/* use world map otherwise */ |
194 |
|
context->appdata->map.pos.lat = 0.0; |
195 |
|
context->appdata->map.pos.lon = 0.0; |
196 |
|
context->appdata->map.zoom = 1; |
197 |
|
} |
198 |
|
} |
199 |
|
|
200 |
|
/* jump to initial position */ |
201 |
|
osm_gps_map_set_mapcenter(OSM_GPS_MAP(context->widget), |
202 |
|
context->appdata->map.pos.lat, |
203 |
|
context->appdata->map.pos.lon, |
204 |
|
context->appdata->map.zoom); |
205 |
|
|
206 |
return FALSE; |
return FALSE; |
207 |
} |
} |
208 |
|
|
224 |
GMainLoop *loop; |
GMainLoop *loop; |
225 |
} popup_context_t; |
} popup_context_t; |
226 |
|
|
227 |
|
/* draw shape */ |
228 |
|
#define ARROW_BORDER 20 |
229 |
|
#define CORNER_RADIUS 10 |
230 |
|
|
231 |
#ifndef USE_HILDON |
#ifndef USE_MAEMO |
232 |
#define POPUP_WIDTH 300 |
#define POPUP_WIDTH 300 |
233 |
#define POPUP_HEIGHT 100 |
#define POPUP_HEIGHT 100 |
234 |
#else |
#else |
235 |
#define POPUP_WIDTH 600 |
#define POPUP_WIDTH 350 |
236 |
#define POPUP_HEIGHT 200 |
#define POPUP_HEIGHT 120 |
237 |
#endif |
#endif |
238 |
|
|
239 |
static gboolean |
static gboolean |
257 |
GdkEventButton *event, popup_context_t *context) { |
GdkEventButton *event, popup_context_t *context) { |
258 |
gboolean in = pointer_in_window(widget, event->x_root, event->y_root); |
gboolean in = pointer_in_window(widget, event->x_root, event->y_root); |
259 |
|
|
260 |
printf("overlay button press(in = %d)\n", in); |
printf("overlay button press (in = %d)\n", in); |
261 |
return !in; |
return !in; |
262 |
} |
} |
263 |
|
|
266 |
GdkEventButton *event, popup_context_t *context) { |
GdkEventButton *event, popup_context_t *context) { |
267 |
gboolean in = pointer_in_window(widget, event->x_root, event->y_root); |
gboolean in = pointer_in_window(widget, event->x_root, event->y_root); |
268 |
|
|
269 |
printf("overlay button release(in = %d)\n", in); |
printf("overlay button release (in = %d)\n", in); |
270 |
|
|
271 |
if(!in) { |
if(!in) { |
272 |
printf("destroying popup\n"); |
printf("destroying popup\n"); |
300 |
shutdown_loop(context); |
shutdown_loop(context); |
301 |
} |
} |
302 |
|
|
303 |
void cache_popup(appdata_t *appdata, cache_t *cache) { |
static void popup_window_shape(GtkWidget *window, int tip_x, int tip_y) { |
304 |
popup_context_t context; |
GdkBitmap *mask = gdk_pixmap_new(NULL, POPUP_WIDTH, POPUP_HEIGHT, 1); |
305 |
context.appdata = appdata; |
|
306 |
|
GdkGC *gc = gdk_gc_new(mask); |
307 |
context.window = gtk_window_new(GTK_WINDOW_POPUP); |
GdkColormap *colormap; |
308 |
gtk_widget_realize(context.window); |
GdkColor black; |
309 |
gtk_window_set_default_size(GTK_WINDOW(context.window), |
GdkColor white; |
310 |
|
|
311 |
|
/* get black/white color values */ |
312 |
|
colormap = gdk_colormap_get_system(); |
313 |
|
gdk_color_black(colormap, &black); |
314 |
|
gdk_color_white(colormap, &white); |
315 |
|
|
316 |
|
/* erase */ |
317 |
|
gdk_gc_set_foreground(gc, &black); |
318 |
|
gdk_gc_set_background(gc, &white); |
319 |
|
|
320 |
|
/* erase background */ |
321 |
|
gdk_draw_rectangle(mask, gc, TRUE, 0, 0, POPUP_WIDTH, POPUP_HEIGHT); |
322 |
|
|
323 |
|
gdk_gc_set_foreground(gc, &white); |
324 |
|
gdk_gc_set_background(gc, &black); |
325 |
|
|
326 |
|
/* the tip is always above or below the "bubble" but never at its side */ |
327 |
|
guint tip_offset = (tip_y == 0)?ARROW_BORDER:0; |
328 |
|
|
329 |
|
gdk_draw_rectangle(mask, gc, TRUE, |
330 |
|
0, tip_offset + CORNER_RADIUS, |
331 |
|
POPUP_WIDTH, |
332 |
|
POPUP_HEIGHT - 2*CORNER_RADIUS - ARROW_BORDER); |
333 |
|
|
334 |
|
gdk_draw_rectangle(mask, gc, TRUE, |
335 |
|
CORNER_RADIUS, tip_offset, |
336 |
|
POPUP_WIDTH - 2*CORNER_RADIUS, |
337 |
|
POPUP_HEIGHT - ARROW_BORDER); |
338 |
|
|
339 |
|
int off[][2] = { |
340 |
|
{ CORNER_RADIUS, tip_offset + CORNER_RADIUS }, |
341 |
|
{ POPUP_WIDTH - CORNER_RADIUS, tip_offset + CORNER_RADIUS }, |
342 |
|
{ POPUP_WIDTH - CORNER_RADIUS, |
343 |
|
POPUP_HEIGHT - CORNER_RADIUS - ARROW_BORDER + tip_offset}, |
344 |
|
{ CORNER_RADIUS, |
345 |
|
POPUP_HEIGHT - CORNER_RADIUS - ARROW_BORDER + tip_offset}}; |
346 |
|
|
347 |
|
int i; |
348 |
|
for(i=0;i<4;i++) { |
349 |
|
gdk_draw_arc(mask, gc, TRUE, |
350 |
|
off[i][0]-CORNER_RADIUS, off[i][1]-CORNER_RADIUS, |
351 |
|
2*CORNER_RADIUS, 2*CORNER_RADIUS, |
352 |
|
0, 360*64); |
353 |
|
} |
354 |
|
|
355 |
|
GdkPoint points[3] = { {POPUP_WIDTH*1/3, POPUP_HEIGHT/2}, |
356 |
|
{POPUP_WIDTH*2/3, POPUP_HEIGHT/2}, |
357 |
|
{tip_x,tip_y} }; |
358 |
|
gdk_draw_polygon(mask, gc, TRUE, points, 3); |
359 |
|
|
360 |
|
|
361 |
|
gdk_window_shape_combine_mask(window->window, mask, 0, 0); |
362 |
|
} |
363 |
|
|
364 |
|
/* create a left aligned label (normal ones are centered) */ |
365 |
|
static GtkWidget *gtk_label_left_new(char *str) { |
366 |
|
GtkWidget *label = gtk_label_new(str); |
367 |
|
gtk_misc_set_alignment(GTK_MISC(label), 0.f, .5f); |
368 |
|
return label; |
369 |
|
} |
370 |
|
|
371 |
|
/* the small labels are actually only on maemo small */ |
372 |
|
#ifdef USE_MAEMO |
373 |
|
#define MARKUP_SMALL "<span size='small'>%s</span>" |
374 |
|
GtkWidget *gtk_label_small_left_new(char *str) { |
375 |
|
GtkWidget *label = gtk_label_new(""); |
376 |
|
char *markup = g_markup_printf_escaped(MARKUP_SMALL, str); |
377 |
|
gtk_label_set_markup(GTK_LABEL(label), markup); |
378 |
|
g_free(markup); |
379 |
|
gtk_misc_set_alignment(GTK_MISC(label), 0.f, .5f); |
380 |
|
return label; |
381 |
|
} |
382 |
|
#define gtk_label_big_left_new(a) gtk_label_left_new(a) |
383 |
|
#else |
384 |
|
#define gtk_label_small_left_new(a) gtk_label_left_new(a) |
385 |
|
#define MARKUP_BIG "<span size='x-large'>%s</span>" |
386 |
|
GtkWidget *gtk_label_big_left_new(char *str) { |
387 |
|
GtkWidget *label = gtk_label_new(""); |
388 |
|
char *markup = g_markup_printf_escaped(MARKUP_BIG, str); |
389 |
|
gtk_label_set_markup(GTK_LABEL(label), markup); |
390 |
|
g_free(markup); |
391 |
|
gtk_misc_set_alignment(GTK_MISC(label), 0.f, .5f); |
392 |
|
return label; |
393 |
|
} |
394 |
|
#endif |
395 |
|
|
396 |
|
void cache_popup(map_context_t *mcontext, cache_t *cache) { |
397 |
|
popup_context_t pcontext; |
398 |
|
pcontext.appdata = mcontext->appdata; |
399 |
|
|
400 |
|
pcontext.window = gtk_window_new(GTK_WINDOW_POPUP); |
401 |
|
gtk_widget_realize(pcontext.window); |
402 |
|
gtk_window_set_default_size(GTK_WINDOW(pcontext.window), |
403 |
POPUP_WIDTH, POPUP_HEIGHT); |
POPUP_WIDTH, POPUP_HEIGHT); |
404 |
gtk_window_resize(GTK_WINDOW(context.window), |
gtk_window_resize(GTK_WINDOW(pcontext.window), POPUP_WIDTH, POPUP_HEIGHT); |
405 |
POPUP_WIDTH, POPUP_HEIGHT); |
// gtk_window_set_resizable(GTK_WINDOW(pcontext.window), FALSE); |
406 |
// gtk_window_set_resizable(GTK_WINDOW(context.window), FALSE); |
gtk_window_set_transient_for(GTK_WINDOW(pcontext.window), |
407 |
gtk_window_set_transient_for(GTK_WINDOW(context.window), |
GTK_WINDOW(mcontext->appdata->window)); |
408 |
GTK_WINDOW(appdata->window)); |
gtk_window_set_keep_above(GTK_WINDOW(pcontext.window), TRUE); |
409 |
gtk_window_set_keep_above(GTK_WINDOW(context.window), TRUE); |
gtk_window_set_destroy_with_parent(GTK_WINDOW(pcontext.window), TRUE); |
410 |
gtk_window_set_destroy_with_parent(GTK_WINDOW(context.window), TRUE); |
gtk_window_set_gravity(GTK_WINDOW(pcontext.window), GDK_GRAVITY_STATIC); |
411 |
gtk_window_set_gravity(GTK_WINDOW(context.window), GDK_GRAVITY_STATIC); |
gtk_window_set_modal(GTK_WINDOW(pcontext.window), TRUE); |
|
gtk_window_set_modal(GTK_WINDOW(context.window), TRUE); |
|
412 |
|
|
413 |
/* connect events */ |
/* connect events */ |
414 |
g_signal_connect(G_OBJECT(context.window), "button-press-event", |
g_signal_connect(G_OBJECT(pcontext.window), "button-press-event", |
415 |
G_CALLBACK(on_button_press_event), &context); |
G_CALLBACK(on_button_press_event), &pcontext); |
416 |
g_signal_connect(G_OBJECT(context.window), "button-release-event", |
g_signal_connect(G_OBJECT(pcontext.window), "button-release-event", |
417 |
G_CALLBACK(on_button_release_event), &context); |
G_CALLBACK(on_button_release_event), &pcontext); |
418 |
g_signal_connect(G_OBJECT(context.window), "delete-event", |
g_signal_connect(G_OBJECT(pcontext.window), "delete-event", |
419 |
G_CALLBACK(run_delete_handler), &context); |
G_CALLBACK(run_delete_handler), &pcontext); |
420 |
g_signal_connect(G_OBJECT(context.window), "destroy", |
g_signal_connect(G_OBJECT(pcontext.window), "destroy", |
421 |
G_CALLBACK(run_destroy_handler), &context); |
G_CALLBACK(run_destroy_handler), &pcontext); |
422 |
g_signal_connect(G_OBJECT(context.window), "unmap", |
g_signal_connect(G_OBJECT(pcontext.window), "unmap", |
423 |
G_CALLBACK(run_unmap_handler), &context); |
G_CALLBACK(run_unmap_handler), &pcontext); |
424 |
|
|
425 |
gdk_pointer_grab(context.window->window, TRUE, |
gdk_pointer_grab(pcontext.window->window, TRUE, |
426 |
GDK_BUTTON_PRESS_MASK | GDK_BUTTON_RELEASE_MASK | GDK_BUTTON_MOTION_MASK, |
GDK_BUTTON_PRESS_MASK | GDK_BUTTON_RELEASE_MASK | GDK_BUTTON_MOTION_MASK, |
427 |
NULL, NULL, GDK_CURRENT_TIME); |
NULL, NULL, GDK_CURRENT_TIME); |
428 |
gtk_grab_add(context.window); |
gtk_grab_add(pcontext.window); |
429 |
|
|
430 |
// gint x, y; |
/* check whether cache is in upper or lower half of window */ |
431 |
// gdk_window_get_origin(button->window, &x, &y); |
gint x, y, sx, sy; |
432 |
|
osm_gps_map_geographic_to_screen(OSM_GPS_MAP(mcontext->widget), |
433 |
// gtk_window_move(GTK_WINDOW(context.window), |
cache->pos.lat, cache->pos.lon, |
434 |
// x + button->allocation.x, |
&sx, &sy); |
435 |
// y + button->allocation.y - HEIGHT); |
|
436 |
|
gdk_window_get_origin(mcontext->widget->window, &x, &y); |
437 |
|
|
438 |
|
gint ax = 0, ay = 0; |
439 |
|
if(sx > mcontext->widget->allocation.width/2) |
440 |
|
ax = POPUP_WIDTH; |
441 |
|
|
442 |
|
if(sy > mcontext->widget->allocation.height/2) |
443 |
|
ay = POPUP_HEIGHT; |
444 |
|
|
445 |
gtk_window_move(GTK_WINDOW(context.window), |
#if !defined(USE_MAEMO) || (MAEMO_VERSION_MAJOR < 5) |
446 |
100, |
GdkColor color; |
447 |
100); |
gdk_color_parse("darkgray", &color); |
448 |
|
gtk_widget_modify_bg(GTK_WIDGET(pcontext.window), GTK_STATE_NORMAL, &color); |
449 |
|
#endif |
450 |
|
|
451 |
|
gtk_window_move(GTK_WINDOW(pcontext.window), |
452 |
|
x + mcontext->widget->allocation.x + sx - ax, |
453 |
|
y + mcontext->widget->allocation.y + sy - ay); |
454 |
|
|
455 |
|
|
456 |
|
GtkWidget *alignment = gtk_alignment_new(0.5, 0.5, 1.0, 1.0); |
457 |
|
gtk_alignment_set_padding(GTK_ALIGNMENT(alignment), |
458 |
|
CORNER_RADIUS/2 + (ay?0:ARROW_BORDER), |
459 |
|
CORNER_RADIUS/2 + (ay?ARROW_BORDER:0), |
460 |
|
CORNER_RADIUS, CORNER_RADIUS); |
461 |
|
|
462 |
|
/* --- actual content ---- */ |
463 |
|
GtkWidget *vbox = gtk_vbox_new(FALSE, 0); |
464 |
|
|
465 |
|
if(cache->id) { |
466 |
|
GtkWidget *ihbox = gtk_hbox_new(FALSE, 0); |
467 |
|
|
468 |
/* a frame with a vscale inside */ |
gtk_box_pack_start(GTK_BOX(ihbox), |
469 |
GtkWidget *frame = gtk_frame_new(NULL); |
icon_get_widget(ICON_CACHE_TYPE, cache->type), |
470 |
gtk_frame_set_shadow_type(GTK_FRAME(frame), GTK_SHADOW_OUT); |
FALSE, FALSE, 5); |
471 |
|
|
472 |
|
gtk_box_pack_start_defaults(GTK_BOX(ihbox), |
473 |
|
gtk_label_big_left_new(cache->id)); |
474 |
|
|
475 |
|
gtk_box_pack_start_defaults(GTK_BOX(vbox), ihbox); |
476 |
|
} |
477 |
|
|
478 |
|
if(cache->name) { |
479 |
|
GtkWidget *label = gtk_label_small_left_new(cache->name); |
480 |
|
gtk_label_set_ellipsize(GTK_LABEL(label), PANGO_ELLIPSIZE_END); |
481 |
|
gtk_box_pack_start_defaults(GTK_BOX(vbox), label); |
482 |
|
} |
483 |
|
|
484 |
gtk_container_add(GTK_CONTAINER(frame), gtk_label_new(cache->name)); |
GtkWidget *hbox = gtk_hbox_new(FALSE, 0); |
485 |
gtk_container_add(GTK_CONTAINER(context.window), frame); |
if(cache->terrain) { |
486 |
|
GtkWidget *ihbox = gtk_hbox_new(FALSE, 0); |
487 |
|
gtk_box_pack_start(GTK_BOX(ihbox), |
488 |
|
gtk_label_small_left_new(_("Terrain:")), FALSE, FALSE, 0); |
489 |
|
gtk_box_pack_start(GTK_BOX(ihbox), |
490 |
|
icon_get_widget(ICON_STARS, (int)(cache->terrain*2-2)), |
491 |
|
FALSE, FALSE, 5); |
492 |
|
gtk_box_pack_start_defaults(GTK_BOX(hbox), ihbox); |
493 |
|
} |
494 |
|
|
495 |
|
if(cache->difficulty) { |
496 |
|
GtkWidget *ihbox = gtk_hbox_new(FALSE, 0); |
497 |
|
gtk_box_pack_start(GTK_BOX(ihbox), |
498 |
|
gtk_label_small_left_new(_("Difficulty:")), FALSE, FALSE, 0); |
499 |
|
gtk_box_pack_start(GTK_BOX(ihbox), |
500 |
|
icon_get_widget(ICON_STARS, (int)(cache->difficulty*2-2)), |
501 |
|
FALSE, FALSE, 5); |
502 |
|
gtk_box_pack_start_defaults(GTK_BOX(hbox), ihbox); |
503 |
|
} |
504 |
|
|
505 |
|
gtk_box_pack_start(GTK_BOX(vbox), hbox, FALSE, FALSE, 0); |
506 |
|
|
507 |
|
gtk_container_add(GTK_CONTAINER(alignment), vbox); |
508 |
|
/* ----------------------- */ |
509 |
|
|
510 |
|
|
511 |
|
gtk_container_add(GTK_CONTAINER(pcontext.window), alignment); |
512 |
|
|
513 |
gtk_widget_show_all(context.window); |
/* give window its shape */ |
514 |
|
popup_window_shape(pcontext.window, ax, ay); |
515 |
|
|
516 |
|
gtk_widget_show_all(pcontext.window); |
517 |
|
|
518 |
/* handle this popup until it's gone */ |
/* handle this popup until it's gone */ |
519 |
|
|
520 |
context.loop = g_main_loop_new(NULL, FALSE); |
pcontext.loop = g_main_loop_new(NULL, FALSE); |
521 |
|
|
522 |
GDK_THREADS_LEAVE(); |
GDK_THREADS_LEAVE(); |
523 |
g_main_loop_run(context.loop); |
g_main_loop_run(pcontext.loop); |
524 |
GDK_THREADS_ENTER(); |
GDK_THREADS_ENTER(); |
525 |
|
|
526 |
g_main_loop_unref(context.loop); |
g_main_loop_unref(pcontext.loop); |
527 |
|
|
528 |
printf("cache popup removed\n"); |
printf("cache popup removed\n"); |
529 |
} |
} |
530 |
|
|
|
#define RAD2DEG(a) (((a)*180.0)/M_PI) |
|
|
|
|
531 |
static void |
static void |
532 |
map_cachelist_nearest(cache_t *cache, pos_t *pos, |
map_cachelist_nearest(cache_t *cache, pos_t *pos, |
533 |
cache_t **result, float *distance) { |
cache_t **result, float *distance) { |
576 |
return pos; |
return pos; |
577 |
} |
} |
578 |
|
|
579 |
|
static int dist2pixel(map_context_t *context, float km, float lat) { |
580 |
|
gint zoom; |
581 |
|
g_object_get(OSM_GPS_MAP(context->widget), "zoom", &zoom, NULL); |
582 |
|
|
583 |
|
/* world at zoom 1 == 512 pixels */ |
584 |
|
float m_per_pix = |
585 |
|
cos(DEG2RAD(lat))*2*M_PI*EQ_RADIUS/(1<<(8+zoom)); |
586 |
|
|
587 |
|
return 1000.0*km/m_per_pix; |
588 |
|
} |
589 |
|
|
590 |
|
#define CLICK_FUZZ (24) |
591 |
|
|
592 |
static gboolean |
static gboolean |
593 |
on_map_button_press_event(GtkWidget *widget, |
on_map_button_press_event(GtkWidget *widget, |
594 |
GdkEventButton *event, map_context_t *context) { |
GdkEventButton *event, map_context_t *context) { |
595 |
OsmGpsMap *map = OSM_GPS_MAP(context->widget); |
OsmGpsMap *map = OSM_GPS_MAP(context->widget); |
596 |
|
|
597 |
pos_t pos = |
/* got a press event without release event? eat it! */ |
598 |
coord2pos(osm_gps_map_get_co_ordinates(map, (int)event->x, (int)event->y)); |
if(context->press_on != NULL) { |
599 |
|
printf("PRESS: already\n"); |
600 |
|
return TRUE; |
601 |
|
} |
602 |
|
|
603 |
printf("clicked at %f/%f\n", pos.lat, pos.lon); |
pos_t pos = |
604 |
|
coord2pos(osm_gps_map_get_co_ordinates(map, event->x, event->y)); |
605 |
|
|
606 |
|
cache_t *nearest = map_closest(context, &pos); |
607 |
|
if(nearest) { |
608 |
|
float dist = gpx_pos_get_distance(pos, nearest->pos, FALSE); |
609 |
|
if(dist2pixel(context, dist, nearest->pos.lat) < CLICK_FUZZ) |
610 |
|
context->press_on = nearest; |
611 |
|
} |
612 |
|
|
613 |
return FALSE; |
return FALSE; |
614 |
} |
} |
615 |
|
|
618 |
GdkEventButton *event, map_context_t *context) { |
GdkEventButton *event, map_context_t *context) { |
619 |
OsmGpsMap *map = OSM_GPS_MAP(context->widget); |
OsmGpsMap *map = OSM_GPS_MAP(context->widget); |
620 |
|
|
621 |
pos_t pos = |
if(context->press_on) { |
622 |
coord2pos(osm_gps_map_get_co_ordinates(map, (int)event->x, (int)event->y)); |
pos_t pos = |
623 |
|
coord2pos(osm_gps_map_get_co_ordinates(map, event->x, event->y)); |
624 |
printf("released at %f/%f\n", pos.lat, pos.lon); |
|
625 |
|
cache_t *nearest = map_closest(context, &pos); |
626 |
/* return true if we clicked a cache */ |
if(nearest && nearest == context->press_on) { |
627 |
/* ... */ |
float dist = gpx_pos_get_distance(pos, nearest->pos, FALSE); |
628 |
|
if(dist2pixel(context, dist, nearest->pos.lat) < CLICK_FUZZ) |
629 |
cache_t *nearest = map_closest(context, &pos); |
cache_popup(context, nearest); |
630 |
|
} |
631 |
if(nearest) { |
context->press_on = NULL; |
632 |
float dist = gpx_pos_get_distance(pos, nearest->pos, FALSE); |
} else { |
633 |
|
/* save new map position */ |
634 |
printf("nearest = %s, distance = %fkm\n", nearest->name, dist); |
gfloat lat, lon; |
635 |
|
g_object_get(map, "latitude", &lat, "longitude", &lon, NULL); |
636 |
cache_popup(context->appdata, nearest); |
context->appdata->map.pos.lat = lat; |
637 |
|
context->appdata->map.pos.lon = lon; |
|
return TRUE; |
|
638 |
} |
} |
639 |
|
|
640 |
return FALSE; |
return FALSE; |
641 |
} |
} |
642 |
|
|
643 |
|
static void save_map_state(map_context_t *context) { |
644 |
|
/* save map parameters */ |
645 |
|
OsmGpsMap *map = OSM_GPS_MAP(context->widget); |
646 |
|
gint zoom; |
647 |
|
g_object_get(map, "zoom", &zoom, NULL); |
648 |
|
context->appdata->map.zoom = zoom; |
649 |
|
|
650 |
|
gfloat lat, lon; |
651 |
|
g_object_get(map, "latitude", &lat, "longitude", &lon, NULL); |
652 |
|
context->appdata->map.pos.lat = lat; |
653 |
|
context->appdata->map.pos.lon = lon; |
654 |
|
} |
655 |
|
|
656 |
#if MAEMO_VERSION_MAJOR == 5 |
#if MAEMO_VERSION_MAJOR == 5 |
657 |
static void on_window_destroy(GtkWidget *widget, map_context_t *context) { |
static void on_window_destroy(GtkWidget *widget, map_context_t *context) { |
658 |
printf("destroy map view\n"); |
printf("destroy map view\n"); |
659 |
|
|
660 |
|
save_map_state(context); |
661 |
|
|
662 |
/* restore cur_view */ |
/* restore cur_view */ |
663 |
context->appdata->cur_view = context->old_view; |
context->appdata->cur_view = context->old_view; |
664 |
|
|
677 |
const char *proxy = get_proxy_uri(appdata); |
const char *proxy = get_proxy_uri(appdata); |
678 |
|
|
679 |
context->widget = g_object_new(OSM_TYPE_GPS_MAP, |
context->widget = g_object_new(OSM_TYPE_GPS_MAP, |
680 |
"repo-uri", MAP_SOURCE_OPENSTREETMAP, |
"repo-uri", MAP_SOURCE_OPENSTREETMAP, |
681 |
"tile-cache", path, |
"tile-cache", path, |
682 |
proxy?"proxy-uri":NULL, proxy, |
"auto-center", FALSE, |
683 |
|
"record-trip-history", FALSE, |
684 |
|
"show-trip-history", FALSE, |
685 |
NULL); |
NULL); |
686 |
|
|
687 |
|
if(proxy) |
688 |
|
g_object_set(OSM_GPS_MAP(context->widget), "proxy-uri", proxy, NULL); |
689 |
|
|
690 |
g_free(path); |
g_free(path); |
691 |
|
|
692 |
char *name = NULL; |
char *name = NULL; |
703 |
#ifdef USE_MAEMO |
#ifdef USE_MAEMO |
704 |
} else { |
} else { |
705 |
map_draw_cachelist(context->widget, appdata->cur_gpx->cache); |
map_draw_cachelist(context->widget, appdata->cur_gpx->cache); |
706 |
name = g_strdup(_("appdata->cur_gpx->name")); |
name = g_strdup(appdata->cur_gpx->name); |
707 |
} |
} |
708 |
#endif |
#endif |
709 |
|
|
721 |
NULL); |
NULL); |
722 |
|
|
723 |
#ifndef USE_MAEMO |
#ifndef USE_MAEMO |
724 |
gtk_window_set_default_size(GTK_WINDOW(dialog), 400, 350); |
gtk_window_set_default_size(GTK_WINDOW(dialog), 640, 480); |
725 |
#else |
#else |
726 |
gtk_window_set_default_size(GTK_WINDOW(dialog), 800, 480); |
gtk_window_set_default_size(GTK_WINDOW(dialog), 800, 480); |
727 |
#endif |
#endif |
743 |
GtkWidget *vbox = gtk_vbox_new(FALSE,0); |
GtkWidget *vbox = gtk_vbox_new(FALSE,0); |
744 |
|
|
745 |
context->zoomin = |
context->zoomin = |
746 |
map_add_button(GTK_STOCK_ZOOM_IN, G_CALLBACK(cb_map_zoomin), |
map_add_button(10, G_CALLBACK(cb_map_zoomin), |
747 |
context, _("Zoom in")); |
context, _("Zoom in")); |
748 |
gtk_box_pack_start(GTK_BOX(vbox), context->zoomin, FALSE, FALSE, 0); |
gtk_box_pack_start(GTK_BOX(vbox), context->zoomin, FALSE, FALSE, 0); |
749 |
|
|
750 |
context->zoomout = |
context->zoomout = |
751 |
map_add_button(GTK_STOCK_ZOOM_OUT, G_CALLBACK(cb_map_zoomout), |
map_add_button(11, G_CALLBACK(cb_map_zoomout), |
752 |
context, _("Zoom out")); |
context, _("Zoom out")); |
753 |
gtk_box_pack_start(GTK_BOX(vbox), context->zoomout, FALSE, FALSE, 0); |
gtk_box_pack_start(GTK_BOX(vbox), context->zoomout, FALSE, FALSE, 0); |
754 |
|
|
755 |
context->gps = |
context->gps = |
756 |
map_add_button(GTK_STOCK_HOME, G_CALLBACK(cb_map_gps), |
map_add_button(9, G_CALLBACK(cb_map_gps), |
757 |
context, _("Jump to GPS position")); |
context, _("Jump to GPS position")); |
758 |
gtk_widget_set_sensitive(context->gps, FALSE); |
gtk_widget_set_sensitive(context->gps, FALSE); |
759 |
/* install handler for timed updates of the gps button */ |
/* install handler for timed updates of the gps button */ |
778 |
gtk_dialog_set_default_response(GTK_DIALOG(dialog), GTK_RESPONSE_CLOSE); |
gtk_dialog_set_default_response(GTK_DIALOG(dialog), GTK_RESPONSE_CLOSE); |
779 |
gtk_widget_show_all(dialog); |
gtk_widget_show_all(dialog); |
780 |
gtk_dialog_run(GTK_DIALOG(dialog)); |
gtk_dialog_run(GTK_DIALOG(dialog)); |
781 |
|
save_map_state(context); |
782 |
gtk_timeout_remove(context->handler_id); |
gtk_timeout_remove(context->handler_id); |
783 |
gtk_widget_destroy(dialog); |
gtk_widget_destroy(dialog); |
784 |
g_free(context); |
g_free(context); |