diff options
| author | Jon A. Cruz <jon@joncruz.org> | 2012-05-17 09:10:15 +0000 |
|---|---|---|
| committer | Jon A. Cruz <jon@joncruz.org> | 2012-05-17 09:10:15 +0000 |
| commit | b6ea2239ffc053e66238eb8484bbc5c1ba8700ac (patch) | |
| tree | aa69d18959e71ca3a5d268acdc24b85e24663e29 /src/ui | |
| parent | Fix for 997888 : Merge into Document Properties (diff) | |
| download | inkscape-b6ea2239ffc053e66238eb8484bbc5c1ba8700ac.tar.gz inkscape-b6ea2239ffc053e66238eb8484bbc5c1ba8700ac.zip | |
Extended resizing to node handles.
(bzr r11375)
Diffstat (limited to 'src/ui')
| -rw-r--r-- | src/ui/Makefile_insert | 1 | ||||
| -rw-r--r-- | src/ui/control-manager.cpp | 89 | ||||
| -rw-r--r-- | src/ui/control-manager.h | 9 | ||||
| -rw-r--r-- | src/ui/tool/control-point.cpp | 27 | ||||
| -rw-r--r-- | src/ui/tool/control-point.h | 6 | ||||
| -rw-r--r-- | src/ui/tool/curve-drag-point.cpp | 2 | ||||
| -rw-r--r-- | src/ui/tool/multi-path-manipulator.cpp | 5 | ||||
| -rw-r--r-- | src/ui/tool/multi-path-manipulator.h | 1 | ||||
| -rw-r--r-- | src/ui/tool/node-tool.cpp | 17 | ||||
| -rw-r--r-- | src/ui/tool/node-tool.h | 1 | ||||
| -rw-r--r-- | src/ui/tool/node.cpp | 73 | ||||
| -rw-r--r-- | src/ui/tool/node.h | 2 | ||||
| -rw-r--r-- | src/ui/tool/path-manipulator.cpp | 9 | ||||
| -rw-r--r-- | src/ui/tool/path-manipulator.h | 1 | ||||
| -rw-r--r-- | src/ui/tool/selector.cpp | 2 | ||||
| -rw-r--r-- | src/ui/tool/transform-handle-set.cpp | 2 |
16 files changed, 186 insertions, 61 deletions
diff --git a/src/ui/Makefile_insert b/src/ui/Makefile_insert index 59b290dc4..4081f86f8 100644 --- a/src/ui/Makefile_insert +++ b/src/ui/Makefile_insert @@ -5,6 +5,7 @@ ink_common_sources += \ ui/clipboard.h \ ui/control-manager.cpp \ ui/control-manager.h \ + ui/control-types.h \ ui/icon-names.h \ ui/previewable.h \ ui/previewfillable.h \ diff --git a/src/ui/control-manager.cpp b/src/ui/control-manager.cpp index d19c4a877..33d262c31 100644 --- a/src/ui/control-manager.cpp +++ b/src/ui/control-manager.cpp @@ -16,6 +16,7 @@ #include <glib-object.h> #include "display/sodipodi-ctrl.h" // for SP_TYPE_CTRL +#include "display/sp-canvas-item.h" #include "display/sp-ctrlline.h" #include "display/sp-ctrlpoint.h" #include "preferences.h" @@ -43,6 +44,8 @@ public: ~ControlManagerImpl() {} + SPCanvasItem *createControl(SPCanvasGroup *parent, ControlType type); + void setControlSize(int size, bool force = false); void track(SPCanvasItem *anchor); @@ -98,7 +101,7 @@ ControlManagerImpl::ControlManagerImpl() : _sizeTable[CTRL_TYPE_ANCHOR] = std::vector<int>(sizes, sizes + (sizeof(sizes) / sizeof(sizes[0]))); } { - int sizes[] = {2, 3, 4, 7, 8, 9, 10}; + int sizes[] = {2, 4, 7, 8, 9, 10, 12}; _sizeTable[CTRL_TYPE_ADJ_HANDLE] = std::vector<int>(sizes, sizes + (sizeof(sizes) / sizeof(sizes[0]))); } { @@ -112,6 +115,10 @@ ControlManagerImpl::ControlManagerImpl() : int sizes[] = {2, 3, 4, 7, 8, 9, 10}; _sizeTable[CTRL_TYPE_ORIGIN] = std::vector<int>(sizes, sizes + (sizeof(sizes) / sizeof(sizes[0]))); } + { + int sizes[] = {1, 1, 1, 1, 1, 1, 1}; + _sizeTable[CTRL_TYPE_INVISIPOINT] = std::vector<int>(sizes, sizes + (sizeof(sizes) / sizeof(sizes[0]))); + } } @@ -133,6 +140,52 @@ void ControlManagerImpl::setControlSize(int size, bool force) } } +SPCanvasItem *ControlManagerImpl::createControl(SPCanvasGroup *parent, ControlType type) +{ + SPCanvasItem *item = 0; + double targetSize = _sizeTable[type][_size - 1]; + switch (type) + { + case CTRL_TYPE_ADJ_HANDLE: + item = sp_canvas_item_new(parent, SP_TYPE_CTRL, + "shape", SP_CTRL_SHAPE_CIRCLE, + "size", targetSize, + "filled", 0, + "fill_color", 0xff00007f, + "stroked", 1, + "stroke_color", 0x0000ff7f, + NULL); + break; + case CTRL_TYPE_ANCHOR: + item = sp_canvas_item_new(parent, SP_TYPE_CTRL, + "size", targetSize, + "filled", 1, + "fill_color", FILL_COLOR_NORMAL, + "stroked", 1, + "stroke_color", 0x000000ff, + NULL); + break; + case CTRL_TYPE_ORIGIN: + item = sp_canvas_item_new(parent, SP_TYPE_CTRLPOINT, + "size", targetSize, + NULL); + break; + case CTRL_TYPE_INVISIPOINT: + item = sp_canvas_item_new(parent, SP_TYPE_CTRL, + "shape", SP_CTRL_SHAPE_SQUARE, + "size", targetSize, + NULL); + break; + case CTRL_TYPE_UNKNOWN: + default: + item = sp_canvas_item_new(parent, SP_TYPE_CTRL, NULL); + } + if (item) { + item->ctrlType = type; + } + return item; +} + void ControlManagerImpl::track(SPCanvasItem *item) { g_object_weak_ref( G_OBJECT(item), ControlManagerImpl::thingFinalized, this ); @@ -202,39 +255,7 @@ ControlManager &ControlManager::getManager() SPCanvasItem *ControlManager::createControl(SPCanvasGroup *parent, ControlType type) { - SPCanvasItem *item = 0; - switch (type) - { - case CTRL_TYPE_ADJ_HANDLE: - item = sp_canvas_item_new(parent, SP_TYPE_CTRL, - "shape", SP_CTRL_SHAPE_CIRCLE, - "size", 4.0, - "filled", 0, - "fill_color", 0xff00007f, - "stroked", 1, - "stroke_color", 0x0000ff7f, - NULL); - break; - case CTRL_TYPE_ANCHOR: - item = sp_canvas_item_new(parent, SP_TYPE_CTRL, - "size", 6.0, - "filled", 1, - "fill_color", FILL_COLOR_NORMAL, - "stroked", 1, - "stroke_color", 0x000000ff, - NULL); - break; - case CTRL_TYPE_ORIGIN: - item = sp_canvas_item_new(parent, SP_TYPE_CTRLPOINT, NULL); - break; - case CTRL_TYPE_UNKNOWN: - default: - item = sp_canvas_item_new(parent, SP_TYPE_CTRL, NULL); - } - if (item) { - item->ctrlType = type; - } - return item; + return _impl->createControl(parent, type); } SPCtrlLine *ControlManager::createControlLine(SPCanvasGroup *parent, CtrlLineType type) diff --git a/src/ui/control-manager.h b/src/ui/control-manager.h index 986d474d0..9f0e62543 100644 --- a/src/ui/control-manager.h +++ b/src/ui/control-manager.h @@ -14,12 +14,19 @@ #include <memory> #include <sigc++/sigc++.h> -#include "display/sp-canvas-item.h" +#include "ui/control-types.h" struct SPCanvasGroup; struct SPCanvasItem; struct SPCtrlLine; +namespace Geom +{ + +class Point; + +} // namespace Geom + namespace Inkscape { enum CtrlLineType { diff --git a/src/ui/tool/control-point.cpp b/src/ui/tool/control-point.cpp index a10db03c7..9c559be03 100644 --- a/src/ui/tool/control-point.cpp +++ b/src/ui/tool/control-point.cpp @@ -19,6 +19,7 @@ #include "preferences.h" #include "snap-preferences.h" #include "sp-namedview.h" +#include "ui/control-manager.h" #include "ui/tool/control-point.h" #include "ui/tool/event-utils.h" #include "ui/tool/transform-handle-set.h" @@ -105,6 +106,25 @@ ControlPoint::ControlPoint(SPDesktop *d, Geom::Point const &initial_pos, SPAncho _commonInit(); } +ControlPoint::ControlPoint(SPDesktop *d, Geom::Point const &initial_pos, SPAnchorType anchor, + ControlType type, + ColorSet const &cset, SPCanvasGroup *group) : + _desktop(d), + _canvas_item(NULL), + _cset(cset), + _state(STATE_NORMAL), + _position(initial_pos), + _lurking(false) +{ + _canvas_item = ControlManager::getManager().createControl(group ? group : sp_desktop_controls(_desktop), type); + g_object_set(_canvas_item, + "anchor", anchor, + "filled", TRUE, "fill_color", _cset.normal.fill, + "stroked", TRUE, "stroke_color", _cset.normal.stroke, + "mode", SP_CTRL_MODE_XOR, NULL); + _commonInit(); +} + ControlPoint::~ControlPoint() { // avoid storing invalid points in mouseovered_point @@ -528,6 +548,13 @@ void ControlPoint::_setState(State state) _state = state; } +void ControlPoint::_handleControlStyling() +{ + if (_canvas_item->ctrlType != CTRL_TYPE_UNKNOWN) { + ControlManager::getManager().updateItem(_canvas_item); + } +} + void ControlPoint::_setColors(ColorEntry colors) { g_object_set(_canvas_item, "fill_color", colors.fill, "stroke_color", colors.stroke, NULL); diff --git a/src/ui/tool/control-point.h b/src/ui/tool/control-point.h index 621c1134a..20122e09c 100644 --- a/src/ui/tool/control-point.h +++ b/src/ui/tool/control-point.h @@ -236,6 +236,10 @@ protected: Glib::RefPtr<Gdk::Pixbuf> pixbuf, ColorSet const &cset = _default_color_set, SPCanvasGroup *group = 0); + ControlPoint(SPDesktop *d, Geom::Point const &initial_pos, SPAnchorType anchor, + ControlType type, + ColorSet const &cset = _default_color_set, SPCanvasGroup *group = 0); + /// @name Handle control point events in subclasses /// @{ /** @@ -292,6 +296,8 @@ protected: */ virtual void _setState(State state); + void _handleControlStyling(); + void _setColors(ColorEntry c); unsigned int _size() const; diff --git a/src/ui/tool/curve-drag-point.cpp b/src/ui/tool/curve-drag-point.cpp index 19b0e3b84..b83ce1b3c 100644 --- a/src/ui/tool/curve-drag-point.cpp +++ b/src/ui/tool/curve-drag-point.cpp @@ -25,7 +25,7 @@ bool CurveDragPoint::_segment_was_degenerate = false; CurveDragPoint::CurveDragPoint(PathManipulator &pm) : ControlPoint(pm._multi_path_manipulator._path_data.node_data.desktop, Geom::Point(), SP_ANCHOR_CENTER, - SP_CTRL_SHAPE_CIRCLE, 1.0, + CTRL_TYPE_INVISIPOINT, invisible_cset, pm._multi_path_manipulator._path_data.dragpoint_group), _pm(pm) { diff --git a/src/ui/tool/multi-path-manipulator.cpp b/src/ui/tool/multi-path-manipulator.cpp index 3fc202b69..8f3f03aae 100644 --- a/src/ui/tool/multi-path-manipulator.cpp +++ b/src/ui/tool/multi-path-manipulator.cpp @@ -554,6 +554,11 @@ void MultiPathManipulator::updateOutlineColors() //} } +void MultiPathManipulator::updateHandles() +{ + invokeForAll(&PathManipulator::updateHandles); +} + bool MultiPathManipulator::event(SPEventContext *event_context, GdkEvent *event) { _tracker.event(event); diff --git a/src/ui/tool/multi-path-manipulator.h b/src/ui/tool/multi-path-manipulator.h index 2c05a1252..54a9b5753 100644 --- a/src/ui/tool/multi-path-manipulator.h +++ b/src/ui/tool/multi-path-manipulator.h @@ -70,6 +70,7 @@ public: void setLiveOutline(bool set); 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 diff --git a/src/ui/tool/node-tool.cpp b/src/ui/tool/node-tool.cpp index 7127ae968..76b309ad6 100644 --- a/src/ui/tool/node-tool.cpp +++ b/src/ui/tool/node-tool.cpp @@ -29,6 +29,7 @@ #include "sp-object-group.h" #include "sp-path.h" #include "sp-text.h" +#include "ui/control-manager.h" #include "ui/tool/node-tool.h" #include "ui/tool/control-point-selection.h" #include "ui/tool/event-utils.h" @@ -104,7 +105,10 @@ * tools to be defined in extensions or shared library plugins. */ +using Inkscape::ControlManager; + namespace { + SPCanvasGroup *create_control_group(SPDesktop *d); void ink_node_tool_class_init(InkNodeToolClass *klass); void ink_node_tool_init(InkNodeTool *node_context); @@ -120,6 +124,9 @@ void ink_node_tool_selection_changed(InkNodeTool *nt, Inkscape::Selection *sel); void ink_node_tool_select_area(InkNodeTool *nt, Geom::Rect const &, GdkEventButton *); void ink_node_tool_select_point(InkNodeTool *nt, Geom::Point const &, GdkEventButton *); void ink_node_tool_mouseover_changed(InkNodeTool *nt, Inkscape::UI::ControlPoint *p); + +void handleControlUiStyleChange(InkNodeTool *nt); + } // anonymous namespace GType ink_node_tool_get_type() @@ -178,6 +185,7 @@ void ink_node_tool_init(InkNodeTool *nt) new (&nt->_selection_changed_connection) sigc::connection(); new (&nt->_selection_modified_connection) sigc::connection(); new (&nt->_mouseover_changed_connection) sigc::connection(); + new (&nt->_sizeUpdatedConn) sigc::connection(); //new (&nt->_mgroup) Inkscape::UI::ManipulatorGroup(nt->desktop); new (&nt->_selected_nodes) CSelPtr(); new (&nt->_multipath) MultiPathPtr(); @@ -195,6 +203,7 @@ void ink_node_tool_dispose(GObject *object) nt->_selection_changed_connection.disconnect(); nt->_selection_modified_connection.disconnect(); nt->_mouseover_changed_connection.disconnect(); + nt->_sizeUpdatedConn.disconnect(); nt->_multipath.~MultiPathPtr(); nt->_selected_nodes.~CSelPtr(); nt->_selector.~SelectorPtr(); @@ -212,6 +221,7 @@ void ink_node_tool_dispose(GObject *object) nt->_selection_changed_connection.~connection(); nt->_selection_modified_connection.~connection(); nt->_mouseover_changed_connection.~connection(); + nt->_sizeUpdatedConn.~connection(); if (nt->_node_message_context) { delete nt->_node_message_context; @@ -264,6 +274,8 @@ void ink_node_tool_setup(SPEventContext *ec) sigc::bind<0>( sigc::ptr_fun(&ink_node_tool_mouseover_changed), nt)); + + nt->_sizeUpdatedConn = ControlManager::getManager().connectCtrlSizeChanged(sigc::bind(sigc::ptr_fun(&handleControlUiStyleChange), nt)); nt->_selected_nodes.reset( new Inkscape::UI::ControlPointSelection(nt->desktop, nt->_transform_handle_group)); @@ -681,6 +693,11 @@ void ink_node_tool_mouseover_changed(InkNodeTool *nt, Inkscape::UI::ControlPoint } } +void handleControlUiStyleChange(InkNodeTool *nt) +{ + nt->_multipath->updateHandles(); +} + } // anonymous namespace /* diff --git a/src/ui/tool/node-tool.h b/src/ui/tool/node-tool.h index 6f7ab01d4..49b1496d4 100644 --- a/src/ui/tool/node-tool.h +++ b/src/ui/tool/node-tool.h @@ -52,6 +52,7 @@ struct InkNodeTool : public SPEventContext sigc::connection _selection_changed_connection; sigc::connection _mouseover_changed_connection; sigc::connection _selection_modified_connection; + sigc::connection _sizeUpdatedConn; Inkscape::MessageContext *_node_message_context; SPItem *flashed_item; Inkscape::Display::TemporaryItem *flash_tempitem; diff --git a/src/ui/tool/node.cpp b/src/ui/tool/node.cpp index 1a26b5d55..7408e4309 100644 --- a/src/ui/tool/node.cpp +++ b/src/ui/tool/node.cpp @@ -83,7 +83,7 @@ bool Handle::_drag_out = false; Handle::Handle(NodeSharedData const &data, Geom::Point const &initial_pos, Node *parent) : ControlPoint(data.desktop, initial_pos, SP_ANCHOR_CENTER, - SP_CTRL_SHAPE_CIRCLE, 7.0, + CTRL_TYPE_ADJ_HANDLE, _handle_colors, data.handle_group), _parent(parent), _handle_line(ControlManager::getManager().createControlLine(data.handle_line_group)), @@ -627,10 +627,23 @@ void Node::_updateAutoHandles() void Node::showHandles(bool v) { _handles_shown = v; - if (!_front.isDegenerate()) _front.setVisible(v); - if (!_back.isDegenerate()) _back.setVisible(v); + if (!_front.isDegenerate()) { + _front.setVisible(v); + } + if (!_back.isDegenerate()) { + _back.setVisible(v); + } } +void Node::updateHandles() +{ + _handleControlStyling(); + + _front._handleControlStyling(); + _back._handleControlStyling(); +} + + void Node::setType(NodeType type, bool update_handles) { if (type == NODE_PICK_BEST) { @@ -954,28 +967,36 @@ void Node::_setState(State state) { // change node size to match type and selection state switch (_type) { - case NODE_AUTO: - case NODE_CUSP: - if (selected()) _setSize(11); - else _setSize(9); - break; - default: - if(selected()) _setSize(9); - else _setSize(7); - break; + case NODE_AUTO: + case NODE_CUSP: + if (selected()) { + _setSize(11); + } else { + _setSize(9); + } + break; + default: + if (selected()) { + _setSize(9); + } else { + _setSize(7); + } + break; } SelectableControlPoint::_setState(state); } bool Node::grabbed(GdkEventMotion *event) { - if (SelectableControlPoint::grabbed(event)) + if (SelectableControlPoint::grabbed(event)) { return true; + } // Dragging out handles with Shift + drag on a node. - if (!held_shift(*event)) return false; + if (!held_shift(*event)) { + return false; + } - Handle *h; Geom::Point evp = event_point(*event); Geom::Point rel_evp = evp - _last_click_event_point(); @@ -996,8 +1017,11 @@ bool Node::grabbed(GdkEventMotion *event) angle_prev = fabs(Geom::angle_between(rel_evp, prev_relpos)); has_degenerate = true; } - if (!has_degenerate) return false; - h = angle_next < angle_prev ? &_front : &_back; + if (!has_degenerate) { + return false; + } + + Handle *h = angle_next < angle_prev ? &_front : &_back; h->setPosition(_desktop->w2d(evp)); h->setVisible(true); @@ -1283,11 +1307,16 @@ bool Node::_is_line_segment(Node *first, Node *second) SPCtrlShapeType Node::_node_type_to_shape(NodeType type) { switch(type) { - case NODE_CUSP: return SP_CTRL_SHAPE_DIAMOND; - case NODE_SMOOTH: return SP_CTRL_SHAPE_SQUARE; - case NODE_AUTO: return SP_CTRL_SHAPE_CIRCLE; - case NODE_SYMMETRIC: return SP_CTRL_SHAPE_SQUARE; - default: return SP_CTRL_SHAPE_DIAMOND; + case NODE_CUSP: + return SP_CTRL_SHAPE_DIAMOND; + case NODE_SMOOTH: + return SP_CTRL_SHAPE_SQUARE; + case NODE_AUTO: + return SP_CTRL_SHAPE_CIRCLE; + case NODE_SYMMETRIC: + return SP_CTRL_SHAPE_SQUARE; + default: + return SP_CTRL_SHAPE_DIAMOND; } } diff --git a/src/ui/tool/node.h b/src/ui/tool/node.h index daab19cae..084ea1dff 100644 --- a/src/ui/tool/node.h +++ b/src/ui/tool/node.h @@ -166,6 +166,8 @@ public: void showHandles(bool v); + void updateHandles(); + /** * Pick the best type for this node, based on the position of its handles. diff --git a/src/ui/tool/path-manipulator.cpp b/src/ui/tool/path-manipulator.cpp index 97e25069f..e292a9347 100644 --- a/src/ui/tool/path-manipulator.cpp +++ b/src/ui/tool/path-manipulator.cpp @@ -915,6 +915,15 @@ void PathManipulator::setLiveObjects(bool set) _live_objects = set; } +void PathManipulator::updateHandles() +{ + for (SubpathList::iterator i = _subpaths.begin(); i != _subpaths.end(); ++i) { + for (NodeList::iterator j = (*i)->begin(); j != (*i)->end(); ++j) { + j->updateHandles(); + } + } +} + void PathManipulator::setControlsTransform(Geom::Affine const &tnew) { Geom::Affine delta = _i2d_transform.inverse() * _edit_transform.inverse() * tnew * _i2d_transform; diff --git a/src/ui/tool/path-manipulator.h b/src/ui/tool/path-manipulator.h index fe73555c8..a51b8c410 100644 --- a/src/ui/tool/path-manipulator.h +++ b/src/ui/tool/path-manipulator.h @@ -86,6 +86,7 @@ public: void showPathDirection(bool show); void setLiveOutline(bool set); void setLiveObjects(bool set); + void updateHandles(); void setControlsTransform(Geom::Affine const &); void hideDragPoint(); MultiPathManipulator &mpm() { return _multi_path_manipulator; } diff --git a/src/ui/tool/selector.cpp b/src/ui/tool/selector.cpp index 19ffd498a..5122d3c0f 100644 --- a/src/ui/tool/selector.cpp +++ b/src/ui/tool/selector.cpp @@ -35,7 +35,7 @@ class SelectorPoint : public ControlPoint { public: SelectorPoint(SPDesktop *d, SPCanvasGroup *group, Selector *s) : ControlPoint(d, Geom::Point(0,0), SP_ANCHOR_CENTER, - SP_CTRL_SHAPE_SQUARE, 1, + CTRL_TYPE_INVISIPOINT, invisible_cset, group), _selector(s), _cancel(false) diff --git a/src/ui/tool/transform-handle-set.cpp b/src/ui/tool/transform-handle-set.cpp index 0e94cb25e..f0bf149f4 100644 --- a/src/ui/tool/transform-handle-set.cpp +++ b/src/ui/tool/transform-handle-set.cpp @@ -125,7 +125,6 @@ bool TransformHandle::grabbed(GdkEventMotion *) _th._setActiveHandle(this); _setLurking(true); - g_message("Lurk ON for %p", this); _setState(_state); // Collect the snap-candidates, one for each selected node. These will be stored in the _snap_points vector. @@ -176,7 +175,6 @@ void TransformHandle::ungrabbed(GdkEventButton *) _snap_points.clear(); _th._clearActiveHandle(); _setLurking(false); - g_message("Lurk off for %p", this); _setState(_state); endTransform(); _th.signal_commit.emit(getCommitEvent()); |
