diff options
| author | Jabier Arraiza Cenoz <jabier.arraiza@marker.es> | 2013-11-13 00:00:04 +0000 |
|---|---|---|
| committer | Jabiertxof <jtx@jtx.marker.es> | 2013-11-13 00:00:04 +0000 |
| commit | 152a0caf7e216e7ceafeed20822500c385e3e2df (patch) | |
| tree | a3b5d60e08f3bd8221ba2e50eea80b087e5d541a /src/ui/tool | |
| parent | Update to trunk (diff) | |
| parent | fix C++11 compilation. There A LOT of const_casts in this file... :-( (diff) | |
| download | inkscape-152a0caf7e216e7ceafeed20822500c385e3e2df.tar.gz inkscape-152a0caf7e216e7ceafeed20822500c385e3e2df.zip | |
Update to trunk
(bzr r12588.1.26)
Diffstat (limited to 'src/ui/tool')
| -rw-r--r-- | src/ui/tool/Makefile_insert | 2 | ||||
| -rw-r--r-- | src/ui/tool/control-point-selection.cpp | 2 | ||||
| -rw-r--r-- | src/ui/tool/control-point-selection.h | 2 | ||||
| -rw-r--r-- | src/ui/tool/control-point.cpp | 8 | ||||
| -rw-r--r-- | src/ui/tool/control-point.h | 13 | ||||
| -rw-r--r-- | src/ui/tool/curve-drag-point.cpp | 2 | ||||
| -rw-r--r-- | src/ui/tool/curve-drag-point.h | 2 | ||||
| -rw-r--r-- | src/ui/tool/manipulator.h | 6 | ||||
| -rw-r--r-- | src/ui/tool/multi-path-manipulator.cpp | 2 | ||||
| -rw-r--r-- | src/ui/tool/multi-path-manipulator.h | 2 | ||||
| -rw-r--r-- | src/ui/tool/node-tool.cpp | 697 | ||||
| -rw-r--r-- | src/ui/tool/node-tool.h | 97 | ||||
| -rw-r--r-- | src/ui/tool/node.cpp | 4 | ||||
| -rw-r--r-- | src/ui/tool/node.h | 12 | ||||
| -rw-r--r-- | src/ui/tool/path-manipulator.cpp | 2 | ||||
| -rw-r--r-- | src/ui/tool/path-manipulator.h | 2 | ||||
| -rw-r--r-- | src/ui/tool/selector.cpp | 10 | ||||
| -rw-r--r-- | src/ui/tool/selector.h | 2 | ||||
| -rw-r--r-- | src/ui/tool/transform-handle-set.cpp | 6 | ||||
| -rw-r--r-- | src/ui/tool/transform-handle-set.h | 2 |
20 files changed, 48 insertions, 827 deletions
diff --git a/src/ui/tool/Makefile_insert b/src/ui/tool/Makefile_insert index 2a72dd645..f46f48b72 100644 --- a/src/ui/tool/Makefile_insert +++ b/src/ui/tool/Makefile_insert @@ -19,8 +19,6 @@ ink_common_sources += \ ui/tool/node.cpp \ ui/tool/node.h \ ui/tool/node-types.h \ - ui/tool/node-tool.cpp \ - ui/tool/node-tool.h \ ui/tool/path-manipulator.cpp \ ui/tool/path-manipulator.h \ ui/tool/selectable-control-point.cpp \ diff --git a/src/ui/tool/control-point-selection.cpp b/src/ui/tool/control-point-selection.cpp index 1c42c5d90..b5ee0a597 100644 --- a/src/ui/tool/control-point-selection.cpp +++ b/src/ui/tool/control-point-selection.cpp @@ -582,7 +582,7 @@ void ControlPointSelection::_commitHandlesTransform(CommitEvent ce) signal_commit.emit(ce); } -bool ControlPointSelection::event(SPEventContext * /*event_context*/, GdkEvent *event) +bool ControlPointSelection::event(Inkscape::UI::Tools::ToolBase * /*event_context*/, GdkEvent *event) { // implement generic event handling that should apply for all control point selections here; // for example, keyboard moves and transformations. This way this functionality doesn't need diff --git a/src/ui/tool/control-point-selection.h b/src/ui/tool/control-point-selection.h index f5eb47026..a087e0455 100644 --- a/src/ui/tool/control-point-selection.h +++ b/src/ui/tool/control-point-selection.h @@ -90,7 +90,7 @@ public: void invertSelection(); void spatialGrow(SelectableControlPoint *origin, int dir); - virtual bool event(SPEventContext *, GdkEvent *); + virtual bool event(Inkscape::UI::Tools::ToolBase *, GdkEvent *); void transform(Geom::Affine const &m); void align(Geom::Dim2 d); diff --git a/src/ui/tool/control-point.cpp b/src/ui/tool/control-point.cpp index 069dcc67b..e98c7b2a2 100644 --- a/src/ui/tool/control-point.cpp +++ b/src/ui/tool/control-point.cpp @@ -14,7 +14,7 @@ #include "desktop-handles.h" #include "display/sp-canvas.h" #include "display/snap-indicator.h" -#include "event-context.h" +#include "ui/tools/tool-base.h" #include "message-context.h" #include "preferences.h" #include "snap-preferences.h" @@ -218,7 +218,7 @@ int ControlPoint::_event_handler(SPCanvasItem */*item*/, GdkEvent *event, Contro } // main event callback, which emits all other callbacks. -bool ControlPoint::_eventHandler(SPEventContext *event_context, GdkEvent *event) +bool ControlPoint::_eventHandler(Inkscape::UI::Tools::ToolBase *event_context, GdkEvent *event) { // NOTE the static variables below are shared for all points! // TODO handle clicks and drags from other buttons too @@ -310,7 +310,7 @@ bool ControlPoint::_eventHandler(SPEventContext *event_context, GdkEvent *event) _desktop->set_coordinate_status(_position); sp_event_context_snap_delay_handler(event_context, NULL, (gpointer) this, &event->motion, - DelayedSnapEvent::CONTROL_POINT_HANDLER); + Inkscape::UI::Tools::DelayedSnapEvent::CONTROL_POINT_HANDLER); } return true; } @@ -375,7 +375,7 @@ bool ControlPoint::_eventHandler(SPEventContext *event_context, GdkEvent *event) // update tips on modifier state change // TODO add ESC keybinding as drag cancel case GDK_KEY_PRESS: - switch (get_group0_keyval(&event->key)) + switch (Inkscape::UI::Tools::get_group0_keyval(&event->key)) { case GDK_KEY_Escape: { // ignore Escape if this is not a drag diff --git a/src/ui/tool/control-point.h b/src/ui/tool/control-point.h index 30efe8a27..b3ed9545e 100644 --- a/src/ui/tool/control-point.h +++ b/src/ui/tool/control-point.h @@ -23,7 +23,16 @@ #include "enums.h" class SPDesktop; -class SPEventContext; + +namespace Inkscape { +namespace UI { +namespace Tools { + +class ToolBase; + +} +} +} namespace Inkscape { namespace UI { @@ -181,7 +190,7 @@ public: static Glib::ustring format_tip(char const *format, ...) G_GNUC_PRINTF(1,2); // temporarily public, until snap delay is refactored a little - virtual bool _eventHandler(SPEventContext *event_context, GdkEvent *event); + virtual bool _eventHandler(Inkscape::UI::Tools::ToolBase *event_context, GdkEvent *event); SPDesktop *const _desktop; ///< The desktop this control point resides on. protected: diff --git a/src/ui/tool/curve-drag-point.cpp b/src/ui/tool/curve-drag-point.cpp index b83ce1b3c..4ca736f80 100644 --- a/src/ui/tool/curve-drag-point.cpp +++ b/src/ui/tool/curve-drag-point.cpp @@ -32,7 +32,7 @@ CurveDragPoint::CurveDragPoint(PathManipulator &pm) : setVisible(false); } -bool CurveDragPoint::_eventHandler(SPEventContext *event_context, GdkEvent *event) +bool CurveDragPoint::_eventHandler(Inkscape::UI::Tools::ToolBase *event_context, GdkEvent *event) { // do not process any events when the manipulator is empty if (_pm.empty()) { diff --git a/src/ui/tool/curve-drag-point.h b/src/ui/tool/curve-drag-point.h index 73e4cd969..ea83978e0 100644 --- a/src/ui/tool/curve-drag-point.h +++ b/src/ui/tool/curve-drag-point.h @@ -35,7 +35,7 @@ public: void setSize(double sz) { _setSize(sz); } void setTimeValue(double t) { _t = t; } void setIterator(NodeList::iterator i) { first = i; } - virtual bool _eventHandler(SPEventContext *event_context, GdkEvent *event); + virtual bool _eventHandler(Inkscape::UI::Tools::ToolBase *event_context, GdkEvent *event); protected: diff --git a/src/ui/tool/manipulator.h b/src/ui/tool/manipulator.h index ffed370d3..07e01a656 100644 --- a/src/ui/tool/manipulator.h +++ b/src/ui/tool/manipulator.h @@ -18,7 +18,7 @@ #include <glib.h> #include <gdk/gdk.h> #include <boost/shared_ptr.hpp> -#include "event-context.h" +#include "ui/tools/tool-base.h" class SPDesktop; namespace Inkscape { @@ -40,7 +40,7 @@ public: virtual ~Manipulator() {} /// Handle input event. Returns true if handled. - virtual bool event(SPEventContext *, GdkEvent *)=0; + virtual bool event(Inkscape::UI::Tools::ToolBase *, GdkEvent *)=0; SPDesktop *const _desktop; }; @@ -145,7 +145,7 @@ public: } } - virtual bool event(SPEventContext *event_context, GdkEvent *event) { + virtual bool event(Inkscape::UI::Tools::ToolBase *event_context, GdkEvent *event) { for (typename MapType::iterator i = _mmap.begin(); i != _mmap.end(); ++i) { if ((*i).second->event(event_context, event)) return true; } diff --git a/src/ui/tool/multi-path-manipulator.cpp b/src/ui/tool/multi-path-manipulator.cpp index 5d5ea2adc..519c4ac6a 100644 --- a/src/ui/tool/multi-path-manipulator.cpp +++ b/src/ui/tool/multi-path-manipulator.cpp @@ -557,7 +557,7 @@ void MultiPathManipulator::updateHandles() invokeForAll(&PathManipulator::updateHandles); } -bool MultiPathManipulator::event(SPEventContext *event_context, GdkEvent *event) +bool MultiPathManipulator::event(Inkscape::UI::Tools::ToolBase *event_context, GdkEvent *event) { _tracker.event(event); guint key = 0; diff --git a/src/ui/tool/multi-path-manipulator.h b/src/ui/tool/multi-path-manipulator.h index 54a9b5753..1328372c6 100644 --- a/src/ui/tool/multi-path-manipulator.h +++ b/src/ui/tool/multi-path-manipulator.h @@ -36,7 +36,7 @@ class MultiPathManipulator : public PointManipulator { public: MultiPathManipulator(PathSharedData &data, sigc::connection &chg); virtual ~MultiPathManipulator(); - virtual bool event(SPEventContext *, GdkEvent *event); + virtual bool event(Inkscape::UI::Tools::ToolBase *, GdkEvent *event); bool empty() { return _mmap.empty(); } unsigned size() { return _mmap.empty(); } diff --git a/src/ui/tool/node-tool.cpp b/src/ui/tool/node-tool.cpp deleted file mode 100644 index 76e33e506..000000000 --- a/src/ui/tool/node-tool.cpp +++ /dev/null @@ -1,697 +0,0 @@ -/** - * @file - * New node tool - implementation. - */ -/* Authors: - * Krzysztof Kosiński <tweenk@gmail.com> - * Abhishek Sharma - * - * Copyright (C) 2009 Authors - * Released under GNU GPL, read the file 'COPYING' for more information - */ - -#include "curve-drag-point.h" -#include <glib/gi18n.h> -#include "desktop.h" -#include "desktop-handles.h" -#include "display/sp-canvas-group.h" -#include "display/canvas-bpath.h" -#include "display/curve.h" -#include "display/sp-canvas.h" -#include "document.h" -#include "live_effects/lpeobject.h" -#include "message-context.h" -#include "selection.h" -#include "shape-editor.h" // temporary! -#include "sp-clippath.h" -#include "sp-item-group.h" -#include "sp-mask.h" -#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" -#include "ui/tool/manipulator.h" -#include "ui/tool/multi-path-manipulator.h" -#include "ui/tool/path-manipulator.h" -#include "ui/tool/selector.h" -#include "ui/tool/shape-record.h" - -#include "pixmaps/cursor-node.xpm" -#include "pixmaps/cursor-node-d.xpm" -#include "selection-chemistry.h" - -#include <gdk/gdkkeysyms.h> - -/** @struct InkNodeTool - * - * Node tool event context. - * - * @par Architectural overview of the tool - * @par - * Here's a breakdown of what each object does. - * - Handle: shows a handle and keeps the node type constraint (smooth / symmetric) by updating - * the other handle's position when dragged. Its move() method cannot violate the constraints. - * - Node: keeps node type constraints for auto nodes and smooth nodes at ends of linear segments. - * Its move() method cannot violate constraints. Handles linear grow and dispatches spatial grow - * to MultiPathManipulator. Keeps a reference to its NodeList. - * - NodeList: exposes an iterator-based interface to nodes. It is possible to obtain an iterator - * to a node from the node. Keeps a reference to its SubpathList. - * - SubpathList: list of NodeLists that represents an editable pathvector. Keeps a reference - * to its PathManipulator. - * - PathManipulator: performs most of the single-path actions like reverse subpaths, - * delete segment, shift selection, etc. Keeps a reference to MultiPathManipulator. - * - MultiPathManipulator: performs additional operations for actions that are not per-path, - * for example node joins and segment joins. Tracks the control transforms for PMs that edit - * clipping paths and masks. It is more or less equivalent to ShapeEditor and in the future - * it might handle all shapes. Handles XML commit of actions that affect all paths or - * the node selection and removes PathManipulators that have no nodes left after e.g. node - * deletes. - * - ControlPointSelection: keeps track of node selection and a set of nodes that can potentially - * be selected. There can be more than one selection. Performs actions that require no - * knowledge about the path, only about the nodes, like dragging and transforms. It is not - * specific to nodes and can accomodate any control point derived from SelectableControlPoint. - * Transforms nodes in response to transform handle events. - * - TransformHandleSet: displays nodeset transform handles and emits transform events. The aim - * is to eventually use a common class for object and control point transforms. - * - SelectableControlPoint: base for any type of selectable point. It can belong to only one - * selection. - * - * @par Functionality that resides in weird places - * @par - * - * This list is probably incomplete. - * - Curve dragging: CurveDragPoint, controlled by PathManipulator - * - Single handle shortcuts: MultiPathManipulator::event(), ModifierTracker - * - Linear and spatial grow: Node, spatial grow routed to ControlPointSelection - * - Committing handle actions performed with the mouse: PathManipulator - * - Sculpting: ControlPointSelection - * - * @par Plans for the future - * @par - * - MultiPathManipulator should become a generic shape editor that manages all active manipulator, - * more or less like the old ShapeEditor. - * - Knotholder should be rewritten into one manipulator class per shape, using the control point - * classes. Interesting features like dragging rectangle sides could be added along the way. - * - Better handling of clip and mask editing, particularly in response to undo. - * - High level refactoring of the event context hierarchy. All aspects of tools, like toolbox - * controls, icons, event handling should be collected in one class, though each aspect - * of a tool might be in an separate class for better modularity. The long term goal is to allow - * tools to be defined in extensions or shared library plugins. - */ - -using Inkscape::ControlManager; - -SPCanvasGroup *create_control_group(SPDesktop *d); - -#include "tool-factory.h" - -namespace { - SPEventContext* createNodesContext() { - return new InkNodeTool(); - } - - bool nodesContextRegistered = ToolFactory::instance().registerObject("/tools/nodes", createNodesContext); -} - -const std::string& InkNodeTool::getPrefsPath() { - return InkNodeTool::prefsPath; -} - -const std::string InkNodeTool::prefsPath = "/tools/nodes"; - -InkNodeTool::InkNodeTool() : SPEventContext() { - this->show_handles = false; - this->single_node_transform_handles = false; - this->show_transform_handles = false; - this->cursor_drag = false; - this->live_objects = false; - this->edit_clipping_paths = false; - this->live_outline = false; - this->flashed_item = 0; - this->_transform_handle_group = 0; - this->show_path_direction = false; - this->_last_over = 0; - this->edit_masks = false; - this->show_outline = false; - this->flash_tempitem = 0; - - this->cursor_shape = cursor_node_xpm; - this->hot_x = 1; - this->hot_y = 1; - - this->_selected_nodes = 0; - this->_multipath = 0; - this->_selector = 0; - this->_path_data = 0; -} - -SPCanvasGroup *create_control_group(SPDesktop *d) -{ - return reinterpret_cast<SPCanvasGroup*>(sp_canvas_item_new( - sp_desktop_controls(d), SP_TYPE_CANVAS_GROUP, NULL)); -} - -void destroy_group(SPCanvasGroup *g) -{ - sp_canvas_item_destroy(SP_CANVAS_ITEM(g)); -} - -InkNodeTool::~InkNodeTool() { - this->enableGrDrag(false); - - if (this->flash_tempitem) { - this->desktop->remove_temporary_canvasitem(this->flash_tempitem); - } - - this->_selection_changed_connection.disconnect(); - //this->_selection_modified_connection.disconnect(); - this->_mouseover_changed_connection.disconnect(); - this->_sizeUpdatedConn.disconnect(); - - delete this->_multipath; - delete this->_selected_nodes; - delete this->_selector; - - Inkscape::UI::PathSharedData &data = *this->_path_data; - destroy_group(data.node_data.node_group); - destroy_group(data.node_data.handle_group); - destroy_group(data.node_data.handle_line_group); - destroy_group(data.outline_group); - destroy_group(data.dragpoint_group); - destroy_group(this->_transform_handle_group); -} - -void InkNodeTool::setup() { - SPEventContext::setup(); - - this->_path_data = new Inkscape::UI::PathSharedData(); - - Inkscape::UI::PathSharedData &data = *this->_path_data; - data.node_data.desktop = this->desktop; - - // selector has to be created here, so that its hidden control point is on the bottom - this->_selector = new Inkscape::UI::Selector(this->desktop); - - // Prepare canvas groups for controls. This guarantees correct z-order, so that - // for example a dragpoint won't obscure a node - data.outline_group = create_control_group(this->desktop); - data.node_data.handle_line_group = create_control_group(this->desktop); - data.dragpoint_group = create_control_group(this->desktop); - this->_transform_handle_group = create_control_group(this->desktop); - data.node_data.node_group = create_control_group(this->desktop); - data.node_data.handle_group = create_control_group(this->desktop); - - Inkscape::Selection *selection = sp_desktop_selection (this->desktop); - - this->_selection_changed_connection.disconnect(); - this->_selection_changed_connection = - selection->connectChanged(sigc::mem_fun(this, &InkNodeTool::selection_changed)); - - this->_mouseover_changed_connection.disconnect(); - this->_mouseover_changed_connection = - Inkscape::UI::ControlPoint::signal_mouseover_change.connect(sigc::mem_fun(this, &InkNodeTool::mouseover_changed)); - - this->_sizeUpdatedConn = ControlManager::getManager().connectCtrlSizeChanged( - sigc::mem_fun(this, &InkNodeTool::handleControlUiStyleChange) - ); - - this->_selected_nodes = new Inkscape::UI::ControlPointSelection(this->desktop, this->_transform_handle_group); - - data.node_data.selection = this->_selected_nodes; - - this->_multipath = new Inkscape::UI::MultiPathManipulator(data, this->_selection_changed_connection); - - this->_selector->signal_point.connect(sigc::mem_fun(this, &InkNodeTool::select_point)); - this->_selector->signal_area.connect(sigc::mem_fun(this, &InkNodeTool::select_area)); - - this->_multipath->signal_coords_changed.connect( - sigc::bind( - sigc::mem_fun(*this->desktop, &SPDesktop::emitToolSubselectionChanged), - (void*)NULL - ) - ); - - this->_selected_nodes->signal_point_changed.connect( - // Hide both signal parameters and bind the function parameter to 0 - // sigc::signal<void, SelectableControlPoint *, bool> - // <=> - // void update_tip(GdkEvent *event) - sigc::hide(sigc::hide(sigc::bind( - sigc::mem_fun(this, &InkNodeTool::update_tip), - (GdkEvent*)NULL - ))) - ); - - this->cursor_drag = false; - this->show_transform_handles = true; - this->single_node_transform_handles = false; - this->flash_tempitem = NULL; - this->flashed_item = NULL; - this->_last_over = NULL; - - // read prefs before adding items to selection to prevent momentarily showing the outline - sp_event_context_read(this, "show_handles"); - sp_event_context_read(this, "show_outline"); - sp_event_context_read(this, "live_outline"); - sp_event_context_read(this, "live_objects"); - sp_event_context_read(this, "show_path_direction"); - sp_event_context_read(this, "show_transform_handles"); - sp_event_context_read(this, "single_node_transform_handles"); - sp_event_context_read(this, "edit_clipping_paths"); - sp_event_context_read(this, "edit_masks"); - - this->selection_changed(selection); - this->update_tip(NULL); - - Inkscape::Preferences *prefs = Inkscape::Preferences::get(); - - if (prefs->getBool("/tools/nodes/selcue")) { - this->enableSelectionCue(); - } - - if (prefs->getBool("/tools/nodes/gradientdrag")) { - this->enableGrDrag(); - } - - this->desktop->emitToolSubselectionChanged(NULL); // sets the coord entry fields to inactive -} - -void InkNodeTool::set(const Inkscape::Preferences::Entry& value) { - Glib::ustring entry_name = value.getEntryName(); - - if (entry_name == "show_handles") { - this->show_handles = value.getBool(true); - this->_multipath->showHandles(this->show_handles); - } else if (entry_name == "show_outline") { - this->show_outline = value.getBool(); - this->_multipath->showOutline(this->show_outline); - } else if (entry_name == "live_outline") { - this->live_outline = value.getBool(); - this->_multipath->setLiveOutline(this->live_outline); - } else if (entry_name == "live_objects") { - this->live_objects = value.getBool(); - this->_multipath->setLiveObjects(this->live_objects); - } else if (entry_name == "show_path_direction") { - this->show_path_direction = value.getBool(); - this->_multipath->showPathDirection(this->show_path_direction); - } else if (entry_name == "show_transform_handles") { - this->show_transform_handles = value.getBool(true); - this->_selected_nodes->showTransformHandles( - this->show_transform_handles, this->single_node_transform_handles); - } else if (entry_name == "single_node_transform_handles") { - this->single_node_transform_handles = value.getBool(); - this->_selected_nodes->showTransformHandles( - this->show_transform_handles, this->single_node_transform_handles); - } else if (entry_name == "edit_clipping_paths") { - this->edit_clipping_paths = value.getBool(); - this->selection_changed(this->desktop->selection); - } else if (entry_name == "edit_masks") { - this->edit_masks = value.getBool(); - this->selection_changed(this->desktop->selection); - } else { - SPEventContext::set(value); - } -} - -/** Recursively collect ShapeRecords */ -void gather_items(InkNodeTool *nt, SPItem *base, SPObject *obj, Inkscape::UI::ShapeRole role, - std::set<Inkscape::UI::ShapeRecord> &s) -{ - using namespace Inkscape::UI; - - if (!obj) { - return; - } - - //XML Tree being used directly here while it shouldn't be. - if (SP_IS_PATH(obj) && obj->getRepr()->attribute("inkscape:original-d") != NULL) { - ShapeRecord r; - r.item = static_cast<SPItem*>(obj); - r.edit_transform = Geom::identity(); // TODO wrong? - r.role = role; - s.insert(r); - } else if (role != SHAPE_ROLE_NORMAL && (SP_IS_GROUP(obj) || SP_IS_OBJECTGROUP(obj))) { - for (SPObject *c = obj->children; c; c = c->next) { - gather_items(nt, base, c, role, s); - } - } else if (SP_IS_ITEM(obj)) { - SPItem *item = static_cast<SPItem*>(obj); - ShapeRecord r; - r.item = item; - // TODO add support for objectBoundingBox - r.edit_transform = base ? base->i2doc_affine() : Geom::identity(); - r.role = role; - - if (s.insert(r).second) { - // this item was encountered the first time - if (nt->edit_clipping_paths && item->clip_ref) { - gather_items(nt, item, item->clip_ref->getObject(), SHAPE_ROLE_CLIPPING_PATH, s); - } - - if (nt->edit_masks && item->mask_ref) { - gather_items(nt, item, item->mask_ref->getObject(), SHAPE_ROLE_MASK, s); - } - } - } -} - -void InkNodeTool::selection_changed(Inkscape::Selection *sel) { - using namespace Inkscape::UI; - - std::set<ShapeRecord> shapes; - - GSList const *ilist = sel->itemList(); - - for (GSList *i = const_cast<GSList*>(ilist); i; i = i->next) { - SPObject *obj = static_cast<SPObject*>(i->data); - - if (SP_IS_ITEM(obj)) { - gather_items(this, NULL, static_cast<SPItem*>(obj), SHAPE_ROLE_NORMAL, shapes); - } - } - - // use multiple ShapeEditors for now, to allow editing many shapes at once - // needs to be rethought - for (boost::ptr_map<SPItem*, ShapeEditor>::iterator i = this->_shape_editors.begin(); - i != this->_shape_editors.end(); ) - { - ShapeRecord s; - s.item = i->first; - - if (shapes.find(s) == shapes.end()) { - this->_shape_editors.erase(i++); - } else { - ++i; - } - } - - for (std::set<ShapeRecord>::iterator i = shapes.begin(); i != shapes.end(); ++i) { - ShapeRecord const &r = *i; - - if ((SP_IS_SHAPE(r.item) || SP_IS_TEXT(r.item)) && - this->_shape_editors.find(r.item) == this->_shape_editors.end()) - { - ShapeEditor *si = new ShapeEditor(this->desktop); - si->set_item(r.item, SH_KNOTHOLDER); - this->_shape_editors.insert(const_cast<SPItem*&>(r.item), si); - } - } - - this->_multipath->setItems(shapes); - this->update_tip(NULL); - this->desktop->updateNow(); -} - -bool InkNodeTool::root_handler(GdkEvent* event) { - /* things to handle here: - * 1. selection of items - * 2. passing events to manipulators - * 3. some keybindings - */ - using namespace Inkscape::UI; // pull in event helpers - - Inkscape::Selection *selection = desktop->selection; - static Inkscape::Preferences *prefs = Inkscape::Preferences::get(); - - if (this->_multipath->event(this, event)) { - return true; - } - - if (this->_selector->event(this, event)) { - return true; - } - - if (this->_selected_nodes->event(this, event)) { - return true; - } - - switch (event->type) - { - case GDK_MOTION_NOTIFY: { - combine_motion_events(desktop->canvas, event->motion, 0); - SPItem *over_item = sp_event_context_find_item (desktop, event_point(event->button), - FALSE, TRUE); - - if (over_item != this->_last_over) { - this->_last_over = over_item; - //ink_node_tool_update_tip(nt, event); - this->update_tip(event); - } - - // create pathflash outline - if (prefs->getBool("/tools/nodes/pathflash_enabled")) { - if (over_item == this->flashed_item) { - break; - } - - if (!prefs->getBool("/tools/nodes/pathflash_selected") && selection->includes(over_item)) { - break; - } - - if (this->flash_tempitem) { - desktop->remove_temporary_canvasitem(this->flash_tempitem); - this->flash_tempitem = NULL; - this->flashed_item = NULL; - } - - if (!SP_IS_SHAPE(over_item)) { - break; // for now, handle only shapes - } - - this->flashed_item = over_item; - SPCurve *c = SP_SHAPE(over_item)->getCurveBeforeLPE(); - - if (!c) { - break; // break out when curve doesn't exist - } - - c->transform(over_item->i2dt_affine()); - SPCanvasItem *flash = sp_canvas_bpath_new(sp_desktop_tempgroup(desktop), c); - - sp_canvas_bpath_set_stroke(SP_CANVAS_BPATH(flash), - prefs->getInt("/tools/nodes/highlight_color", 0xff0000ff), 1.0, - SP_STROKE_LINEJOIN_MITER, SP_STROKE_LINECAP_BUTT); - - sp_canvas_bpath_set_fill(SP_CANVAS_BPATH(flash), 0, SP_WIND_RULE_NONZERO); - - this->flash_tempitem = desktop->add_temporary_canvasitem(flash, - prefs->getInt("/tools/nodes/pathflash_timeout", 500)); - - c->unref(); - } - } break; // do not return true, because we need to pass this event to the parent context - // otherwise some features cease to work - - case GDK_KEY_PRESS: - switch (get_group0_keyval(&event->key)) - { - case GDK_KEY_Escape: // deselect everything - if (this->_selected_nodes->empty()) { - Inkscape::SelectionHelper::selectNone(desktop); - } else { - this->_selected_nodes->clear(); - } - //ink_node_tool_update_tip(nt, event); - this->update_tip(event); - return TRUE; - - case GDK_KEY_a: - case GDK_KEY_A: - if (held_control(event->key) && held_alt(event->key)) { - this->_selected_nodes->selectAll(); - // Ctrl+A is handled in selection-chemistry.cpp via verb - //ink_node_tool_update_tip(nt, event); - this->update_tip(event); - return TRUE; - } - break; - - case GDK_KEY_h: - case GDK_KEY_H: - if (held_only_control(event->key)) { - Inkscape::Preferences *prefs = Inkscape::Preferences::get(); - prefs->setBool("/tools/nodes/show_handles", !this->show_handles); - return TRUE; - } - break; - - default: - break; - } - //ink_node_tool_update_tip(nt, event); - this->update_tip(event); - break; - - case GDK_KEY_RELEASE: - //ink_node_tool_update_tip(nt, event); - this->update_tip(event); - break; - - default: - break; - } - - return SPEventContext::root_handler(event); -} - -void InkNodeTool::update_tip(GdkEvent *event) { - using namespace Inkscape::UI; - - if (event && (event->type == GDK_KEY_PRESS || event->type == GDK_KEY_RELEASE)) { - unsigned new_state = state_after_event(event); - - if (new_state == event->key.state) { - return; - } - - if (state_held_shift(new_state)) { - if (this->_last_over) { - this->message_context->set(Inkscape::NORMAL_MESSAGE, - C_("Node tool tip", "<b>Shift</b>: drag to add nodes to the selection, " - "click to toggle object selection")); - } else { - this->message_context->set(Inkscape::NORMAL_MESSAGE, - C_("Node tool tip", "<b>Shift</b>: drag to add nodes to the selection")); - } - - return; - } - } - - unsigned sz = this->_selected_nodes->size(); - unsigned total = this->_selected_nodes->allPoints().size(); - - if (sz != 0) { - char *nodestring = g_strdup_printf( - ngettext("<b>%u of %u</b> node selected.", "<b>%u of %u</b> nodes selected.", total), - sz, total); - - if (this->_last_over) { - // TRANSLATORS: The %s below is where the "%u of %u nodes selected" sentence gets put - char *dyntip = g_strdup_printf(C_("Node tool tip", - "%s Drag to select nodes, click to edit only this object (more: Shift)"), - nodestring); - this->message_context->set(Inkscape::NORMAL_MESSAGE, dyntip); - g_free(dyntip); - } else { - char *dyntip = g_strdup_printf(C_("Node tool tip", - "%s Drag to select nodes, click clear the selection"), - nodestring); - this->message_context->set(Inkscape::NORMAL_MESSAGE, dyntip); - g_free(dyntip); - } - g_free(nodestring); - } else if (!this->_multipath->empty()) { - if (this->_last_over) { - this->message_context->set(Inkscape::NORMAL_MESSAGE, C_("Node tool tip", - "Drag to select nodes, click to edit only this object")); - } else { - this->message_context->set(Inkscape::NORMAL_MESSAGE, C_("Node tool tip", - "Drag to select nodes, click to clear the selection")); - } - } else { - if (this->_last_over) { - this->message_context->set(Inkscape::NORMAL_MESSAGE, C_("Node tool tip", - "Drag to select objects to edit, click to edit this object (more: Shift)")); - } else { - this->message_context->set(Inkscape::NORMAL_MESSAGE, C_("Node tool tip", - "Drag to select objects to edit")); - } - } -} - -void InkNodeTool::select_area(Geom::Rect const &sel, GdkEventButton *event) { - using namespace Inkscape::UI; - - if (this->_multipath->empty()) { - // if multipath is empty, select rubberbanded items rather than nodes - Inkscape::Selection *selection = this->desktop->selection; - GSList *items = sp_desktop_document(this->desktop)->getItemsInBox(this->desktop->dkey, sel); - selection->setList(items); - g_slist_free(items); - } else { - if (!held_shift(*event)) { - this->_selected_nodes->clear(); - } - - this->_selected_nodes->selectArea(sel); - } -} - -void InkNodeTool::select_point(Geom::Point const &sel, GdkEventButton *event) { - using namespace Inkscape::UI; // pull in event helpers - - if (!event) { - return; - } - - if (event->button != 1) { - return; - } - - Inkscape::Selection *selection = this->desktop->selection; - - SPItem *item_clicked = sp_event_context_find_item (this->desktop, event_point(*event), - (event->state & GDK_MOD1_MASK) && !(event->state & GDK_CONTROL_MASK), TRUE); - - if (item_clicked == NULL) { // nothing under cursor - // if no Shift, deselect - // if there are nodes selected, the first click should deselect the nodes - // and the second should deselect the items - if (!state_held_shift(event->state)) { - if (this->_selected_nodes->empty()) { - selection->clear(); - } else { - this->_selected_nodes->clear(); - } - } - } else { - if (held_shift(*event)) { - selection->toggle(item_clicked); - } else { - selection->set(item_clicked); - } - - this->desktop->updateNow(); - } -} - -void InkNodeTool::mouseover_changed(Inkscape::UI::ControlPoint *p) { - using Inkscape::UI::CurveDragPoint; - - CurveDragPoint *cdp = dynamic_cast<CurveDragPoint*>(p); - - if (cdp && !this->cursor_drag) { - this->cursor_shape = cursor_node_d_xpm; - this->hot_x = 1; - this->hot_y = 1; - this->sp_event_context_update_cursor(); - this->cursor_drag = true; - } else if (!cdp && this->cursor_drag) { - this->cursor_shape = cursor_node_xpm; - this->hot_x = 1; - this->hot_y = 1; - this->sp_event_context_update_cursor(); - this->cursor_drag = false; - } -} - -void InkNodeTool::handleControlUiStyleChange() { - this->_multipath->updateHandles(); -} - -//} // anonymous namespace - -/* - Local Variables: - mode:c++ - c-file-style:"stroustrup" - c-file-offsets:((innamespace . 0)(inline-open . 0)(case-label . +)) - indent-tabs-mode:nil - fill-column:99 - End: -*/ -// vim: filetype=cpp:expandtab:shiftwidth=4:tabstop=8:softtabstop=4:fileencoding=utf-8:textwidth=99 : diff --git a/src/ui/tool/node-tool.h b/src/ui/tool/node-tool.h deleted file mode 100644 index c41f50650..000000000 --- a/src/ui/tool/node-tool.h +++ /dev/null @@ -1,97 +0,0 @@ -/** @file - * @brief New node tool with support for multiple path editing - */ -/* Authors: - * Krzysztof Kosiński <tweenk@gmail.com> - * - * Copyright (C) 2009 Authors - * Released under GNU GPL, read the file 'COPYING' for more information - */ - -#ifndef SEEN_UI_TOOL_NODE_TOOL_H -#define SEEN_UI_TOOL_NODE_TOOL_H - -#include <boost/ptr_container/ptr_map.hpp> -#include <glib.h> -#include "event-context.h" - -namespace Inkscape { - namespace Display { - class TemporaryItem; - } - - namespace UI { - class MultiPathManipulator; - class ControlPointSelection; - class Selector; - class ControlPoint; - - struct PathSharedData; - } -} - -#define INK_NODE_TOOL(obj) (dynamic_cast<InkNodeTool*>((SPEventContext*)obj)) -#define INK_IS_NODE_TOOL(obj) (dynamic_cast<const InkNodeTool*>((const SPEventContext*)obj)) - -class InkNodeTool : public SPEventContext { -public: - InkNodeTool(); - virtual ~InkNodeTool(); - - Inkscape::UI::ControlPointSelection* _selected_nodes; - Inkscape::UI::MultiPathManipulator* _multipath; - - bool edit_clipping_paths; - bool edit_masks; - - static const std::string prefsPath; - - virtual void setup(); - virtual void set(const Inkscape::Preferences::Entry& val); - virtual bool root_handler(GdkEvent* event); - - virtual const std::string& getPrefsPath(); - -private: - sigc::connection _selection_changed_connection; - sigc::connection _mouseover_changed_connection; - sigc::connection _sizeUpdatedConn; - - SPItem *flashed_item; - Inkscape::Display::TemporaryItem *flash_tempitem; - Inkscape::UI::Selector* _selector; - Inkscape::UI::PathSharedData* _path_data; - SPCanvasGroup *_transform_handle_group; - SPItem *_last_over; - boost::ptr_map<SPItem*, ShapeEditor> _shape_editors; - - bool cursor_drag; - bool show_handles; - bool show_outline; - bool live_outline; - bool live_objects; - bool show_path_direction; - bool show_transform_handles; - bool single_node_transform_handles; - - void selection_changed(Inkscape::Selection *sel); - - void select_area(Geom::Rect const &sel, GdkEventButton *event); - void select_point(Geom::Point const &sel, GdkEventButton *event); - void mouseover_changed(Inkscape::UI::ControlPoint *p); - void update_tip(GdkEvent *event); - void handleControlUiStyleChange(); -}; - -#endif - -/* - Local Variables: - mode:c++ - c-file-style:"stroustrup" - c-file-offsets:((innamespace . 0)(inline-open . 0)(case-label . +)) - indent-tabs-mode:nil - fill-column:99 - End: -*/ -// vim: filetype=cpp:expandtab:shiftwidth=4:tabstop=8:softtabstop=4:fileencoding=utf-8:textwidth=99 : diff --git a/src/ui/tool/node.cpp b/src/ui/tool/node.cpp index 76ec68c3e..e246bf997 100644 --- a/src/ui/tool/node.cpp +++ b/src/ui/tool/node.cpp @@ -250,7 +250,7 @@ char const *Handle::handle_type_to_localized_string(NodeType type) } } -bool Handle::_eventHandler(SPEventContext *event_context, GdkEvent *event) +bool Handle::_eventHandler(Inkscape::UI::Tools::ToolBase *event_context, GdkEvent *event) { switch (event->type) { @@ -834,7 +834,7 @@ NodeType Node::parse_nodetype(char x) } } -bool Node::_eventHandler(SPEventContext *event_context, GdkEvent *event) +bool Node::_eventHandler(Inkscape::UI::Tools::ToolBase *event_context, GdkEvent *event) { int dir = 0; diff --git a/src/ui/tool/node.h b/src/ui/tool/node.h index 591dd8532..b874949f5 100644 --- a/src/ui/tool/node.h +++ b/src/ui/tool/node.h @@ -16,7 +16,13 @@ #include <iosfwd> #include <stdexcept> #include <cstddef> + +#if __cplusplus >= 201103L +#include <functional> +#else #include <tr1/functional> +#endif + #include <boost/enable_shared_from_this.hpp> #include <boost/shared_ptr.hpp> #include "ui/tool/selectable-control-point.h" @@ -31,11 +37,13 @@ template <typename> class NodeIterator; } } +#if __cplusplus < 201103L namespace std { namespace tr1 { template <typename N> struct hash< Inkscape::UI::NodeIterator<N> >; } } +#endif namespace Inkscape { namespace UI { @@ -106,7 +114,7 @@ protected: Handle(NodeSharedData const &data, Geom::Point const &initial_pos, Node *parent); - virtual bool _eventHandler(SPEventContext *event_context, GdkEvent *event); + 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); @@ -217,7 +225,7 @@ public: // temporarily public /** Customized event handler to catch scroll events needed for selection grow/shrink. */ - virtual bool _eventHandler(SPEventContext *event_context, GdkEvent *event); + virtual bool _eventHandler(Inkscape::UI::Tools::ToolBase *event_context, GdkEvent *event); Inkscape::SnapCandidatePoint snapCandidatePoint(); diff --git a/src/ui/tool/path-manipulator.cpp b/src/ui/tool/path-manipulator.cpp index d12e2958b..ec58e2141 100644 --- a/src/ui/tool/path-manipulator.cpp +++ b/src/ui/tool/path-manipulator.cpp @@ -157,7 +157,7 @@ PathManipulator::~PathManipulator() } /** Handle motion events to update the position of the curve drag point. */ -bool PathManipulator::event(SPEventContext * /*event_context*/, GdkEvent *event) +bool PathManipulator::event(Inkscape::UI::Tools::ToolBase * /*event_context*/, GdkEvent *event) { if (empty()) return false; diff --git a/src/ui/tool/path-manipulator.h b/src/ui/tool/path-manipulator.h index e01e8617f..7a13ce723 100644 --- a/src/ui/tool/path-manipulator.h +++ b/src/ui/tool/path-manipulator.h @@ -56,7 +56,7 @@ public: PathManipulator(MultiPathManipulator &mpm, SPPath *path, Geom::Affine const &edit_trans, guint32 outline_color, Glib::ustring lpe_key); ~PathManipulator(); - virtual bool event(SPEventContext *, GdkEvent *); + virtual bool event(Inkscape::UI::Tools::ToolBase *, GdkEvent *); bool empty(); void writeXML(); diff --git a/src/ui/tool/selector.cpp b/src/ui/tool/selector.cpp index 2b3ba837c..bdeacadc9 100644 --- a/src/ui/tool/selector.cpp +++ b/src/ui/tool/selector.cpp @@ -13,7 +13,7 @@ #include "desktop.h" #include "desktop-handles.h" #include "display/sodipodi-ctrlrect.h" -#include "event-context.h" +#include "ui/tools/tool-base.h" #include "preferences.h" #include "ui/tool/event-utils.h" #include "ui/tool/selector.h" @@ -48,12 +48,12 @@ public: SPDesktop *desktop() { return _desktop; } - bool event(SPEventContext *ec, GdkEvent *e) { + bool event(Inkscape::UI::Tools::ToolBase *ec, GdkEvent *e) { return _eventHandler(ec, e); } protected: - virtual bool _eventHandler(SPEventContext *event_context, GdkEvent *event) { + virtual bool _eventHandler(Inkscape::UI::Tools::ToolBase *event_context, GdkEvent *event) { if (event->type == GDK_KEY_PRESS && shortcut_key(event->key) == GDK_KEY_Escape && sp_canvas_item_is_visible(_rubber)) { @@ -110,7 +110,7 @@ Selector::~Selector() delete _dragger; } -bool Selector::event(SPEventContext *event_context, GdkEvent *event) +bool Selector::event(Inkscape::UI::Tools::ToolBase *event_context, GdkEvent *event) { // The hidden control point will capture all events after it obtains the grab, // but it relies on this function to initiate it. If we pass only first button @@ -118,7 +118,7 @@ bool Selector::event(SPEventContext *event_context, GdkEvent *event) switch (event->type) { case GDK_BUTTON_PRESS: // Do not pass button presses other than left button to the control point. - // This way middle click and right click can be handled in SPEventContext. + // This way middle click and right click can be handled in ToolBase. if (event->button.button == 1 && !event_context->space_panning) { _dragger->setPosition(_desktop->w2d(event_point(event->motion))); return _dragger->event(event_context, event); diff --git a/src/ui/tool/selector.h b/src/ui/tool/selector.h index 7e2759b69..dbe751ede 100644 --- a/src/ui/tool/selector.h +++ b/src/ui/tool/selector.h @@ -28,7 +28,7 @@ class Selector : public Manipulator { public: Selector(SPDesktop *d); virtual ~Selector(); - virtual bool event(SPEventContext *, GdkEvent *); + virtual bool event(Inkscape::UI::Tools::ToolBase *, GdkEvent *); sigc::signal<void, Geom::Rect const &, GdkEventButton*> signal_area; sigc::signal<void, Geom::Point const &, GdkEventButton*> signal_point; diff --git a/src/ui/tool/transform-handle-set.cpp b/src/ui/tool/transform-handle-set.cpp index daed3a523..f21e1661a 100644 --- a/src/ui/tool/transform-handle-set.cpp +++ b/src/ui/tool/transform-handle-set.cpp @@ -26,7 +26,7 @@ #include "ui/tool/selectable-control-point.h" #include "ui/tool/event-utils.h" #include "ui/tool/transform-handle-set.h" -#include "ui/tool/node-tool.h" +#include "ui/tools/node-tool.h" #include "ui/tool/node.h" #include "seltrans.h" @@ -128,7 +128,7 @@ bool TransformHandle::grabbed(GdkEventMotion *) _setState(_state); // Collect the snap-candidates, one for each selected node. These will be stored in the _snap_points vector. - InkNodeTool *nt = INK_NODE_TOOL(_th._desktop->event_context); + Inkscape::UI::Tools::NodeTool *nt = INK_NODE_TOOL(_th._desktop->event_context); //ControlPointSelection *selection = nt->_selected_nodes.get(); ControlPointSelection* selection = nt->_selected_nodes; @@ -754,7 +754,7 @@ void TransformHandleSet::setBounds(Geom::Rect const &r, bool preserve_center) } } -bool TransformHandleSet::event(SPEventContext *, GdkEvent*) +bool TransformHandleSet::event(Inkscape::UI::Tools::ToolBase *, GdkEvent*) { return false; } diff --git a/src/ui/tool/transform-handle-set.h b/src/ui/tool/transform-handle-set.h index ce949cbb2..54f81adf5 100644 --- a/src/ui/tool/transform-handle-set.h +++ b/src/ui/tool/transform-handle-set.h @@ -40,7 +40,7 @@ public: TransformHandleSet(SPDesktop *d, SPCanvasGroup *th_group); virtual ~TransformHandleSet(); - virtual bool event(SPEventContext *, GdkEvent *); + virtual bool event(Inkscape::UI::Tools::ToolBase *, GdkEvent *); bool visible() const { return _visible; } Mode mode() const { return _mode; } |
