diff --git a/src/seltrans.cpp b/src/seltrans.cpp index 96e6b2c94a2e2063fda172835dd56ae0da91e3a0..ef2207d99e8cbd01dc367c41f6a4c0ee70f1ff1c 100644 --- a/src/seltrans.cpp +++ b/src/seltrans.cpp @@ -1404,6 +1404,12 @@ void Inkscape::SelTrans::rotate(Geom::Point &/*pt*/, guint /*state*/) void Inkscape::SelTrans::moveTo(Geom::Point const &xy, guint state) { + static bool snaped = false; + static Geom::Point prevsnappoint; + Inkscape::Preferences *prefs = Inkscape::Preferences::get(); + double snapdistance = prefs->getDoubleLimited("/options/snapweight/value", 0.5, 0, 1); + snapdistance *= 50.0; //snapped-point.cpp:186 + SnapManager &m = _desktop->namedview->snap_manager; /* The amount that we've moved by during this drag */ @@ -1486,12 +1492,29 @@ void Inkscape::SelTrans::moveTo(Geom::Point const &xy, guint state) best_snapped_point = bb->best_snapped_point; dxy = bb->getTranslationSnapped(); } - + Geom::Point origin = best_snapped_point.getPoint(); + Geom::Point snap = origin; + best_snapped_point.getPointIfSnapped(snap); if (best_snapped_point.getSnapped()) { + Geom::Point p = best_snapped_point.getPoint(); + if (!Geom::are_near(origin, snap) || !Geom::are_near(prevsnappoint,snap)) { + snaped = false; + } + prevsnappoint = snap; + if (!snaped) { + snaped = true; + Geom::Affine const move((Geom::Translate(dxy))); + Geom::Point const norm(0, 0); + transform(move, norm); + } _desktop->snapindicator->set_new_snaptarget(best_snapped_point); } else { - // We didn't snap, so remove any previous snap indicator - _desktop->snapindicator->remove_snaptarget(); + if (snapdistance < std::abs(Geom::distance(dxy, snap))) { + snaped = false; + // We didn't snap, so remove any previous snap indicator + _desktop->snapindicator->remove_snaptarget(); + } + if (control) { // If we didn't snap, then we should still constrain horizontally or vertically // (When we did snap, then this constraint has already been enforced by @@ -1506,11 +1529,11 @@ void Inkscape::SelTrans::moveTo(Geom::Point const &xy, guint state) delete bb; delete sn; } - - Geom::Affine const move((Geom::Translate(dxy))); - Geom::Point const norm(0, 0); - transform(move, norm); - + if (!snaped) { + Geom::Affine const move((Geom::Translate(dxy))); + Geom::Point const norm(0, 0); + transform(move, norm); + } // status text Inkscape::Util::Quantity x_q = Inkscape::Util::Quantity(dxy[Geom::X], "px"); Inkscape::Util::Quantity y_q = Inkscape::Util::Quantity(dxy[Geom::Y], "px"); diff --git a/src/ui/tools/tool-base.cpp b/src/ui/tools/tool-base.cpp index 4a12a7b829e5473eb612074f5c9590fcc706aa25..90f4b8eef25957999fe0f9d7d0f1e229524fe992 100644 --- a/src/ui/tools/tool-base.cpp +++ b/src/ui/tools/tool-base.cpp @@ -1108,34 +1108,6 @@ gint sp_event_context_root_handler(ToolBase * event_context, GdkEvent * event) { - if (!event_context->_uses_snap) { - return sp_event_context_virtual_root_handler(event_context, event); - } - - switch (event->type) { - case GDK_MOTION_NOTIFY: - sp_event_context_snap_delay_handler(event_context, nullptr, nullptr, - (GdkEventMotion *) event, - DelayedSnapEvent::EVENTCONTEXT_ROOT_HANDLER); - break; - case GDK_BUTTON_RELEASE: - if (event_context && event_context->_delayed_snap_event) { - // If we have any pending snapping action, then invoke it now - sp_event_context_snap_watchdog_callback( - event_context->_delayed_snap_event); - } - break; - case GDK_BUTTON_PRESS: - case GDK_2BUTTON_PRESS: - case GDK_3BUTTON_PRESS: - // Snapping will be on hold if we're moving the mouse at high speeds. When starting - // drawing a new shape we really should snap though. - event_context->desktop->namedview->snap_manager.snapprefs.setSnapPostponedGlobally(false); - break; - default: - break; - } - return sp_event_context_virtual_root_handler(event_context, event); }