From: Diederik van Lierop Date: Wed, 17 Nov 2010 21:17:44 +0000 (+0100) Subject: Shift should disable snapping when dragging the rotation center of an object X-Git-Url: https://git.tokkee.org/?a=commitdiff_plain;h=717e3e0553e247516a48527f2e4675099f6f40d1;p=inkscape.git Shift should disable snapping when dragging the rotation center of an object --- diff --git a/src/seltrans.cpp b/src/seltrans.cpp index 5a8e5d3db..cdfcee742 100644 --- a/src/seltrans.cpp +++ b/src/seltrans.cpp @@ -1323,26 +1323,30 @@ gboolean Inkscape::SelTrans::rotateRequest(Geom::Point &pt, guint state) // Move the item's transformation center gboolean Inkscape::SelTrans::centerRequest(Geom::Point &pt, guint state) { - SnapManager &m = _desktop->namedview->snap_manager; - m.setup(_desktop); - // When dragging the transformation center while multiple items have been selected, then those // items will share a single center. While dragging that single center, it should never snap to the // centers of any of the selected objects. Therefore we will have to pass the list of selected items // to the snapper, to avoid self-snapping of the rotation center GSList *items = (GSList *) const_cast(_selection)->itemList(); + SnapManager &m = _desktop->namedview->snap_manager; + m.setup(_desktop); m.setRotationCenterSource(items); - m.freeSnapReturnByRef(pt, Inkscape::SNAPSOURCE_ROTATION_CENTER); - m.unSetup(); - if (state & GDK_CONTROL_MASK) { - if ( fabs(_point[Geom::X] - pt[Geom::X]) > fabs(_point[Geom::Y] - pt[Geom::Y]) ) { - pt[Geom::Y] = _point[Geom::Y]; - } else { - pt[Geom::X] = _point[Geom::X]; + if (state & GDK_CONTROL_MASK) { // with Ctrl, constrain to axes + std::vector constraints; + constraints.push_back(Inkscape::Snapper::SnapConstraint(_point, Geom::Point(1, 0))); + constraints.push_back(Inkscape::Snapper::SnapConstraint(_point, Geom::Point(0, 1))); + Inkscape::SnappedPoint sp = m.multipleConstrainedSnaps(Inkscape::SnapCandidatePoint(pt, Inkscape::SNAPSOURCE_ROTATION_CENTER), constraints, state & GDK_SHIFT_MASK); + pt = sp.getPoint(); + } + else { + if (!(state & GDK_SHIFT_MASK)) { // Shift disables snapping + m.freeSnapReturnByRef(pt, Inkscape::SNAPSOURCE_ROTATION_CENTER); } } + m.unSetup(); + // status text GString *xs = SP_PX_TO_METRIC_STRING(pt[Geom::X], _desktop->namedview->getDefaultMetric()); GString *ys = SP_PX_TO_METRIC_STRING(pt[Geom::Y], _desktop->namedview->getDefaultMetric()); diff --git a/src/snap.cpp b/src/snap.cpp index 8b2d188e6..79f398cc5 100644 --- a/src/snap.cpp +++ b/src/snap.cpp @@ -319,11 +319,12 @@ Geom::Point SnapManager::multipleOfGridPitch(Geom::Point const &t, Geom::Point c * constrainedSnapReturnByRef() is equal in snapping behavior to * constrainedSnap(), but the former returns the snapped point trough the referenced * parameter p. This parameter p initially contains the position of the snap - * source and will we overwritten by the target position if snapping has occurred. + * source and will be overwritten by the target position if snapping has occurred. * This makes snapping transparent to the calling code. If this is not desired * because either the calling code must know whether snapping has occurred, or * because the original position should not be touched, then constrainedSnap() should - * be called instead. + * be called instead. If there's nothing to snap to or if snapping has been disabled, + * then this method will still apply the constraint (but without snapping) * * PS: * 1) SnapManager::setup() must have been called before calling this method, @@ -357,6 +358,8 @@ void SnapManager::constrainedSnapReturnByRef(Geom::Point &p, * * PS: SnapManager::setup() must have been called before calling this method, * but only once for a set of points + * PS: If there's nothing to snap to or if snapping has been disabled, then this + * method will still apply the constraint (but without snapping) * * \param p Source point to be snapped * \param constraint The direction or line along which snapping must occur @@ -421,12 +424,14 @@ Inkscape::SnappedPoint SnapManager::constrainedSnap(Inkscape::SnapCandidatePoint * and will try to snap the SnapCandidatePoint to all of the provided constraints and see which one fits best * \param p Source point to be snapped * \param constraints List of directions or lines along which snapping must occur + * \param dont_snap If true then we will only apply the constraint, without snapping * \param bbox_to_snap Bounding box hulling the set of points, all from the same selection and having the same transformation */ Inkscape::SnappedPoint SnapManager::multipleConstrainedSnaps(Inkscape::SnapCandidatePoint const &p, std::vector const &constraints, + bool dont_snap, Geom::OptRect const &bbox_to_snap) const { @@ -438,7 +443,7 @@ Inkscape::SnappedPoint SnapManager::multipleConstrainedSnaps(Inkscape::SnapCandi SnappedConstraints sc; SnapperList const snappers = getSnappers(); std::vector projections; - bool snapping_is_futile = !someSnapperMightSnap(); + bool snapping_is_futile = !someSnapperMightSnap() || dont_snap; Inkscape::SnappedPoint result = no_snap; @@ -452,7 +457,7 @@ Inkscape::SnappedPoint SnapManager::multipleConstrainedSnaps(Inkscape::SnapCandi projections.push_back(pp); } - if (snap_mouse && p.isSingleHandle()) { + if (snap_mouse && p.isSingleHandle() && !dont_snap) { // 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 is basically // then just a freesnap with the constraint applied afterwards diff --git a/src/snap.h b/src/snap.h index 3c9af7d51..c79bd308a 100644 --- a/src/snap.h +++ b/src/snap.h @@ -135,8 +135,9 @@ public: Geom::OptRect const &bbox_to_snap = Geom::OptRect()) const; Inkscape::SnappedPoint multipleConstrainedSnaps(Inkscape::SnapCandidatePoint const &p, - std::vector const &constraints, - Geom::OptRect const &bbox_to_snap = Geom::OptRect()) const; + std::vector const &constraints, + bool dont_snap = false, + Geom::OptRect const &bbox_to_snap = Geom::OptRect()) const; Inkscape::SnappedPoint constrainedAngularSnap(Inkscape::SnapCandidatePoint const &p, boost::optional const &p_ref, diff --git a/src/ui/tool/node.cpp b/src/ui/tool/node.cpp index 9ab495488..6460d9062 100644 --- a/src/ui/tool/node.cpp +++ b/src/ui/tool/node.cpp @@ -1020,12 +1020,12 @@ void Node::dragged(Geom::Point &new_pos, GdkEventMotion *event) constraints.push_back(Inkscape::Snapper::SnapConstraint(origin, *bperp_point)); } - sp = sm.multipleConstrainedSnaps(Inkscape::SnapCandidatePoint(new_pos, _snapSourceType()), constraints); + sp = sm.multipleConstrainedSnaps(Inkscape::SnapCandidatePoint(new_pos, _snapSourceType()), constraints, held_shift(*event)); } else { // with Ctrl, constrain to axes constraints.push_back(Inkscape::Snapper::SnapConstraint(origin, Geom::Point(1, 0))); constraints.push_back(Inkscape::Snapper::SnapConstraint(origin, Geom::Point(0, 1))); - sp = sm.multipleConstrainedSnaps(Inkscape::SnapCandidatePoint(new_pos, _snapSourceType()), constraints); + sp = sm.multipleConstrainedSnaps(Inkscape::SnapCandidatePoint(new_pos, _snapSourceType()), constraints, held_shift(*event)); } new_pos = sp.getPoint(); } else if (snap) {