From ae1bd880cb7f913509b1b0e2de1fa4aa7e430d15 Mon Sep 17 00:00:00 2001 From: Jabier Arraiza Cenoz Date: Sat, 21 Mar 2015 12:45:38 +0100 Subject: Improve the cache system of bspline, "Correctly" show bspline weight power on nodes and handles (bzr r14023) --- src/ui/tool/curve-drag-point.cpp | 4 ++-- src/ui/tool/node.cpp | 15 ++++++++------- src/ui/tool/path-manipulator.cpp | 21 +++++++++++++++++---- src/ui/tool/path-manipulator.h | 2 +- 4 files changed, 28 insertions(+), 14 deletions(-) (limited to 'src/ui/tool') diff --git a/src/ui/tool/curve-drag-point.cpp b/src/ui/tool/curve-drag-point.cpp index 49c949107..a90dfb155 100644 --- a/src/ui/tool/curve-drag-point.cpp +++ b/src/ui/tool/curve-drag-point.cpp @@ -54,7 +54,7 @@ bool CurveDragPoint::grabbed(GdkEventMotion */*event*/) // delta is a vector equal 1/3 of distance from first to second Geom::Point delta = (second->position() - first->position()) / 3.0; // only update the nodes if the mode is bspline - if(!_pm.isBSpline(false)){ + if(!_pm.isBSpline()){ first->front()->move(first->front()->position() + delta); second->back()->move(second->back()->position() - delta); } @@ -91,7 +91,7 @@ void CurveDragPoint::dragged(Geom::Point &new_pos, GdkEventMotion *event) Geom::Point offset1 = (weight/(3*t*t*(1-t))) * delta; //modified so that, if the trace is bspline, it only acts if the SHIFT key is pressed - if(!_pm.isBSpline(false)){ + if(!_pm.isBSpline()){ first->front()->move(first->front()->position() + offset0); second->back()->move(second->back()->position() + offset1); }else if(weight>=0.8){ diff --git a/src/ui/tool/node.cpp b/src/ui/tool/node.cpp index eeea47e4d..08cc6708d 100644 --- a/src/ui/tool/node.cpp +++ b/src/ui/tool/node.cpp @@ -192,7 +192,7 @@ void Handle::move(Geom::Point const &new_pos) setRelativePos(new_delta); //move the handler and its oposite the same proportion - if(_pm().isBSpline()){ + if(_pm().isBSpline()){ setPosition(_pm().BSplineHandleReposition(this,this)); this->other()->setPosition(_pm().BSplineHandleReposition(this->other(),this)); } @@ -222,7 +222,6 @@ void Handle::move(Geom::Point const &new_pos) setPosition(_pm().BSplineHandleReposition(this,this)); this->other()->setPosition(_pm().BSplineHandleReposition(this->other(),this)); } - } void Handle::setPosition(Geom::Point const &p) @@ -382,7 +381,7 @@ void Handle::dragged(Geom::Point &new_pos, GdkEventMotion *event) std::vector unselected; //if the snap adjustment is activated and it is not bspline - if (snap && !_pm().isBSpline(false)) { + if (snap && !_pm().isBSpline()) { ControlPointSelection::Set &nodes = _parent->_selection.allPoints(); for (ControlPointSelection::Set::iterator i = nodes.begin(); i != nodes.end(); ++i) { Node *n = static_cast(*i); @@ -486,7 +485,7 @@ Glib::ustring Handle::_getTip(unsigned state) const char const *more; // a trick to mark as bspline if the node has no strength, we are going to use it later // to show the appropiate messages. We cannot do it in any different way becasue the function is constant - + Handle *h = const_cast(this); bool isBSpline = _pm().isBSpline(); bool can_shift_rotate = _parent->type() == NODE_CUSP && !other()->isDegenerate(); if (can_shift_rotate && !isBSpline) { @@ -550,7 +549,7 @@ Glib::ustring Handle::_getTip(unsigned state) const "Auto node handle: drag to convert to smooth node (%s)"), more); }else{ return format_tip(C_("Path handle tip", - "BSpline node handle: Shift to drag, double click to reset (%s)"), more); + "BSpline node handle: Shift to drag, double click to reset (%s). %g power"),more,_pm().BSplineHandlePosition(h,NULL)); } } } @@ -1435,6 +1434,8 @@ Node *Node::nodeAwayFrom(Handle *h) Glib::ustring Node::_getTip(unsigned state) const { bool isBSpline = _pm().isBSpline(); + Handle *h = const_cast(&_front); + Handle *h2 = const_cast(&_back); if (state_held_shift(state)) { bool can_drag_out = (_next() && _front.isDegenerate()) || (_prev() && _back.isDegenerate()); if (can_drag_out) { @@ -1469,7 +1470,7 @@ Glib::ustring Node::_getTip(unsigned state) const "%s: drag to shape the path (more: Shift, Ctrl, Alt)"), nodetype); }else if(_selection.size() == 1){ return format_tip(C_("Path node tip", - "BSpline node: %g weight, drag to shape the path (more: Shift, Ctrl, Alt)"),noPower/*this->bsplineWeight*/); + "BSpline node: drag to shape the path (more: Shift, Ctrl, Alt). %g power"),_pm().BSplineHandlePosition(h,h2)); } return format_tip(C_("Path node tip", "%s: drag to shape the path, click to toggle scale/rotation handles (more: Shift, Ctrl, Alt)"), nodetype); @@ -1479,7 +1480,7 @@ Glib::ustring Node::_getTip(unsigned state) const "%s: drag to shape the path, click to select only this node (more: Shift, Ctrl, Alt)"), nodetype); }else{ return format_tip(C_("Path node tip", - "BSpline node: drag to shape the path, click to select only this node (more: Shift, Ctrl, Alt)")); + "BSpline node: drag to shape the path, click to select only this node (more: Shift, Ctrl, Alt). %g power"),_pm().BSplineHandlePosition(h,h2)); } } diff --git a/src/ui/tool/path-manipulator.cpp b/src/ui/tool/path-manipulator.cpp index dbcde240a..8b735f3e6 100644 --- a/src/ui/tool/path-manipulator.cpp +++ b/src/ui/tool/path-manipulator.cpp @@ -1240,17 +1240,29 @@ int PathManipulator::BSplineGetSteps() const { // determines if the trace has bspline effect bool PathManipulator::isBSpline(bool recalculate){ if(recalculate){ - _is_bspline = this->BSplineGetSteps() > 0; + SPLPEItem * path = dynamic_cast(_path); + if (path){ + if(path->hasPathEffect()){ + Inkscape::LivePathEffect::Effect const *thisEffect = path->getPathEffectOfType(Inkscape::LivePathEffect::BSPLINE); + if(thisEffect){ + _is_bspline = true; + return _is_bspline; + } + } + } + } + _is_bspline = false; return _is_bspline; } bool PathManipulator::isBSpline() const { - return BSplineGetSteps() > 0; + return _is_bspline; } // returns the corresponding strength to the position of the handlers -double PathManipulator::BSplineHandlePosition(Handle *h, Handle *h2){ +double PathManipulator::BSplineHandlePosition(Handle *h, Handle *h2) +{ using Geom::X; using Geom::Y; if(h2){ @@ -1275,7 +1287,8 @@ double PathManipulator::BSplineHandlePosition(Handle *h, Handle *h2){ } // give the location for the handler in the corresponding position -Geom::Point PathManipulator::BSplineHandleReposition(Handle *h, Handle *h2){ +Geom::Point PathManipulator::BSplineHandleReposition(Handle *h, Handle *h2) +{ double pos = this->BSplineHandlePosition(h, h2); return BSplineHandleReposition(h,pos); } diff --git a/src/ui/tool/path-manipulator.h b/src/ui/tool/path-manipulator.h index 4d2bf4300..4badec569 100644 --- a/src/ui/tool/path-manipulator.h +++ b/src/ui/tool/path-manipulator.h @@ -107,7 +107,7 @@ private: void _createControlPointsFromGeometry(); - bool isBSpline(bool recalculate = false); + bool isBSpline(bool recalculate); bool isBSpline() const; double BSplineHandlePosition(Handle *h, Handle *h2 = NULL); Geom::Point BSplineHandleReposition(Handle *h, Handle *h2 = NULL); -- cgit v1.2.3