]> err.no Git - mapper/commitdiff
Display speed with location. Use helper to calculate and set speed. Add toolbar item...
authorKaj-Michael Lang <milang@onion.tal.org>
Fri, 3 Aug 2007 09:21:48 +0000 (12:21 +0300)
committerKaj-Michael Lang <milang@onion.tal.org>
Fri, 3 Aug 2007 09:21:48 +0000 (12:21 +0300)
src/gps-nmea-parse.c
src/gps-panels.c
src/gps-panels.h [new file with mode: 0644]
src/map.c
src/settings-gui.c
src/ui-common.c
src/ui-common.h

index 915ea79d2d2bf0457a09de83f3047a29289c290a..fd8fd577958287e92cd32515b0c83376631b07b9 100644 (file)
@@ -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. */
index af5335d8128bfc3bf47996abe93c0d4d87be786a..8206157f977dc3b406336ecdb1cdc5f114cd7b2f 100644 (file)
 #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 (file)
index 0000000..b01bc32
--- /dev/null
@@ -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
index 59c1c66ed2053633b65c0010b9e8bd4759d5ae25..0d69ecc55893b54759b0c15b7e8a0c867bc51114 100644 (file)
--- 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) {
index 4f3959be74ba4c0dedefc07fac1bcdc386f817fb..339f720ae507b9c8809000a6d0793ec59aca36fc 100644 (file)
@@ -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. */
index f4491f36e031180c9351c3af072dcd22f0bf04b2..2b61f0b8d686aebf3b8b2f83273ad06379a0de1c 100644 (file)
@@ -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);
index 16c7a0959287f4a8dc905aca2c45216276e4d565..09e228147e92c34e478f1d6953990081ff724267 100644 (file)
@@ -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;