summary | shortlog | log | commit | commitdiff | tree
raw | patch | inline | side by side (parent: d6d9423)
raw | patch | inline | side by side (parent: d6d9423)
author | Diederik van Lierop <mailat-signdiedenrezidotnl> | |
Tue, 20 Jul 2010 19:18:58 +0000 (21:18 +0200) | ||
committer | Diederik van Lierop <mailat-signdiedenrezidotnl> | |
Tue, 20 Jul 2010 19:18:58 +0000 (21:18 +0200) |
- Improve the logic behind the snapping buttons, i.e. what snaps to what for each of the buttons
src/object-snapper.cpp | patch | blob | history | |
src/object-snapper.h | patch | blob | history | |
src/seltrans.cpp | patch | blob | history | |
src/snap.cpp | patch | blob | history |
diff --git a/src/object-snapper.cpp b/src/object-snapper.cpp
index 7d593dfc47f55e5e973d8e3cab466df74c7d2f72..4c5ad800c461511069a8f4ae723ce0c1eff24f99 100644 (file)
--- a/src/object-snapper.cpp
+++ b/src/object-snapper.cpp
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;
}
// 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
_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
*/
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 b0084c2d77fc0478238a7c73e34563781b1c7dfa..f3b54ed08f00e3b32ee6508bb83f251a198933bb 100644 (file)
--- a/src/object-snapper.h
+++ b/src/object-snapper.h
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 9c83dd63ebf3ce399f6fef40b6d0dfcfc3e25409..b9bf4c6ce8a9efc280fa1bfb35758e6a8dcae283 100644 (file)
--- a/src/seltrans.cpp
+++ b/src/seltrans.cpp
}
}
- 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 ccaf3dee3b8bb652ca835b8421467f9e8b4adf61..ccbd449bd4c461a5757a3323975f28b764d6baa2 100644 (file)
--- a/src/snap.cpp
+++ b/src/snap.cpp
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);
}