From cc25a3d62cfb7c8a9676fe4df8c09ad4ac7ac303 Mon Sep 17 00:00:00 2001 From: Kaj-Michael Lang Date: Sat, 3 Nov 2007 18:20:55 +0200 Subject: [PATCH] Add "click-on-poi" code --- src/map-poi.c | 108 +++++++++++++++++++++++++++++++++++++----------- src/map-poi.h | 33 +++++++++++++++ src/map.c | 39 +++++++++++++---- src/map.h | 2 + src/ui-common.c | 2 +- 5 files changed, 152 insertions(+), 32 deletions(-) create mode 100644 src/map-poi.h diff --git a/src/map-poi.c b/src/map-poi.c index f630d8f..e260b7a 100644 --- a/src/map-poi.c +++ b/src/map-poi.c @@ -28,7 +28,6 @@ #define _GNU_SOURCE #include -#include #include "utils.h" #include "poi.h" @@ -37,7 +36,8 @@ #include "settings.h" #include "mapper-types.h" #include "ui-common.h" -#include "db.h" +#include "map-poi.h" +#include "latlon.h" #define POI_FONT_SIZE_BIG (10) #define POI_FONT_SIZE_SMALL (8) @@ -54,6 +54,13 @@ static GdkGC *poi_gc; /* POI Icon theme. "classic" or "square". Should be made into a configuration option */ static gchar *theme="square"; +static GtkListStore *poi_store=NULL; + +static gint last_zoom=-1; +static guint prev_ux=0, prev_uy=0; + +/****************************************************************************/ + gboolean map_poi_init(GtkWidget *map_widget) { @@ -125,6 +132,76 @@ if (gdk_color_parse(hexcolor, &color)) { return def; } +static gboolean +map_poi_reload_poi(guint unitx, guint unity, gdouble lat1, gdouble lon1, gdouble lat2, gdouble lon2) +{ +guint pois; + +/* Reload POIs if we zoom out or have moved */ +if ((last_zoom<_zoom || prev_ux!=unitx || prev_uy!=unity) && poi_store!=NULL) { + gtk_list_store_clear(poi_store); + g_object_unref(G_OBJECT(poi_store)); + poi_store=NULL; + g_printf("Reloading POIs\n"); +} else { + g_printf("Using cached POIs\n"); +} + +if (poi_store==NULL) { + if (poi_get_list_inside(lat1, lon1, lat2, lon2, &poi_store, &pois)==FALSE) + return FALSE; +} +return TRUE; +} + +gboolean +map_poi_find_at_latlon(gdouble lat, gdouble lon, guint *poi_id) +{ +GtkTreeIter iter; +gboolean found=FALSE; +gboolean valid; +gdouble pdist=99999.0; + +if (_poi_zoom <= _zoom) + return FALSE; + +#if 0 +if (_zoom>5) + return FALSE; +#endif + +if (poi_store==NULL) + return FALSE; + +valid=gtk_tree_model_get_iter_first(GTK_TREE_MODEL(poi_store), &iter); +if (valid==FALSE) + return FALSE; + +while (valid) { + gdouble tmp, plat, plon; + guint id; + + gtk_tree_model_get(GTK_TREE_MODEL(poi_store), + &iter, + ITEM_ID, &id, + ITEM_LAT, &plat, + ITEM_LON, &plon, + -1); + + /* XXX: Use quicker and simple distance check */ + tmp=calculate_distance(lat, lon, plat, plon); + if ((tmpwindow, - _conn_state == RCVR_FIXED ? _gc[COLORABLE_MARK] : _gc[COLORABLE_MARK_OLD], FALSE, - _mark_x1 - _draw_width, _mark_y1 - _draw_width, - 2 * _draw_width, 2 * _draw_width, 0, 360 * 64); -gdk_draw_line(_map_widget->window, - _conn_state == RCVR_FIXED ? (_show_velvec ? _gc[COLORABLE_MARK_VELOCITY] : _gc[COLORABLE_MARK]) : _gc[COLORABLE_MARK_OLD], +gdk_draw_arc(_map_widget->window, _conn_state == RCVR_FIXED ? _gc[COLORABLE_MARK] : _gc[COLORABLE_MARK_OLD], FALSE, + _mark_x1 - _draw_width, _mark_y1 - _draw_width, 2 * _draw_width, 2 * _draw_width, 0, 360 * 64); +gdk_draw_line(_map_widget->window, _conn_state == RCVR_FIXED ? (_show_velvec ? _gc[COLORABLE_MARK_VELOCITY] : _gc[COLORABLE_MARK]) : _gc[COLORABLE_MARK_OLD], _mark_x1, _mark_y1, _mark_x2, _mark_y2); } @@ -555,9 +559,11 @@ map_update_location_from_center(void) { /* Force re-validation of place if user is clicking around */ map_loc.valid=FALSE; +/* XXX: hmm, not the right place for this */ if (_gps.fix<2) { _pos.unitx=_center.unitx; _pos.unity=_center.unity; + unit2latlon(_pos.unitx, _pos.unity, _gps.lat, _gps.lon); } map_update_location(_center.unitx, _center.unity, TRUE); return FALSE; @@ -1145,6 +1151,9 @@ map_drag_id=g_signal_connect(G_OBJECT(_map_widget), "motion_notify_event", G_CAL static void map_drag_stop(gint x, gint y) { +if (map_drag_id==0) + return; + release[0]=x; release[1]=y; g_signal_handler_disconnect(G_OBJECT(_map_widget), map_drag_id); @@ -1160,6 +1169,10 @@ map_drag_id=0; gboolean map_cb_button_press(GtkWidget * widget, GdkEventButton * event) { +gdouble lat, lon; +guint poi_id; +gint ux, uy; + _cmenu_position_x = event->x + 0.5; _cmenu_position_y = event->y + 0.5; @@ -1167,11 +1180,21 @@ switch (event->button) { case 1: if (event->type==GDK_2BUTTON_PRESS) { map_center_unit(x2unit((gint) (event->x + 0.5)), y2unit((gint) (event->y + 0.5))); + map_set_zoom(_zoom - 1); return FALSE; } if (event->type==GDK_3BUTTON_PRESS) return FALSE; - map_drag_start(event->x, event->y); + + ux=x2unit(_cmenu_position_x); + uy=y2unit(_cmenu_position_y); + + unit2latlon(ux, uy, lat, lon); + if (map_poi_find_at_latlon(lat, lon, &poi_id)==TRUE) { + g_printf("POI: %d\n", poi_id); + } else { + map_drag_start(event->x, event->y); + } break; case 2: map_set_zoom(_zoom - 1); @@ -1208,9 +1231,9 @@ case 1: default: map_drag_stop(event->x, event->y); map_render_data(); + g_idle_add_full(G_PRIORITY_HIGH_IDLE,(GSourceFunc)map_update_location_from_center, NULL, NULL); break; } - g_idle_add_full(G_PRIORITY_HIGH_IDLE,(GSourceFunc)map_update_location_from_center, NULL, NULL); break; case 2: /* */ diff --git a/src/map.h b/src/map.h index 51f52a7..7ecd9c0 100644 --- a/src/map.h +++ b/src/map.h @@ -68,6 +68,8 @@ guint _key_zoom_timeout_sid; gboolean _map_location_known; gdouble _map_location_dist; +GtkWidget *map_new(void); + gboolean map_key_zoom_timeout(); int map_zoom(gint zdir); diff --git a/src/ui-common.c b/src/ui-common.c index fe56cea..8da365c 100644 --- a/src/ui-common.c +++ b/src/ui-common.c @@ -751,7 +751,7 @@ gtk_box_pack_start(GTK_BOX(mapvbox), hbox, TRUE, TRUE, 0); ui_notebook.map=gtk_notebook_append_page(notebook, mapvbox, label); /* Map widget */ -_map_widget = gtk_drawing_area_new(); +_map_widget = map_new(); gtk_paned_add2(GTK_PANED(hbox), _map_widget); gtk_widget_realize(_map_widget); -- 2.39.5