diff options
| author | Jabier Arraiza Cenoz <jabier.arraiza@marker.es> | 2013-12-30 19:41:32 +0000 |
|---|---|---|
| committer | Jabiertxof <jtx@jtx.marker.es> | 2013-12-30 19:41:32 +0000 |
| commit | 4c6918c72721a35e0347e9e087396238e72eb62e (patch) | |
| tree | 22d7e8b0c0ecff9d8c6ff73ab0311a2fa9873ae7 /src/ui/tool | |
| parent | Refactorizing (diff) | |
| download | inkscape-4c6918c72721a35e0347e9e087396238e72eb62e.tar.gz inkscape-4c6918c72721a35e0347e9e087396238e72eb62e.zip | |
Refactorizing
(bzr r11950.1.212)
Diffstat (limited to 'src/ui/tool')
| -rw-r--r-- | src/ui/tool/curve-drag-point.cpp | 2 | ||||
| -rw-r--r-- | src/ui/tool/multi-path-manipulator.cpp | 3 | ||||
| -rw-r--r-- | src/ui/tool/multi-path-manipulator.h | 2 | ||||
| -rw-r--r-- | src/ui/tool/node.cpp | 21 | ||||
| -rw-r--r-- | src/ui/tool/node.h | 9 | ||||
| -rw-r--r-- | src/ui/tool/path-manipulator.cpp | 11 | ||||
| -rw-r--r-- | src/ui/tool/path-manipulator.h | 7 |
7 files changed, 16 insertions, 39 deletions
diff --git a/src/ui/tool/curve-drag-point.cpp b/src/ui/tool/curve-drag-point.cpp index f847a6ab3..5387e597d 100644 --- a/src/ui/tool/curve-drag-point.cpp +++ b/src/ui/tool/curve-drag-point.cpp @@ -53,12 +53,10 @@ 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; - //BSpline if(!_pm.isBSpline){ first->front()->move(first->front()->position() + delta); second->back()->move(second->back()->position() - delta); } - //BSpline End _pm.update(); } else { _segment_was_degenerate = false; diff --git a/src/ui/tool/multi-path-manipulator.cpp b/src/ui/tool/multi-path-manipulator.cpp index 6da8b4104..3612f9c56 100644 --- a/src/ui/tool/multi-path-manipulator.cpp +++ b/src/ui/tool/multi-path-manipulator.cpp @@ -298,7 +298,6 @@ void MultiPathManipulator::invertSelectionInSubpaths() invokeForAll(&PathManipulator::invertSelectionInSubpaths); } - void MultiPathManipulator::setNodeType(NodeType type) { if (_selection.empty()) return; @@ -327,7 +326,6 @@ void MultiPathManipulator::setNodeType(NodeType type) _done(retract_handles ? _("Retract handles") : _("Change node type")); } - void MultiPathManipulator::setSegmentType(SegmentType type) { if (_selection.empty()) return; @@ -691,7 +689,6 @@ bool MultiPathManipulator::event(Inkscape::UI::Tools::ToolBase *event_context, G deleteNodes(true); } else - //BSpline end deleteNodes(del_preserves_shape ^ held_control(event->key)); // Delete any selected gradient nodes as well diff --git a/src/ui/tool/multi-path-manipulator.h b/src/ui/tool/multi-path-manipulator.h index 4566a7a98..1328372c6 100644 --- a/src/ui/tool/multi-path-manipulator.h +++ b/src/ui/tool/multi-path-manipulator.h @@ -71,7 +71,7 @@ public: void setLiveObjects(bool set); void updateOutlineColors(); void updateHandles(); - + sigc::signal<void> signal_coords_changed; /// Emitted whenever the coordinates /// shown in the status bar need updating private: diff --git a/src/ui/tool/node.cpp b/src/ui/tool/node.cpp index 70e374424..7266c85bb 100644 --- a/src/ui/tool/node.cpp +++ b/src/ui/tool/node.cpp @@ -28,9 +28,7 @@ #include "ui/tool/node.h" #include "ui/tool/path-manipulator.h" #include <gdk/gdkkeysyms.h> - #include <math.h> -; namespace { @@ -137,7 +135,7 @@ 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; - + if (Geom::are_near(new_pos, _parent->position())) { // The handle becomes degenerate. // Adjust node type as necessary. @@ -308,7 +306,6 @@ bool Handle::_eventHandler(Inkscape::UI::Tools::ToolBase *event_context, GdkEven return ControlPoint::_eventHandler(event_context, event); } - void Handle::handle_2button_press(){ if(_pm().isBSpline){ setPosition(_pm().BSplineHandleReposition(this,0.3334)); @@ -318,7 +315,6 @@ void Handle::handle_2button_press(){ } } - bool Handle::grabbed(GdkEventMotion *) { _saved_other_pos = other()->position(); @@ -335,6 +331,7 @@ void Handle::dragged(Geom::Point &new_pos, GdkEventMotion *event) SnapManager &sm = _desktop->namedview->snap_manager; bool snap = held_shift(*event) ? false : sm.someSnapperMightSnap(); boost::optional<Inkscape::Snapper::SnapConstraint> ctrl_constraint; + // with Alt, preserve length if (held_alt(*event)) { new_pos = parent_pos + Geom::unit_vector(new_pos - parent_pos) * _saved_length; @@ -366,14 +363,13 @@ void Handle::dragged(Geom::Point &new_pos, GdkEventMotion *event) ctrl_constraint = Inkscape::Snapper::SnapConstraint(parent_pos, parent_pos - perp_pos); } new_pos = result; - + if(_pm().isBSpline){ setPosition(new_pos); int steps = _pm().BSplineGetSteps(); _parent->bsplineWeight = ceilf(_pm().BSplineHandlePosition(this)*steps)/steps; new_pos=_pm().BSplineHandleReposition(this,_parent->bsplineWeight); } - } std::vector<Inkscape::SnapCandidatePoint> unselected; @@ -627,22 +623,22 @@ 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(); - + double oldPos = 0.0000; Node *n = this; if(_pm().isBSpline){ oldPos = n->bsplineWeight; } - + setPosition(new_pos); _front.setPosition(_front.position() + delta); _back.setPosition(_back.position() + delta); - + // if the node has a smooth handle after a line segment, it should be kept colinear // with the segment _fixNeighbors(old_pos, new_pos); - + if(_pm().isBSpline){ _front.setPosition(_pm().BSplineHandleReposition(this->front(),oldPos)); _back.setPosition(_pm().BSplineHandleReposition(this->back(),oldPos)); @@ -774,6 +770,7 @@ void Node::setType(NodeType type, bool update_handles) updateState(); // The size of the control might have changed return; } + // if update_handles is true, adjust handle positions to match the node type // handle degenerate handles appropriately if (update_handles) { @@ -861,7 +858,6 @@ void Node::setType(NodeType type, bool update_handles) _front.setPosition(_pm().BSplineHandleReposition(this->front(),this->bsplineWeight)); _back.setPosition(_pm().BSplineHandleReposition(this->back(),this->bsplineWeight)); } - } _type = type; _setControlType(nodeTypeToCtrlType(_type)); @@ -1124,7 +1120,6 @@ void Node::_setState(State state) this->back()->setPosition(_pm().BSplineHandleReposition(this->back(),this->bsplineWeight)); } } - break; } SelectableControlPoint::_setState(state); diff --git a/src/ui/tool/node.h b/src/ui/tool/node.h index d257db86a..01159e6a0 100644 --- a/src/ui/tool/node.h +++ b/src/ui/tool/node.h @@ -97,6 +97,7 @@ public: virtual void setVisible(bool); virtual void move(Geom::Point const &p); + virtual void setPosition(Geom::Point const &p); inline void setRelativePos(Geom::Point const &p); void setLength(double len); @@ -112,28 +113,25 @@ public: protected: Handle(NodeSharedData const &data, Geom::Point const &initial_pos, Node *parent); - //Bspline virtual void handle_2button_press(); - //BSpline End - virtual bool _eventHandler(Inkscape::UI::Tools::ToolBase *event_context, GdkEvent *event); - virtual void dragged(Geom::Point &new_pos, GdkEventMotion *event); virtual bool grabbed(GdkEventMotion *event); virtual void ungrabbed(GdkEventButton *event); virtual bool clicked(GdkEventButton *event); - virtual Glib::ustring _getTip(unsigned state) const; virtual Glib::ustring _getDragTip(GdkEventMotion *event) const; virtual bool _hasDragTips() const { return true; } private: + inline PathManipulator &_pm(); Node *_parent; // the handle's lifetime does not extend beyond that of the parent node, // so a naked pointer is OK and allows setting it during Node's construction SPCtrlLine *_handle_line; bool _degenerate; // True if the handle is retracted, i.e. has zero length. This is used often internally so it makes sense to cache this + /** * Control point of a cubic Bezier curve in a path. * @@ -190,6 +188,7 @@ public: Handle *front() { return &_front; } Handle *back() { return &_back; } double bsplineWeight; + /** * Gets the handle that faces the given adjacent node. * Will abort with error if the given node is not adjacent. diff --git a/src/ui/tool/path-manipulator.cpp b/src/ui/tool/path-manipulator.cpp index 4aec42100..4cb6ce296 100644 --- a/src/ui/tool/path-manipulator.cpp +++ b/src/ui/tool/path-manipulator.cpp @@ -43,10 +43,8 @@ #include "ui/tool/multi-path-manipulator.h" #include "xml/node.h" #include "xml/node-observer.h" - #include "live_effects/lpe-bspline.h" - namespace Inkscape { namespace UI { @@ -668,7 +666,6 @@ unsigned PathManipulator::_deleteStretch(NodeList::iterator start, NodeList::ite nl.erase(start); start = next; } - if(isBSpline){ double pos = 0.0000; if(start.prev()){ @@ -680,7 +677,6 @@ unsigned PathManipulator::_deleteStretch(NodeList::iterator start, NodeList::ite end->back()->setPosition(BSplineHandleReposition(end->back(),pos)); } } - return del_len; } @@ -856,9 +852,9 @@ void PathManipulator::rotateHandle(Node *n, int which, int dir, bool pixel) int snaps = prefs->getIntLimited("/options/rotationsnapsperpi/value", 12, 1, 1000); angle = M_PI * dir / snaps; } + h->setRelativePos(h->relativePos() * Geom::Rotate(angle)); update(); - gchar const *key = which < 0 ? "handle:rotate:left" : "handle:rotate:right"; _commit(_("Rotate handle"), key); } @@ -915,9 +911,7 @@ void PathManipulator::showHandles(bool show) /** Set the visibility of outline. */ void PathManipulator::showOutline(bool show) { - if(isBSpline) show = true; - if (show == _show_outline) return; _show_outline = show; _updateOutline(); @@ -1307,7 +1301,6 @@ void PathManipulator::_createGeometryFromControlPoints(bool alert_LPE) build_segment(builder, prev.ptr(), i.ptr()); prev = i; } - if (subpath->closed()) { // Here we link the last and first node if the path is closed. // If the last segment is Bezier, we add it. @@ -1319,7 +1312,6 @@ void PathManipulator::_createGeometryFromControlPoints(bool alert_LPE) } ++spi; } - builder.finish(); Geom::PathVector pathv = builder.peek() * (_edit_transform * _i2d_transform).inverse(); _spcurve->set_pathvector(pathv); @@ -1380,6 +1372,7 @@ void PathManipulator::_updateOutline() sp_canvas_item_hide(_outline); return; } + Geom::PathVector pv = _spcurve->get_pathvector(); pv *= (_edit_transform * _i2d_transform); // This SPCurve thing has to be killed with extreme prejudice diff --git a/src/ui/tool/path-manipulator.h b/src/ui/tool/path-manipulator.h index 547e687a7..31cc0d1fd 100644 --- a/src/ui/tool/path-manipulator.h +++ b/src/ui/tool/path-manipulator.h @@ -19,10 +19,8 @@ #include <boost/weak_ptr.hpp> #include "ui/tool/node.h" #include "ui/tool/manipulator.h" - #include "live_effects/lpe-bspline.h" - struct SPCanvasItem; class SPCurve; class SPPath; @@ -97,10 +95,9 @@ public: NodeList::iterator subdivideSegment(NodeList::iterator after, double t); NodeList::iterator extremeNode(NodeList::iterator origin, bool search_selected, bool search_unselected, bool closest); - + bool isBSpline; int BSplineGetSteps(); - // this is necessary for Tab-selection in MultiPathManipulator SubpathList &subpathList() { return _subpaths; } @@ -110,13 +107,11 @@ private: typedef boost::shared_ptr<NodeList> SubpathPtr; void _createControlPointsFromGeometry(); - void BSpline(); double BSplineHandlePosition(Handle *h); Geom::Point BSplineHandleReposition(Handle *h); Geom::Point BSplineHandleReposition(Handle *h,double pos); void BSplineNodeHandlesReposition(Node *n); - void _createGeometryFromControlPoints(bool alert_LPE = false); unsigned _deleteStretch(NodeList::iterator first, NodeList::iterator last, bool keep_shape); std::string _createTypeString(); |
