From: dvlierop2 Date: Sun, 23 Aug 2009 13:55:47 +0000 (+0000) Subject: When dragging a knot along a constraint line, then allow snapping the position of... X-Git-Url: https://git.tokkee.org/?a=commitdiff_plain;h=b7447d3e7c77718d7da174d9992fd42a3efcbf33;p=inkscape.git When dragging a knot along a constraint line, then allow snapping the position of the mouse pointer instead of its projection onto the constraint line (for this a check box has been added to the preferences dialog) --- diff --git a/src/knot-holder-entity.cpp b/src/knot-holder-entity.cpp index 4225dd9e3..bf7505f3c 100644 --- a/src/knot-holder-entity.cpp +++ b/src/knot-holder-entity.cpp @@ -91,9 +91,12 @@ KnotHolderEntity::snap_knot_position(Geom::Point const &p) { Geom::Matrix const i2d (sp_item_i2d_affine(item)); Geom::Point s = p * i2d; + SnapManager &m = desktop->namedview->snap_manager; m.setup(desktop, true, item); + m.freeSnapReturnByRef(Inkscape::SnapPreferences::SNAPPOINT_NODE, s, Inkscape::SNAPSOURCE_HANDLE); + return s * i2d.inverse(); } @@ -102,10 +105,28 @@ KnotHolderEntity::snap_knot_position_constrained(Geom::Point const &p, Inkscape: { Geom::Matrix const i2d (sp_item_i2d_affine(item)); Geom::Point s = p * i2d; - Inkscape::Snapper::ConstraintLine transformed_constraint = Inkscape::Snapper::ConstraintLine(constraint.getPoint() * i2d, (constraint.getPoint() + constraint.getDirection()) * i2d - constraint.getPoint() * i2d); + SnapManager &m = desktop->namedview->snap_manager; m.setup(desktop, true, item); - m.constrainedSnapReturnByRef(Inkscape::SnapPreferences::SNAPPOINT_NODE, s, Inkscape::SNAPSOURCE_HANDLE, transformed_constraint); + + Inkscape::Preferences *prefs = Inkscape::Preferences::get(); + if ((prefs->getBool("/options/snapmousepointer/value", false))) { // legacy behavior (pre v0.47) + // Snapping the mouse pointer instead of the constrained position of the knot allows to snap to + // things which don't intersect with the constraint line. This should be handled by the + // smart dynamic guides which are yet to be implemented, making this behavior more clean and + // transparent. With the current implementation it leads to unexpected results, and it doesn't + // allow accurately controlling what is being snapped to. + + // freeSnap() will try snapping point p. This will not take into account the constraint, which + // is therefore to be enforced after snap_knot_position_constrained() has finished + m.freeSnapReturnByRef(Inkscape::SnapPreferences::SNAPPOINT_NODE, s, Inkscape::SNAPSOURCE_HANDLE); + } else { + // constrainedSnap() will first project the point p onto the constraint line and then try to snap along that line. + // This way the constraint is already enforced, no need to worry about that later on + Inkscape::Snapper::ConstraintLine transformed_constraint = Inkscape::Snapper::ConstraintLine(constraint.getPoint() * i2d, (constraint.getPoint() + constraint.getDirection()) * i2d - constraint.getPoint() * i2d); + m.constrainedSnapReturnByRef(Inkscape::SnapPreferences::SNAPPOINT_NODE, s, Inkscape::SNAPSOURCE_HANDLE, transformed_constraint); + } + return s * i2d.inverse(); } diff --git a/src/object-snapper.cpp b/src/object-snapper.cpp index aece2e9ec..af0d9f1a2 100644 --- a/src/object-snapper.cpp +++ b/src/object-snapper.cpp @@ -161,8 +161,8 @@ void Inkscape::ObjectSnapper::_findCandidates(SPObject* parent, // This item is within snapping range, so record it as a candidate _candidates->push_back(SnapCandidate(item, clip_or_mask, additional_affine)); // For debugging: print the id of the candidate to the console - // SPObject *obj = (SPObject*)item; - // std::cout << "Snap candidate added: " << obj->id << std::endl; + //SPObject *obj = (SPObject*)item; + //std::cout << "Snap candidate added: " << obj->id << std::endl; } } } @@ -554,7 +554,7 @@ void Inkscape::ObjectSnapper::_snapPathsConstrained(SnappedConstraints &sc, // The intersection point of the constraint line with any path, // must lie within two points on the constraintline: p_min_on_cl and p_max_on_cl // The distance between those points is twice the snapping tolerance - Geom::Point const p_proj_on_cl = c.projection(p); + Geom::Point const p_proj_on_cl = p; // projection has already been taken care of in constrainedSnap in the snapmanager; Geom::Point const p_min_on_cl = _snapmanager->getDesktop()->dt2doc(p_proj_on_cl - getSnapperTolerance() * direction_vector); Geom::Point const p_max_on_cl = _snapmanager->getDesktop()->dt2doc(p_proj_on_cl + getSnapperTolerance() * direction_vector); diff --git a/src/snap.cpp b/src/snap.cpp index f0769e0a1..c03f2e1e6 100644 --- a/src/snap.cpp +++ b/src/snap.cpp @@ -378,7 +378,10 @@ Inkscape::SnappedPoint SnapManager::constrainedSnap(Inkscape::SnapPreferences::P items_to_ignore = _items_to_ignore; } + + // First project the mouse pointer onto the constraint Geom::Point pp = constraint.projection(p); + // Then try to snap the projected point SnappedConstraints sc; SnapperList const snappers = getSnappers(); diff --git a/src/ui/dialog/inkscape-preferences.cpp b/src/ui/dialog/inkscape-preferences.cpp index ba07597e7..9b6d9e084 100644 --- a/src/ui/dialog/inkscape-preferences.cpp +++ b/src/ui/dialog/inkscape-preferences.cpp @@ -230,6 +230,10 @@ void InkscapePreferences::initPageSnapping() _page_snapping.add_line( false, _("Weight factor:"), _snap_weight, "", _("When multiple snap solutions are found, then Inkscape can either prefer the closest transformation (when set to 0), or prefer the node that was initially the closest to the pointer (when set to 1)"), true); + _snap_mouse_pointer.init( _("Snap the mouse pointer when dragging a constrained knot"), "/options/snapmousepointer/value", false); + _page_snapping.add_line( false, "", _snap_mouse_pointer, "", + _("When dragging a knot along a constraint line, then snap the position of the mouse pointer instead of snapping the projection of the knot onto the constraint line")); + this->AddPage(_page_snapping, _("Snapping"), PREFS_PAGE_SNAPPING); } diff --git a/src/ui/dialog/inkscape-preferences.h b/src/ui/dialog/inkscape-preferences.h index 7bcbe7d49..aa0da3a37 100644 --- a/src/ui/dialog/inkscape-preferences.h +++ b/src/ui/dialog/inkscape-preferences.h @@ -131,7 +131,7 @@ protected: PrefCheckButton _wheel_zoom; Gtk::HScale *_slider_snapping_delay; - PrefCheckButton _snap_indicator, _snap_closest_only; + PrefCheckButton _snap_indicator, _snap_closest_only, _snap_mouse_pointer; PrefCombo _steps_rot_snap; PrefCheckButton _steps_compass;