Code

wrtlprnft's patch for bug 234834 - keeps guidelines in same position relative to...
authorsasilver <sasilver@users.sourceforge.net>
Sat, 31 May 2008 15:16:57 +0000 (15:16 +0000)
committersasilver <sasilver@users.sourceforge.net>
Sat, 31 May 2008 15:16:57 +0000 (15:16 +0000)
src/desktop.cpp
src/desktop.h
src/document.cpp
src/sp-namedview.cpp
src/sp-namedview.h

index eee0446dbcbcad8288bcec2c709f66de49ea3f15..5796ed6386ba810fa01aef91ed359249c94f47d8 100644 (file)
@@ -975,6 +975,16 @@ SPDesktop::zoom_drawing()
     set_display_area(*d, 10);
 }
 
+/**
+ * Scroll canvas by specific coordinate amount in svg coordinates.
+ */
+void
+SPDesktop::scroll_world_in_svg_coords (double dx, double dy, bool is_scrolling)
+{
+    double scale = expansion(_d2w);
+    scroll_world(dx*scale, dy*scale, is_scrolling);
+}
+
 /**
  * Scroll canvas by specific coordinate amount.
  */
index df9848282b42ce571122ff7c0896bdd6f2fae008..af0d41b2a573ff7335480670e114e1faee43ab77 100644 (file)
@@ -257,6 +257,7 @@ struct SPDesktop : public Inkscape::UI::View::View
         using NR::Y;
         scroll_world(scroll[X], scroll[Y], is_scrolling);
     }
+    void scroll_world_in_svg_coords (double dx, double dy, bool is_scrolling = false);
 
     void getWindowGeometry (gint &x, gint &y, gint &w, gint &h);
     void setWindowPosition (NR::Point p);
index d0792ab8a7c5c01931638528d1088cd38f43b417..bf5ef089e625fb186c80860ce4e1fbf7a5020fea 100644 (file)
@@ -48,6 +48,8 @@
 #include "inkscape-private.h"
 #include "inkscape_version.h"
 #include "sp-object-repr.h"
+#include "sp-namedview.h"
+#include "desktop.h"
 #include "document-private.h"
 #include "dir-util.h"
 #include "unit-constants.h"
@@ -557,6 +559,14 @@ void SPDocument::fitToRect(NR::Rect const &rect)
     NR::translate const tr(NR::Point(0, (old_height - h))
                            - rect.min());
     SP_GROUP(root)->translateChildItems(tr);
+    SPNamedView *nv = sp_document_namedview(this, 0);
+    if(nv) {
+        NR::translate tr2(-rect.min());
+        nv->translateGuides(tr2);
+
+        // update the viewport so the drawing appears to stay where it was
+        nv->scrollAllDesktops(-tr2[0], tr2[1], false);
+    }
 }
 
 void sp_document_set_uri(SPDocument *document, gchar const *uri)
index 3575ce6aeaf5fa79a831971e1bb64be036a12798..3f52232cb52d78f1cca3c5aced43c7a5732ceb05 100644 (file)
@@ -1063,6 +1063,23 @@ Inkscape::CanvasGrid * sp_namedview_get_first_enabled_grid(SPNamedView *namedvie
     return NULL;
 }
 
+void SPNamedView::translateGuides(NR::translate const &tr) {
+    for (GSList *l = guides; l != NULL; l = l->next) {
+        SPGuide &guide = *SP_GUIDE(l->data);
+        Geom::Point point_on_line = guide.point_on_line;
+        point_on_line[0] += tr[0];
+        point_on_line[1] += tr[1];
+        sp_guide_moveto(guide, point_on_line, true);
+    }
+}
+
+void SPNamedView::scrollAllDesktops(double dx, double dy, bool is_scrolling) {
+        for(GSList *l = views; l; l = l->next) {
+            SPDesktop *desktop = static_cast<SPDesktop *>(l->data);
+            desktop->scroll_world_in_svg_coords(dx, dy, is_scrolling);
+        }
+}
+
 
 /*
   Local Variables:
index 6055f5c71e8c45f0e90dfcdb5445509327c20d00..cfc57d1c4cab6688481796e6f86932f6312622b3 100644 (file)
@@ -87,6 +87,9 @@ struct SPNamedView : public SPObjectGroup {
     guint getViewCount();
     GSList const *getViewList() const;
     SPMetric getDefaultMetric() const;
+
+    void translateGuides(NR::translate const &translation);
+    void scrollAllDesktops(double dx, double dy, bool is_scrolling);
 };
 
 struct SPNamedViewClass {