From: Kaj-Michael Lang Date: Tue, 18 Dec 2007 15:51:33 +0000 (+0200) Subject: Don't bother rendering anything if map widget is not shown. X-Git-Url: https://err.no/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=ac0d2ac6c88cd0f0c569096e68140d0dcea91bd0;p=mapper Don't bother rendering anything if map widget is not shown. Move announcements to their own function (Move all announcements to a common .c file in the future) --- diff --git a/src/map.c b/src/map.c index 1ca3299..381594f 100644 --- a/src/map.c +++ b/src/map.c @@ -278,6 +278,9 @@ map_render_tile(guint tilex, guint tiley, guint destx, guint desty, gboolean fas GdkPixbuf *pixbuf=NULL; gint zoff; +if (!GTK_WIDGET_MAPPED(_map_pixmap)) + return; + if (tilex<_world_size_tiles && tiley<_world_size_tiles) { /* The tile is possible. */ for (zoff = (_curr_repo->double_size ? 1 : 0); !pixbuf && (_zoom + zoff) <= MAX_ZOOM && zoff <= TILE_SIZE_P2; zoff += 1) { @@ -1015,11 +1018,29 @@ gtk_label_set_label(GTK_LABEL(info_banner.location), buffer); #define KM10KNOTS 5.39956803 +static void +announce_distance_to_destination(gdouble distance, gchar *unit, gdouble climit) +{ +gchar buffer[64]; +if (distance>climit) { + snprintf(buffer, sizeof(buffer), "Distance to destination: %.0f %s", distance, unit); +} else { + snprintf(buffer, sizeof(buffer), "Distance to destination: %.02f %s", distance, unit); +} +speak_text(buffer); +} + +static void +announce_destination_reached() +{ +speak_text("You have reached your destination."); +} + static void map_update_destination(gdouble lat, gdouble lon) { gdouble dh=0.0; -gdouble dt; +gdouble dt, cdist; static gdouble prev_dt=99999.0; static gboolean dest_reached=FALSE; gchar buffer[64]; @@ -1027,17 +1048,18 @@ gchar buffer[64]; if (_dest.valid) { dt=calculate_distance(lat, lon, _dest.lat, _dest.lon); 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<0 ? 360+dh : dh); + cdist=dt*UNITS_CONVERT[_units]; + + snprintf(buffer, sizeof(buffer), "%.02f %s (%0.02f)", cdist, UNITS_TEXT[_units], dh<0 ? 360+dh : dh); gtk_label_set_label(GTK_LABEL(info_banner.distance), buffer); + if (dt<0.005 && dest_reached==FALSE) { if (_center_mode>0) - speak_text("You have reached your destination."); + announce_destination_reached(); dest_reached=TRUE; } else if (dt0) { - snprintf(buffer, sizeof(buffer), "Distance to destination: %.02f %s", dt * UNITS_CONVERT[_units], UNITS_TEXT[_units]); - speak_text(buffer); - } + if (_center_mode>0) + announce_distance_to_destination(cdist, UNITS_TEXT[_units], KM10KNOTS); prev_dt=dt; } else if (dt>prev_dt+KM10KNOTS/4) { prev_dt=dt;