]> err.no Git - mapper/commitdiff
Set back course to next waypoint functionality
authorKaj-Michael Lang <milang@angel.tal.org>
Fri, 19 Oct 2007 12:05:42 +0000 (15:05 +0300)
committerKaj-Michael Lang <milang@angel.tal.org>
Fri, 19 Oct 2007 12:05:42 +0000 (15:05 +0300)
src/map.c

index 35d4cc1a4dd626345a77c91cfb12b32b85c7ae34..ab0f3f966ba96d493784d85e4741cca91c5b8403 100644 (file)
--- a/src/map.c
+++ b/src/map.c
@@ -590,10 +590,16 @@ gdk_draw_pixbuf(_map_pixmap, _gc[COLORABLE_POI],
 void
 map_draw_position_icon(Position *pos)
 {
-guint x,y;
+guint x,y, x1,y1;
 GdkPixbuf *p;
 
 latlon2unit(pos->lat, pos->lon, x, y);
+x1=unit2bufx(x);
+y1=unit2bufy(y);
+
+if ((x1 > BUF_WIDTH_PIXELS) || (y1 > BUF_HEIGHT_PIXELS))
+       return;
+
 p=gdk_pixbuf_new_from_file(DATADIR "/pixmaps/mapper/home.png", NULL);
 if (p) {
        map_draw_pixbuf(x,y,p);
@@ -712,32 +718,32 @@ map_render_path(Path * path, GdkGC ** gc)
 void 
 map_render_paths(void)
 {
-       if ((_show_tracks & ROUTES_MASK) && _route.head != _route.tail) {
-               map_render_path(&_route, _gc + COLORABLE_ROUTE);
-
-               /* Now, draw the next waypoint on top of all other waypoints. */
-               if (_next_way) {
-                       guint x1 = unit2bufx(_next_way->point->unitx);
-                       guint y1 = unit2bufy(_next_way->point->unity);
-                       if ((x1 < BUF_WIDTH_PIXELS)
-                           && (y1 < BUF_HEIGHT_PIXELS)) {
-                               /* Draw the next waypoint as a break. */
-                               gdk_draw_arc(_map_pixmap, _gc[COLORABLE_ROUTE_BREAK], FALSE,    /* FALSE: not filled. */
-                                            x1 - _draw_width, y1 - _draw_width, 2 * _draw_width, 2 * _draw_width, 0,   /* start at 0 degrees. */
-                                            360 * 64);
-                       }
+if ((_show_tracks & ROUTES_MASK) && _route.head != _route.tail) {
+       map_render_path(&_route, _gc + COLORABLE_ROUTE);
+
+       /* Now, draw the next waypoint on top of all other waypoints. */
+       if (_next_way) {
+               guint x1 = unit2bufx(_next_way->point->unitx);
+               guint y1 = unit2bufy(_next_way->point->unity);
+
+               if ((x1 < BUF_WIDTH_PIXELS) && (y1 < BUF_HEIGHT_PIXELS)) {
+                       /* Draw the next waypoint as a break. */
+                       gdk_draw_arc(_map_pixmap, _gc[COLORABLE_ROUTE_BREAK], FALSE,    /* FALSE: not filled. */
+                            x1 - _draw_width, y1 - _draw_width, 4 * _draw_width, 4 * _draw_width, 0,   /* start at 0 degrees. */
+                            360 * 64);
                }
        }
-       if (_show_tracks & TRACKS_MASK)
-               map_render_path(&_track, _gc + COLORABLE_TRACK);
+}
+if (_show_tracks & TRACKS_MASK)
+       map_render_path(&_track, _gc + COLORABLE_TRACK);
 }
 
 /**
  * 
  *
  */
-static 
-gboolean map_follow_move(GtkWidget *widget, GdkEventMotion *event)
+static gboolean 
+map_follow_move_cb(GtkWidget *widget, GdkEventMotion *event)
 {
 GdkModifierType state;
 gint xx, yy;
@@ -1020,6 +1026,7 @@ map_update_destination(gdouble lat, gdouble lon)
 gdouble dh=0.0;
 gdouble dt;
 static gdouble prev_dt=99999.0;
+static gboolean dest_reached=FALSE;
 gchar buffer[64];
 
 if (_dest.valid) {
@@ -1027,20 +1034,43 @@ if (_dest.valid) {
        dh=calculate_course(lat, lon, _dest.lat, _dest.lon);
        snprintf(buffer, sizeof(buffer), "%.02f %s (%0.02f)", dt * UNITS_CONVERT[_units], UNITS_TEXT[_units], dh);
        gtk_label_set_label(GTK_LABEL(info_banner.distance), buffer);
-       if (dt<prev_dt-KM10KNOTS) {
+       if (dt<0.005 && dest_reached==FALSE) {
+               speak_text("You have reached your destination.");
+               dest_reached=TRUE;
+       } else if (dt<prev_dt-KM10KNOTS) {
                snprintf(buffer, sizeof(buffer), "Distance to destination: %.02f %s", dt * UNITS_CONVERT[_units], UNITS_TEXT[_units]);
                speak_text(buffer);
                prev_dt=dt;
-       } else if (dt>prev_dt+KM10KNOTS) {
+       } else if (dt>prev_dt+KM10KNOTS/4) {
                prev_dt=dt;
        }
+       if (dt>0.05) {
+               dest_reached=FALSE;
+       }
+#if 0
        g_printf("%f (Prev:%f)\n", prev_dt, dt);
+#endif
 } else {
+       dest_reached=FALSE;
        prev_dt=99999.0;
        gtk_label_set_label(GTK_LABEL(info_banner.distance), "");
 }
 gtk_compass_set_dest_heading(_gps_compass, _dest.valid, (gfloat)dh);
 gtk_compass_set_dest_heading(_tab_compass, _dest.valid, (gfloat)dh);
+
+if (_next_way && _next_way->point) {
+       gdouble wp_lat, wp_lon;
+       gfloat wc;
+
+       unit2latlon(_next_way->point->unitx,_next_way->point->unity, wp_lat, wp_lon);
+       wc=calculate_course(lat, lon, wp_lat, wp_lon);
+       gtk_compass_set_way_heading(_gps_compass, TRUE, wc);
+       gtk_compass_set_way_heading(_tab_compass, TRUE, wc);
+} else {
+       gtk_compass_set_way_heading(_gps_compass, FALSE, 0);
+       gtk_compass_set_way_heading(_tab_compass, FALSE, 0);
+}
+
 }
 
 static void 
@@ -1104,7 +1134,7 @@ press[0] = x;
 press[1] = y;
 before[0] = press[0];
 before[1] = press[1];
-map_drag_id=g_signal_connect(G_OBJECT(_map_widget), "motion_notify_event", G_CALLBACK(map_follow_move), NULL);
+map_drag_id=g_signal_connect(G_OBJECT(_map_widget), "motion_notify_event", G_CALLBACK(map_follow_move_cb), NULL);
 }
 
 /**