summary | shortlog | log | commit | commitdiff | tree
raw | patch | inline | side by side (parent: 4fdbec4)
raw | patch | inline | side by side (parent: 4fdbec4)
author | dvlierop2 <dvlierop2@users.sourceforge.net> | |
Tue, 8 Jan 2008 22:02:30 +0000 (22:02 +0000) | ||
committer | dvlierop2 <dvlierop2@users.sourceforge.net> | |
Tue, 8 Jan 2008 22:02:30 +0000 (22:02 +0000) |
diff --git a/src/object-snapper.cpp b/src/object-snapper.cpp
index 9ffdc764cbde7a79358143911758f764591f052e..7c6b0fc3b3e9ce5bb345e0640d115cf77c563215 100644 (file)
--- a/src/object-snapper.cpp
+++ b/src/object-snapper.cpp
std::vector<NR::Point> &points_to_snap,
DimensionToSnap const snap_dim) const
{
- if (ThisSnapperMightSnap()) {
- SPDesktop const *desktop = SP_ACTIVE_DESKTOP;
-
- if (first_point) {
- _candidates->clear();
- }
-
- for (SPObject* o = sp_object_first_child(r); o != NULL; o = SP_OBJECT_NEXT(o)) {
- if (SP_IS_ITEM(o) && !SP_ITEM(o)->isLocked() && !desktop->itemIsHidden(SP_ITEM(o))) {
+ bool const c1 = (snap_dim == TRANSL_SNAP_XY) && ThisSnapperMightSnap();
+ bool const c2 = (snap_dim != TRANSL_SNAP_XY) && GuidesMightSnap();
+ bool const c3 = points_to_snap.size() == 0;
+
+ if (!(c1 || c2) || c3) {
+ return;
+ }
+
+ SPDesktop const *desktop = SP_ACTIVE_DESKTOP;
- /* See if this item is on the ignore list */
- std::list<SPItem const *>::const_iterator i = it.begin();
- while (i != it.end() && *i != o) {
- i++;
- }
+ if (first_point) {
+ _candidates->clear();
+ }
+
+ NR::Maybe<NR::Rect> bbox = NR::Rect(); // a default NR::Rect is infinitely large
+ NR::Coord t = getSnapperTolerance();
+
+ // When dragging a guide...
+ NR::Point p_guide = points_to_snap[0];
+ if (!getSnapperAlwaysSnap()) {
+ bbox = NR::Rect(p_guide, p_guide); // bbox is now just a single point: p_guide
+ bbox->growBy(t); // bbox width and height now measure 2x snapper tolerance
+ // for angled guidelines the bbox is now larger than really needed
+ // (up to sqrt(2) for 45 deg. guidelines) but we'll leave it like that
+ } // else: use an infinitely large bbox to find candidates
+
+ for (SPObject* o = sp_object_first_child(r); o != NULL; o = SP_OBJECT_NEXT(o)) {
+ if (SP_IS_ITEM(o) && !SP_ITEM(o)->isLocked() && !desktop->itemIsHidden(SP_ITEM(o))) {
+
+ /* See if this item is on the ignore list */
+ std::list<SPItem const *>::const_iterator i = it.begin();
+ while (i != it.end() && *i != o) {
+ i++;
+ }
- if (i == it.end()) {
- /* See if the item is within range */
- if (SP_IS_GROUP(o)) {
- _findCandidates(o, it, false, points_to_snap, snap_dim);
- } else {
- // Now let's see if any of the snapping points is within
- // snapping range of this object
- NR::Maybe<NR::Rect> b = sp_item_bbox_desktop(SP_ITEM(o));
- if (b) {
- for (std::vector<NR::Point>::const_iterator i = points_to_snap.begin(); i != points_to_snap.end(); i++) {
- NR::Point b_min = b->min();
- NR::Point b_max = b->max();
- NR::Coord t = getSnapperTolerance();
- bool withinX = ((*i)[NR::X] >= b_min[NR::X] - t) && ((*i)[NR::X] <= b_max[NR::X] + t);
- bool withinY = ((*i)[NR::Y] >= b_min[NR::Y] - t) && ((*i)[NR::Y] <= b_max[NR::Y] + t);
- bool c1 = snap_dim == GUIDE_TRANSL_SNAP_X && withinX;
- bool c2 = snap_dim == GUIDE_TRANSL_SNAP_Y && withinY;
- bool c3 = snap_dim == TRANSL_SNAP_XY && withinX && withinY;
- // For an angled guide at e.g 45 deg., the bbox is very large and might even span
- // the full desktop. Therefore we will simply return _any_ candidate, without looking at
- // the bbox and the snapping distance.
- bool c4 = snap_dim == ANGLED_GUIDE_TRANSL_SNAP || snap_dim == ANGLED_GUIDE_ROT_SNAP;
- if ( c1 || c2 || c3 || c4) {
- //We've found a point that is within snapping range
- //of this object, so record it as a candidate
- _candidates->push_back(SP_ITEM(o));
- break;
- }
+ if (i == it.end()) {
+ /* See if the item is within range */
+ if (SP_IS_GROUP(o)) {
+ _findCandidates(o, it, false, points_to_snap, snap_dim);
+ } else {
+ // Now let's see if any of the snapping points is within snapping range of this object
+ if (snap_dim == TRANSL_SNAP_XY) {
+ bbox = sp_item_bbox_desktop(SP_ITEM(o));
+ } // else: we're snapping a guide to an object and we will use the bbox as defined above
+
+ if (bbox) {
+ for (std::vector<NR::Point>::const_iterator i = points_to_snap.begin(); i != points_to_snap.end(); i++) {
+ NR::Point b_min = bbox->min();
+ NR::Point b_max = bbox->max();
+ bool withinX = ((*i)[NR::X] >= b_min[NR::X] - t) && ((*i)[NR::X] <= b_max[NR::X] + t);
+ bool withinY = ((*i)[NR::Y] >= b_min[NR::Y] - t) && ((*i)[NR::Y] <= b_max[NR::Y] + t);
+ if (withinX && withinY) {
+ //We've found a point that is within snapping range
+ //of this object, so record it as a candidate
+ _candidates->push_back(SP_ITEM(o));
+ break;
}
}
}
@@ -213,12 +225,15 @@ void Inkscape::ObjectSnapper::_snapTranslatingGuideToNodes(SnappedConstraints &s
SnappedPoint s;
bool success = false;
+ NR::Coord tol = getSnapperTolerance();
+
for (std::vector<NR::Point>::const_iterator k = _points_to_snap_to->begin(); k != _points_to_snap_to->end(); k++) {
// Project each node (*k) on the guide line (running through point p)
NR::Point p_proj = project_on_linesegment(*k, p, p + NR::rot90(guide_normal));
- NR::Coord dist = NR::L2(*k - p_proj);
- if (dist < getSnapperTolerance() && dist < s.getDistance()) {
- s = SnappedPoint(*k, dist, getSnapperTolerance(), getSnapperAlwaysSnap());
+ NR::Coord dist = NR::L2(*k - p_proj); // distance from node to the guide
+ NR::Coord dist2 = NR::L2(p - p_proj); // distance from projection of node on the guide, to the mouse location
+ if ((dist < tol && dist2 < tol || getSnapperAlwaysSnap()) && dist < s.getDistance()) {
+ s = SnappedPoint(*k, dist, tol, getSnapperAlwaysSnap());
success = true;
}
}
}
-
+// This method is used to snap a guide to nodes, while dragging the guide around
void Inkscape::ObjectSnapper::guideSnap(SnappedConstraints &sc,
NR::Point const &p,
NR::Point const &guide_normal) const
if ( NULL == _named_view ) {
return;
}
-
+
/* Get a list of all the SPItems that we will try to snap to */
std::vector<SPItem*> cand;
std::list<SPItem const *> const it; //just an empty list
std::vector<NR::Point> points_to_snap;
points_to_snap.push_back(p);
- // This method is used to snap a guide to nodes, while dragging the guide around
DimensionToSnap snap_dim;
if (guide_normal == component_vectors[NR::Y]) {
snap_dim = GUIDE_TRANSL_SNAP_Y;
return (_snap_enabled && _snap_from != 0 && snap_to_something);
}
+bool Inkscape::ObjectSnapper::GuidesMightSnap() const
+{
+ bool snap_to_something = _snap_to_itemnode || _snap_to_bboxnode;
+ return (_snap_enabled && (_snap_from & SNAPPOINT_GUIDE) && snap_to_something);
+}
+
void Inkscape::ObjectSnapper::_clear_paths() const
{
for (std::vector<NArtBpath*>::const_iterator k = _bpaths_to_snap_to->begin(); k != _bpaths_to_snap_to->end(); k++) {
diff --git a/src/object-snapper.h b/src/object-snapper.h
index a2d199c875d63d9528dd3b9596d96a03a244f59b..73c62251713c688c9ae7816d0cc53b6c201c273a 100644 (file)
--- a/src/object-snapper.h
+++ b/src/object-snapper.h
NR::Point const &guide_normal) const;
bool ThisSnapperMightSnap() const;
+ bool GuidesMightSnap() const;
private:
//store some lists of candidates, points and paths, so we don't have to rebuild them for each point we want to snap
diff --git a/src/snap.cpp b/src/snap.cpp
index a6e165d5030b14d88a4a429e9722186e1fb72f5f..3bee26f730377cd215b5b4eeb6c06cda80824a0f 100644 (file)
--- a/src/snap.cpp
+++ b/src/snap.cpp
{
// This method is used to snap a guide to nodes, while dragging the guide around
- if (!(object.ThisSnapperMightSnap() && _snap_enabled_globally)) {
+ if (!(object.GuidesMightSnap() && _snap_enabled_globally)) {
return Inkscape::SnappedPoint(p, NR_HUGE, 0, false);
}
diff --git a/src/snapper.cpp b/src/snapper.cpp
index efdc6bcbea8a4bebcd8630f56108a284187cb2bf..5f5261885fa75a6fb190e833617c31bb6aecb261 100644 (file)
--- a/src/snapper.cpp
+++ b/src/snapper.cpp
*
* Authors:
* Carl Hetherington <inkscape@carlh.net>
+ * Diederik van Lierop <mail@diedenrezi.nl>
*
* Released under GNU GPL, read the file 'COPYING' for more information.
*/
index a3e0fdfbc07f72aaab5a545eefc8343a9161e3b2..cf398ccce6a095671a1e20724dbe67bbeb50f2a5 100644 (file)
"guidehicolor", "guidehiopacity", _wr);
_rcbsng.init (_("_Snap guides while dragging"),
- _("While dragging a guide, snap to object nodes or bounding box corners ('Snap to nodes' or 'snap to bounding box corners' must be enabled in the 'Snap' tab)"),
+ _("While dragging a guide, snap to object nodes or bounding box corners ('Snap to nodes' or 'snap to bounding box corners' must be enabled in the 'Snap' tab; only a small part of the guide near the cursor will snap)"),
"inkscape:snap-guide", _wr);
Gtk::Label *label_gui = manage (new Gtk::Label);