From b9346d08c7c43cb2d8eada6a3b573d4c93d841a2 Mon Sep 17 00:00:00 2001 From: Kaj-Michael Lang Date: Fri, 3 Aug 2007 12:21:48 +0300 Subject: [PATCH] Display speed with location. Use helper to calculate and set speed. Add toolbar item to display gps details. Small cleanups. --- src/gps-nmea-parse.c | 6 ++-- src/gps-panels.c | 79 +++++++++++++++----------------------------- src/gps-panels.h | 7 ++++ src/map.c | 6 +++- src/settings-gui.c | 2 +- src/ui-common.c | 39 ++++++++++++++++------ src/ui-common.h | 9 +++-- 7 files changed, 79 insertions(+), 69 deletions(-) create mode 100644 src/gps-panels.h diff --git a/src/gps-nmea-parse.c b/src/gps-nmea-parse.c index 915ea79..fd8fd57 100644 --- a/src/gps-nmea-parse.c +++ b/src/gps-nmea-parse.c @@ -23,7 +23,7 @@ #include "map.h" #include "track.h" #include "route.h" - +#include "gps-panels.h" #include "settings.h" gint track_drop_cnt=0; @@ -132,8 +132,10 @@ void channel_parse_rmc(gchar * sentence) token = strsep(&sentence, DELIM); if (token && *token) { MACRO_PARSE_FLOAT(_gps.speed, token); - if (_gps.fix > 1) + if (_gps.fix > 1) { _gps.maxspeed = MAX(_gps.maxspeed, _gps.speed); + gps_display_data_speed(info_banner.speed, _gps.speed); + } } /* Parse heading, degrees from true north. */ diff --git a/src/gps-panels.c b/src/gps-panels.c index af5335d..8206157 100644 --- a/src/gps-panels.c +++ b/src/gps-panels.c @@ -21,6 +21,28 @@ #include "mapper-types.h" #include "ui-common.h" +void +gps_display_data_speed(GtkWidget *widget, gfloat s) +{ +gchar *buffer; +gfloat speed = s * UNITS_CONVERT[_units]; + +switch (_units) { + case UNITS_MI: + buffer = g_strdup_printf("%.1f mph", speed); + break; + case UNITS_NM: + buffer = g_strdup_printf("%.1f kn", speed); + break; + default: + buffer = g_strdup_printf("%.1f km/h", speed); + break; + } + +gtk_label_set_label(GTK_LABEL(widget), buffer); +g_free(buffer); +} + void gps_display_data(void) { @@ -39,8 +61,6 @@ if (_gps.fix < 2) { gtk_label_set_label(GTK_LABEL(_text_alt), " --- "); gtk_label_set_label(GTK_LABEL(_text_dop), "0/0/0"); } else { - gfloat speed = _gps.speed * UNITS_CONVERT[_units]; - /* latitude */ lat_format(_gps.lat, litbuf); gtk_label_set_label(GTK_LABEL(_text_lat), litbuf); @@ -50,26 +70,13 @@ if (_gps.fix < 2) { gtk_label_set_label(GTK_LABEL(_text_lon), litbuf); /* speed */ - switch (_units) { - case UNITS_MI: - buffer = g_strdup_printf("Spd: %.1f mph", speed); - break; - case UNITS_NM: - buffer = g_strdup_printf("Spd: %.1f kn", speed); - break; - default: - buffer = g_strdup_printf("Spd: %.1f km/h", speed); - break; - } - gtk_label_set_label(GTK_LABEL(_text_speed), buffer); - g_free(buffer); + gps_display_data_speed(_text_speed, _gps.speed); /* altitude */ switch (_units) { case UNITS_MI: case UNITS_NM: - buffer = g_strdup_printf("Alt: %.1f ft", - _pos.altitude * 3.2808399f); + buffer = g_strdup_printf("Alt: %.1f ft", _pos.altitude * 3.2808399f); break; default: buffer = g_strdup_printf("Alt: %.1f m", _pos.altitude); @@ -217,8 +224,7 @@ gchar *tmp = NULL; guint x, y; printf("%s()\n", __PRETTY_FUNCTION__); -draw_sat_info(widget, - 0, 0, +draw_sat_info(widget, 0, 0, widget->allocation.width, widget->allocation.height, FALSE); @@ -602,8 +608,6 @@ gps_display_details(void) gtk_label_set_label(GTK_LABEL(_sdi_hea), " --- "); gtk_label_set_label(GTK_LABEL(_sdi_tim), " --:--:-- "); } else { - gfloat speed = _gps.speed * UNITS_CONVERT[_units]; - /* latitude */ lat_format(_gps.lat, litbuf); gtk_label_set_label(GTK_LABEL(_sdi_lat), litbuf); @@ -613,19 +617,7 @@ gps_display_details(void) gtk_label_set_label(GTK_LABEL(_sdi_lon), litbuf); /* speed */ - switch (_units) { - case UNITS_MI: - buffer = g_strdup_printf("%.1f mph", speed); - break; - case UNITS_NM: - buffer = g_strdup_printf("%.1f kn", speed); - break; - default: - buffer = g_strdup_printf("%.1f km/h", speed); - break; - } - gtk_label_set_label(GTK_LABEL(_sdi_spd), buffer); - g_free(buffer); + gps_display_data_speed(_sdi_spd, _gps.speed); /* altitude */ switch (_units) { @@ -711,24 +703,7 @@ gps_display_details(void) g_free(buffer); /* max speed */ - { - gfloat maxspeed = _gps.maxspeed * UNITS_CONVERT[_units]; - - /* speed */ - switch (_units) { - case UNITS_MI: - buffer = g_strdup_printf("%.1f mph", maxspeed); - break; - case UNITS_NM: - buffer = g_strdup_printf("%.1f kn", maxspeed); - break; - default: - buffer = g_strdup_printf("%.1f km/h", maxspeed); - break; - } - gtk_label_set_label(GTK_LABEL(_sdi_msp), buffer); - g_free(buffer); - } + gps_display_data_speed(_sdi_msp, _gps.maxspeed); /* refresh sat panel */ gtk_widget_queue_draw_area(GTK_WIDGET(_sat_details_panel), diff --git a/src/gps-panels.h b/src/gps-panels.h new file mode 100644 index 0000000..b01bc32 --- /dev/null +++ b/src/gps-panels.h @@ -0,0 +1,7 @@ +#ifndef _GPS_PANELS_H +#define _GPS_PANELS_H + +void gps_display_data_speed(GtkWidget *widget, gfloat s); +void gps_display_data(void); + +#endif diff --git a/src/map.c b/src/map.c index 59c1c66..0d69ecc 100644 --- a/src/map.c +++ b/src/map.c @@ -1412,7 +1412,7 @@ if (!s && !mp && !sp) { (mp && mp->name) ? " in " : "", (mp && mp->name) ? mp->name : ""); } -gtk_label_set_label(GTK_LABEL(_info_banner), buffer); +gtk_label_set_label(GTK_LABEL(info_banner.location), buffer); } /* XXX: Move this to osm-db.c */ @@ -1443,7 +1443,11 @@ if (map_loc.street && osm_way_distance(ilat, ilon, map_loc.street->node_f, map_l _map_location_known=map_loc.street ? TRUE : FALSE; _map_location_dist=map_loc.street ? map_loc.street->dist : 900000.0; +#if 0 p=poi_find_nearest(lat, lon); +#else +p=NULL; +#endif fs=osm_find_nearest_place(NODE_PLACE_SUBURB, ilat, ilon, &map_loc.secondary); if (fs==TRUE && map_loc.secondary && map_loc.secondary->isin!=0) { diff --git a/src/settings-gui.c b/src/settings-gui.c index 4f3959b..339f720 100644 --- a/src/settings-gui.c +++ b/src/settings-gui.c @@ -522,7 +522,7 @@ settings_dialog(void) gtk_table_attach(GTK_TABLE(table), label = gtk_label_new(_("Distance to OSM Data")), 0, 1, 4, 5, GTK_FILL, 0, 2, 4); gtk_misc_set_alignment(GTK_MISC(label), 1.f, 0.5f); - gtk_table_attach(GTK_TABLE(table), num_osm_dist = gtk_hscale_new_with_range(0, 5000, 1), + gtk_table_attach(GTK_TABLE(table), num_osm_dist = gtk_hscale_new_with_range(0, 5000, 50), 1, 2, 4, 5, GTK_EXPAND | GTK_FILL, 0, 2, 4); /* Auto-Center page. */ diff --git a/src/ui-common.c b/src/ui-common.c index f4491f3..2b61f0b 100644 --- a/src/ui-common.c +++ b/src/ui-common.c @@ -698,6 +698,10 @@ item = gtk_tool_button_new_from_stock (GTK_STOCK_ADD); g_signal_connect (item, "clicked", G_CALLBACK (cb_add_poi), NULL); gtk_toolbar_insert (GTK_TOOLBAR (_toolbar), item, -1); +item = gtk_tool_button_new_from_stock (GTK_STOCK_INFO); +g_signal_connect (item, "clicked", G_CALLBACK (menu_cb_gps_details), NULL); +gtk_toolbar_insert (GTK_TOOLBAR (_toolbar), item, -1); + item = gtk_separator_tool_item_new(); gtk_toolbar_insert (GTK_TOOLBAR (_toolbar), item, -1); @@ -740,16 +744,8 @@ gtk_toolbar_insert (GTK_TOOLBAR (_toolbar), item, -1); #endif } -/** - * Initialize everything required in preparation for calling gtk_main(). - */ -void mapper_init(gint argc, gchar ** argv) +void mapper_init_variables(void) { - GtkWidget *hbox, *mapvbox, *label, *vbox, *vbox_main; - GtkWidget *notebook; - GdkColor color; - printf("%s()\n", __PRETTY_FUNCTION__); - /* Set enum-based constants. */ UNITS_TEXT[UNITS_KM] = _("km"); UNITS_TEXT[UNITS_MI] = _("mi."); @@ -856,6 +852,19 @@ void mapper_init(gint argc, gchar ** argv) SPEED_LOCATION_TEXT[SPEED_LOCATION_TOP_RIGHT] = _("Top-Right"); SPEED_LOCATION_TEXT[SPEED_LOCATION_BOTTOM_RIGHT] = _("Bottom-Right"); SPEED_LOCATION_TEXT[SPEED_LOCATION_BOTTOM_LEFT] = _("Bottom-Left"); +} + +/** + * Initialize everything required in preparation for calling gtk_main(). + */ +void mapper_init(gint argc, gchar ** argv) +{ + GtkWidget *hbox, *mapvbox, *label, *vbox, *vbox_main; + GtkWidget *notebook, *hbanner; + GdkColor color; + printf("%s()\n", __PRETTY_FUNCTION__); + + mapper_init_variables(); /* Set up track array (must be done before config). */ memset(&_track, 0, sizeof(_track)); @@ -890,7 +899,14 @@ void mapper_init(gint argc, gchar ** argv) label = gtk_label_new("Map"); hbox = gtk_hpaned_new(); - _info_banner = gtk_label_new(""); + + info_banner.container=gtk_hbox_new(FALSE, 0); + info_banner.location=gtk_label_new(""); + info_banner.speed=gtk_label_new(""); + gtk_label_set_max_width_chars(info_banner.speed, 16); + gtk_label_set_width_chars(info_banner.speed, 14); + gtk_box_pack_start(GTK_BOX(info_banner.container), info_banner.speed, FALSE, FALSE, 0); + gtk_box_pack_start(GTK_BOX(info_banner.container), info_banner.location, TRUE, TRUE, 0); mapvbox = gtk_vbox_new(FALSE, 0); @@ -916,7 +932,8 @@ void mapper_init(gint argc, gchar ** argv) gtk_widget_show_all(vbox_main); #endif - gtk_box_pack_start(GTK_BOX(mapvbox), _info_banner, FALSE, FALSE, 0); + gtk_box_pack_start(GTK_BOX(mapvbox), info_banner.container, FALSE, FALSE, 0); + gtk_box_pack_start(GTK_BOX(mapvbox), hbox, TRUE, TRUE, 0); gtk_notebook_append_page(GTK_WIDGET(notebook), mapvbox, label); gtk_widget_show_all(mapvbox); diff --git a/src/ui-common.h b/src/ui-common.h index 16c7a09..09e2281 100644 --- a/src/ui-common.h +++ b/src/ui-common.h @@ -189,9 +189,14 @@ GtkWidget *_cmenu_poi_goto_nearpoi; /* Banners/Progress bars */ GtkWidget *_download_banner; - GtkWidget *_status_bar; -GtkWidget *_info_banner; + +struct _info_banner { + GtkWidget *container; + GtkWidget *location; + GtkWidget *speed; +}; +struct _info_banner info_banner; GtkMenu *_menu_map; -- 2.39.5