]> err.no Git - mapper/commitdiff
Don't bother rendering anything if map widget is not shown.
authorKaj-Michael Lang <milang@onion.tal.org>
Tue, 18 Dec 2007 15:51:33 +0000 (17:51 +0200)
committerKaj-Michael Lang <milang@onion.tal.org>
Tue, 18 Dec 2007 15:51:33 +0000 (17:51 +0200)
Move announcements to their own function (Move all announcements to a common .c file in the future)

src/map.c

index 1ca32994c800bd0c66bc224fe08d73ebe8674244..381594f4a5d8998af630bb9bf041a339aec94d25 100644 (file)
--- 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 (dt<prev_dt-KM10KNOTS) {
-               if (_center_mode>0) {
-                       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;