Code

Also snap new guides, which are being dragged off the ruler.
authordvlierop2 <dvlierop2@users.sourceforge.net>
Fri, 7 Sep 2007 19:22:55 +0000 (19:22 +0000)
committerdvlierop2 <dvlierop2@users.sourceforge.net>
Fri, 7 Sep 2007 19:22:55 +0000 (19:22 +0000)
src/desktop-events.cpp
src/snap.cpp
src/snap.h

index 7f9ce0b04158d08d3e5b96c86a93179de54dcf9e..90c02a7723b0fffc5d8d51748442de777a5d5000 100644 (file)
@@ -77,10 +77,15 @@ static gint sp_dt_ruler_event(GtkWidget *widget, GdkEvent *event, SPDesktopWidge
        case GDK_MOTION_NOTIFY:
             if (dragging) {
                 NR::Point const event_w(sp_canvas_window_to_world(dtw->canvas, event_win));
-                NR::Point const event_dt(desktop->w2d(event_w));
+                NR::Point event_dt(desktop->w2d(event_w));
+                
+                SnapManager const &m = desktop->namedview->snap_manager;
+                event_dt = m.guideSnap(event_dt, component_vectors[horiz ? NR::Y : NR::X]).getPoint();
+                
                 double const guide_pos_dt = event_dt[ horiz
                                                       ? NR::Y
                                                       : NR::X ];
+                
                 sp_guideline_set_position(SP_GUIDELINE(guide), guide_pos_dt);
                 desktop->set_coordinate_status(event_dt);
                 desktop->setPosition (event_dt);
@@ -141,7 +146,7 @@ gint sp_dt_guide_event(SPCanvasItem *item, GdkEvent *event, gpointer data)
     SPGuide *guide = SP_GUIDE(data);
     SPDesktop *desktop = static_cast<SPDesktop*>(gtk_object_get_data(GTK_OBJECT(item->canvas), "SPDesktop"));
 
-    switch (event->type) {
+       switch (event->type) {
        case GDK_2BUTTON_PRESS:
             if (event->button.button == 1) {
                 dragging = false;
@@ -168,8 +173,10 @@ gint sp_dt_guide_event(SPCanvasItem *item, GdkEvent *event, gpointer data)
                                          event->motion.y);
                 NR::Point motion_dt(desktop->w2d(motion_w));
                 
+                // This is for snapping while dragging existing guidelines. New guidelines, 
+                // which are dragged off the ruler, are being snapped in sp_dt_ruler_event
                 SnapManager const &m = desktop->namedview->snap_manager;
-                motion_dt = m.guideSnap(motion_dt, *guide).getPoint();
+                motion_dt = m.guideSnap(motion_dt, guide->normal).getPoint();
                 
                 sp_guide_moveto(*guide, sp_guide_position_from_pt(guide, motion_dt), false);
                 moved = true;
@@ -189,7 +196,7 @@ gint sp_dt_guide_event(SPCanvasItem *item, GdkEvent *event, gpointer data)
                     //whereas it might have been at a snapped position a millisecond before.
                     //See GDK_MOTION_NOTIFY above. Why's that????
                     SnapManager const &m = desktop->namedview->snap_manager;
-                       event_dt = m.guideSnap(event_dt, *guide).getPoint();
+                       event_dt = m.guideSnap(event_dt, guide->normal).getPoint();
                 
                     if (sp_canvas_world_pt_inside_window(item->canvas, event_w)) {
                         sp_guide_moveto(*guide, sp_guide_position_from_pt(guide, event_dt), true);
index 7a451f5d51a4d990abb39718390b8b687238dadd..886a1216ff30d94340fa9ca06afc0a9dfb90d782 100644 (file)
@@ -352,12 +352,12 @@ Inkscape::SnappedPoint SnapManager::constrainedSnap(Inkscape::Snapper::PointType
 }
 
 Inkscape::SnappedPoint SnapManager::guideSnap(NR::Point const &p,
-                                                       SPGuide const &guide) const
+                                                       NR::Point const &guide_normal) const
 {
        Inkscape::ObjectSnapper::DimensionToSnap snap_dim;
-       if (guide.normal == component_vectors[NR::Y]) {
+       if (guide_normal == component_vectors[NR::Y]) {
                snap_dim = Inkscape::ObjectSnapper::SNAP_Y;
-       } else if (guide.normal == component_vectors[NR::X]) {
+       } else if (guide_normal == component_vectors[NR::X]) {
                snap_dim = Inkscape::ObjectSnapper::SNAP_X;
        } else {
                g_warning("WARNING: snapping of angled guides is not supported yet!");
index cdd707d01167238aa8a3828aa39cd6b42d8109f8..f44df8923f68c9651db6541d1bc299bd146a1aa2 100644 (file)
@@ -84,7 +84,7 @@ public:
                                            std::list<SPItem const *> const &it) const;
                                            
        Inkscape::SnappedPoint guideSnap(NR::Point const &p,
-                                                                        SPGuide const &guide) const;
+                                                                        NR::Point const &guide_normal) const;
 
     std::pair<NR::Point, bool> freeSnapTranslation(Inkscape::Snapper::PointType t,
                                                    std::vector<NR::Point> const &p,