]> git.street.me.uk Git - andy/viking.git/commitdiff
Some work on zoom-in overflow bugs
authorEvan Battaglia <gtoevan@gmx.net>
Sun, 16 Oct 2005 02:38:01 +0000 (02:38 +0000)
committerEvan Battaglia <gtoevan@gmx.net>
Sun, 16 Oct 2005 02:38:01 +0000 (02:38 +0000)
TODO
src/viktrwlayer.c
src/vikviewport.c
src/vikviewport.h
src/vikwindow.c

diff --git a/TODO b/TODO
index 7913349f6d739ffe38e1a4b999aef55ae59a5797..23d4e1a4ee0b8225b58cb0c181b681b142af7067 100644 (file)
--- a/TODO
+++ b/TODO
@@ -15,6 +15,7 @@ BEFORE RELEASE:
        arrows to show track direction
 
 EASY FIXES:
+       "Interesting" stuff happens when we swich modes while using the ruler.
        "click to go there" elevation map: average out, not nearest trackpoint.
        Ruler: calculate degrees by spherical geometry formula ('zoom in too much' bug -- coord_to_screen out of range of double)
                for UTM: rotate compass for declination.
index 6a4c93d1d13bf0bd5fa9c736152dcc8190977000..25ca229860d1793996b856aef7fa75e006793f53 100644 (file)
@@ -1588,7 +1588,7 @@ static void trw_layer_drag_drop_request ( VikTrwLayer *vtl_src, VikTrwLayer *vtl
       iter = iter->next;
     }
     if (items) 
-      g_list_free(items);
+      g_slist_free(items);
   } else {
     gchar *name = vik_treeview_item_get_pointer(vt, src_item_iter);
     trw_layer_move_item(vtl_src, vtl_dest, name, type);
index 65d0499f76ab06599b8a13c76545ab31041772d4..b20646c1273f2a14b61aaf7a69e4890921915f45 100644 (file)
@@ -684,11 +684,36 @@ void vik_viewport_coord_to_screen ( VikViewport *vvp, const VikCoord *coord, int
   }
 }
 
+void a_viewport_clip_line ( gint *x1, gint *y1, gint *x2, gint *y2 )
+{
+  if ( *x1 > 20000 || *x1 < -20000 ) {
+    gdouble shrinkfactor = ABS(20000.0 / *x1);
+    *x1 = *x2 + (shrinkfactor * (*x1-*x2));
+    *y1 = *y2 + (shrinkfactor * (*y1-*y2));
+  } else if ( *y1 > 20000 || *y1 < -20000 ) {
+    gdouble shrinkfactor = ABS(20000.0 / *x1);
+    *x1 = *x2 + (shrinkfactor * (*x1-*x2));
+    *y1 = *y2 + (shrinkfactor * (*y1-*y2));
+  } else if ( *x2 > 20000 || *x2 < -20000 ) {
+    gdouble shrinkfactor = ABS(20000.0 / (gdouble)*x2);
+    *x2 = *x1 + (shrinkfactor * (*x2-*x1));
+    *y2 = *y1 + (shrinkfactor * (*y2-*y1));
+    printf("%f, %d, %d\n", shrinkfactor, *x2, *y2);
+  } else if ( *y2 > 20000 || *y2 < -20000 ) {
+    gdouble shrinkfactor = ABS(20000.0 / (gdouble)*x2);
+    *x2 = *x1 + (shrinkfactor * (*x2-*x1));
+    *y2 = *y1 + (shrinkfactor * (*y2-*y1));
+  }
+}
+
 void vik_viewport_draw_line ( VikViewport *vvp, GdkGC *gc, gint x1, gint y1, gint x2, gint y2 )
 {
   if ( ! ( ( x1 < 0 && x2 < 0 ) || ( y1 < 0 && y2 < 0 ) ||
-       ( x1 > vvp->width && x2 > vvp->width ) || ( y1 > vvp->height && y2 > vvp->height ) ) )
-   gdk_draw_line ( vvp->scr_buffer, gc, x1, y1, x2, y2);
+       ( x1 > vvp->width && x2 > vvp->width ) || ( y1 > vvp->height && y2 > vvp->height ) ) ) {
+    /*** clipping, yeah! ***/
+    a_viewport_clip_line ( &x1, &y1, &x2, &y2 );
+    gdk_draw_line ( vvp->scr_buffer, gc, x1, y1, x2, y2);
+  }
 }
 
 void vik_viewport_draw_rectangle ( VikViewport *vvp, GdkGC *gc, gboolean filled, gint x1, gint y1, gint x2, gint y2 )
index 1add97aeeb49a851479aa173b6137faa5022651f..802e582b0330ad82960c7e1f48372fb21fcfd895 100644 (file)
@@ -102,6 +102,9 @@ gint vik_viewport_get_height ( VikViewport *vvp );
 
 GdkGC *vik_viewport_new_gc ( VikViewport *vvp, const gchar *colorname, gint thickness );
 
+/* run this before drawing a line. vik_viewport_draw_line runs it for you */
+void a_viewport_clip_line ( gint *x1, gint *y1, gint *x2, gint *y2 );
+
 void vik_viewport_draw_line ( VikViewport *vvp, GdkGC *gc, gint x1, gint y1, gint x2, gint y2 );
 void vik_viewport_draw_rectangle ( VikViewport *vvp, GdkGC *gc, gboolean filled, gint x1, gint y1, gint x2, gint y2 );
 void vik_viewport_draw_string ( VikViewport *vvp, GdkFont *font, GdkGC *gc, gint x1, gint y1, const gchar *string );
index d98c8ad876a7f3edf941b433f5c8edaa079ea9ee..8c5789469b87e28051872371c1afb37990f3660c 100644 (file)
@@ -323,7 +323,15 @@ static void draw_ruler(VikViewport *vvp, GdkDrawable *d, GdkGC *gc, gint x1, gin
   gint i;
 
   /* draw line with arrow ends */
-  gdk_draw_line(d, gc, x1, y1, x2, y2);
+  {
+    gint tmp_x1=x1, tmp_y1=y1, tmp_x2=x2, tmp_y2=y2;
+    a_viewport_clip_line(&tmp_x1, &tmp_y1, &tmp_x2, &tmp_y2);
+    gdk_draw_line(d, gc, tmp_x1, tmp_y1, tmp_x2, tmp_y2);
+  }
+
+    a_viewport_clip_line(&x1, &y1, &x2, &y2);
+    gdk_draw_line(d, gc, x1, y1, x2, y2);
+
   gdk_draw_line(d, gc, x1 - dy, y1 + dx, x1 + dy, y1 - dx);
   gdk_draw_line(d, gc, x2 - dy, y2 + dx, x2 + dy, y2 - dx);
   gdk_draw_line(d, gc, x2, y2, x2 - (dx * c + dy * s), y2 - (dy * c - dx * s));