f2b2426ae81527bcdacdc8775f0aad1d134f02cb
1 /** @file
2 * @brief New node tool - implementation
3 */
4 /* Authors:
5 * Krzysztof KosiĆski <tweenk@gmail.com>
6 *
7 * Copyright (C) 2009 Authors
8 * Released under GNU GPL, read the file 'COPYING' for more information
9 */
11 #include <glib.h>
12 #include <glib/gi18n.h>
13 #include "desktop.h"
14 #include "desktop-handles.h"
15 #include "display/canvas-bpath.h"
16 #include "display/curve.h"
17 #include "display/sp-canvas.h"
18 #include "document.h"
19 #include "live_effects/lpeobject.h"
20 #include "message-context.h"
21 #include "selection.h"
22 #include "shape-editor.h" // temporary!
23 #include "sp-clippath.h"
24 #include "sp-item-group.h"
25 #include "sp-mask.h"
26 #include "sp-object-group.h"
27 #include "sp-path.h"
28 #include "ui/tool/node-tool.h"
29 #include "ui/tool/control-point-selection.h"
30 #include "ui/tool/curve-drag-point.h"
31 #include "ui/tool/event-utils.h"
32 #include "ui/tool/manipulator.h"
33 #include "ui/tool/multi-path-manipulator.h"
34 #include "ui/tool/path-manipulator.h"
35 #include "ui/tool/selector.h"
36 #include "ui/tool/shape-record.h"
38 #include "pixmaps/cursor-node.xpm"
39 #include "pixmaps/cursor-node-d.xpm"
41 /** @struct InkNodeTool
42 *
43 * Node tool event context.
44 *
45 * @par Architectural overview of the tool
46 * @par
47 * Here's a breakdown of what each object does.
48 * - Handle: shows a handle and keeps the node type constraint (smooth / symmetric) by updating
49 * the other handle's position when dragged. Its move() method cannot violate the constraints.
50 * - Node: keeps node type constraints for auto nodes and smooth nodes at ends of linear segments.
51 * Its move() method cannot violate constraints. Handles linear grow and dispatches spatial grow
52 * to MultiPathManipulator. Keeps a reference to its NodeList.
53 * - NodeList: exposes an iterator-based interface to nodes. It is possible to obtain an iterator
54 * to a node from the node. Keeps a reference to its SubpathList.
55 * - SubpathList: list of NodeLists that represents an editable pathvector. Keeps a reference
56 * to its PathManipulator.
57 * - PathManipulator: performs most of the single-path actions like reverse subpaths,
58 * delete segment, shift selection, etc. Keeps a reference to MultiPathManipulator.
59 * - MultiPathManipulator: performs additional operations for actions that are not per-path,
60 * for example node joins and segment joins. Tracks the control transforms for PMs that edit
61 * clipping paths and masks. It is more or less equivalent to ShapeEditor and in the future
62 * it might handle all shapes. Handles XML commit of actions that affect all paths or
63 * the node selection and removes PathManipulators that have no nodes left after e.g. node
64 * deletes.
65 * - ControlPointSelection: keeps track of node selection and a set of nodes that can potentially
66 * be selected. There can be more than one selection. Performs actions that require no
67 * knowledge about the path, only about the nodes, like dragging and transforms. It is not
68 * specific to nodes and can accomodate any control point derived from SelectableControlPoint.
69 * Transforms nodes in response to transform handle events.
70 * - TransformHandleSet: displays nodeset transform handles and emits transform events. The aim
71 * is to eventually use a common class for object and control point transforms.
72 * - SelectableControlPoint: base for any type of selectable point. It can belong to only one
73 * selection.
74 *
75 * @par Plans for the future
76 * @par
77 * - MultiPathManipulator should become a generic shape editor that manages all active manipulator,
78 * more or less like the old ShapeEditor.
79 * - Knotholder should be rewritten into one manipulator class per shape, using the control point
80 * classes. Interesting features like dragging rectangle sides could be added along the way.
81 * - Better handling of clip and mask editing, particularly in response to undo.
82 * - High level refactoring of the event context hierarchy. All aspects of tools, like toolbox
83 * controls, icons, event handling should be collected in one class, though each aspect
84 * of a tool might be in an separate class for better modularity. The long term goal is to allow
85 * tools to be defined in extensions or shared library plugins.
86 */
88 namespace {
89 SPCanvasGroup *create_control_group(SPDesktop *d);
90 void ink_node_tool_class_init(InkNodeToolClass *klass);
91 void ink_node_tool_init(InkNodeTool *node_context);
92 void ink_node_tool_dispose(GObject *object);
94 void ink_node_tool_setup(SPEventContext *ec);
95 gint ink_node_tool_root_handler(SPEventContext *event_context, GdkEvent *event);
96 gint ink_node_tool_item_handler(SPEventContext *event_context, SPItem *item, GdkEvent *event);
97 void ink_node_tool_set(SPEventContext *ec, Inkscape::Preferences::Entry *value);
99 void ink_node_tool_update_tip(InkNodeTool *nt, GdkEvent *event);
100 void ink_node_tool_selection_changed(InkNodeTool *nt, Inkscape::Selection *sel);
101 void ink_node_tool_select_area(InkNodeTool *nt, Geom::Rect const &, GdkEventButton *);
102 void ink_node_tool_select_point(InkNodeTool *nt, Geom::Point const &, GdkEventButton *);
103 void ink_node_tool_mouseover_changed(InkNodeTool *nt, Inkscape::UI::ControlPoint *p);
104 } // anonymous namespace
106 GType ink_node_tool_get_type()
107 {
108 static GType type = 0;
109 if (!type) {
110 GTypeInfo info = {
111 sizeof(InkNodeToolClass),
112 NULL, NULL,
113 (GClassInitFunc) ink_node_tool_class_init,
114 NULL, NULL,
115 sizeof(InkNodeTool),
116 4,
117 (GInstanceInitFunc) ink_node_tool_init,
118 NULL, /* value_table */
119 };
120 type = g_type_register_static(SP_TYPE_EVENT_CONTEXT, "InkNodeTool", &info, (GTypeFlags)0);
121 }
122 return type;
123 }
125 namespace {
127 SPCanvasGroup *create_control_group(SPDesktop *d)
128 {
129 return reinterpret_cast<SPCanvasGroup*>(sp_canvas_item_new(
130 sp_desktop_controls(d), SP_TYPE_CANVAS_GROUP, NULL));
131 }
133 void destroy_group(SPCanvasGroup *g)
134 {
135 gtk_object_destroy(GTK_OBJECT(g));
136 }
138 void ink_node_tool_class_init(InkNodeToolClass *klass)
139 {
140 GObjectClass *object_class = (GObjectClass *) klass;
141 SPEventContextClass *event_context_class = (SPEventContextClass *) klass;
143 object_class->dispose = ink_node_tool_dispose;
145 event_context_class->setup = ink_node_tool_setup;
146 event_context_class->set = ink_node_tool_set;
147 event_context_class->root_handler = ink_node_tool_root_handler;
148 event_context_class->item_handler = ink_node_tool_item_handler;
149 }
151 void ink_node_tool_init(InkNodeTool *nt)
152 {
153 SPEventContext *event_context = SP_EVENT_CONTEXT(nt);
155 event_context->cursor_shape = cursor_node_xpm;
156 event_context->hot_x = 1;
157 event_context->hot_y = 1;
159 new (&nt->_selection_changed_connection) sigc::connection();
160 new (&nt->_selection_modified_connection) sigc::connection();
161 new (&nt->_mouseover_changed_connection) sigc::connection();
162 //new (&nt->_mgroup) Inkscape::UI::ManipulatorGroup(nt->desktop);
163 new (&nt->_selected_nodes) CSelPtr();
164 new (&nt->_multipath) MultiPathPtr();
165 new (&nt->_selector) SelectorPtr();
166 new (&nt->_path_data) PathSharedDataPtr();
167 new (&nt->_shape_editors) ShapeEditors();
168 }
170 void ink_node_tool_dispose(GObject *object)
171 {
172 InkNodeTool *nt = INK_NODE_TOOL(object);
174 nt->enableGrDrag(false);
176 nt->_selection_changed_connection.disconnect();
177 nt->_selection_modified_connection.disconnect();
178 nt->_mouseover_changed_connection.disconnect();
179 nt->_multipath.~MultiPathPtr();
180 nt->_selected_nodes.~CSelPtr();
181 nt->_selector.~SelectorPtr();
182 nt->_shape_editors.~ShapeEditors();
184 Inkscape::UI::PathSharedData &data = *nt->_path_data;
185 destroy_group(data.node_data.node_group);
186 destroy_group(data.node_data.handle_group);
187 destroy_group(data.node_data.handle_line_group);
188 destroy_group(data.outline_group);
189 destroy_group(data.dragpoint_group);
190 destroy_group(nt->_transform_handle_group);
192 nt->_path_data.~PathSharedDataPtr();
193 nt->_selection_changed_connection.~connection();
194 nt->_selection_modified_connection.~connection();
195 nt->_mouseover_changed_connection.~connection();
197 if (nt->_node_message_context) {
198 delete nt->_node_message_context;
199 }
200 if (nt->shape_editor) {
201 nt->shape_editor->unset_item(SH_KNOTHOLDER);
202 delete nt->shape_editor;
203 }
205 G_OBJECT_CLASS(g_type_class_peek(g_type_parent(INK_TYPE_NODE_TOOL)))->dispose(object);
206 }
208 void ink_node_tool_setup(SPEventContext *ec)
209 {
210 InkNodeTool *nt = INK_NODE_TOOL(ec);
212 SPEventContextClass *parent = (SPEventContextClass *) g_type_class_peek(g_type_parent(INK_TYPE_NODE_TOOL));
213 if (parent->setup) parent->setup(ec);
215 nt->_node_message_context = new Inkscape::MessageContext((ec->desktop)->messageStack());
217 nt->_path_data.reset(new Inkscape::UI::PathSharedData());
218 Inkscape::UI::PathSharedData &data = *nt->_path_data;
219 data.node_data.desktop = nt->desktop;
221 // selector has to be created here, so that its hidden control point is on the bottom
222 nt->_selector.reset(new Inkscape::UI::Selector(nt->desktop));
224 // Prepare canvas groups for controls. This guarantees correct z-order, so that
225 // for example a dragpoint won't obscure a node
226 data.outline_group = create_control_group(nt->desktop);
227 data.node_data.handle_line_group = create_control_group(nt->desktop);
228 data.dragpoint_group = create_control_group(nt->desktop);
229 nt->_transform_handle_group = create_control_group(nt->desktop);
230 data.node_data.node_group = create_control_group(nt->desktop);
231 data.node_data.handle_group = create_control_group(nt->desktop);
233 Inkscape::Selection *selection = sp_desktop_selection (ec->desktop);
234 nt->_selection_changed_connection.disconnect();
235 nt->_selection_changed_connection =
236 selection->connectChanged(
237 sigc::bind<0>(
238 sigc::ptr_fun(&ink_node_tool_selection_changed),
239 nt));
240 /*nt->_selection_modified_connection.disconnect();
241 nt->_selection_modified_connection =
242 selection->connectModified(
243 sigc::hide(sigc::bind<0>(
244 sigc::ptr_fun(&ink_node_tool_selection_modified),
245 nt)));*/
246 nt->_mouseover_changed_connection.disconnect();
247 nt->_mouseover_changed_connection =
248 Inkscape::UI::ControlPoint::signal_mouseover_change.connect(
249 sigc::bind<0>(
250 sigc::ptr_fun(&ink_node_tool_mouseover_changed),
251 nt));
253 nt->_selected_nodes.reset(
254 new Inkscape::UI::ControlPointSelection(nt->desktop, nt->_transform_handle_group));
255 data.node_data.selection = nt->_selected_nodes.get();
256 nt->_multipath.reset(new Inkscape::UI::MultiPathManipulator(data,
257 nt->_selection_changed_connection));
259 nt->_selector->signal_point.connect(
260 sigc::bind<0>(
261 sigc::ptr_fun(&ink_node_tool_select_point),
262 nt));
263 nt->_selector->signal_area.connect(
264 sigc::bind<0>(
265 sigc::ptr_fun(&ink_node_tool_select_area),
266 nt));
268 nt->_multipath->signal_coords_changed.connect(
269 sigc::bind(
270 sigc::mem_fun(*nt->desktop, &SPDesktop::emitToolSubselectionChanged),
271 (void*) 0));
272 nt->_selected_nodes->signal_point_changed.connect(
273 sigc::hide( sigc::hide(
274 sigc::bind(
275 sigc::bind(
276 sigc::ptr_fun(ink_node_tool_update_tip),
277 (GdkEvent*)0),
278 nt))));
280 nt->cursor_drag = false;
281 nt->show_transform_handles = true;
282 nt->single_node_transform_handles = false;
283 nt->flash_tempitem = NULL;
284 nt->flashed_item = NULL;
285 nt->_last_over = NULL;
286 // TODO long term, fold ShapeEditor into MultiPathManipulator and rename MPM
287 // to something better
288 //nt->shape_editor = new ShapeEditor(nt->desktop);
290 // read prefs before adding items to selection to prevent momentarily showing the outline
291 sp_event_context_read(nt, "show_handles");
292 sp_event_context_read(nt, "show_outline");
293 sp_event_context_read(nt, "live_outline");
294 sp_event_context_read(nt, "live_objects");
295 sp_event_context_read(nt, "show_path_direction");
296 sp_event_context_read(nt, "show_transform_handles");
297 sp_event_context_read(nt, "single_node_transform_handles");
298 sp_event_context_read(nt, "edit_clipping_paths");
299 sp_event_context_read(nt, "edit_masks");
301 ink_node_tool_selection_changed(nt, selection);
302 ink_node_tool_update_tip(nt, NULL);
304 Inkscape::Preferences *prefs = Inkscape::Preferences::get();
305 if (prefs->getBool("/tools/nodes/selcue")) {
306 ec->enableSelectionCue();
307 }
308 if (prefs->getBool("/tools/nodes/gradientdrag")) {
309 ec->enableGrDrag();
310 }
312 nt->desktop->emitToolSubselectionChanged(NULL); // sets the coord entry fields to inactive
313 }
315 void ink_node_tool_set(SPEventContext *ec, Inkscape::Preferences::Entry *value)
316 {
317 InkNodeTool *nt = INK_NODE_TOOL(ec);
318 Glib::ustring entry_name = value->getEntryName();
320 if (entry_name == "show_handles") {
321 nt->show_handles = value->getBool(true);
322 nt->_multipath->showHandles(nt->show_handles);
323 } else if (entry_name == "show_outline") {
324 nt->show_outline = value->getBool();
325 nt->_multipath->showOutline(nt->show_outline);
326 } else if (entry_name == "live_outline") {
327 nt->live_outline = value->getBool();
328 nt->_multipath->setLiveOutline(nt->live_outline);
329 } else if (entry_name == "live_objects") {
330 nt->live_objects = value->getBool();
331 nt->_multipath->setLiveObjects(nt->live_objects);
332 } else if (entry_name == "show_path_direction") {
333 nt->show_path_direction = value->getBool();
334 nt->_multipath->showPathDirection(nt->show_path_direction);
335 } else if (entry_name == "show_transform_handles") {
336 nt->show_transform_handles = value->getBool(true);
337 nt->_selected_nodes->showTransformHandles(
338 nt->show_transform_handles, nt->single_node_transform_handles);
339 } else if (entry_name == "single_node_transform_handles") {
340 nt->single_node_transform_handles = value->getBool();
341 nt->_selected_nodes->showTransformHandles(
342 nt->show_transform_handles, nt->single_node_transform_handles);
343 } else if (entry_name == "edit_clipping_paths") {
344 nt->edit_clipping_paths = value->getBool();
345 ink_node_tool_selection_changed(nt, nt->desktop->selection);
346 } else if (entry_name == "edit_masks") {
347 nt->edit_masks = value->getBool();
348 ink_node_tool_selection_changed(nt, nt->desktop->selection);
349 } else {
350 SPEventContextClass *parent_class =
351 (SPEventContextClass *) g_type_class_peek(g_type_parent(INK_TYPE_NODE_TOOL));
352 if (parent_class->set)
353 parent_class->set(ec, value);
354 }
355 }
357 /** Recursively collect ShapeRecords */
358 void gather_items(InkNodeTool *nt, SPItem *base, SPObject *obj, Inkscape::UI::ShapeRole role,
359 std::set<Inkscape::UI::ShapeRecord> &s)
360 {
361 using namespace Inkscape::UI;
362 if (!obj) return;
364 if (SP_IS_PATH(obj) && obj->repr->attribute("inkscape:original-d") != NULL) {
365 ShapeRecord r;
366 r.item = static_cast<SPItem*>(obj);
367 r.edit_transform = Geom::identity(); // TODO wrong?
368 r.role = role;
369 s.insert(r);
370 } else if (role != SHAPE_ROLE_NORMAL && (SP_IS_GROUP(obj) || SP_IS_OBJECTGROUP(obj))) {
371 for (SPObject *c = obj->children; c; c = c->next) {
372 gather_items(nt, base, c, role, s);
373 }
374 } else if (SP_IS_ITEM(obj)) {
375 SPItem *item = static_cast<SPItem*>(obj);
376 ShapeRecord r;
377 r.item = item;
378 // TODO add support for objectBoundingBox
379 r.edit_transform = base ? sp_item_i2doc_affine(base) : Geom::identity();
380 r.role = role;
381 if (s.insert(r).second) {
382 // this item was encountered the first time
383 if (nt->edit_clipping_paths && item->clip_ref) {
384 gather_items(nt, item, item->clip_ref->getObject(), SHAPE_ROLE_CLIPPING_PATH, s);
385 }
386 if (nt->edit_masks && item->mask_ref) {
387 gather_items(nt, item, item->mask_ref->getObject(), SHAPE_ROLE_MASK, s);
388 }
389 }
390 }
391 }
393 void ink_node_tool_selection_changed(InkNodeTool *nt, Inkscape::Selection *sel)
394 {
395 using namespace Inkscape::UI;
397 std::set<ShapeRecord> shapes;
399 GSList const *ilist = sel->itemList();
401 for (GSList *i = const_cast<GSList*>(ilist); i; i = i->next) {
402 SPObject *obj = static_cast<SPObject*>(i->data);
403 if (SP_IS_ITEM(obj)) {
404 gather_items(nt, NULL, static_cast<SPItem*>(obj), SHAPE_ROLE_NORMAL, shapes);
405 }
406 }
408 nt->_shape_editors.clear();
410 // use multiple ShapeEditors for now, to allow editing many shapes at once
411 // needs to be rethought
413 for (std::set<ShapeRecord>::iterator i = shapes.begin(); i != shapes.end(); ++i) {
414 ShapeRecord const &r = *i;
415 if (SP_IS_SHAPE(r.item))
416 {
417 ShapeEditor *si = new ShapeEditor(nt->desktop);
418 si->set_item(r.item, SH_KNOTHOLDER);
419 nt->_shape_editors.push_back(si);
420 //nt->shape_editor->set_item(r.item, SH_KNOTHOLDER);
421 }
422 }
424 nt->_multipath->setItems(shapes);
425 ink_node_tool_update_tip(nt, NULL);
426 nt->desktop->updateNow();
427 }
429 gint ink_node_tool_root_handler(SPEventContext *event_context, GdkEvent *event)
430 {
431 /* things to handle here:
432 * 1. selection of items
433 * 2. passing events to manipulators
434 * 3. some keybindings
435 */
436 using namespace Inkscape::UI; // pull in event helpers
438 SPDesktop *desktop = event_context->desktop;
439 Inkscape::Selection *selection = desktop->selection;
440 InkNodeTool *nt = static_cast<InkNodeTool*>(event_context);
441 static Inkscape::Preferences *prefs = Inkscape::Preferences::get();
443 if (nt->_multipath->event(event)) return true;
444 if (nt->_selector->event(event)) return true;
445 if (nt->_selected_nodes->event(event)) return true;
447 switch (event->type)
448 {
449 case GDK_MOTION_NOTIFY: {
450 combine_motion_events(desktop->canvas, event->motion, 0);
451 SPItem *over_item = sp_event_context_find_item (desktop, event_point(event->button),
452 FALSE, TRUE);
453 if (over_item != nt->_last_over) {
454 nt->_last_over = over_item;
455 ink_node_tool_update_tip(nt, event);
456 }
458 // create pathflash outline
459 if (prefs->getBool("/tools/nodes/pathflash_enabled")) {
460 if (over_item == nt->flashed_item) break;
461 if (!prefs->getBool("/tools/nodes/pathflash_selected") && selection->includes(over_item)) break;
462 if (nt->flash_tempitem) {
463 desktop->remove_temporary_canvasitem(nt->flash_tempitem);
464 nt->flash_tempitem = NULL;
465 nt->flashed_item = NULL;
466 }
467 if (!SP_IS_PATH(over_item)) break; // for now, handle only paths
469 nt->flashed_item = over_item;
470 SPCurve *c = sp_path_get_curve_for_edit(SP_PATH(over_item));
471 c->transform(sp_item_i2d_affine(over_item));
472 SPCanvasItem *flash = sp_canvas_bpath_new(sp_desktop_tempgroup(desktop), c);
473 sp_canvas_bpath_set_stroke(SP_CANVAS_BPATH(flash),
474 prefs->getInt("/tools/nodes/highlight_color", 0xff0000ff), 1.0,
475 SP_STROKE_LINEJOIN_MITER, SP_STROKE_LINECAP_BUTT);
476 sp_canvas_bpath_set_fill(SP_CANVAS_BPATH(flash), 0, SP_WIND_RULE_NONZERO);
477 nt->flash_tempitem = desktop->add_temporary_canvasitem(flash,
478 prefs->getInt("/tools/nodes/pathflash_timeout", 500));
479 c->unref();
480 }
481 } break; // do not return true, because we need to pass this event to the parent context
482 // otherwise some features cease to work
484 case GDK_KEY_PRESS:
485 switch (get_group0_keyval(&event->key))
486 {
487 case GDK_Escape: // deselect everything
488 if (nt->_selected_nodes->empty()) {
489 selection->clear();
490 } else {
491 nt->_selected_nodes->clear();
492 }
493 ink_node_tool_update_tip(nt, event);
494 return TRUE;
495 case GDK_a:
496 case GDK_A:
497 if (held_control(event->key) && held_alt(event->key)) {
498 nt->_selected_nodes->selectAll();
499 // Ctrl+A is handled in selection-chemistry.cpp via verb
500 ink_node_tool_update_tip(nt, event);
501 return TRUE;
502 }
503 break;
504 case GDK_h:
505 case GDK_H:
506 if (held_only_control(event->key)) {
507 Inkscape::Preferences *prefs = Inkscape::Preferences::get();
508 prefs->setBool("/tools/nodes/show_handles", !nt->show_handles);
509 return TRUE;
510 }
511 break;
512 default:
513 break;
514 }
515 ink_node_tool_update_tip(nt, event);
516 break;
517 case GDK_KEY_RELEASE:
518 ink_node_tool_update_tip(nt, event);
519 break;
520 default: break;
521 }
523 SPEventContextClass *parent_class = (SPEventContextClass *) g_type_class_peek(g_type_parent(INK_TYPE_NODE_TOOL));
524 if (parent_class->root_handler)
525 return parent_class->root_handler(event_context, event);
526 return FALSE;
527 }
529 void ink_node_tool_update_tip(InkNodeTool *nt, GdkEvent *event)
530 {
531 using namespace Inkscape::UI;
532 if (event && (event->type == GDK_KEY_PRESS || event->type == GDK_KEY_RELEASE)) {
533 unsigned new_state = state_after_event(event);
534 if (new_state == event->key.state) return;
535 if (state_held_shift(new_state)) {
536 if (nt->_last_over) {
537 nt->_node_message_context->set(Inkscape::NORMAL_MESSAGE,
538 C_("Node tool tip", "<b>Shift</b>: drag to add nodes to the selection, "
539 "click to toggle object selection"));
540 } else {
541 nt->_node_message_context->set(Inkscape::NORMAL_MESSAGE,
542 C_("Node tool tip", "<b>Shift</b>: drag to add nodes to the selection"));
543 }
544 return;
545 }
546 }
547 unsigned sz = nt->_selected_nodes->size();
548 unsigned total = nt->_selected_nodes->allPoints().size();
549 if (sz != 0) {
550 if (nt->_last_over) {
551 char *dyntip = g_strdup_printf(C_("Node tool tip",
552 "<b>%u of %u nodes</b> selected. "
553 "Drag to select nodes, click to edit only this object (more: Shift)"), sz, total);
554 nt->_node_message_context->set(Inkscape::NORMAL_MESSAGE, dyntip);
555 g_free(dyntip);
556 } else {
557 char *dyntip = g_strdup_printf(C_("Node tool tip",
558 "<b>%u of %u nodes</b> selected. "
559 "Drag to select nodes, click clear the selection"), sz, total);
560 nt->_node_message_context->set(Inkscape::NORMAL_MESSAGE, dyntip);
561 g_free(dyntip);
562 }
563 } else if (!nt->_multipath->empty()) {
564 if (nt->_last_over) {
565 nt->_node_message_context->set(Inkscape::NORMAL_MESSAGE, C_("Node tool tip",
566 "Drag to select nodes, click to edit only this object"));
567 } else {
568 nt->_node_message_context->set(Inkscape::NORMAL_MESSAGE, C_("Node tool tip",
569 "Drag to select nodes, click to clear the selection"));
570 }
571 } else {
572 if (nt->_last_over) {
573 nt->_node_message_context->set(Inkscape::NORMAL_MESSAGE, C_("Node tool tip",
574 "Drag to select objects to edit, click to edit this object (more: Shift)"));
575 } else {
576 nt->_node_message_context->set(Inkscape::NORMAL_MESSAGE, C_("Node tool tip",
577 "Drag to select objects to edit"));
578 }
579 }
580 }
582 gint ink_node_tool_item_handler(SPEventContext *event_context, SPItem *item, GdkEvent *event)
583 {
584 SPEventContextClass *parent_class =
585 (SPEventContextClass *) g_type_class_peek(g_type_parent(INK_TYPE_NODE_TOOL));
586 if (parent_class->item_handler)
587 return parent_class->item_handler(event_context, item, event);
588 return FALSE;
589 }
591 void ink_node_tool_select_area(InkNodeTool *nt, Geom::Rect const &sel, GdkEventButton *event)
592 {
593 using namespace Inkscape::UI;
594 if (nt->_multipath->empty()) {
595 // if multipath is empty, select rubberbanded items rather than nodes
596 Inkscape::Selection *selection = nt->desktop->selection;
597 GSList *items = sp_document_items_in_box(
598 sp_desktop_document(nt->desktop), nt->desktop->dkey, sel);
599 selection->setList(items);
600 g_slist_free(items);
601 } else {
602 if (!held_shift(*event)) nt->_selected_nodes->clear();
603 nt->_selected_nodes->selectArea(sel);
604 }
605 }
606 void ink_node_tool_select_point(InkNodeTool *nt, Geom::Point const &/*sel*/, GdkEventButton *event)
607 {
608 using namespace Inkscape::UI; // pull in event helpers
609 if (!event) return;
610 if (event->button != 1) return;
612 Inkscape::Selection *selection = nt->desktop->selection;
614 SPItem *item_clicked = sp_event_context_find_item (nt->desktop, event_point(*event),
615 (event->state & GDK_MOD1_MASK) && !(event->state & GDK_CONTROL_MASK), TRUE);
617 if (item_clicked == NULL) { // nothing under cursor
618 // if no Shift, deselect
619 if (!(event->state & GDK_SHIFT_MASK)) {
620 selection->clear();
621 }
622 } else {
623 if (held_shift(*event)) {
624 selection->toggle(item_clicked);
625 } else {
626 selection->set(item_clicked);
627 }
628 nt->desktop->updateNow();
629 }
630 }
632 void ink_node_tool_mouseover_changed(InkNodeTool *nt, Inkscape::UI::ControlPoint *p)
633 {
634 using Inkscape::UI::CurveDragPoint;
635 CurveDragPoint *cdp = dynamic_cast<CurveDragPoint*>(p);
636 if (cdp && !nt->cursor_drag) {
637 nt->cursor_shape = cursor_node_d_xpm;
638 nt->hot_x = 1;
639 nt->hot_y = 1;
640 sp_event_context_update_cursor(nt);
641 nt->cursor_drag = true;
642 } else if (!cdp && nt->cursor_drag) {
643 nt->cursor_shape = cursor_node_xpm;
644 nt->hot_x = 1;
645 nt->hot_y = 1;
646 sp_event_context_update_cursor(nt);
647 nt->cursor_drag = false;
648 }
649 }
651 } // anonymous namespace
653 /*
654 Local Variables:
655 mode:c++
656 c-file-style:"stroustrup"
657 c-file-offsets:((innamespace . 0)(inline-open . 0)(case-label . +))
658 indent-tabs-mode:nil
659 fill-column:99
660 End:
661 */
662 // vim: filetype=cpp:expandtab:shiftwidth=4:tabstop=8:softtabstop=4:encoding=utf-8:textwidth=99 :