summaryrefslogtreecommitdiffstats
path: root/src/ui/tool/node.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'src/ui/tool/node.cpp')
-rw-r--r--src/ui/tool/node.cpp131
1 files changed, 127 insertions, 4 deletions
diff --git a/src/ui/tool/node.cpp b/src/ui/tool/node.cpp
index dc6e0fbae..bee2cc477 100644
--- a/src/ui/tool/node.cpp
+++ b/src/ui/tool/node.cpp
@@ -13,7 +13,6 @@
#include <glib/gi18n.h>
#include <2geom/bezier-utils.h>
#include <2geom/transforms.h>
-
#include "display/sp-ctrlline.h"
#include "display/sp-canvas.h"
#include "display/sp-canvas-util.h"
@@ -30,6 +29,9 @@
#include "ui/tool/node.h"
#include "ui/tool/path-manipulator.h"
#include <gdk/gdkkeysyms.h>
+//BSpline
+#include <math.h>
+//BSpline End;
namespace {
@@ -136,6 +138,24 @@ void Handle::move(Geom::Point const &new_pos)
Node *node_away = _parent->nodeAwayFrom(this); // node in the opposite direction
Handle *towards = node_towards ? node_towards->handleAwayFrom(_parent) : NULL;
Handle *towards_second = node_towards ? node_towards->handleToward(_parent) : NULL;
+ //BSpline
+ bool isBSpline = false;
+ double pos = 0;
+ Handle *h = NULL;
+ Handle *h2 = NULL;
+ if(_pm().isBSpline()){
+ isBSpline = true;
+ typedef ControlPointSelection::Set Set;
+ Set &nodes = _parent->_selection.allPoints();
+ for (Set::iterator i = nodes.begin(); i != nodes.end(); ++i) {
+ Node *n = static_cast<Node*>(*i);
+ if(n != _parent)
+ _parent->_selection.erase(n);
+ }
+ if(!_parent->selected())
+ _parent->_selection.insert(_parent);
+ }
+ //BSpline End
if (Geom::are_near(new_pos, _parent->position())) {
// The handle becomes degenerate.
@@ -167,6 +187,15 @@ void Handle::move(Geom::Point const &new_pos)
}
}
setPosition(new_pos);
+ //BSpline
+ if(isBSpline){
+ h = this;
+ setPosition(_pm().BSplineHandleReposition(h));
+ pos = _pm().BSplineHandlePosition(h);
+ h2 = this->other();
+ this->other()->setPosition(_pm().BSplineHandleReposition(h2,pos));
+ }
+ //BSpline End
return;
}
@@ -196,8 +225,16 @@ void Handle::move(Geom::Point const &new_pos)
break;
default: break;
}
-
setPosition(new_pos);
+ //BSpline
+ if(isBSpline){
+ h = this;
+ setPosition(_pm().BSplineHandleReposition(h));
+ pos = _pm().BSplineHandlePosition(h);
+ h2 = this->other();
+ this->other()->setPosition(_pm().BSplineHandleReposition(h2,pos));
+ }
+ //BSpline End
}
void Handle::setPosition(Geom::Point const &p)
@@ -274,12 +311,33 @@ bool Handle::_eventHandler(SPEventContext *event_context, GdkEvent *event)
break;
default: break;
}
+ //BSpline
+ case GDK_2BUTTON_PRESS:
+ handle_2button_press();
+ break;
+ //BSpline End
default: break;
}
return ControlPoint::_eventHandler(event_context, event);
}
+//BSpline
+void Handle::handle_2button_press(){
+ if(_pm().isBSpline()){
+ Handle *h = NULL;
+ Handle *h2 = NULL;
+ double pos = 0;
+ h = this;
+ setPosition(_pm().BSplineHandleReposition(h,0.3334));
+ pos = _pm().BSplineHandlePosition(h);
+ h2 = this->other();
+ this->other()->setPosition(_pm().BSplineHandleReposition(h2,pos));
+ _pm().update();
+ }
+}
+//BSpline End
+
bool Handle::grabbed(GdkEventMotion *)
{
_saved_other_pos = other()->position();
@@ -327,6 +385,16 @@ void Handle::dragged(Geom::Point &new_pos, GdkEventMotion *event)
ctrl_constraint = Inkscape::Snapper::SnapConstraint(parent_pos, parent_pos - perp_pos);
}
new_pos = result;
+ //BSpline
+ if(_pm().isBSpline()){
+ Handle *h = NULL;
+ double pos = 0;
+ h = this;
+ setPosition(new_pos);
+ pos = ceilf(_pm().BSplineHandlePosition(h)*10)/10;
+ new_pos=_pm().BSplineHandleReposition(h,pos);
+ }
+ //BSpline End
}
std::vector<Inkscape::SnapCandidatePoint> unselected;
@@ -550,13 +618,45 @@ void Node::move(Geom::Point const &new_pos)
// move handles when the node moves.
Geom::Point old_pos = position();
Geom::Point delta = new_pos - position();
+ //BSpline
+ double prevPos = 0;
+ double pos = 0;
+ double nextPos = 0;
+ Node *n = this;
+ Node * nextNode = n->nodeToward(n->front());
+ Node * prevNode = n->nodeToward(n->back());
+ if(_pm().isBSpline()){
+ if(prevNode)
+ prevPos = _pm().BSplineHandlePosition(prevNode->front());
+ pos = _pm().BSplineHandlePosition(n->front());
+ if(pos == 0)
+ pos = _pm().BSplineHandlePosition(n->back());
+ if(nextNode)
+ nextPos = _pm().BSplineHandlePosition(nextNode->back());
+ }
+ //BSpline End
setPosition(new_pos);
+ //BSpline
+ if(_pm().isBSpline()){
+ if(prevNode)
+ prevNode->front()->setPosition(_pm().BSplineHandleReposition(prevNode->front(),prevPos));
+ if(nextNode)
+ nextNode->back()->setPosition(_pm().BSplineHandleReposition(nextNode->back(),nextPos));
+ }
+ //BSpline End
_front.setPosition(_front.position() + delta);
_back.setPosition(_back.position() + delta);
-
+ //BSpline End
// if the node has a smooth handle after a line segment, it should be kept colinear
// with the segment
_fixNeighbors(old_pos, new_pos);
+ //BSpline
+ if(_pm().isBSpline()){
+ Handle* front = &_front;
+ Handle* back = &_back;
+ _front.setPosition(_pm().BSplineHandleReposition(front,pos));
+ _back.setPosition(_pm().BSplineHandleReposition(back,pos));
+ }
}
void Node::transform(Geom::Affine const &m)
@@ -663,7 +763,7 @@ void Node::updateHandles()
_front._handleControlStyling();
_back._handleControlStyling();
}
-
+
void Node::setType(NodeType type, bool update_handles)
{
@@ -673,6 +773,27 @@ void Node::setType(NodeType type, bool update_handles)
return;
}
+ //BSpline
+ if(_pm().isBSpline()){
+ if (isEndNode()) return;
+ Handle* front = &_front;
+ Handle* back = &_back;
+ double pos = 0.3334;
+ switch (type) {
+ case NODE_CUSP:
+ if(update_handles)
+ pos = 0;
+ else
+ pos = _pm().BSplineHandlePosition(front);;
+ break;
+ default: break;
+ }
+ type = NODE_CUSP;
+ _front.setPosition(_pm().BSplineHandleReposition(front,pos));
+ _back.setPosition(_pm().BSplineHandleReposition(back,pos));
+ }
+ //BSpline End
+
// if update_handles is true, adjust handle positions to match the node type
// handle degenerate handles appropriately
if (update_handles) {
@@ -756,7 +877,9 @@ void Node::setType(NodeType type, bool update_handles)
default: break;
}
}
+
_type = type;
+
_setControlType(nodeTypeToCtrlType(_type));
updateState();
}