Code

Snap guides to grids (fixes bug #170741)
authordvlierop2 <dvlierop2@users.sourceforge.net>
Sun, 2 Aug 2009 09:55:12 +0000 (09:55 +0000)
committerdvlierop2 <dvlierop2@users.sourceforge.net>
Sun, 2 Aug 2009 09:55:12 +0000 (09:55 +0000)
src/desktop-events.cpp
src/snap.cpp
src/snap.h

index 1fae9367ce22fc9d3442f452047160d06695e09f..cea478f85847c35d149ef913d8e6d63b32b26856 100644 (file)
@@ -150,7 +150,7 @@ static gint sp_dt_ruler_event(GtkWidget *widget, GdkEvent *event, SPDesktopWidge
                 // We only have a temporary guide which is not stored in our document yet.
                 // Because the guide snapper only looks in the document for guides to snap to,
                 // we don't have to worry about a guide snapping to itself here
-                m.guideFreeSnap(event_dt, normal);
+                m.guideFreeSnap(event_dt, normal, SP_DRAG_MOVE_ORIGIN);
 
                 sp_guideline_set_position(SP_GUIDELINE(guide), from_2geom(event_dt));
                 desktop->set_coordinate_status(to_2geom(event_dt));
@@ -168,7 +168,7 @@ static gint sp_dt_ruler_event(GtkWidget *widget, GdkEvent *event, SPDesktopWidge
                 // We only have a temporary guide which is not stored in our document yet.
                 // Because the guide snapper only looks in the document for guides to snap to,
                 // we don't have to worry about a guide snapping to itself here
-                m.guideFreeSnap(event_dt, normal);
+                m.guideFreeSnap(event_dt, normal, SP_DRAG_MOVE_ORIGIN);
 
                 dragging = false;
 
@@ -213,15 +213,6 @@ int sp_dt_vruler_event(GtkWidget *widget, GdkEvent *event, SPDesktopWidget *dtw)
     return sp_dt_ruler_event(widget, event, dtw, false);
 }
 
-/* Guides */
-enum SPGuideDragType {
-    SP_DRAG_TRANSLATE,
-    SP_DRAG_TRANSLATE_CONSTRAINED, // Is not being used currently!
-    SP_DRAG_ROTATE,
-    SP_DRAG_MOVE_ORIGIN,
-    SP_DRAG_NONE
-};
-
 static Geom::Point drag_origin;
 static SPGuideDragType drag_type = SP_DRAG_NONE;
 //static bool reset_drag_origin = false; // when Ctrl is pressed while dragging, this is used to trigger resetting of the
@@ -303,7 +294,7 @@ gint sp_dt_guide_event(SPCanvasItem *item, GdkEvent *event, gpointer data)
                     motion_dt = line.pointAt(t);
                     m.guideConstrainedSnap(motion_dt, *guide);
                 } else {
-                    m.guideFreeSnap(motion_dt, guide->normal_to_line);
+                    m.guideFreeSnap(motion_dt, guide->normal_to_line, drag_type);
                 }
 
                 switch (drag_type) {
@@ -312,12 +303,6 @@ gint sp_dt_guide_event(SPCanvasItem *item, GdkEvent *event, gpointer data)
                         sp_guide_moveto(*guide, motion_dt, false);
                         break;
                     }
-                    case SP_DRAG_TRANSLATE_CONSTRAINED: // Is not being used currently!
-                    {
-                        Geom::Point pt_constr = Geom::constrain_angle(guide->point_on_line, motion_dt);
-                        sp_guide_moveto(*guide, pt_constr, false);
-                        break;
-                    }
                     case SP_DRAG_ROTATE:
                     {
                         Geom::Point pt = motion_dt - guide->point_on_line;
@@ -368,7 +353,7 @@ gint sp_dt_guide_event(SPCanvasItem *item, GdkEvent *event, gpointer data)
                         event_dt = line.pointAt(t);
                        m.guideConstrainedSnap(event_dt, *guide);
                     } else {
-                        m.guideFreeSnap(event_dt, guide->normal_to_line);
+                        m.guideFreeSnap(event_dt, guide->normal_to_line, drag_type);
                     }
 
                     if (sp_canvas_world_pt_inside_window(item->canvas, event_w)) {
@@ -378,12 +363,6 @@ gint sp_dt_guide_event(SPCanvasItem *item, GdkEvent *event, gpointer data)
                                 sp_guide_moveto(*guide, event_dt, true);
                                 break;
                             }
-                            case SP_DRAG_TRANSLATE_CONSTRAINED: // Is not being used currently!
-                            {
-                                Geom::Point pt_constr = Geom::constrain_angle(guide->point_on_line, event_dt);
-                                sp_guide_moveto(*guide, pt_constr, true);
-                                break;
-                            }
                             case SP_DRAG_ROTATE:
                             {
                                 Geom::Point pt = event_dt - guide->point_on_line;
index 9b8a7aea7ea5960a513db73556ba39bc316b91f3..f0769e0a1ad1903326446d38f50986fa7d4bc5f1 100644 (file)
@@ -405,7 +405,7 @@ Inkscape::SnappedPoint SnapManager::constrainedSnap(Inkscape::SnapPreferences::P
  *  \param p Current position of the point on the guide that is to be snapped; will be overwritten by the position of the snap target if snapping has occurred
  *  \param guide_normal Vector normal to the guide line
  */
-void SnapManager::guideFreeSnap(Geom::Point &p, Geom::Point const &guide_normal) const
+void SnapManager::guideFreeSnap(Geom::Point &p, Geom::Point const &guide_normal, SPGuideDragType drag_type) const
 {
     if (!snapprefs.getSnapEnabledGlobally() || snapprefs.getSnapPostponedGlobally()) {
         return;
@@ -415,21 +415,26 @@ void SnapManager::guideFreeSnap(Geom::Point &p, Geom::Point const &guide_normal)
         return;
     }
 
+    Inkscape::SnapSourceType source_type = Inkscape::SNAPSOURCE_GUIDE_ORIGIN;
+    if (drag_type == SP_DRAG_ROTATE) {
+       source_type = Inkscape::SNAPSOURCE_GUIDE;
+    }
+
     // Snap to nodes
     SnappedConstraints sc;
     if (object.GuidesMightSnap()) {
         object.guideFreeSnap(sc, p, guide_normal);
     }
 
-    // Snap to guides
-    if (snapprefs.getSnapToGuides()) {
-        guide.freeSnap(sc, Inkscape::SnapPreferences::SNAPPOINT_GUIDE, p, Inkscape::SNAPSOURCE_GUIDE, true, Geom::OptRect(), NULL, NULL);
-    }
-
-    // We won't snap to grids, what's the use?
+    // Snap to guides & grid lines
+    SnapperList snappers = getGridSnappers();
+    snappers.push_back(&guide);
+       for (SnapperList::const_iterator i = snappers.begin(); i != snappers.end(); i++) {
+               (*i)->freeSnap(sc, Inkscape::SnapPreferences::SNAPPOINT_GUIDE, p, source_type, true, Geom::OptRect(), NULL, NULL);
+       }
 
-    // Including snapping to intersections of curves, but not to the curves themself! (see _snapTranslatingGuideToNodes in object-snapper.cpp)
-    Inkscape::SnappedPoint const s = findBestSnap(p, Inkscape::SNAPSOURCE_GUIDE, sc, false, true);
+    // Snap to intersections of curves, but not to the curves themselves! (see _snapTranslatingGuideToNodes in object-snapper.cpp)
+    Inkscape::SnappedPoint const s = findBestSnap(p, source_type, sc, false, true);
 
     s.getPoint(p);
 }
@@ -458,21 +463,23 @@ void SnapManager::guideConstrainedSnap(Geom::Point &p, SPGuide const &guideline)
         return;
     }
 
+    Inkscape::SnapSourceType source_type = Inkscape::SNAPSOURCE_GUIDE_ORIGIN;
+
     // Snap to nodes or paths
     SnappedConstraints sc;
     Inkscape::Snapper::ConstraintLine cl(guideline.point_on_line, Geom::rot90(guideline.normal_to_line));
     if (object.ThisSnapperMightSnap()) {
-        object.constrainedSnap(sc, Inkscape::SnapPreferences::SNAPPOINT_GUIDE, p, Inkscape::SNAPSOURCE_GUIDE_ORIGIN, true, Geom::OptRect(), cl, NULL);
-    }
-
-    // Snap to guides
-    if (snapprefs.getSnapToGuides()) {
-        guide.constrainedSnap(sc, Inkscape::SnapPreferences::SNAPPOINT_GUIDE, p, Inkscape::SNAPSOURCE_GUIDE_ORIGIN, true, Geom::OptRect(), cl, NULL);
+        object.constrainedSnap(sc, Inkscape::SnapPreferences::SNAPPOINT_GUIDE, p, source_type, true, Geom::OptRect(), cl, NULL);
     }
 
-    // We won't snap to grids, what's the use?
+    // Snap to guides & grid lines
+       SnapperList snappers = getGridSnappers();
+       snappers.push_back(&guide);
+       for (SnapperList::const_iterator i = snappers.begin(); i != snappers.end(); i++) {
+               (*i)->constrainedSnap(sc, Inkscape::SnapPreferences::SNAPPOINT_GUIDE, p, source_type, true, Geom::OptRect(), cl, NULL);
+       }
 
-    Inkscape::SnappedPoint const s = findBestSnap(p, Inkscape::SNAPSOURCE_GUIDE, sc, false);
+    Inkscape::SnappedPoint const s = findBestSnap(p, source_type, sc, false);
     s.getPoint(p);
 }
 
index e360eda004a360b412616a108631a7d70e71a281..e621bdb605334cb1b1e0fa4619368d2c09ca69f4 100644 (file)
 #include "object-snapper.h"
 #include "snap-preferences.h"
 
+/* Guides */
+enum SPGuideDragType { // used both here and in desktop-events.cpp
+    SP_DRAG_TRANSLATE,
+    SP_DRAG_ROTATE,
+    SP_DRAG_MOVE_ORIGIN,
+    SP_DRAG_NONE
+};
+
 class SPNamedView;
 
 /// Class to coordinate snapping operations
@@ -103,7 +111,7 @@ public:
                                                                                   bool first_point = true,
                                            Geom::OptRect const &bbox_to_snap = Geom::OptRect()) const;
 
-    void guideFreeSnap(Geom::Point &p, Geom::Point const &guide_normal) const;
+    void guideFreeSnap(Geom::Point &p, Geom::Point const &guide_normal, SPGuideDragType drag_type) const;
     void guideConstrainedSnap(Geom::Point &p, SPGuide const &guideline) const;
 
     Inkscape::SnappedPoint freeSnapTranslation(Inkscape::SnapPreferences::PointType point_type,