From 2d4b6e2f1977a42d24fcaab660f8491c50016c9e Mon Sep 17 00:00:00 2001 From: johanengelen Date: Tue, 4 Mar 2008 21:33:35 +0000 Subject: [PATCH] add snapindicator to rect tool but not satisfactory yet... --- src/context-fns.cpp | 19 ++++++++++++++++--- src/rect-context.cpp | 18 ++++++++++++++---- 2 files changed, 30 insertions(+), 7 deletions(-) diff --git a/src/context-fns.cpp b/src/context-fns.cpp index c845fd275..32c7eef00 100644 --- a/src/context-fns.cpp +++ b/src/context-fns.cpp @@ -12,6 +12,7 @@ #include "desktop-affine.h" #include "event-context.h" #include "sp-namedview.h" +#include "display/snap-indicator.h" static const double midpt_1_goldenratio = (1 + goldenratio) / 2; static const double midpt_goldenratio_2 = (goldenratio + 2) / 2; @@ -85,6 +86,7 @@ NR::Rect Inkscape::snap_rectangular_box(SPDesktop const *desktop, SPItem *item, bool const control = state & GDK_CONTROL_MASK; SnapManager const &m = desktop->namedview->snap_manager; + Inkscape::SnappedPoint snappoint; if (control) { @@ -140,17 +142,20 @@ NR::Rect Inkscape::snap_rectangular_box(SPDesktop const *desktop, SPItem *item, if (s[0].getDistance() < s[1].getDistance()) { p[0] = s[0].getPoint(); p[1] = 2 * center - s[0].getPoint(); + snappoint = s[0]; } else { p[0] = 2 * center - s[1].getPoint(); p[1] = s[1].getPoint(); + snappoint = s[1]; } } else { /* Our origin is the opposite corner. Snap the drag point along the constraint vector */ p[0] = center; - p[1] = m.constrainedSnap(Inkscape::Snapper::SNAPPOINT_NODE, p[1], - Inkscape::Snapper::ConstraintLine(p[1] - p[0]), item).getPoint(); + snappoint = m.constrainedSnap(Inkscape::Snapper::SNAPPOINT_NODE, p[1], + Inkscape::Snapper::ConstraintLine(p[1] - p[0]), item); + p[1] = snappoint.getPoint(); } } else if (shift) { @@ -170,16 +175,24 @@ NR::Rect Inkscape::snap_rectangular_box(SPDesktop const *desktop, SPItem *item, if (s[0].getDistance() < s[1].getDistance()) { p[0] = s[0].getPoint(); p[1] = 2 * center - s[0].getPoint(); + snappoint = s[0]; } else { p[0] = 2 * center - s[1].getPoint(); p[1] = s[1].getPoint(); + snappoint = s[1]; } } else { /* There's no constraint on the corner point, so just snap it to anything */ p[0] = center; - p[1] = m.freeSnap(Inkscape::Snapper::SNAPPOINT_NODE, pt, item).getPoint(); + snappoint = m.freeSnap(Inkscape::Snapper::SNAPPOINT_NODE, pt, item); + p[1] = snappoint.getPoint(); + } + + if (snappoint.getDistance() < NR_HUGE) { + // this does not work well enough yet. +// desktop->snapindicator->set_new_snappoint(snappoint.getPoint().to_2geom()); } p[0] = sp_desktop_dt2root_xy_point(desktop, p[0]); diff --git a/src/rect-context.cpp b/src/rect-context.cpp index 6aa7d418c..70d7b7721 100644 --- a/src/rect-context.cpp +++ b/src/rect-context.cpp @@ -23,6 +23,7 @@ #include "macros.h" #include "display/sp-canvas.h" +#include "display/snap-indicator.h" #include "sp-rect.h" #include "document.h" #include "sp-namedview.h" @@ -283,6 +284,8 @@ static gint sp_rect_context_root_handler(SPEventContext *event_context, GdkEvent event_context->tolerance = prefs_get_int_attribute_limited("options.dragtolerance", "value", 0, 0, 100); + desktop->snapindicator->remove_snappoint(); + gint ret = FALSE; switch (event->type) { case GDK_BUTTON_PRESS: @@ -305,8 +308,11 @@ static gint sp_rect_context_root_handler(SPEventContext *event_context, GdkEvent /* Snap center */ SnapManager const &m = desktop->namedview->snap_manager; - rc->center = m.freeSnap(Inkscape::Snapper::SNAPPOINT_NODE, - button_dt, rc->item).getPoint(); + Inkscape::SnappedPoint s = m.freeSnap(Inkscape::Snapper::SNAPPOINT_NODE, button_dt, rc->item); + rc->center = s.getPoint(); + if (s.getDistance() < NR_HUGE) { + desktop->snapindicator->set_new_snappoint(s.getPoint().to_2geom()); + } sp_canvas_item_grab(SP_CANVAS_ITEM(desktop->acetate), ( GDK_KEY_PRESS_MASK | @@ -336,8 +342,12 @@ static gint sp_rect_context_root_handler(SPEventContext *event_context, GdkEvent NR::Point motion_dt(desktop->w2d(motion_w)); SnapManager const &m = desktop->namedview->snap_manager; - motion_dt = m.freeSnap(Inkscape::Snapper::SNAPPOINT_NODE, motion_dt, rc->item).getPoint(); - + Inkscape::SnappedPoint s = m.freeSnap(Inkscape::Snapper::SNAPPOINT_NODE, motion_dt, rc->item); + motion_dt = s.getPoint(); + if (s.getDistance() < NR_HUGE) { + desktop->snapindicator->set_new_snappoint(s.getPoint().to_2geom()); + } + sp_rect_drag(*rc, motion_dt, event->motion.state); gobble_motion_events(GDK_BUTTON1_MASK); ret = TRUE; -- 2.30.2