summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorDiederik van Lierop <mail@diedenrezi.nl>2011-08-25 20:08:16 +0000
committerDiederik van Lierop <mail@diedenrezi.nl>2011-08-25 20:08:16 +0000
commit3da0fd8b645937bcdd26d2ab3db716982030fc19 (patch)
tree7a179f4738231b660719a116a5f0ce0dcc2ba178
parentExtensions. Missing files for Text>Extract... (diff)
downloadinkscape-3da0fd8b645937bcdd26d2ab3db716982030fc19.tar.gz
inkscape-3da0fd8b645937bcdd26d2ab3db716982030fc19.zip
Fix "snap guides" toggle
Fixed bugs: - https://launchpad.net/bugs/814457 (bzr r10582)
-rw-r--r--src/object-snapper.cpp22
-rw-r--r--src/seltrans.cpp2
-rw-r--r--src/snap-enums.h25
-rw-r--r--src/snap-preferences.cpp62
-rw-r--r--src/snap-preferences.h4
-rw-r--r--src/snap.cpp7
6 files changed, 70 insertions, 52 deletions
diff --git a/src/object-snapper.cpp b/src/object-snapper.cpp
index 82114e2c4..fd8ef0c7c 100644
--- a/src/object-snapper.cpp
+++ b/src/object-snapper.cpp
@@ -177,7 +177,7 @@ void Inkscape::ObjectSnapper::_collectNodes(SnapSourceType const &t,
bool p_is_a_node = t & SNAPSOURCE_NODE_CATEGORY;
bool p_is_a_bbox = t & SNAPSOURCE_BBOX_CATEGORY;
- bool p_is_other = t & SNAPSOURCE_OTHERS_CATEGORY;
+ bool p_is_other = t & SNAPSOURCE_OTHERS_CATEGORY || t & SNAPSOURCE_DATUMS_CATEGORY;
// A point considered for snapping should be either a node, a bbox corner or a guide/other. Pick only ONE!
if (((p_is_a_node && p_is_a_bbox) || (p_is_a_bbox && p_is_other) || (p_is_a_node && p_is_other))) {
@@ -364,7 +364,7 @@ void Inkscape::ObjectSnapper::_collectPaths(Geom::Point /*p*/,
bool p_is_a_node = source_type & SNAPSOURCE_NODE_CATEGORY;
bool p_is_a_bbox = source_type & SNAPSOURCE_BBOX_CATEGORY;
- bool p_is_other = source_type & SNAPSOURCE_OTHERS_CATEGORY;
+ bool p_is_other = source_type & SNAPSOURCE_OTHERS_CATEGORY || source_type & SNAPSOURCE_DATUMS_CATEGORY;
if (_snapmanager->snapprefs.isTargetSnappable(SNAPTARGET_BBOX_EDGE)) {
Preferences *prefs = Preferences::get();
@@ -444,7 +444,7 @@ void Inkscape::ObjectSnapper::_collectPaths(Geom::Point /*p*/,
}
//Add the item's bounding box to snap to
- if (_snapmanager->snapprefs.isTargetSnappable(SNAPTARGET_BBOX_EDGE) && (_snapmanager->snapprefs.getSnapModeBBox() || _snapmanager->snapprefs.getSnapModeOthers())) {
+ if (_snapmanager->snapprefs.isTargetSnappable(SNAPTARGET_BBOX_EDGE)) {
if (p_is_other || p_is_a_bbox || (!_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
@@ -747,10 +747,7 @@ void Inkscape::ObjectSnapper::constrainedSnap( SnappedConstraints &sc,
*/
bool Inkscape::ObjectSnapper::ThisSnapperMightSnap() const
{
- return _snapmanager->snapprefs.getSnapModeBBox()
- || _snapmanager->snapprefs.getSnapModeNode()
- || _snapmanager->snapprefs.getSnapModeOthers()
- || _snapmanager->snapprefs.isTargetSnappable(SNAPTARGET_PAGE_CORNER);
+ return true;
}
void Inkscape::ObjectSnapper::_clear_paths() const
@@ -814,16 +811,13 @@ void Inkscape::getBBoxPoints(Geom::OptRect const bbox,
bool Inkscape::ObjectSnapper::_allowSourceToSnapToTarget(SnapSourceType source, SnapTargetType target, bool strict_snapping) const
{
- bool allow_this_pair_to_snap = false;
+ bool allow_this_pair_to_snap = true;
if (strict_snapping) { // bounding boxes will not snap to nodes/paths and vice versa
- int source_cat = source & (SNAPSOURCE_BBOX_CATEGORY | SNAPSOURCE_NODE_CATEGORY | SNAPSOURCE_OTHERS_CATEGORY);
- int target_cat = target & (SNAPTARGET_BBOX_CATEGORY | SNAPTARGET_NODE_CATEGORY | SNAPTARGET_OTHERS_CATEGORY);
- if (source_cat == target_cat || source_cat == SNAPSOURCE_OTHERS_CATEGORY || target_cat == SNAPTARGET_OTHERS_CATEGORY) {
- allow_this_pair_to_snap = true;
+ if (((source & SNAPSOURCE_BBOX_CATEGORY) && (target & SNAPTARGET_NODE_CATEGORY)) ||
+ ((source & SNAPSOURCE_NODE_CATEGORY) && (target & SNAPTARGET_BBOX_CATEGORY))) {
+ allow_this_pair_to_snap = false;
}
- } else { // anything will snap to anything
- allow_this_pair_to_snap = true;
}
return allow_this_pair_to_snap;
diff --git a/src/seltrans.cpp b/src/seltrans.cpp
index 7538e15d9..3a204a49e 100644
--- a/src/seltrans.cpp
+++ b/src/seltrans.cpp
@@ -360,7 +360,7 @@ void Inkscape::SelTrans::grab(Geom::Point const &p, gdouble x, gdouble y, bool s
// points immediately.
if (prefs->getBool("/options/snapclosestonly/value", false)) {
- if (m.snapprefs.getSnapModeNode() || m.snapprefs.getSnapModeOthers()) {
+ if (m.snapprefs.getSnapModeNode() || m.snapprefs.getSnapModeOthers() || m.snapprefs.getSnapModeDatums()) {
m.keepClosestPointOnly(_snap_points, p);
} else {
_snap_points.clear(); // don't keep any point
diff --git a/src/snap-enums.h b/src/snap-enums.h
index fd28910a8..8a95bb2dd 100644
--- a/src/snap-enums.h
+++ b/src/snap-enums.h
@@ -20,14 +20,14 @@ enum SnapSourceType {
//-------------------------------------------------------------------
// Bbox points can be located at the edge of the stroke (for visual bboxes); they will therefore not snap
// to nodes because these are always located at the center of the stroke
- SNAPSOURCE_BBOX_CATEGORY = 32, // will be used as a flag and must therefore be a power of two. Also,
+ SNAPSOURCE_BBOX_CATEGORY = 16, // will be used as a flag and must therefore be a power of two. Also,
// must be larger than the largest number of targets in a single group
SNAPSOURCE_BBOX_CORNER,
SNAPSOURCE_BBOX_MIDPOINT,
SNAPSOURCE_BBOX_EDGE_MIDPOINT,
//-------------------------------------------------------------------
// For the same reason, nodes will not snap to bbox points
- SNAPSOURCE_NODE_CATEGORY = 64, // will be used as a flag and must therefore be a power of two
+ SNAPSOURCE_NODE_CATEGORY = 32, // will be used as a flag and must therefore be a power of two
SNAPSOURCE_NODE_SMOOTH, // Symmetrical nodes are also considered to be smooth; there's no dedicated type for symm. nodes
SNAPSOURCE_NODE_CUSP,
SNAPSOURCE_LINE_MIDPOINT,
@@ -37,13 +37,16 @@ enum SnapSourceType {
SNAPSOURCE_ELLIPSE_QUADRANT_POINT,
SNAPSOURCE_NODE_HANDLE, // eg. nodes in the path editor, handles of stars or rectangles, etc. (tied to a stroke)
//-------------------------------------------------------------------
- // Other points (e.g. guides, gradient knots) will snap to both bounding boxes and nodes
+ // Other points (e.g. guides) will snap to both bounding boxes and nodes
+ SNAPSOURCE_DATUMS_CATEGORY = 64, // will be used as a flag and must therefore be a power of two
+ SNAPSOURCE_GUIDE,
+ SNAPSOURCE_GUIDE_ORIGIN,
+ //-------------------------------------------------------------------
+ // Other points (e.g. gradient knots, image corners) will snap to both bounding boxes and nodes
SNAPSOURCE_OTHERS_CATEGORY = 128, // will be used as a flag and must therefore be a power of two
SNAPSOURCE_ROTATION_CENTER,
SNAPSOURCE_OBJECT_MIDPOINT, // midpoint of rectangles, ellipses, polygon, etc.
SNAPSOURCE_IMG_CORNER,
- SNAPSOURCE_GUIDE,
- SNAPSOURCE_GUIDE_ORIGIN,
SNAPSOURCE_TEXT_ANCHOR,
SNAPSOURCE_OTHER_HANDLE, // eg. the handle of a gradient or of a connector (ie not being tied to a stroke)
SNAPSOURCE_GRID_PITCH, // eg. when pasting or alt-dragging in the selector tool; not realy a snap source
@@ -52,7 +55,7 @@ enum SnapSourceType {
enum SnapTargetType {
SNAPTARGET_UNDEFINED = 0,
//-------------------------------------------------------------------
- SNAPTARGET_BBOX_CATEGORY = 32, // will be used as a flag and must therefore be a power of two. Also,
+ SNAPTARGET_BBOX_CATEGORY = 16, // will be used as a flag and must therefore be a power of two. Also,
// must be larger than the largest number of targets in a single group
// i.e > 15 because that's the number of targets in the "others" group
SNAPTARGET_BBOX_CORNER,
@@ -60,7 +63,7 @@ enum SnapTargetType {
SNAPTARGET_BBOX_EDGE_MIDPOINT,
SNAPTARGET_BBOX_MIDPOINT,
//-------------------------------------------------------------------
- SNAPTARGET_NODE_CATEGORY = 64, // will be used as a flag and must therefore be a power of two
+ SNAPTARGET_NODE_CATEGORY = 32, // will be used as a flag and must therefore be a power of two
SNAPTARGET_NODE_SMOOTH,
SNAPTARGET_NODE_CUSP,
SNAPTARGET_LINE_MIDPOINT,
@@ -69,18 +72,20 @@ enum SnapTargetType {
SNAPTARGET_ELLIPSE_QUADRANT_POINT, // this corner is at the center of the stroke
SNAPTARGET_RECT_CORNER, // of a rectangle, so this corner is at the center of the stroke
//-------------------------------------------------------------------
- SNAPTARGET_OTHERS_CATEGORY = 128, // will be used as a flag and must therefore be a power of two
+ SNAPTARGET_DATUMS_CATEGORY = 64, // will be used as a flag and must therefore be a power of two
SNAPTARGET_GRID,
SNAPTARGET_GRID_INTERSECTION,
SNAPTARGET_GUIDE,
SNAPTARGET_GUIDE_INTERSECTION,
SNAPTARGET_GUIDE_ORIGIN,
SNAPTARGET_GRID_GUIDE_INTERSECTION,
+ SNAPTARGET_PAGE_BORDER,
+ SNAPTARGET_PAGE_CORNER,
+ //-------------------------------------------------------------------
+ SNAPTARGET_OTHERS_CATEGORY = 128, // will be used as a flag and must therefore be a power of two
SNAPTARGET_OBJECT_MIDPOINT,
SNAPTARGET_IMG_CORNER,
SNAPTARGET_ROTATION_CENTER,
- SNAPTARGET_PAGE_BORDER,
- SNAPTARGET_PAGE_CORNER,
SNAPTARGET_TEXT_ANCHOR,
SNAPTARGET_TEXT_BASELINE,
SNAPTARGET_CONSTRAINED_ANGLE,
diff --git a/src/snap-preferences.cpp b/src/snap-preferences.cpp
index b1fadcfff..d655564f2 100644
--- a/src/snap-preferences.cpp
+++ b/src/snap-preferences.cpp
@@ -19,14 +19,13 @@ Inkscape::SnapPreferences::SnapPreferences() :
_snap_postponed_globally(false),
_strict_snapping(true)
{
- // Check for enough space to hold all snap target toggles in the "others" group; see the comments in snap-enums.h
- g_assert(SNAPTARGET_MAX_ENUM_VALUE - SNAPTARGET_OTHERS_CATEGORY < SNAPTARGET_BBOX_CATEGORY);
// Check for powers of two; see the comments in snap-enums.h
g_assert((SNAPTARGET_BBOX_CATEGORY != 0) && !(SNAPTARGET_BBOX_CATEGORY & (SNAPTARGET_BBOX_CATEGORY - 1)));
g_assert((SNAPTARGET_NODE_CATEGORY != 0) && !(SNAPTARGET_NODE_CATEGORY & (SNAPTARGET_NODE_CATEGORY - 1)));
+ g_assert((SNAPTARGET_DATUMS_CATEGORY != 0) && !(SNAPTARGET_DATUMS_CATEGORY & (SNAPTARGET_DATUMS_CATEGORY - 1)));
g_assert((SNAPTARGET_OTHERS_CATEGORY != 0) && !(SNAPTARGET_OTHERS_CATEGORY & (SNAPTARGET_OTHERS_CATEGORY - 1)));
- setSnapFrom(SnapSourceType(SNAPSOURCE_BBOX_CATEGORY | SNAPSOURCE_NODE_CATEGORY | SNAPSOURCE_OTHERS_CATEGORY), true); //Snap any point. In v0.45 and earlier, this was controlled in the preferences tab
+ setSnapFrom(SnapSourceType(SNAPSOURCE_BBOX_CATEGORY | SNAPSOURCE_NODE_CATEGORY | SNAPSOURCE_DATUMS_CATEGORY | SNAPSOURCE_OTHERS_CATEGORY), true); //Snap any point. In v0.45 and earlier, this was controlled in the preferences tab
for (int n = 0; n < Inkscape::SNAPTARGET_MAX_ENUM_VALUE; n++) {
_active_snap_targets[n] = -1;
}
@@ -88,6 +87,11 @@ bool Inkscape::SnapPreferences::getSnapModeOthers() const
return (_snap_from & Inkscape::SNAPSOURCE_OTHERS_CATEGORY);
}
+bool Inkscape::SnapPreferences::getSnapModeDatums() const
+{
+ return isTargetSnappable(Inkscape::SNAPTARGET_GUIDE);
+}
+
bool Inkscape::SnapPreferences::getSnapModeAny() const
{
return (_snap_from != 0);
@@ -135,31 +139,55 @@ void Inkscape::SnapPreferences::_mapTargetToArrayIndex(Inkscape::SnapTargetType
{
if (target & SNAPTARGET_BBOX_CATEGORY) {
group_on = getSnapModeBBox(); // Only if the group with bbox sources/targets has been enabled, then we might snap to any of the bbox targets
+
+
} else if (target & SNAPTARGET_NODE_CATEGORY) {
group_on = getSnapModeNode(); // Only if the group with path/node sources/targets has been enabled, then we might snap to any of the nodes/paths
if (target == SNAPTARGET_RECT_CORNER || target == SNAPTARGET_ELLIPSE_QUADRANT_POINT) { // Don't have their own button; on when the group is on
target = SNAPTARGET_NODE_CATEGORY;
}
- } else if (target & SNAPTARGET_OTHERS_CATEGORY) {
- // Only if the group with "other" snap sources/targets has been enabled, then we might snap to any of those targets
- // ... but this doesn't hold for the page border, grids, and guides
- group_on = getSnapModeOthers();
+
+
+ } else if (target & SNAPTARGET_DATUMS_CATEGORY) {
+ group_on = true; // These snap targets cannot be disabled as part of a disabled group;
switch (target) {
// Some snap targets don't have their own toggle. These targets are called "secondary targets". We will re-map
- // them to their cousin which does have a toggle, and which is called a "primary target"
+ // them to their cousin which does have a toggle, and which is called a "primary target"case SNAPTARGET_GRID_INTERSECTION:
case SNAPTARGET_GRID_INTERSECTION:
- group_on = true; // cannot be disabled as part of a disabled group;
target = SNAPTARGET_GRID;
break;
case SNAPTARGET_GUIDE_INTERSECTION:
case SNAPTARGET_GUIDE_ORIGIN:
- group_on = true; // cannot be disabled as part of a disabled group;
target = SNAPTARGET_GUIDE;
break;
case SNAPTARGET_PAGE_CORNER:
- group_on = true; // cannot be disabled as part of a disabled group;
target = SNAPTARGET_PAGE_BORDER;
break;
+
+ // Some snap targets cannot be toggled at all, and are therefore always enabled
+ case SNAPTARGET_GRID_GUIDE_INTERSECTION:
+ always_on = true; // Doesn't have it's own button
+ break;
+
+ // These are only listed for completeness
+ case SNAPTARGET_GRID:
+ case SNAPTARGET_GUIDE:
+ case SNAPTARGET_PAGE_BORDER:
+ case SNAPTARGET_DATUMS_CATEGORY:
+ break;
+ default:
+ g_warning("Snap-preferences warning: Undefined snap target (#%i)", target);
+ break;
+ }
+
+
+ } else if (target & SNAPTARGET_OTHERS_CATEGORY) {
+ // Only if the group with "other" snap sources/targets has been enabled, then we might snap to any of those targets
+ // ... but this doesn't hold for the page border, grids, and guides
+ group_on = getSnapModeOthers();
+ switch (target) {
+ // Some snap targets don't have their own toggle. These targets are called "secondary targets". We will re-map
+ // them to their cousin which does have a toggle, and which is called a "primary target"
case SNAPTARGET_TEXT_ANCHOR:
target = SNAPTARGET_TEXT_BASELINE;
break;
@@ -168,31 +196,23 @@ void Inkscape::SnapPreferences::_mapTargetToArrayIndex(Inkscape::SnapTargetType
target = SNAPTARGET_OTHERS_CATEGORY;
break;
// Some snap targets cannot be toggled at all, and are therefore always enabled
- case SNAPTARGET_GRID_GUIDE_INTERSECTION:
case SNAPTARGET_CONSTRAINED_ANGLE:
case SNAPTARGET_CONSTRAINT:
always_on = true; // Doesn't have it's own button
break;
- case SNAPTARGET_GRID:
- case SNAPTARGET_GUIDE:
- case SNAPTARGET_PAGE_BORDER:
- group_on = true; // cannot be disabled as part of a disabled group;
- break;
// These are only listed for completeness
case SNAPTARGET_OBJECT_MIDPOINT:
case SNAPTARGET_ROTATION_CENTER:
case SNAPTARGET_TEXT_BASELINE:
- break;
-
- case SNAPTARGET_BBOX_CATEGORY:
- case SNAPTARGET_NODE_CATEGORY:
case SNAPTARGET_OTHERS_CATEGORY:
break;
default:
g_warning("Snap-preferences warning: Undefined snap target (#%i)", target);
break;
}
+
+
} else if (target == SNAPTARGET_UNDEFINED ) {
g_warning("Snap-preferences warning: Undefined snaptarget (#%i)", target);
}
diff --git a/src/snap-preferences.h b/src/snap-preferences.h
index dac11b3aa..cfcdf6137 100644
--- a/src/snap-preferences.h
+++ b/src/snap-preferences.h
@@ -28,9 +28,6 @@ public:
bool isTargetSnappable(Inkscape::SnapTargetType const target1, Inkscape::SnapTargetType const target2) const;
bool isTargetSnappable(Inkscape::SnapTargetType const target1, Inkscape::SnapTargetType const target2, Inkscape::SnapTargetType const target3) const;
bool isTargetSnappable(Inkscape::SnapTargetType const target1, Inkscape::SnapTargetType const target2, Inkscape::SnapTargetType const target3, Inkscape::SnapTargetType const target4) const;
- //bool isAnyBBoxSnappable() const;
- //bool isAnyNodeOrPathSnappable() const;
- //bool isAnyOtherSnappable() const;
bool isSnapButtonEnabled(Inkscape::SnapTargetType const target) const;
void setSnapModeBBox(bool enabled);
@@ -38,6 +35,7 @@ public:
void setSnapModeOthers(bool enabled);
bool getSnapModeBBox() const;
bool getSnapModeNode() const;
+ bool getSnapModeDatums() const;
bool getSnapModeOthers() const;
bool getSnapModeAny() const;
diff --git a/src/snap.cpp b/src/snap.cpp
index c4ca32364..7647341fe 100644
--- a/src/snap.cpp
+++ b/src/snap.cpp
@@ -1413,9 +1413,10 @@ void SnapManager::_displaySnapsource(Inkscape::SnapCandidatePoint const &p) cons
Inkscape::Preferences *prefs = Inkscape::Preferences::get();
if (prefs->getBool("/options/snapclosestonly/value")) {
- bool p_is_a_node = p.getSourceType() & Inkscape::SNAPSOURCE_NODE_CATEGORY;
- bool p_is_a_bbox = p.getSourceType() & Inkscape::SNAPSOURCE_BBOX_CATEGORY;
- bool p_is_other = p.getSourceType() & Inkscape::SNAPSOURCE_OTHERS_CATEGORY;
+ Inkscape::SnapSourceType t = p.getSourceType();
+ bool p_is_a_node = t & Inkscape::SNAPSOURCE_NODE_CATEGORY;
+ bool p_is_a_bbox = t & Inkscape::SNAPSOURCE_BBOX_CATEGORY;
+ bool p_is_other = t & Inkscape::SNAPSOURCE_OTHERS_CATEGORY || t & Inkscape::SNAPSOURCE_DATUMS_CATEGORY;
g_assert(_desktop != NULL);
if (snapprefs.getSnapEnabledGlobally() && (p_is_other || (p_is_a_node && snapprefs.getSnapModeNode()) || (p_is_a_bbox && snapprefs.getSnapModeBBox()))) {