From: Diederik van Lierop Date: Tue, 20 Jul 2010 19:18:58 +0000 (+0200) Subject: - Remove some old code which snapped the rotation center to the bbox, and which disca... X-Git-Url: https://git.tokkee.org/?a=commitdiff_plain;h=75bbef79b0ac9fed0049660182ff6ef9e96d1a73;p=inkscape.git - Remove some old code which snapped the rotation center to the bbox, and which discarded all of the snapping settings - Improve the logic behind the snapping buttons, i.e. what snaps to what for each of the buttons --- diff --git a/src/object-snapper.cpp b/src/object-snapper.cpp index 7d593dfc4..4c5ad800c 100644 --- a/src/object-snapper.cpp +++ b/src/object-snapper.cpp @@ -86,10 +86,7 @@ void Inkscape::ObjectSnapper::_findCandidates(SPObject* parent, bool const clip_or_mask, Geom::Matrix const additional_affine) const // transformation of the item being clipped / masked { - bool const c1 = (snap_dim == TRANSL_SNAP_XY) && ThisSnapperMightSnap(); - bool const c2 = (snap_dim != TRANSL_SNAP_XY) && GuidesMightSnap(); - - if (!(c1 || c2)) { + if (!((snap_dim == TRANSL_SNAP_XY) && ThisSnapperMightSnap())) { return; } @@ -98,7 +95,6 @@ void Inkscape::ObjectSnapper::_findCandidates(SPObject* parent, // Apparently the etup() method from the SnapManager class hasn't been called before trying to snap. } - if (first_point) { _candidates->clear(); } @@ -338,7 +334,7 @@ void Inkscape::ObjectSnapper::_collectPaths(Inkscape::SnapCandidatePoint const & } // Consider the page border for snapping - if (_snapmanager->snapprefs.getSnapToPageBorder()) { + if (_snapmanager->snapprefs.getSnapToPageBorder() && _snapmanager->snapprefs.getSnapModeBBoxOrNodes()) { Geom::PathVector *border_path = _getBorderPathv(); if (border_path != NULL) { _paths_to_snap_to->push_back(Inkscape::SnapCandidatePath(border_path, SNAPTARGET_PAGE_BORDER, Geom::OptRect())); @@ -363,7 +359,7 @@ void Inkscape::ObjectSnapper::_collectPaths(Inkscape::SnapCandidatePoint const & //Build a list of all paths considered for snapping to //Add the item's path to snap to - if (_snapmanager->snapprefs.getSnapToItemPath()) { + if (_snapmanager->snapprefs.getSnapToItemPath() && _snapmanager->snapprefs.getSnapModeNode()) { if (p_is_other || !(_snapmanager->snapprefs.getStrictSnapping() && !p_is_a_node)) { // Snapping to the path of characters is very cool, but for a large // chunk of text this will take ages! So limit snapping to text paths @@ -402,7 +398,7 @@ void Inkscape::ObjectSnapper::_collectPaths(Inkscape::SnapCandidatePoint const & } //Add the item's bounding box to snap to - if (_snapmanager->snapprefs.getSnapToBBoxPath()) { + if (_snapmanager->snapprefs.getSnapToBBoxPath() && _snapmanager->snapprefs.getSnapModeBBox()) { if (p_is_other || !(_snapmanager->snapprefs.getStrictSnapping() && p_is_a_node)) { // Discard the bbox of a clipped path / mask, because we don't want to snap to both the bbox // of the item AND the bbox of the clipping path at the same time @@ -606,15 +602,28 @@ void Inkscape::ObjectSnapper::freeSnap(SnappedConstraints &sc, _findCandidates(sp_document_root(_snapmanager->getDocument()), it, p.getSourceNum() == 0, local_bbox_to_snap, TRANSL_SNAP_XY, false, Geom::identity()); } - if (_snapmanager->snapprefs.getSnapToItemNode() || _snapmanager->snapprefs.getSnapSmoothNodes() - || _snapmanager->snapprefs.getSnapToBBoxNode() || _snapmanager->snapprefs.getSnapToPageBorder() - || _snapmanager->snapprefs.getSnapLineMidpoints() || _snapmanager->snapprefs.getSnapObjectMidpoints() - || _snapmanager->snapprefs.getSnapBBoxEdgeMidpoints() || _snapmanager->snapprefs.getSnapBBoxMidpoints() - || _snapmanager->snapprefs.getIncludeItemCenter()) { + + bool snap_nodes = _snapmanager->snapprefs.getSnapModeNode() && ( + _snapmanager->snapprefs.getSnapToItemNode() || + _snapmanager->snapprefs.getSnapSmoothNodes() || + _snapmanager->snapprefs.getSnapLineMidpoints() || + _snapmanager->snapprefs.getSnapObjectMidpoints() + ) || _snapmanager->snapprefs.getSnapModeBBox() && ( + _snapmanager->snapprefs.getSnapToBBoxNode() || + _snapmanager->snapprefs.getSnapBBoxEdgeMidpoints() || + _snapmanager->snapprefs.getSnapBBoxMidpoints() + ) || _snapmanager->snapprefs.getSnapModeBBoxOrNodes() && ( + _snapmanager->snapprefs.getIncludeItemCenter() || + _snapmanager->snapprefs.getSnapToPageBorder() + ); + + if (snap_nodes) { _snapNodes(sc, p, unselected_nodes); } - if (_snapmanager->snapprefs.getSnapToItemPath() || _snapmanager->snapprefs.getSnapToBBoxPath() || _snapmanager->snapprefs.getSnapToPageBorder()) { + if (_snapmanager->snapprefs.getSnapModeNode() && _snapmanager->snapprefs.getSnapToItemPath() || + _snapmanager->snapprefs.getSnapModeBBox() && _snapmanager->snapprefs.getSnapToBBoxPath() || + _snapmanager->snapprefs.getSnapModeBBoxOrNodes() && _snapmanager->snapprefs.getSnapToPageBorder()) { unsigned n = (unselected_nodes == NULL) ? 0 : unselected_nodes->size(); if (n > 0) { /* While editing a path in the node tool, findCandidates must ignore that path because @@ -719,29 +728,23 @@ void Inkscape::ObjectSnapper::guideConstrainedSnap(SnappedConstraints &sc, */ bool Inkscape::ObjectSnapper::ThisSnapperMightSnap() const { - bool snap_to_something = _snapmanager->snapprefs.getSnapToItemPath() - || _snapmanager->snapprefs.getSnapToItemNode() || _snapmanager->snapprefs.getSnapSmoothNodes() - || _snapmanager->snapprefs.getSnapToBBoxPath() - || _snapmanager->snapprefs.getSnapToBBoxNode() - || _snapmanager->snapprefs.getSnapToPageBorder() - || _snapmanager->snapprefs.getSnapLineMidpoints() || _snapmanager->snapprefs.getSnapObjectMidpoints() - || _snapmanager->snapprefs.getSnapBBoxEdgeMidpoints() || _snapmanager->snapprefs.getSnapBBoxMidpoints() - || _snapmanager->snapprefs.getIncludeItemCenter(); - - return (_snap_enabled && _snapmanager->snapprefs.getSnapModeBBoxOrNodes() && snap_to_something); -} - -bool Inkscape::ObjectSnapper::GuidesMightSnap() const // almost the same as ThisSnapperMightSnap above, but only looking at points (and not paths) -{ - bool snap_to_something = _snapmanager->snapprefs.getSnapToItemNode() || _snapmanager->snapprefs.getSnapSmoothNodes() - || _snapmanager->snapprefs.getSnapToPageBorder() - || (_snapmanager->snapprefs.getSnapModeBBox() && _snapmanager->snapprefs.getSnapToBBoxNode()) - || (_snapmanager->snapprefs.getSnapModeBBox() && (_snapmanager->snapprefs.getSnapBBoxEdgeMidpoints() || _snapmanager->snapprefs.getSnapBBoxMidpoints())) - || (_snapmanager->snapprefs.getSnapModeNode() && (_snapmanager->snapprefs.getSnapLineMidpoints() || _snapmanager->snapprefs.getSnapObjectMidpoints())) - || (_snapmanager->snapprefs.getSnapModeNode() && _snapmanager->snapprefs.getIncludeItemCenter()) - || (_snapmanager->snapprefs.getSnapModeNode() && (_snapmanager->snapprefs.getSnapToItemPath() && _snapmanager->snapprefs.getSnapIntersectionCS())); - - return (_snap_enabled && _snapmanager->snapprefs.getSnapModeGuide() && snap_to_something); + bool snap_to_something = (_snapmanager->snapprefs.getSnapModeNode() && ( + _snapmanager->snapprefs.getSnapToItemPath() || + _snapmanager->snapprefs.getSnapToItemNode() || + _snapmanager->snapprefs.getSnapSmoothNodes() || + _snapmanager->snapprefs.getSnapLineMidpoints() || + _snapmanager->snapprefs.getSnapObjectMidpoints() + )) || (_snapmanager->snapprefs.getSnapModeBBox() && ( + _snapmanager->snapprefs.getSnapToBBoxPath() || + _snapmanager->snapprefs.getSnapToBBoxNode() || + _snapmanager->snapprefs.getSnapBBoxEdgeMidpoints() || + _snapmanager->snapprefs.getSnapBBoxMidpoints() + )) || (_snapmanager->snapprefs.getSnapModeBBoxOrNodes() && ( + _snapmanager->snapprefs.getSnapToPageBorder() || + _snapmanager->snapprefs.getIncludeItemCenter() + )); + + return (_snap_enabled && snap_to_something); } void Inkscape::ObjectSnapper::_clear_paths() const diff --git a/src/object-snapper.h b/src/object-snapper.h index b0084c2d7..f3b54ed08 100644 --- a/src/object-snapper.h +++ b/src/object-snapper.h @@ -49,7 +49,6 @@ public: SnapConstraint const &c) const; bool ThisSnapperMightSnap() const; - bool GuidesMightSnap() const; Geom::Coord getSnapperTolerance() const; //returns the tolerance of the snapper in screen pixels (i.e. independent of zoom) bool getSnapperAlwaysSnap() const; //if true, then the snapper will always snap, regardless of its tolerance diff --git a/src/seltrans.cpp b/src/seltrans.cpp index 9c83dd63e..b9bf4c6ce 100644 --- a/src/seltrans.cpp +++ b/src/seltrans.cpp @@ -1339,25 +1339,6 @@ gboolean Inkscape::SelTrans::centerRequest(Geom::Point &pt, guint state) } } - if ( !(state & GDK_SHIFT_MASK) && _bbox ) { - // screen pixels to snap center to bbox -#define SNAP_DIST 5 - // FIXME: take from prefs - double snap_dist = SNAP_DIST / _desktop->current_zoom(); - - for (int i = 0; i < 2; i++) { - if (fabs(pt[i] - _bbox->min()[i]) < snap_dist) { - pt[i] = _bbox->min()[i]; - } - if (fabs(pt[i] - _bbox->midpoint()[i]) < snap_dist) { - pt[i] = _bbox->midpoint()[i]; - } - if (fabs(pt[i] - _bbox->max()[i]) < snap_dist) { - pt[i] = _bbox->max()[i]; - } - } - } - // 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 ccaf3dee3..ccbd449bd 100644 --- a/src/snap.cpp +++ b/src/snap.cpp @@ -174,7 +174,6 @@ void SnapManager::freeSnapReturnByRef(Geom::Point &p, Inkscape::SnapSourceType const source_type, Geom::OptRect const &bbox_to_snap) const { - //TODO: SnapCandidatePoint and point_type are somewhat redundant; can't we get rid of the point_type parameter? Inkscape::SnappedPoint const s = freeSnap(Inkscape::SnapCandidatePoint(p, source_type), bbox_to_snap); s.getPoint(p); } @@ -408,7 +407,7 @@ void SnapManager::guideFreeSnap(Geom::Point &p, Geom::Point const &guide_normal, return; } - if (!(object.GuidesMightSnap() || snapprefs.getSnapToGuides())) { + if (!(object.ThisSnapperMightSnap() || snapprefs.getSnapToGuides())) { return; } @@ -419,7 +418,7 @@ void SnapManager::guideFreeSnap(Geom::Point &p, Geom::Point const &guide_normal, // Snap to nodes SnappedConstraints sc; - if (object.GuidesMightSnap()) { + if (object.ThisSnapperMightSnap()) { object.guideFreeSnap(sc, p, guide_normal); }