From 8e605dd148c19e58a75d520b03d258108ffee661 Mon Sep 17 00:00:00 2001 From: Jabiertxof Date: Thu, 14 May 2020 18:35:21 +0200 Subject: [PATCH] Get precise snapping Snaping is not precise, user couldent be sure if on release the target is snaped or not To fix it I improve snaping in two ways: 1. General one (creartion tools) we remove snaping from root event and use only item based events 2. For transforms we define a treshold to the snaped item become unsnaped --- src/seltrans.cpp | 39 ++++++++++++++++++++++++++++++-------- src/ui/tools/tool-base.cpp | 28 --------------------------- 2 files changed, 31 insertions(+), 36 deletions(-) diff --git a/src/seltrans.cpp b/src/seltrans.cpp index 96e6b2c94a..ef2207d99e 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 4a12a7b829..90f4b8eef2 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); } -- GitLab