56 |
#ifdef ENABLE_OSM_GPS_MAP |
#ifdef ENABLE_OSM_GPS_MAP |
57 |
struct { |
struct { |
58 |
GtkWidget *widget; |
GtkWidget *widget; |
59 |
GtkWidget *zoomin, *zoomout, *center, *modesel, *gps; |
gboolean needs_redraw; |
|
gboolean needs_redraw, drag_mode; |
|
60 |
gint handler_id; |
gint handler_id; |
61 |
coord_t start; |
coord_t start; |
62 |
} map; |
} map; |
203 |
/* we know the widgets pixel size, we know the required real size, */ |
/* we know the widgets pixel size, we know the required real size, */ |
204 |
/* we want the zoom! */ |
/* we want the zoom! */ |
205 |
double vzoom = LOG2((45.0 * context->map.widget->allocation.height)/ |
double vzoom = LOG2((45.0 * context->map.widget->allocation.height)/ |
206 |
((context->max.lat - context->min.lat)*32.0)); |
((context->max.lat - context->min.lat)*32.0)) -1; |
207 |
|
|
208 |
double hzoom = LOG2((45.0 * context->map.widget->allocation.width)/ |
double hzoom = LOG2((45.0 * context->map.widget->allocation.width)/ |
209 |
((context->max.lon - context->min.lon)*32.0)); |
((context->max.lon - context->min.lon)*32.0)) -1; |
210 |
|
|
211 |
osm_gps_map_set_center(OSM_GPS_MAP(context->map.widget), |
osm_gps_map_set_center(OSM_GPS_MAP(context->map.widget), |
212 |
center_lat, center_lon); |
center_lat, center_lon); |
397 |
static gboolean |
static gboolean |
398 |
on_map_button_press_event(GtkWidget *widget, |
on_map_button_press_event(GtkWidget *widget, |
399 |
GdkEventButton *event, context_t *context) { |
GdkEventButton *event, context_t *context) { |
400 |
if(!context->map.drag_mode) { |
OsmGpsMap *map = OSM_GPS_MAP(context->map.widget); |
|
OsmGpsMap *map = OSM_GPS_MAP(context->map.widget); |
|
|
|
|
|
/* remove existing marker */ |
|
|
osm_gps_map_clear_tracks(map); |
|
401 |
|
|
402 |
/* and remember this location as the start */ |
/* osm-gps-map needs this event to handle the OSD */ |
403 |
context->map.start = |
if(osm_gps_map_osd_check((int)event->x, (int)event->y)) |
404 |
osm_gps_map_get_co_ordinates(map, (int)event->x, (int)event->y); |
return FALSE; |
405 |
|
|
406 |
|
/* remove existing marker */ |
407 |
|
osm_gps_map_clear_tracks(map); |
408 |
|
|
409 |
|
/* and remember this location as the start */ |
410 |
|
context->map.start = |
411 |
|
osm_gps_map_get_co_ordinates(map, (int)event->x, (int)event->y); |
412 |
|
|
413 |
return TRUE; |
return TRUE; |
|
} |
|
|
|
|
|
return FALSE; |
|
414 |
} |
} |
415 |
|
|
416 |
static gboolean |
static gboolean |
417 |
on_map_motion_notify_event(GtkWidget *widget, |
on_map_motion_notify_event(GtkWidget *widget, |
418 |
GdkEventMotion *event, context_t *context) { |
GdkEventMotion *event, context_t *context) { |
419 |
if(!context->map.drag_mode && |
if(!isnan(context->map.start.rlon) && |
|
!isnan(context->map.start.rlon) && |
|
420 |
!isnan(context->map.start.rlat)) { |
!isnan(context->map.start.rlat)) { |
421 |
OsmGpsMap *map = OSM_GPS_MAP(context->map.widget); |
OsmGpsMap *map = OSM_GPS_MAP(context->map.widget); |
422 |
|
|
433 |
box = pos_append_rad(box, start.rlat, start.rlon); |
box = pos_append_rad(box, start.rlat, start.rlon); |
434 |
|
|
435 |
osm_gps_map_add_track(map, box); |
osm_gps_map_add_track(map, box); |
|
|
|
|
return TRUE; |
|
436 |
} |
} |
437 |
|
|
438 |
return FALSE; |
/* always returning true here disables dragging in osm-gps-map */ |
439 |
|
return TRUE; |
440 |
} |
} |
441 |
|
|
442 |
static gboolean |
static gboolean |
443 |
on_map_button_release_event(GtkWidget *widget, |
on_map_button_release_event(GtkWidget *widget, |
444 |
GdkEventButton *event, context_t *context) { |
GdkEventButton *event, context_t *context) { |
445 |
if(!context->map.drag_mode && |
|
446 |
!isnan(context->map.start.rlon) && |
if(!isnan(context->map.start.rlon) && |
447 |
!isnan(context->map.start.rlat)) { |
!isnan(context->map.start.rlat)) { |
448 |
OsmGpsMap *map = OSM_GPS_MAP(context->map.widget); |
OsmGpsMap *map = OSM_GPS_MAP(context->map.widget); |
449 |
|
|
479 |
extent_update(context); |
extent_update(context); |
480 |
|
|
481 |
context->map.start.rlon = context->map.start.rlat = NAN; |
context->map.start.rlon = context->map.start.rlat = NAN; |
|
|
|
|
return TRUE; |
|
482 |
} |
} |
483 |
|
|
484 |
return FALSE; |
/* osm-gps-map needs this event to handle the OSD */ |
485 |
|
if(osm_gps_map_osd_check((int)event->x, (int)event->y)) |
486 |
|
return FALSE; |
487 |
|
|
488 |
|
return TRUE; |
489 |
} |
} |
490 |
|
|
491 |
|
#if 0 |
492 |
static void map_zoom(context_t *context, int step) { |
static void map_zoom(context_t *context, int step) { |
493 |
int zoom; |
int zoom; |
494 |
OsmGpsMap *map = OSM_GPS_MAP(context->map.widget); |
OsmGpsMap *map = OSM_GPS_MAP(context->map.widget); |
495 |
g_object_get(map, "zoom", &zoom, NULL); |
g_object_get(map, "zoom", &zoom, NULL); |
496 |
zoom = osm_gps_map_set_zoom(map, zoom+step); |
zoom = osm_gps_map_set_zoom(map, zoom+step); |
|
|
|
|
/* enable/disable zoom buttons as required */ |
|
|
gtk_widget_set_sensitive(context->map.zoomin, zoom<17); |
|
|
gtk_widget_set_sensitive(context->map.zoomout, zoom>1); |
|
|
} |
|
|
|
|
|
static gboolean |
|
|
cb_map_zoomin(GtkButton *button, context_t *context) { |
|
|
map_zoom(context, +1); |
|
|
return FALSE; |
|
|
} |
|
|
|
|
|
static gboolean |
|
|
cb_map_zoomout(GtkButton *button, context_t *context) { |
|
|
map_zoom(context, -1); |
|
|
return FALSE; |
|
|
} |
|
|
|
|
|
static gboolean |
|
|
cb_map_center(GtkButton *button, context_t *context) { |
|
|
map_update(context, TRUE); |
|
|
return FALSE; |
|
|
} |
|
|
|
|
|
static gboolean |
|
|
cb_map_modesel(GtkButton *button, context_t *context) { |
|
|
/* toggle between "find" icon and "cut" icon */ |
|
|
context->map.drag_mode = !context->map.drag_mode; |
|
|
gtk_button_set_image(GTK_BUTTON(context->map.modesel), |
|
|
gtk_image_new_from_stock(context->map.drag_mode? |
|
|
GTK_STOCK_FIND:GTK_STOCK_CUT, GTK_ICON_SIZE_MENU)); |
|
|
|
|
|
return FALSE; |
|
497 |
} |
} |
498 |
|
#endif |
499 |
|
|
500 |
static gboolean |
static void |
501 |
cb_map_gps(GtkButton *button, context_t *context) { |
cb_map_gps(context_t *context) { |
502 |
pos_t pos; |
pos_t pos; |
503 |
|
|
504 |
/* user clicked "gps" button -> jump to position */ |
/* user clicked "gps" button -> jump to position */ |
510 |
osm_gps_map_set_center(OSM_GPS_MAP(context->map.widget), |
osm_gps_map_set_center(OSM_GPS_MAP(context->map.widget), |
511 |
pos.lat, pos.lon); |
pos.lat, pos.lon); |
512 |
} |
} |
|
|
|
|
return FALSE; |
|
513 |
} |
} |
514 |
|
|
515 |
static void on_page_switch(GtkNotebook *notebook, GtkNotebookPage *page, |
static void on_page_switch(GtkNotebook *notebook, GtkNotebookPage *page, |
523 |
map_update(context, TRUE); |
map_update(context, TRUE); |
524 |
} |
} |
525 |
|
|
|
static GtkWidget |
|
|
*map_add_button(const gchar *icon, GCallback cb, gpointer data, |
|
|
char *tooltip) { |
|
|
GtkWidget *button = gtk_button_new(); |
|
|
gtk_button_set_image(GTK_BUTTON(button), |
|
|
gtk_image_new_from_stock(icon, GTK_ICON_SIZE_MENU)); |
|
|
g_signal_connect(button, "clicked", cb, data); |
|
|
#ifndef USE_HILDON |
|
|
gtk_widget_set_tooltip_text(button, tooltip); |
|
|
#endif |
|
|
return button; |
|
|
} |
|
|
|
|
526 |
static gboolean map_gps_update(gpointer data) { |
static gboolean map_gps_update(gpointer data) { |
527 |
context_t *context = (context_t*)data; |
context_t *context = (context_t*)data; |
528 |
|
|
533 |
gboolean gps_fix = gps_on && |
gboolean gps_fix = gps_on && |
534 |
gps_get_pos(context->area->appdata, NULL, NULL); |
gps_get_pos(context->area->appdata, NULL, NULL); |
535 |
|
|
536 |
gtk_widget_set_sensitive(context->map.gps, gps_fix); |
/* ... and enable "goto" button if it's valid */ |
537 |
|
osm_gps_map_osd_enable_gps(OSM_GPS_MAP(context->map.widget), |
538 |
|
OSM_GPS_MAP_OSD_GPS_CALLBACK(gps_fix?cb_map_gps:NULL), context); |
539 |
|
|
540 |
|
|
541 |
return TRUE; |
return TRUE; |
542 |
} |
} |
597 |
#ifdef ENABLE_OSM_GPS_MAP |
#ifdef ENABLE_OSM_GPS_MAP |
598 |
/* ------------- fetch from map ------------------------ */ |
/* ------------- fetch from map ------------------------ */ |
599 |
|
|
|
GtkWidget *hbox = gtk_hbox_new(FALSE, 0); |
|
|
|
|
600 |
context.map.needs_redraw = FALSE; |
context.map.needs_redraw = FALSE; |
601 |
context.map.widget = g_object_new(OSM_TYPE_GPS_MAP, |
context.map.widget = g_object_new(OSM_TYPE_GPS_MAP, |
602 |
"map-source", OSM_GPS_MAP_SOURCE_OPENSTREETMAP, |
"map-source", OSM_GPS_MAP_SOURCE_OPENSTREETMAP, |
613 |
g_signal_connect(G_OBJECT(context.map.widget), "button-release-event", |
g_signal_connect(G_OBJECT(context.map.widget), "button-release-event", |
614 |
G_CALLBACK(on_map_button_release_event), &context); |
G_CALLBACK(on_map_button_release_event), &context); |
615 |
|
|
|
gtk_box_pack_start_defaults(GTK_BOX(hbox), context.map.widget); |
|
|
|
|
|
/* zoom button box */ |
|
|
vbox = gtk_vbox_new(FALSE,0); |
|
|
|
|
|
context.map.zoomin = |
|
|
map_add_button(GTK_STOCK_ZOOM_IN, G_CALLBACK(cb_map_zoomin), |
|
|
&context, _("Zoom in")); |
|
|
gtk_box_pack_start(GTK_BOX(vbox), context.map.zoomin, FALSE, FALSE, 0); |
|
|
|
|
|
context.map.zoomout = |
|
|
map_add_button(GTK_STOCK_ZOOM_OUT, G_CALLBACK(cb_map_zoomout), |
|
|
&context, _("Zoom out")); |
|
|
gtk_box_pack_start(GTK_BOX(vbox), context.map.zoomout, FALSE, FALSE, 0); |
|
|
|
|
|
context.map.center = |
|
|
map_add_button(GTK_STOCK_HOME, G_CALLBACK(cb_map_center), |
|
|
&context, _("Center selected area")); |
|
|
gtk_box_pack_start(GTK_BOX(vbox), context.map.center, FALSE, FALSE, 0); |
|
|
|
|
|
context.map.gps = |
|
|
map_add_button(GTK_STOCK_ABOUT, G_CALLBACK(cb_map_gps), |
|
|
&context, _("Jump to GPS position")); |
|
|
gtk_widget_set_sensitive(context.map.gps, FALSE); |
|
616 |
/* install handler for timed updates of the gps button */ |
/* install handler for timed updates of the gps button */ |
617 |
context.map.handler_id = gtk_timeout_add(1000, map_gps_update, &context); |
context.map.handler_id = gtk_timeout_add(1000, map_gps_update, &context); |
|
gtk_box_pack_start(GTK_BOX(vbox), context.map.gps, FALSE, FALSE, 0); |
|
|
|
|
|
context.map.drag_mode = TRUE; |
|
618 |
context.map.start.rlon = context.map.start.rlat = NAN; |
context.map.start.rlon = context.map.start.rlat = NAN; |
|
context.map.modesel = |
|
|
map_add_button(GTK_STOCK_FIND, G_CALLBACK(cb_map_modesel), |
|
|
&context, _("Toggle scroll/select")); |
|
|
gtk_box_pack_start(GTK_BOX(vbox), context.map.modesel, FALSE, FALSE, 0); |
|
|
|
|
|
gtk_box_pack_start(GTK_BOX(hbox), vbox, FALSE, FALSE, 0); |
|
619 |
|
|
620 |
gtk_notebook_append_page(GTK_NOTEBOOK(context.notebook), |
gtk_notebook_append_page(GTK_NOTEBOOK(context.notebook), |
621 |
hbox, gtk_label_new(_(TAB_LABEL_MAP))); |
context.map.widget, gtk_label_new(_(TAB_LABEL_MAP))); |
622 |
#endif |
#endif |
623 |
|
|
624 |
/* ------------ direct min/max edit --------------- */ |
/* ------------ direct min/max edit --------------- */ |