From 957324b1de76466c62aec3c1a8bf5b851dd322a2 Mon Sep 17 00:00:00 2001 From: dvlierop2 Date: Fri, 7 Sep 2007 19:22:55 +0000 Subject: [PATCH] Also snap new guides, which are being dragged off the ruler. --- src/desktop-events.cpp | 15 +++++++++++---- src/snap.cpp | 6 +++--- src/snap.h | 2 +- 3 files changed, 15 insertions(+), 8 deletions(-) diff --git a/src/desktop-events.cpp b/src/desktop-events.cpp index 7f9ce0b04..90c02a772 100644 --- a/src/desktop-events.cpp +++ b/src/desktop-events.cpp @@ -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(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); diff --git a/src/snap.cpp b/src/snap.cpp index 7a451f5d5..886a1216f 100644 --- a/src/snap.cpp +++ b/src/snap.cpp @@ -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!"); diff --git a/src/snap.h b/src/snap.h index cdd707d01..f44df8923 100644 --- a/src/snap.h +++ b/src/snap.h @@ -84,7 +84,7 @@ public: std::list const &it) const; Inkscape::SnappedPoint guideSnap(NR::Point const &p, - SPGuide const &guide) const; + NR::Point const &guide_normal) const; std::pair freeSnapTranslation(Inkscape::Snapper::PointType t, std::vector const &p, -- 2.30.2