diff --git a/src/ui/tool/node.cpp b/src/ui/tool/node.cpp
index 1070e4bc38d6deb0df3700b0520b406a4e972a9e..a79a5c409ce9a847991593631e8d3466edccacf0 100644 (file)
--- a/src/ui/tool/node.cpp
+++ b/src/ui/tool/node.cpp
Handle *towards_second = node_towards ? node_towards->handleToward(_parent) : NULL;
if (Geom::are_near(new_pos, _parent->position())) {
Handle *towards_second = node_towards ? node_towards->handleToward(_parent) : NULL;
if (Geom::are_near(new_pos, _parent->position())) {
- // The handle becomes degenerate. If the segment between it and the node
+ // The handle becomes degenerate.
+ // Adjust node type as necessary.
+ if (other->isDegenerate()) {
+ // If both handles become degenerate, convert to parent cusp node
+ _parent->setType(NODE_CUSP, false);
+ } else {
+ // Only 1 handle becomes degenerate
+ switch (_parent->type()) {
+ case NODE_AUTO:
+ case NODE_SYMMETRIC:
+ _parent->setType(NODE_SMOOTH, false);
+ break;
+ default:
+ // do nothing for other node types
+ break;
+ }
+ }
+ // If the segment between the handle and the node
// in its direction becomes linear and there are smooth nodes
// at its ends, make their handles colinear with the segment
// in its direction becomes linear and there are smooth nodes
// at its ends, make their handles colinear with the segment
- if (towards && towards->isDegenerate()) {
+ if (towards && towards_second->isDegenerate()) {
if (node_towards->type() == NODE_SMOOTH) {
if (node_towards->type() == NODE_SMOOTH) {
- towards_second->setDirection(*_parent, *node_towards);
+ towards->setDirection(*_parent, *node_towards);
}
if (_parent->type() == NODE_SMOOTH) {
other->setDirection(*node_towards, *_parent);
}
if (_parent->type() == NODE_SMOOTH) {
other->setDirection(*node_towards, *_parent);
void Handle::setPosition(Geom::Point const &p)
{
void Handle::setPosition(Geom::Point const &p)
{
+ Geom::Point old_pos = position();
ControlPoint::setPosition(p);
sp_ctrlline_set_coords(SP_CTRLLINE(_handle_line), _parent->position(), position());
ControlPoint::setPosition(p);
sp_ctrlline_set_coords(SP_CTRLLINE(_handle_line), _parent->position(), position());
if (Geom::are_near(position(), _parent->position()))
_degenerate = true;
else _degenerate = false;
if (Geom::are_near(position(), _parent->position()))
_degenerate = true;
else _degenerate = false;
+
if (_parent->_handles_shown && _parent->visible() && !_degenerate) {
setVisible(true);
} else {
setVisible(false);
}
if (_parent->_handles_shown && _parent->visible() && !_degenerate) {
setVisible(true);
} else {
setVisible(false);
}
- // If both handles become degenerate, convert to parent cusp node
- if (_parent->isDegenerate()) {
- _parent->setType(NODE_CUSP, false);
- }
}
void Handle::setLength(double len)
}
void Handle::setLength(double len)
void Handle::retract()
{
void Handle::retract()
{
- setPosition(_parent->position());
+ move(_parent->position());
}
void Handle::setDirection(Geom::Point const &from, Geom::Point const &to)
}
void Handle::setDirection(Geom::Point const &from, Geom::Point const &to)
Geom::Point origin = _last_drag_origin();
SnapManager &sm = _desktop->namedview->snap_manager;
bool snap = sm.someSnapperMightSnap();
Geom::Point origin = _last_drag_origin();
SnapManager &sm = _desktop->namedview->snap_manager;
bool snap = sm.someSnapperMightSnap();
+ boost::optional<Inkscape::Snapper::SnapConstraint> ctrl_constraint;
// with Alt, preserve length
if (held_alt(*event)) {
// with Alt, preserve length
if (held_alt(*event)) {
// note: if snapping to the original position is only desired in the original
// direction of the handle, change to Ray instead of Line
Geom::Line original_line(parent_pos, origin);
// note: if snapping to the original position is only desired in the original
// direction of the handle, change to Ray instead of Line
Geom::Line original_line(parent_pos, origin);
+ Geom::Line perp_line(parent_pos, parent_pos + Geom::rot90(origin - parent_pos));
Geom::Point snap_pos = parent_pos + Geom::constrain_angle(
Geom::Point(0,0), new_pos - parent_pos, snaps, Geom::Point(1,0));
Geom::Point orig_pos = original_line.pointAt(original_line.nearestPoint(new_pos));
Geom::Point snap_pos = parent_pos + Geom::constrain_angle(
Geom::Point(0,0), new_pos - parent_pos, snaps, Geom::Point(1,0));
Geom::Point orig_pos = original_line.pointAt(original_line.nearestPoint(new_pos));
+ Geom::Point perp_pos = perp_line.pointAt(perp_line.nearestPoint(new_pos));
- if (Geom::distance(snap_pos, new_pos) < Geom::distance(orig_pos, new_pos)) {
- new_pos = snap_pos;
- } else {
- new_pos = orig_pos;
+ Geom::Point result = snap_pos;
+ ctrl_constraint = Inkscape::Snapper::SnapConstraint(parent_pos, parent_pos - snap_pos);
+ if (Geom::distance(orig_pos, new_pos) < Geom::distance(result, new_pos)) {
+ result = orig_pos;
+ ctrl_constraint = Inkscape::Snapper::SnapConstraint(parent_pos, parent_pos - orig_pos);
}
}
- snap = false;
+ if (Geom::distance(perp_pos, new_pos) < Geom::distance(result, new_pos)) {
+ result = perp_pos;
+ ctrl_constraint = Inkscape::Snapper::SnapConstraint(parent_pos, parent_pos - perp_pos);
+ }
+ new_pos = result;
}
std::vector<Inkscape::SnapCandidatePoint> unselected;
}
std::vector<Inkscape::SnapCandidatePoint> unselected;
}
sm.setupIgnoreSelection(_desktop, true, &unselected);
}
sm.setupIgnoreSelection(_desktop, true, &unselected);
- Node *node_away = (this == &_parent->_front ? _parent->_prev() : _parent->_next());
+ Node *node_away = _parent->nodeAwayFrom(this);
if (_parent->type() == NODE_SMOOTH && Node::_is_line_segment(_parent, node_away)) {
Inkscape::Snapper::SnapConstraint cl(_parent->position(),
_parent->position() - node_away->position());
Inkscape::SnappedPoint p;
p = sm.constrainedSnap(Inkscape::SnapCandidatePoint(new_pos, SNAPSOURCE_NODE_HANDLE), cl);
new_pos = p.getPoint();
if (_parent->type() == NODE_SMOOTH && Node::_is_line_segment(_parent, node_away)) {
Inkscape::Snapper::SnapConstraint cl(_parent->position(),
_parent->position() - node_away->position());
Inkscape::SnappedPoint p;
p = sm.constrainedSnap(Inkscape::SnapCandidatePoint(new_pos, SNAPSOURCE_NODE_HANDLE), cl);
new_pos = p.getPoint();
+ } else if (ctrl_constraint) {
+ // NOTE: this is subtly wrong.
+ // We should get all possible constraints and snap along them using
+ // multipleConstrainedSnaps, instead of first snapping to angle and the to objects
+ Inkscape::SnappedPoint p;
+ p = sm.constrainedSnap(Inkscape::SnapCandidatePoint(new_pos, SNAPSOURCE_NODE_HANDLE), *ctrl_constraint);
+ new_pos = p.getPoint();
} else {
sm.freeSnapReturnByRef(new_pos, SNAPSOURCE_NODE_HANDLE);
}
} else {
sm.freeSnapReturnByRef(new_pos, SNAPSOURCE_NODE_HANDLE);
}
if (update_handles) {
switch (type) {
case NODE_CUSP:
if (update_handles) {
switch (type) {
case NODE_CUSP:
- // if the existing type is also NODE_CUSP, retract handles
- if (_type == NODE_CUSP) {
- _front.retract();
- _back.retract();
- }
+ // nothing to do
break;
case NODE_AUTO:
// auto handles make no sense for endnodes
break;
case NODE_AUTO:
// auto handles make no sense for endnodes
_updateAutoHandles();
break;
case NODE_SMOOTH: {
_updateAutoHandles();
break;
case NODE_SMOOTH: {
+ // ignore attempts to make smooth endnodes.
+ if (isEndNode()) return;
// rotate handles to be colinear
// for degenerate nodes set positions like auto handles
bool prev_line = _is_line_segment(_prev(), this);
bool next_line = _is_line_segment(this, _next());
if (_type == NODE_SMOOTH) {
// rotate handles to be colinear
// for degenerate nodes set positions like auto handles
bool prev_line = _is_line_segment(_prev(), this);
bool next_line = _is_line_segment(this, _next());
if (_type == NODE_SMOOTH) {
- // for a node that is already smooth and has a degenerate handle,
- // drag out the second handle to 1/3 the length of the linear segment
+ // For a node that is already smooth and has a degenerate handle,
+ // drag out the second handle without changing the direction of the first one.
if (_front.isDegenerate()) {
double dist = Geom::distance(_next()->position(), position());
_front.setRelativePos(Geom::unit_vector(-_back.relativePos()) * dist / 3);
if (_front.isDegenerate()) {
double dist = Geom::distance(_next()->position(), position());
_front.setRelativePos(Geom::unit_vector(-_back.relativePos()) * dist / 3);
/** Customized event handler to catch scroll events needed for selection grow/shrink. */
bool Node::_eventHandler(GdkEvent *event)
{
/** Customized event handler to catch scroll events needed for selection grow/shrink. */
bool Node::_eventHandler(GdkEvent *event)
{
- static NodeList::iterator origin;
- static int dir;
+ int dir = 0;
switch (event->type)
{
switch (event->type)
{
dir = -1;
} else break;
if (held_control(event->scroll)) {
dir = -1;
} else break;
if (held_control(event->scroll)) {
- _selection.spatialGrow(this, dir);
+ _linearGrow(dir);
} else {
} else {
+ _selection.spatialGrow(this, dir);
+ }
+ return true;
+ case GDK_KEY_PRESS:
+ switch (shortcut_key(event->key))
+ {
+ case GDK_Page_Up:
+ dir = 1;
+ break;
+ case GDK_Page_Down:
+ dir = -1;
+ break;
+ default: goto bail_out;
+ }
+
+ if (held_control(event->key)) {
_linearGrow(dir);
_linearGrow(dir);
+ } else {
+ _selection.spatialGrow(this, dir);
}
return true;
default:
break;
}
}
return true;
default:
break;
}
+
+ bail_out:
return ControlPoint::_eventHandler(event);
}
return ControlPoint::_eventHandler(event);
}
{
// For a note on how snapping is implemented in Inkscape, see snap.h.
SnapManager &sm = _desktop->namedview->snap_manager;
{
// For a note on how snapping is implemented in Inkscape, see snap.h.
SnapManager &sm = _desktop->namedview->snap_manager;
- bool snap = sm.someSnapperMightSnap();
+ // even if we won't really snap, we might still call the one of the
+ // constrainedSnap() methods to enforce the constraints, so we need
+ // to setup the snapmanager anyway; this is also required for someSnapperMightSnap()
+ sm.setup(_desktop);
+
+ // do not snap when Shift is pressed
+ bool snap = !held_shift(*event) && sm.someSnapperMightSnap();
+
Inkscape::SnappedPoint sp;
std::vector<Inkscape::SnapCandidatePoint> unselected;
if (snap) {
Inkscape::SnappedPoint sp;
std::vector<Inkscape::SnapCandidatePoint> unselected;
if (snap) {
unselected.push_back(p);
}
}
unselected.push_back(p);
}
}
+ sm.unSetup();
sm.setupIgnoreSelection(_desktop, true, &unselected);
sm.setupIgnoreSelection(_desktop, true, &unselected);
- } else {
- // even if we won't really snap, we might still call the one of the
- // constrainedSnap() methods to enforce the constraints, so we need
- // to setup the snapmanager anyway
- sm.setup(_desktop);
}
if (held_control(*event)) {
}
if (held_control(*event)) {
constraints.push_back(Inkscape::Snapper::SnapConstraint(origin, *bperp_point));
}
constraints.push_back(Inkscape::Snapper::SnapConstraint(origin, *bperp_point));
}
- sp = sm.multipleConstrainedSnaps(Inkscape::SnapCandidatePoint(new_pos, _snapSourceType()), constraints);
+ sp = sm.multipleConstrainedSnaps(Inkscape::SnapCandidatePoint(new_pos, _snapSourceType()), constraints, held_shift(*event));
} else {
// with Ctrl, constrain to axes
constraints.push_back(Inkscape::Snapper::SnapConstraint(origin, Geom::Point(1, 0)));
constraints.push_back(Inkscape::Snapper::SnapConstraint(origin, Geom::Point(0, 1)));
} else {
// with Ctrl, constrain to axes
constraints.push_back(Inkscape::Snapper::SnapConstraint(origin, Geom::Point(1, 0)));
constraints.push_back(Inkscape::Snapper::SnapConstraint(origin, Geom::Point(0, 1)));
- sp = sm.multipleConstrainedSnaps(Inkscape::SnapCandidatePoint(new_pos, _snapSourceType()), constraints);
+ sp = sm.multipleConstrainedSnaps(Inkscape::SnapCandidatePoint(new_pos, _snapSourceType()), constraints, held_shift(*event));
}
new_pos = sp.getPoint();
} else if (snap) {
}
new_pos = sp.getPoint();
} else if (snap) {
fill-column:99
End:
*/
fill-column:99
End:
*/
-// vim: filetype=cpp:expandtab:shiftwidth=4:tabstop=8:softtabstop=4:encoding=utf-8:textwidth=99 :
+// vim: filetype=cpp:expandtab:shiftwidth=4:tabstop=8:softtabstop=4:fileencoding=utf-8:textwidth=99 :