diff options
| author | Diederik van Lierop <mail@diedenrezi.nl> | 2008-11-24 19:45:10 +0000 |
|---|---|---|
| committer | dvlierop2 <dvlierop2@users.sourceforge.net> | 2008-11-24 19:45:10 +0000 |
| commit | d6704d3f6d4ed82c1360142e86538b076bb4a279 (patch) | |
| tree | 6013e6009d40a1a4a8cae513668c79e092890dc9 /src/nodepath.cpp | |
| parent | some color support, multi-line text, automatic scaling (diff) | |
| download | inkscape-d6704d3f6d4ed82c1360142e86538b076bb4a279.tar.gz inkscape-d6704d3f6d4ed82c1360142e86538b076bb4a279.zip | |
Add an option to the preferences to _only_ snap the node closest to the mouse pointer
(bzr r6899)
Diffstat (limited to 'src/nodepath.cpp')
| -rw-r--r-- | src/nodepath.cpp | 57 |
1 files changed, 39 insertions, 18 deletions
diff --git a/src/nodepath.cpp b/src/nodepath.cpp index 234aba4cc..7165dab98 100644 --- a/src/nodepath.cpp +++ b/src/nodepath.cpp @@ -1360,25 +1360,46 @@ static void sp_nodepath_selected_nodes_move(Inkscape::NodePath::Path *nodepath, SnapManager &m = nodepath->desktop->namedview->snap_manager; - for (GList *l = nodepath->selected; l != NULL; l = l->next) { + // When only the node closest to the mouse pointer is to be snapped + // then we will not even try to snap to other points and discard those immediately + Inkscape::Preferences *prefs = Inkscape::Preferences::get(); + bool closest_only = prefs->getBool("/options/snapclosestonly/value", false); + + Inkscape::NodePath::Node *closest_node = NULL; + Geom::Coord closest_dist = NR_HUGE; + + if (closest_only) { + for (GList *l = nodepath->selected; l != NULL; l = l->next) { + Inkscape::NodePath::Node *n = (Inkscape::NodePath::Node *) l->data; + Geom::Coord dist = Geom::L2(nodepath->drag_origin_mouse - n->origin); + if (dist < closest_dist) { + closest_node = n; + closest_dist = dist; + } + } + } + + // Iterate through all selected nodes + m.setup(nodepath->desktop, false, SP_PATH(nodepath->item), &unselected_nodes); + for (GList *l = nodepath->selected; l != NULL; l = l->next) { Inkscape::NodePath::Node *n = (Inkscape::NodePath::Node *) l->data; - m.setup(nodepath->desktop, false, SP_PATH(n->subpath->nodepath->item), &unselected_nodes); - Inkscape::SnappedPoint s; - - if (constrained) { - Inkscape::Snapper::ConstraintLine dedicated_constraint = constraint; - dedicated_constraint.setPoint(n->pos); - s = m.constrainedSnap(Inkscape::SnapPreferences::SNAPPOINT_NODE, to_2geom(n->pos + delta), dedicated_constraint); - } else { - s = m.freeSnap(Inkscape::SnapPreferences::SNAPPOINT_NODE, to_2geom(n->pos + delta)); - } - - if (s.getSnapped()) { - s.setPointerDistance(Geom::L2(nodepath->drag_origin_mouse - n->origin)); - if (!s.isOtherOneBetter(best, true)) { - best = s; - best_pt = from_2geom(s.getPoint()) - n->pos; - } + if (!closest_only || n == closest_node) { //try to snap either all selected nodes or only the closest one + Inkscape::SnappedPoint s; + if (constrained) { + Inkscape::Snapper::ConstraintLine dedicated_constraint = constraint; + dedicated_constraint.setPoint(n->pos); + s = m.constrainedSnap(Inkscape::SnapPreferences::SNAPPOINT_NODE, to_2geom(n->pos + delta), dedicated_constraint); + } else { + s = m.freeSnap(Inkscape::SnapPreferences::SNAPPOINT_NODE, to_2geom(n->pos + delta)); + } + + if (s.getSnapped()) { + s.setPointerDistance(Geom::L2(nodepath->drag_origin_mouse - n->origin)); + if (!s.isOtherSnapBetter(best, true)) { + best = s; + best_pt = from_2geom(s.getPoint()) - n->pos; + } + } } } |
