From d7b1e066fa7c7d9e6a83d688fe48c5f06620bf10 Mon Sep 17 00:00:00 2001 From: Marc Jeanmougin Date: Mon, 14 Mar 2016 00:50:24 +0100 Subject: "Relative to" option for node alignment. - Node tool has those new "relative to" alignment options : last selected, first selected, current behaviour (middle), max value(rightmost/topmost) or min value(leftmost/bottommost). - Verbs: --If the node tool is active and whole objects are selected (no individual node is), works as usual for objects; --Else, align horizontal/vertical (SP_VERB_ALIGN_HORIZONTAL_CENTER) honor the "relative to" settings, SP_VERB_ALIGN_HORIZONTAL_LEFT (ctrl+alt+pavnum4) aligns vertically on the leftmost node (same behavior as SP_VERB_ALIGN_HORIZONTAL_LEFT when the setting is "align relative to min value"), and so on with all alignment verbs Fixed bugs: - https://launchpad.net/bugs/171287 (bzr r14703) --- src/ui/tool/control-point-selection.cpp | 29 ++++++++++++++++++++++++++++- 1 file changed, 28 insertions(+), 1 deletion(-) (limited to 'src/ui/tool/control-point-selection.cpp') diff --git a/src/ui/tool/control-point-selection.cpp b/src/ui/tool/control-point-selection.cpp index 998f74ee0..f36ad7374 100644 --- a/src/ui/tool/control-point-selection.cpp +++ b/src/ui/tool/control-point-selection.cpp @@ -19,6 +19,8 @@ #include "ui/tool/transform-handle-set.h" #include "ui/tool/node.h" + + #include namespace Inkscape { @@ -82,6 +84,7 @@ std::pair ControlPointSelection::insert(c } found = _points.insert(x).first; + _points_list.push_back(x); x->updateState(); _pointChanged(x, true); @@ -97,6 +100,7 @@ std::pair ControlPointSelection::insert(c void ControlPointSelection::erase(iterator pos) { SelectableControlPoint *erased = *pos; + _points_list.remove(*pos); _points.erase(pos); erased->updateState(); _pointChanged(erased, false); @@ -219,8 +223,11 @@ void ControlPointSelection::transform(Geom::Affine const &m) /** Align control points on the specified axis. */ void ControlPointSelection::align(Geom::Dim2 axis) { + enum AlignTargetNode { LAST_NODE=0, FIRST_NODE, MID_NODE, MIN_NODE, MAX_NODE }; if (empty()) return; Geom::Dim2 d = static_cast((axis + 1) % 2); + Inkscape::Preferences *prefs = Inkscape::Preferences::get(); + Geom::OptInterval bound; for (iterator i = _points.begin(); i != _points.end(); ++i) { @@ -229,7 +236,27 @@ void ControlPointSelection::align(Geom::Dim2 axis) if (!bound) { return; } - double new_coord = bound->middle(); + double new_coord; + switch (AlignTargetNode(prefs->getInt("/dialogs/align/align-nodes-to", 2))){ + case FIRST_NODE: + new_coord=(_points_list.front())->position()[d]; + break; + case LAST_NODE: + new_coord=(_points_list.back())->position()[d]; + break; + case MID_NODE: + new_coord=bound->middle(); + break; + case MIN_NODE: + new_coord=bound->min(); + break; + case MAX_NODE: + new_coord=bound->max(); + break; + default: + return; + } + for (iterator i = _points.begin(); i != _points.end(); ++i) { Geom::Point pos = (*i)->position(); pos[d] = new_coord; -- cgit v1.2.3