1 /** \file
2 * Pen event context implementation.
3 */
5 /*
6 * Authors:
7 * Lauris Kaplinski <lauris@kaplinski.com>
8 * bulia byak <buliabyak@users.sf.net>
9 *
10 * Copyright (C) 2000 Lauris Kaplinski
11 * Copyright (C) 2000-2001 Ximian, Inc.
12 * Copyright (C) 2002 Lauris Kaplinski
13 * Copyright (C) 2004 Monash University
14 *
15 * Released under GNU GPL, read the file 'COPYING' for more information
16 */
18 #include <gdk/gdkkeysyms.h>
19 #include <cstring>
20 #include <string>
22 #include "pen-context.h"
23 #include "sp-namedview.h"
24 #include "sp-metrics.h"
25 #include "desktop.h"
26 #include "desktop-handles.h"
27 #include "selection.h"
28 #include "selection-chemistry.h"
29 #include "draw-anchor.h"
30 #include "message-stack.h"
31 #include "message-context.h"
32 #include "prefs-utils.h"
33 #include "sp-path.h"
34 #include "display/curve.h"
35 #include "pixmaps/cursor-pen.xpm"
36 #include "display/canvas-bpath.h"
37 #include "display/sp-ctrlline.h"
38 #include "display/sodipodi-ctrl.h"
39 #include <glibmm/i18n.h>
40 #include "libnr/n-art-bpath.h"
41 #include "libnr/nr-point-ops.h"
42 #include "helper/units.h"
43 #include "macros.h"
44 #include "context-fns.h"
46 static void sp_pen_context_class_init(SPPenContextClass *klass);
47 static void sp_pen_context_init(SPPenContext *pc);
48 static void sp_pen_context_dispose(GObject *object);
50 static void sp_pen_context_setup(SPEventContext *ec);
51 static void sp_pen_context_finish(SPEventContext *ec);
52 static void sp_pen_context_set(SPEventContext *ec, gchar const *key, gchar const *val);
53 static gint sp_pen_context_root_handler(SPEventContext *ec, GdkEvent *event);
54 static gint sp_pen_context_item_handler(SPEventContext *event_context, SPItem *item, GdkEvent *event);
56 static void spdc_pen_set_initial_point(SPPenContext *pc, NR::Point const p);
57 static void spdc_pen_set_subsequent_point(SPPenContext *pc, NR::Point const p, bool statusbar);
58 static void spdc_pen_set_ctrl(SPPenContext *pc, NR::Point const p, guint state);
59 static void spdc_pen_finish_segment(SPPenContext *pc, NR::Point p, guint state);
61 static void spdc_pen_finish(SPPenContext *pc, gboolean closed);
63 static gint pen_handle_button_press(SPPenContext *const pc, GdkEventButton const &bevent);
64 static gint pen_handle_motion_notify(SPPenContext *const pc, GdkEventMotion const &mevent);
65 static gint pen_handle_button_release(SPPenContext *const pc, GdkEventButton const &revent);
66 static gint pen_handle_2button_press(SPPenContext *const pc, GdkEventButton const &bevent);
67 static gint pen_handle_key_press(SPPenContext *const pc, GdkEvent *event);
68 static void spdc_reset_colors(SPPenContext *pc);
70 static void pen_disable_events(SPPenContext *const pc);
71 static void pen_enable_events(SPPenContext *const pc);
73 static NR::Point pen_drag_origin_w(0, 0);
74 static bool pen_within_tolerance = false;
76 static SPDrawContextClass *pen_parent_class;
78 /**
79 * Register SPPenContext with Gdk and return its type.
80 */
81 GType
82 sp_pen_context_get_type(void)
83 {
84 static GType type = 0;
85 if (!type) {
86 GTypeInfo info = {
87 sizeof(SPPenContextClass),
88 NULL, NULL,
89 (GClassInitFunc) sp_pen_context_class_init,
90 NULL, NULL,
91 sizeof(SPPenContext),
92 4,
93 (GInstanceInitFunc) sp_pen_context_init,
94 NULL, /* value_table */
95 };
96 type = g_type_register_static(SP_TYPE_DRAW_CONTEXT, "SPPenContext", &info, (GTypeFlags)0);
97 }
98 return type;
99 }
101 /**
102 * Initialize the SPPenContext vtable.
103 */
104 static void
105 sp_pen_context_class_init(SPPenContextClass *klass)
106 {
107 GObjectClass *object_class;
108 SPEventContextClass *event_context_class;
110 object_class = (GObjectClass *) klass;
111 event_context_class = (SPEventContextClass *) klass;
113 pen_parent_class = (SPDrawContextClass*)g_type_class_peek_parent(klass);
115 object_class->dispose = sp_pen_context_dispose;
117 event_context_class->setup = sp_pen_context_setup;
118 event_context_class->finish = sp_pen_context_finish;
119 event_context_class->set = sp_pen_context_set;
120 event_context_class->root_handler = sp_pen_context_root_handler;
121 event_context_class->item_handler = sp_pen_context_item_handler;
122 }
124 /**
125 * Callback to initialize SPPenContext object.
126 */
127 static void
128 sp_pen_context_init(SPPenContext *pc)
129 {
131 SPEventContext *event_context = SP_EVENT_CONTEXT(pc);
133 event_context->cursor_shape = cursor_pen_xpm;
134 event_context->hot_x = 4;
135 event_context->hot_y = 4;
137 pc->npoints = 0;
138 pc->mode = SP_PEN_CONTEXT_MODE_CLICK;
139 pc->state = SP_PEN_CONTEXT_POINT;
141 pc->c0 = NULL;
142 pc->c1 = NULL;
143 pc->cl0 = NULL;
144 pc->cl1 = NULL;
146 pc->events_disabled = 0;
148 pc->polylines_only = false;
149 pc->waiting_LPE = NULL;
150 }
152 /**
153 * Callback to destroy the SPPenContext object's members and itself.
154 */
155 static void
156 sp_pen_context_dispose(GObject *object)
157 {
158 SPPenContext *pc;
160 pc = SP_PEN_CONTEXT(object);
162 if (pc->c0) {
163 gtk_object_destroy(GTK_OBJECT(pc->c0));
164 pc->c0 = NULL;
165 }
166 if (pc->c1) {
167 gtk_object_destroy(GTK_OBJECT(pc->c1));
168 pc->c1 = NULL;
169 }
170 if (pc->cl0) {
171 gtk_object_destroy(GTK_OBJECT(pc->cl0));
172 pc->cl0 = NULL;
173 }
174 if (pc->cl1) {
175 gtk_object_destroy(GTK_OBJECT(pc->cl1));
176 pc->cl1 = NULL;
177 }
179 G_OBJECT_CLASS(pen_parent_class)->dispose(object);
181 pc->polylines_only = false;
182 pc->waiting_LPE = NULL;
183 if (pc->expecting_clicks_for_LPE > 0) {
184 // we received too few clicks to sanely set the parameter path so we remove the LPE from the item
185 sp_lpe_item_remove_current_path_effect(pc->waiting_item, false);
186 }
187 }
189 /**
190 * Callback to initialize SPPenContext object.
191 */
192 static void
193 sp_pen_context_setup(SPEventContext *ec)
194 {
195 SPPenContext *pc;
197 pc = SP_PEN_CONTEXT(ec);
199 if (((SPEventContextClass *) pen_parent_class)->setup) {
200 ((SPEventContextClass *) pen_parent_class)->setup(ec);
201 }
203 /* Pen indicators */
204 pc->c0 = sp_canvas_item_new(sp_desktop_controls(SP_EVENT_CONTEXT_DESKTOP(ec)), SP_TYPE_CTRL, "shape", SP_CTRL_SHAPE_CIRCLE,
205 "size", 4.0, "filled", 0, "fill_color", 0xff00007f, "stroked", 1, "stroke_color", 0x0000ff7f, NULL);
206 pc->c1 = sp_canvas_item_new(sp_desktop_controls(SP_EVENT_CONTEXT_DESKTOP(ec)), SP_TYPE_CTRL, "shape", SP_CTRL_SHAPE_CIRCLE,
207 "size", 4.0, "filled", 0, "fill_color", 0xff00007f, "stroked", 1, "stroke_color", 0x0000ff7f, NULL);
208 pc->cl0 = sp_canvas_item_new(sp_desktop_controls(SP_EVENT_CONTEXT_DESKTOP(ec)), SP_TYPE_CTRLLINE, NULL);
209 sp_ctrlline_set_rgba32(SP_CTRLLINE(pc->cl0), 0x0000007f);
210 pc->cl1 = sp_canvas_item_new(sp_desktop_controls(SP_EVENT_CONTEXT_DESKTOP(ec)), SP_TYPE_CTRLLINE, NULL);
211 sp_ctrlline_set_rgba32(SP_CTRLLINE(pc->cl1), 0x0000007f);
213 sp_canvas_item_hide(pc->c0);
214 sp_canvas_item_hide(pc->c1);
215 sp_canvas_item_hide(pc->cl0);
216 sp_canvas_item_hide(pc->cl1);
218 sp_event_context_read(ec, "mode");
220 pc->anchor_statusbar = false;
222 if (prefs_get_int_attribute("tools.freehand.pen", "selcue", 0) != 0) {
223 ec->enableSelectionCue();
224 }
225 }
227 static void
228 pen_cancel (SPPenContext *const pc)
229 {
230 pc->state = SP_PEN_CONTEXT_STOP;
231 spdc_reset_colors(pc);
232 sp_canvas_item_hide(pc->c0);
233 sp_canvas_item_hide(pc->c1);
234 sp_canvas_item_hide(pc->cl0);
235 sp_canvas_item_hide(pc->cl1);
236 pc->_message_context->clear();
237 pc->_message_context->flash(Inkscape::NORMAL_MESSAGE, _("Drawing cancelled"));
239 sp_canvas_end_forced_full_redraws(pc->desktop->canvas);
240 }
242 /**
243 * Finalization callback.
244 */
245 static void
246 sp_pen_context_finish(SPEventContext *ec)
247 {
248 SPPenContext *pc = SP_PEN_CONTEXT(ec);
250 if (pc->npoints != 0) {
251 pen_cancel (pc);
252 }
254 if (((SPEventContextClass *) pen_parent_class)->finish) {
255 ((SPEventContextClass *) pen_parent_class)->finish(ec);
256 }
257 }
259 /**
260 * Callback that sets key to value in pen context.
261 */
262 static void
263 sp_pen_context_set(SPEventContext *ec, gchar const *key, gchar const *val)
264 {
265 SPPenContext *pc = SP_PEN_CONTEXT(ec);
267 if (!strcmp(key, "mode")) {
268 if ( val && !strcmp(val, "drag") ) {
269 pc->mode = SP_PEN_CONTEXT_MODE_DRAG;
270 } else {
271 pc->mode = SP_PEN_CONTEXT_MODE_CLICK;
272 }
273 }
274 }
276 /**
277 * Snaps new node relative to the previous node.
278 */
279 static void
280 spdc_endpoint_snap(SPPenContext const *const pc, NR::Point &p, guint const state)
281 {
282 if (pc->npoints > 0) {
283 spdc_endpoint_snap_rotation(pc, p, pc->p[0], state);
284 }
286 spdc_endpoint_snap_free(pc, p, state);
287 }
289 /**
290 * Snaps new node's handle relative to the new node.
291 */
292 static void
293 spdc_endpoint_snap_handle(SPPenContext const *const pc, NR::Point &p, guint const state)
294 {
295 g_return_if_fail(( pc->npoints == 2 ||
296 pc->npoints == 5 ));
298 spdc_endpoint_snap_rotation(pc, p, pc->p[pc->npoints - 2], state);
299 spdc_endpoint_snap_free(pc, p, state);
300 }
302 static gint
303 sp_pen_context_item_handler(SPEventContext *ec, SPItem *item, GdkEvent *event)
304 {
305 SPPenContext *const pc = SP_PEN_CONTEXT(ec);
307 gint ret = FALSE;
309 switch (event->type) {
310 case GDK_BUTTON_PRESS:
311 ret = pen_handle_button_press(pc, event->button);
312 break;
313 default:
314 break;
315 }
317 if (!ret) {
318 if (((SPEventContextClass *) pen_parent_class)->item_handler)
319 ret = ((SPEventContextClass *) pen_parent_class)->item_handler(ec, item, event);
320 }
322 return ret;
323 }
325 /**
326 * Callback to handle all pen events.
327 */
328 static gint
329 sp_pen_context_root_handler(SPEventContext *ec, GdkEvent *event)
330 {
331 SPPenContext *const pc = SP_PEN_CONTEXT(ec);
333 gint ret = FALSE;
335 switch (event->type) {
336 case GDK_BUTTON_PRESS:
337 ret = pen_handle_button_press(pc, event->button);
338 break;
340 case GDK_MOTION_NOTIFY:
341 ret = pen_handle_motion_notify(pc, event->motion);
342 break;
344 case GDK_BUTTON_RELEASE:
345 ret = pen_handle_button_release(pc, event->button);
346 break;
348 case GDK_2BUTTON_PRESS:
349 ret = pen_handle_2button_press(pc, event->button);
350 break;
352 case GDK_KEY_PRESS:
353 ret = pen_handle_key_press(pc, event);
354 break;
356 default:
357 break;
358 }
360 if (!ret) {
361 gint (*const parent_root_handler)(SPEventContext *, GdkEvent *)
362 = ((SPEventContextClass *) pen_parent_class)->root_handler;
363 if (parent_root_handler) {
364 ret = parent_root_handler(ec, event);
365 }
366 }
368 return ret;
369 }
371 /**
372 * Handle mouse button press event.
373 */
374 static gint pen_handle_button_press(SPPenContext *const pc, GdkEventButton const &bevent)
375 {
376 if (pc->events_disabled) {
377 // skip event processing if events are disabled
378 return FALSE;
379 }
381 SPDrawContext * const dc = SP_DRAW_CONTEXT(pc);
382 SPDesktop * const desktop = SP_EVENT_CONTEXT_DESKTOP(dc);
383 NR::Point const event_w(bevent.x, bevent.y);
384 NR::Point const event_dt(desktop->w2d(event_w));
385 SPEventContext *event_context = SP_EVENT_CONTEXT(pc);
387 gint ret = FALSE;
388 if (bevent.button == 1 && !event_context->space_panning
389 // when the last click for a waiting LPE occurs we want to finish the path
390 && pc->expecting_clicks_for_LPE != 1) {
392 if (Inkscape::have_viable_layer(desktop, dc->_message_context) == false) {
393 return TRUE;
394 }
396 pen_drag_origin_w = event_w;
397 pen_within_tolerance = true;
399 /* Test whether we hit any anchor. */
400 SPDrawAnchor * const anchor = spdc_test_inside(pc, event_w);
402 switch (pc->mode) {
403 case SP_PEN_CONTEXT_MODE_CLICK:
404 /* In click mode we add point on release */
405 switch (pc->state) {
406 case SP_PEN_CONTEXT_POINT:
407 case SP_PEN_CONTEXT_CONTROL:
408 case SP_PEN_CONTEXT_CLOSE:
409 break;
410 case SP_PEN_CONTEXT_STOP:
411 /* This is allowed, if we just cancelled curve */
412 pc->state = SP_PEN_CONTEXT_POINT;
413 break;
414 default:
415 break;
416 }
417 break;
418 case SP_PEN_CONTEXT_MODE_DRAG:
419 switch (pc->state) {
420 case SP_PEN_CONTEXT_STOP:
421 /* This is allowed, if we just cancelled curve */
422 case SP_PEN_CONTEXT_POINT:
423 if (pc->npoints == 0) {
425 if (bevent.state & GDK_CONTROL_MASK) {
426 freehand_create_single_dot(event_context, event_dt, "tools.freehand.pen", bevent.state);
427 ret = TRUE;
428 break;
429 }
431 // TODO: Perhaps it would be nicer to rearrange the following case
432 // distinction so that the case of a waiting LPE is treated separately
434 /* Set start anchor */
435 pc->sa = anchor;
436 NR::Point p;
437 if (anchor && !sp_pen_context_has_waiting_LPE(pc)) {
438 /* Adjust point to anchor if needed; if we have a waiting LPE, we need
439 a fresh path to be created so don't continue an existing one */
440 p = anchor->dp;
441 desktop->messageStack()->flash(Inkscape::NORMAL_MESSAGE, _("Continuing selected path"));
442 } else {
443 // This is the first click of a new curve; deselect item so that
444 // this curve is not combined with it (unless it is drawn from its
445 // anchor, which is handled by the sibling branch above)
446 Inkscape::Selection * const selection = sp_desktop_selection(desktop);
447 if (!(bevent.state & GDK_SHIFT_MASK) || sp_pen_context_has_waiting_LPE(pc)) {
448 /* if we have a waiting LPE, we need a fresh path to be created
449 so don't append to an existing one */
450 selection->clear();
451 desktop->messageStack()->flash(Inkscape::NORMAL_MESSAGE, _("Creating new path"));
452 } else if (selection->singleItem() && SP_IS_PATH(selection->singleItem())) {
453 desktop->messageStack()->flash(Inkscape::NORMAL_MESSAGE, _("Appending to selected path"));
454 }
456 /* Create green anchor */
457 p = event_dt;
458 spdc_endpoint_snap(pc, p, bevent.state);
459 pc->green_anchor = sp_draw_anchor_new(pc, pc->green_curve, TRUE, p);
460 }
461 spdc_pen_set_initial_point(pc, p);
462 } else {
464 /* Set end anchor */
465 pc->ea = anchor;
466 NR::Point p;
467 if (anchor) {
469 p = anchor->dp;
470 // we hit an anchor, will finish the curve (either with or without closing)
471 // in release handler
472 pc->state = SP_PEN_CONTEXT_CLOSE;
474 if (pc->green_anchor && pc->green_anchor->active) {
475 // we clicked on the current curve start, so close it even if
476 // we drag a handle away from it
477 dc->green_closed = TRUE;
478 }
479 ret = TRUE;
480 break;
482 } else {
484 p = event_dt;
485 spdc_endpoint_snap(pc, p, bevent.state); /* Snap node only if not hitting anchor. */
486 spdc_pen_set_subsequent_point(pc, p, true);
487 if (pc->polylines_only) {
488 spdc_pen_finish_segment(pc, p, bevent.state);
489 }
490 }
492 }
493 pc->state = pc->polylines_only ? SP_PEN_CONTEXT_POINT : SP_PEN_CONTEXT_CONTROL;
494 ret = TRUE;
495 break;
496 case SP_PEN_CONTEXT_CONTROL:
497 g_warning("Button down in CONTROL state");
498 break;
499 case SP_PEN_CONTEXT_CLOSE:
500 g_warning("Button down in CLOSE state");
501 break;
502 default:
503 break;
504 }
505 break;
506 default:
507 break;
508 }
509 } else if (bevent.button == 3 || pc->expecting_clicks_for_LPE == 1) { // when the last click for a waiting LPE occurs we want to finish the path
510 if (pc->npoints != 0) {
512 spdc_pen_finish_segment(pc, event_dt, bevent.state);
513 if (pc->green_closed) {
514 // finishing at the start anchor, close curve
515 spdc_pen_finish(pc, TRUE);
516 } else {
517 // finishing at some other anchor, finish curve but not close
518 spdc_pen_finish(pc, FALSE);
519 }
521 ret = TRUE;
522 }
523 }
525 if (pc->expecting_clicks_for_LPE) {
526 --pc->expecting_clicks_for_LPE;
527 }
529 return ret;
530 }
532 /**
533 * Handle motion_notify event.
534 */
535 static gint
536 pen_handle_motion_notify(SPPenContext *const pc, GdkEventMotion const &mevent)
537 {
538 gint ret = FALSE;
540 SPEventContext *event_context = SP_EVENT_CONTEXT(pc);
542 if (event_context->space_panning || mevent.state & GDK_BUTTON2_MASK || mevent.state & GDK_BUTTON3_MASK) {
543 // allow scrolling
544 return FALSE;
545 }
547 if (pc->events_disabled) {
548 // skip motion events if pen events are disabled
549 return FALSE;
550 }
552 NR::Point const event_w(mevent.x,
553 mevent.y);
554 if (pen_within_tolerance) {
555 gint const tolerance = prefs_get_int_attribute_limited("options.dragtolerance",
556 "value", 0, 0, 100);
557 if ( NR::LInfty( event_w - pen_drag_origin_w ) < tolerance ) {
558 return FALSE; // Do not drag if we're within tolerance from origin.
559 }
560 }
561 // Once the user has moved farther than tolerance from the original location
562 // (indicating they intend to move the object, not click), then always process the
563 // motion notify coordinates as given (no snapping back to origin)
564 pen_within_tolerance = false;
566 SPDesktop *const dt = pc->desktop;
567 if ( ( mevent.state & GDK_BUTTON1_MASK ) && !pc->grab ) {
568 /* Grab mouse, so release will not pass unnoticed */
569 pc->grab = SP_CANVAS_ITEM(dt->acetate);
570 sp_canvas_item_grab(pc->grab, ( GDK_KEY_PRESS_MASK | GDK_BUTTON_PRESS_MASK |
571 GDK_BUTTON_RELEASE_MASK |
572 GDK_POINTER_MOTION_MASK ),
573 NULL, mevent.time);
574 }
576 /* Find desktop coordinates */
577 NR::Point p = dt->w2d(event_w);
579 /* Test, whether we hit any anchor */
580 SPDrawAnchor *anchor = spdc_test_inside(pc, event_w);
582 switch (pc->mode) {
583 case SP_PEN_CONTEXT_MODE_CLICK:
584 switch (pc->state) {
585 case SP_PEN_CONTEXT_POINT:
586 if ( pc->npoints != 0 ) {
587 /* Only set point, if we are already appending */
588 spdc_endpoint_snap(pc, p, mevent.state);
589 spdc_pen_set_subsequent_point(pc, p, true);
590 ret = TRUE;
591 }
592 break;
593 case SP_PEN_CONTEXT_CONTROL:
594 case SP_PEN_CONTEXT_CLOSE:
595 /* Placing controls is last operation in CLOSE state */
596 spdc_endpoint_snap(pc, p, mevent.state);
597 spdc_pen_set_ctrl(pc, p, mevent.state);
598 ret = TRUE;
599 break;
600 case SP_PEN_CONTEXT_STOP:
601 /* This is perfectly valid */
602 break;
603 default:
604 break;
605 }
606 break;
607 case SP_PEN_CONTEXT_MODE_DRAG:
608 switch (pc->state) {
609 case SP_PEN_CONTEXT_POINT:
610 if ( pc->npoints > 0 ) {
611 /* Only set point, if we are already appending */
613 if (!anchor) { /* Snap node only if not hitting anchor */
614 spdc_endpoint_snap(pc, p, mevent.state);
615 }
617 spdc_pen_set_subsequent_point(pc, p, !anchor);
619 if (anchor && !pc->anchor_statusbar) {
620 pc->_message_context->set(Inkscape::NORMAL_MESSAGE, _("<b>Click</b> or <b>click and drag</b> to close and finish the path."));
621 pc->anchor_statusbar = true;
622 } else if (!anchor && pc->anchor_statusbar) {
623 pc->_message_context->clear();
624 pc->anchor_statusbar = false;
625 }
627 ret = TRUE;
628 } else {
629 if (anchor && !pc->anchor_statusbar) {
630 pc->_message_context->set(Inkscape::NORMAL_MESSAGE, _("<b>Click</b> or <b>click and drag</b> to continue the path from this point."));
631 pc->anchor_statusbar = true;
632 } else if (!anchor && pc->anchor_statusbar) {
633 pc->_message_context->clear();
634 pc->anchor_statusbar = false;
635 }
636 }
637 break;
638 case SP_PEN_CONTEXT_CONTROL:
639 case SP_PEN_CONTEXT_CLOSE:
640 /* Placing controls is last operation in CLOSE state */
642 // snap the handle
643 spdc_endpoint_snap_handle(pc, p, mevent.state);
645 if (!pc->polylines_only) {
646 spdc_pen_set_ctrl(pc, p, mevent.state);
647 } else {
648 spdc_pen_set_ctrl(pc, pc->p[1], mevent.state);
649 }
650 gobble_motion_events(GDK_BUTTON1_MASK);
651 ret = TRUE;
652 break;
653 case SP_PEN_CONTEXT_STOP:
654 /* This is perfectly valid */
655 break;
656 default:
657 break;
658 }
659 break;
660 default:
661 break;
662 }
663 return ret;
664 }
666 /**
667 * Handle mouse button release event.
668 */
669 static gint
670 pen_handle_button_release(SPPenContext *const pc, GdkEventButton const &revent)
671 {
672 if (pc->events_disabled) {
673 // skip event processing if events are disabled
674 return FALSE;
675 }
677 gint ret = FALSE;
678 SPEventContext *event_context = SP_EVENT_CONTEXT(pc);
679 if ( revent.button == 1 && !event_context->space_panning) {
681 SPDrawContext *dc = SP_DRAW_CONTEXT (pc);
683 NR::Point const event_w(revent.x,
684 revent.y);
685 /* Find desktop coordinates */
686 NR::Point p = pc->desktop->w2d(event_w);
688 /* Test whether we hit any anchor. */
689 SPDrawAnchor *anchor = spdc_test_inside(pc, event_w);
691 switch (pc->mode) {
692 case SP_PEN_CONTEXT_MODE_CLICK:
693 switch (pc->state) {
694 case SP_PEN_CONTEXT_POINT:
695 if ( pc->npoints == 0 ) {
696 /* Start new thread only with button release */
697 if (anchor) {
698 p = anchor->dp;
699 }
700 pc->sa = anchor;
701 spdc_pen_set_initial_point(pc, p);
702 } else {
703 /* Set end anchor here */
704 pc->ea = anchor;
705 if (anchor) {
706 p = anchor->dp;
707 }
708 }
709 pc->state = SP_PEN_CONTEXT_CONTROL;
710 ret = TRUE;
711 break;
712 case SP_PEN_CONTEXT_CONTROL:
713 /* End current segment */
714 spdc_endpoint_snap(pc, p, revent.state);
715 spdc_pen_finish_segment(pc, p, revent.state);
716 pc->state = SP_PEN_CONTEXT_POINT;
717 ret = TRUE;
718 break;
719 case SP_PEN_CONTEXT_CLOSE:
720 /* End current segment */
721 if (!anchor) { /* Snap node only if not hitting anchor */
722 spdc_endpoint_snap(pc, p, revent.state);
723 }
724 spdc_pen_finish_segment(pc, p, revent.state);
725 spdc_pen_finish(pc, TRUE);
726 pc->state = SP_PEN_CONTEXT_POINT;
727 ret = TRUE;
728 break;
729 case SP_PEN_CONTEXT_STOP:
730 /* This is allowed, if we just cancelled curve */
731 pc->state = SP_PEN_CONTEXT_POINT;
732 ret = TRUE;
733 break;
734 default:
735 break;
736 }
737 break;
738 case SP_PEN_CONTEXT_MODE_DRAG:
739 switch (pc->state) {
740 case SP_PEN_CONTEXT_POINT:
741 case SP_PEN_CONTEXT_CONTROL:
742 if (!pc->polylines_only) {
743 spdc_endpoint_snap(pc, p, revent.state);
744 spdc_pen_finish_segment(pc, p, revent.state);
745 }
746 break;
747 case SP_PEN_CONTEXT_CLOSE:
748 spdc_endpoint_snap(pc, p, revent.state);
749 spdc_pen_finish_segment(pc, p, revent.state);
750 if (pc->green_closed) {
751 // finishing at the start anchor, close curve
752 spdc_pen_finish(pc, TRUE);
753 } else {
754 // finishing at some other anchor, finish curve but not close
755 spdc_pen_finish(pc, FALSE);
756 }
757 break;
758 case SP_PEN_CONTEXT_STOP:
759 /* This is allowed, if we just cancelled curve */
760 break;
761 default:
762 break;
763 }
764 pc->state = SP_PEN_CONTEXT_POINT;
765 ret = TRUE;
766 break;
767 default:
768 break;
769 }
771 if (pc->grab) {
772 /* Release grab now */
773 sp_canvas_item_ungrab(pc->grab, revent.time);
774 pc->grab = NULL;
775 }
777 ret = TRUE;
779 dc->green_closed = FALSE;
780 }
782 // TODO: can we be sure that the path was created correctly?
783 // TODO: should we offer an option to collect the clicks in a list?
784 if (pc->expecting_clicks_for_LPE == 0 && sp_pen_context_has_waiting_LPE(pc)) {
785 pc->polylines_only = false;
787 SPEventContext *ec = SP_EVENT_CONTEXT(pc);
788 Inkscape::Selection *selection = sp_desktop_selection (ec->desktop);
790 if (pc->waiting_LPE) {
791 // we have an already created LPE waiting for a path
792 pc->waiting_LPE->acceptParamPath(SP_PATH(selection->singleItem()));
793 selection->add(SP_OBJECT(pc->waiting_item));
794 pc->waiting_LPE = NULL;
795 pc->polylines_only = false;
796 } else {
797 // the case that we need to create a new LPE and apply it to the just-drawn path is
798 // handled in spdc_check_for_and_apply_waiting_LPE() in draw-context.cpp
799 }
800 }
802 return ret;
803 }
805 static gint
806 pen_handle_2button_press(SPPenContext *const pc, GdkEventButton const &bevent)
807 {
808 gint ret = FALSE;
809 if (pc->npoints != 0 && bevent.button != 2) {
810 spdc_pen_finish(pc, FALSE);
811 ret = TRUE;
812 }
813 return ret;
814 }
816 void
817 pen_redraw_all (SPPenContext *const pc)
818 {
819 // green
820 if (pc->green_bpaths) {
821 // remove old piecewise green canvasitems
822 while (pc->green_bpaths) {
823 gtk_object_destroy(GTK_OBJECT(pc->green_bpaths->data));
824 pc->green_bpaths = g_slist_remove(pc->green_bpaths, pc->green_bpaths->data);
825 }
826 // one canvas bpath for all of green_curve
827 SPCanvasItem *cshape = sp_canvas_bpath_new(sp_desktop_sketch(pc->desktop), pc->green_curve);
828 sp_canvas_bpath_set_stroke(SP_CANVAS_BPATH(cshape), pc->green_color, 1.0, SP_STROKE_LINEJOIN_MITER, SP_STROKE_LINECAP_BUTT);
829 sp_canvas_bpath_set_fill(SP_CANVAS_BPATH(cshape), 0, SP_WIND_RULE_NONZERO);
831 pc->green_bpaths = g_slist_prepend(pc->green_bpaths, cshape);
832 }
834 if (pc->green_anchor)
835 SP_CTRL(pc->green_anchor->ctrl)->moveto(pc->green_anchor->dp);
837 pc->red_curve->reset();
838 pc->red_curve->moveto(pc->p[0]);
839 pc->red_curve->curveto(pc->p[1], pc->p[2], pc->p[3]);
840 sp_canvas_bpath_set_bpath(SP_CANVAS_BPATH(pc->red_bpath), pc->red_curve);
842 // handles
843 if (pc->p[0] != pc->p[1]) {
844 SP_CTRL(pc->c1)->moveto(pc->p[1]);
845 sp_ctrlline_set_coords(SP_CTRLLINE(pc->cl1), pc->p[0], pc->p[1]);
846 sp_canvas_item_show (pc->c1);
847 sp_canvas_item_show (pc->cl1);
848 } else {
849 sp_canvas_item_hide (pc->c1);
850 sp_canvas_item_hide (pc->cl1);
851 }
853 Geom::Curve const * last_seg = pc->green_curve->last_segment();
854 if (last_seg) {
855 Geom::CubicBezier const * cubic = dynamic_cast<Geom::CubicBezier const *>( last_seg );
856 if ( cubic &&
857 (*cubic)[2] != to_2geom(pc->p[0]) )
858 {
859 NR::Point p2 = from_2geom((*cubic)[2]);
860 SP_CTRL(pc->c0)->moveto(p2);
861 sp_ctrlline_set_coords(SP_CTRLLINE(pc->cl0), p2, pc->p[0]);
862 sp_canvas_item_show (pc->c0);
863 sp_canvas_item_show (pc->cl0);
864 } else {
865 sp_canvas_item_hide (pc->c0);
866 sp_canvas_item_hide (pc->cl0);
867 }
868 }
869 }
871 void
872 pen_lastpoint_move (SPPenContext *const pc, gdouble x, gdouble y)
873 {
874 if (pc->npoints != 5)
875 return;
877 // green
878 if (!pc->green_curve->is_empty()) {
879 pc->green_curve->last_point_additive_move( Geom::Point(x,y) );
880 } else {
881 // start anchor too
882 if (pc->green_anchor) {
883 pc->green_anchor->dp += NR::Point(x, y);
884 }
885 }
887 // red
888 pc->p[0] += NR::Point(x, y);
889 pc->p[1] += NR::Point(x, y);
890 pen_redraw_all(pc);
891 }
893 void
894 pen_lastpoint_move_screen (SPPenContext *const pc, gdouble x, gdouble y)
895 {
896 pen_lastpoint_move (pc, x / pc->desktop->current_zoom(), y / pc->desktop->current_zoom());
897 }
899 void
900 pen_lastpoint_tocurve (SPPenContext *const pc)
901 {
902 if (pc->npoints != 5)
903 return;
905 Geom::CubicBezier const * cubic = dynamic_cast<Geom::CubicBezier const *>( pc->green_curve->last_segment() );
906 if ( cubic ) {
907 pc->p[1] = pc->p[0] + from_2geom( (*cubic)[3] - (*cubic)[2] );
908 } else {
909 pc->p[1] = pc->p[0] + (1./3)*(pc->p[3] - pc->p[0]);
910 }
912 pen_redraw_all(pc);
913 }
915 void
916 pen_lastpoint_toline (SPPenContext *const pc)
917 {
918 if (pc->npoints != 5)
919 return;
921 pc->p[1] = pc->p[0];
923 pen_redraw_all(pc);
924 }
927 static gint
928 pen_handle_key_press(SPPenContext *const pc, GdkEvent *event)
929 {
930 gint ret = FALSE;
931 gdouble const nudge = prefs_get_double_attribute_limited("options.nudgedistance", "value", 2, 0, 1000); // in px
933 switch (get_group0_keyval (&event->key)) {
935 case GDK_Left: // move last point left
936 case GDK_KP_Left:
937 case GDK_KP_4:
938 if (!MOD__CTRL) { // not ctrl
939 if (MOD__ALT) { // alt
940 if (MOD__SHIFT) pen_lastpoint_move_screen(pc, -10, 0); // shift
941 else pen_lastpoint_move_screen(pc, -1, 0); // no shift
942 }
943 else { // no alt
944 if (MOD__SHIFT) pen_lastpoint_move(pc, -10*nudge, 0); // shift
945 else pen_lastpoint_move(pc, -nudge, 0); // no shift
946 }
947 ret = TRUE;
948 }
949 break;
950 case GDK_Up: // move last point up
951 case GDK_KP_Up:
952 case GDK_KP_8:
953 if (!MOD__CTRL) { // not ctrl
954 if (MOD__ALT) { // alt
955 if (MOD__SHIFT) pen_lastpoint_move_screen(pc, 0, 10); // shift
956 else pen_lastpoint_move_screen(pc, 0, 1); // no shift
957 }
958 else { // no alt
959 if (MOD__SHIFT) pen_lastpoint_move(pc, 0, 10*nudge); // shift
960 else pen_lastpoint_move(pc, 0, nudge); // no shift
961 }
962 ret = TRUE;
963 }
964 break;
965 case GDK_Right: // move last point right
966 case GDK_KP_Right:
967 case GDK_KP_6:
968 if (!MOD__CTRL) { // not ctrl
969 if (MOD__ALT) { // alt
970 if (MOD__SHIFT) pen_lastpoint_move_screen(pc, 10, 0); // shift
971 else pen_lastpoint_move_screen(pc, 1, 0); // no shift
972 }
973 else { // no alt
974 if (MOD__SHIFT) pen_lastpoint_move(pc, 10*nudge, 0); // shift
975 else pen_lastpoint_move(pc, nudge, 0); // no shift
976 }
977 ret = TRUE;
978 }
979 break;
980 case GDK_Down: // move last point down
981 case GDK_KP_Down:
982 case GDK_KP_2:
983 if (!MOD__CTRL) { // not ctrl
984 if (MOD__ALT) { // alt
985 if (MOD__SHIFT) pen_lastpoint_move_screen(pc, 0, -10); // shift
986 else pen_lastpoint_move_screen(pc, 0, -1); // no shift
987 }
988 else { // no alt
989 if (MOD__SHIFT) pen_lastpoint_move(pc, 0, -10*nudge); // shift
990 else pen_lastpoint_move(pc, 0, -nudge); // no shift
991 }
992 ret = TRUE;
993 }
994 break;
996 case GDK_P:
997 case GDK_p:
998 if (MOD__SHIFT_ONLY) {
999 sp_pen_context_wait_for_LPE_mouse_clicks(pc, Inkscape::LivePathEffect::PARALLEL, 2);
1000 ret = TRUE;
1001 }
1002 break;
1004 case GDK_C:
1005 case GDK_c:
1006 if (MOD__SHIFT_ONLY) {
1007 sp_pen_context_wait_for_LPE_mouse_clicks(pc, Inkscape::LivePathEffect::CIRCLE_3PTS, 3);
1008 ret = TRUE;
1009 }
1010 break;
1012 case GDK_B:
1013 case GDK_b:
1014 if (MOD__SHIFT_ONLY) {
1015 sp_pen_context_wait_for_LPE_mouse_clicks(pc, Inkscape::LivePathEffect::PERP_BISECTOR, 2);
1016 ret = TRUE;
1017 }
1018 break;
1020 case GDK_A:
1021 case GDK_a:
1022 if (MOD__SHIFT_ONLY) {
1023 sp_pen_context_wait_for_LPE_mouse_clicks(pc, Inkscape::LivePathEffect::ANGLE_BISECTOR, 3);
1024 ret = TRUE;
1025 }
1026 break;
1028 case GDK_U:
1029 case GDK_u:
1030 if (MOD__SHIFT_ONLY) {
1031 pen_lastpoint_tocurve(pc);
1032 ret = TRUE;
1033 }
1034 break;
1035 case GDK_L:
1036 case GDK_l:
1037 if (MOD__SHIFT_ONLY) {
1038 pen_lastpoint_toline(pc);
1039 ret = TRUE;
1040 }
1041 break;
1043 case GDK_Return:
1044 case GDK_KP_Enter:
1045 if (pc->npoints != 0) {
1046 spdc_pen_finish(pc, FALSE);
1047 ret = TRUE;
1048 }
1049 break;
1050 case GDK_Escape:
1051 if (pc->npoints != 0) {
1052 // if drawing, cancel, otherwise pass it up for deselecting
1053 pen_cancel (pc);
1054 ret = TRUE;
1055 }
1056 break;
1057 case GDK_z:
1058 case GDK_Z:
1059 if (MOD__CTRL_ONLY && pc->npoints != 0) {
1060 // if drawing, cancel, otherwise pass it up for undo
1061 pen_cancel (pc);
1062 ret = TRUE;
1063 }
1064 break;
1065 case GDK_g:
1066 case GDK_G:
1067 if (MOD__SHIFT_ONLY) {
1068 sp_selection_to_guides();
1069 ret = true;
1070 }
1071 break;
1072 case GDK_BackSpace:
1073 case GDK_Delete:
1074 case GDK_KP_Delete:
1075 if (pc->green_curve->is_empty()) {
1076 if (!pc->red_curve->is_empty()) {
1077 pen_cancel (pc);
1078 ret = TRUE;
1079 } else {
1080 // do nothing; this event should be handled upstream
1081 }
1082 } else {
1083 /* Reset red curve */
1084 pc->red_curve->reset();
1085 /* Destroy topmost green bpath */
1086 if (pc->green_bpaths) {
1087 if (pc->green_bpaths->data)
1088 gtk_object_destroy(GTK_OBJECT(pc->green_bpaths->data));
1089 pc->green_bpaths = g_slist_remove(pc->green_bpaths, pc->green_bpaths->data);
1090 }
1091 /* Get last segment */
1092 NArtBpath const *const p = SP_CURVE_BPATH(pc->green_curve);
1093 gint const e = SP_CURVE_LENGTH(pc->green_curve);
1094 if ( e < 2 ) {
1095 g_warning("Green curve length is %d", e);
1096 break;
1097 }
1098 pc->p[0] = p[e - 2].c(3);
1099 if (p[e - 1].code == NR_CURVETO) {
1100 pc->p[1] = p[e - 1].c(1);
1101 } else {
1102 pc->p[1] = pc->p[0];
1103 }
1104 NR::Point const pt(( pc->npoints < 4
1105 ? p[e - 1].c(3)
1106 : pc->p[3] ));
1107 pc->npoints = 2;
1108 pc->green_curve->backspace();
1109 sp_canvas_item_hide(pc->c0);
1110 sp_canvas_item_hide(pc->c1);
1111 sp_canvas_item_hide(pc->cl0);
1112 sp_canvas_item_hide(pc->cl1);
1113 pc->state = SP_PEN_CONTEXT_POINT;
1114 spdc_pen_set_subsequent_point(pc, pt, true);
1115 ret = TRUE;
1116 }
1117 break;
1118 default:
1119 break;
1120 }
1121 return ret;
1122 }
1124 static void
1125 spdc_reset_colors(SPPenContext *pc)
1126 {
1127 /* Red */
1128 pc->red_curve->reset();
1129 sp_canvas_bpath_set_bpath(SP_CANVAS_BPATH(pc->red_bpath), NULL);
1130 /* Blue */
1131 pc->blue_curve->reset();
1132 sp_canvas_bpath_set_bpath(SP_CANVAS_BPATH(pc->blue_bpath), NULL);
1133 /* Green */
1134 while (pc->green_bpaths) {
1135 gtk_object_destroy(GTK_OBJECT(pc->green_bpaths->data));
1136 pc->green_bpaths = g_slist_remove(pc->green_bpaths, pc->green_bpaths->data);
1137 }
1138 pc->green_curve->reset();
1139 if (pc->green_anchor) {
1140 pc->green_anchor = sp_draw_anchor_destroy(pc->green_anchor);
1141 }
1142 pc->sa = NULL;
1143 pc->ea = NULL;
1144 pc->npoints = 0;
1145 pc->red_curve_is_valid = false;
1146 }
1149 static void
1150 spdc_pen_set_initial_point(SPPenContext *const pc, NR::Point const p)
1151 {
1152 g_assert( pc->npoints == 0 );
1154 pc->p[0] = p;
1155 pc->p[1] = p;
1156 pc->npoints = 2;
1157 sp_canvas_bpath_set_bpath(SP_CANVAS_BPATH(pc->red_bpath), NULL);
1159 sp_canvas_force_full_redraw_after_interruptions(pc->desktop->canvas, 5);
1160 }
1162 /**
1163 * Show the status message for the current line/curve segment.
1164 * This type of message always shows angle/distance as the last
1165 * two parameters ("angle %3.2f°, distance %s").
1166 */
1167 static void
1168 spdc_pen_set_angle_distance_status_message(SPPenContext *const pc, NR::Point const p, int pc_point_to_compare, gchar const *message)
1169 {
1170 g_assert(pc != NULL);
1171 g_assert((pc_point_to_compare == 0) || (pc_point_to_compare == 3)); // exclude control handles
1172 g_assert(message != NULL);
1174 SPDesktop *desktop = SP_EVENT_CONTEXT(pc)->desktop;
1175 NR::Point rel = p - pc->p[pc_point_to_compare];
1176 GString *dist = SP_PX_TO_METRIC_STRING(NR::L2(rel), desktop->namedview->getDefaultMetric());
1177 double angle = atan2(rel[NR::Y], rel[NR::X]) * 180 / M_PI;
1178 if (prefs_get_int_attribute("options.compassangledisplay", "value", 0) != 0)
1179 angle = angle_to_compass (angle);
1181 pc->_message_context->setF(Inkscape::IMMEDIATE_MESSAGE, message, angle, dist->str);
1182 g_string_free(dist, FALSE);
1183 }
1185 static void
1186 spdc_pen_set_subsequent_point(SPPenContext *const pc, NR::Point const p, bool statusbar)
1187 {
1188 g_assert( pc->npoints != 0 );
1189 /* todo: Check callers to see whether 2 <= npoints is guaranteed. */
1191 pc->p[2] = p;
1192 pc->p[3] = p;
1193 pc->p[4] = p;
1194 pc->npoints = 5;
1195 pc->red_curve->reset();
1196 pc->red_curve->moveto(pc->p[0]);
1197 bool is_curve;
1198 if (pc->p[1] != pc->p[0])
1199 {
1200 pc->red_curve->curveto(pc->p[1], p, p);
1201 is_curve = true;
1202 } else {
1203 pc->red_curve->lineto(p);
1204 is_curve = false;
1205 }
1207 sp_canvas_bpath_set_bpath(SP_CANVAS_BPATH(pc->red_bpath), pc->red_curve);
1209 if (statusbar) {
1210 gchar *message = is_curve ?
1211 _("<b>Curve segment</b>: angle %3.2f°, distance %s; with <b>Ctrl</b> to snap angle, <b>Enter</b> to finish the path" ):
1212 _("<b>Line segment</b>: angle %3.2f°, distance %s; with <b>Ctrl</b> to snap angle, <b>Enter</b> to finish the path");
1213 spdc_pen_set_angle_distance_status_message(pc, p, 0, message);
1214 }
1215 }
1217 static void
1218 spdc_pen_set_ctrl(SPPenContext *const pc, NR::Point const p, guint const state)
1219 {
1220 sp_canvas_item_show(pc->c1);
1221 sp_canvas_item_show(pc->cl1);
1223 if ( pc->npoints == 2 ) {
1224 pc->p[1] = p;
1225 sp_canvas_item_hide(pc->c0);
1226 sp_canvas_item_hide(pc->cl0);
1227 SP_CTRL(pc->c1)->moveto(pc->p[1]);
1228 sp_ctrlline_set_coords(SP_CTRLLINE(pc->cl1), pc->p[0], pc->p[1]);
1230 spdc_pen_set_angle_distance_status_message(pc, p, 0, _("<b>Curve handle</b>: angle %3.2f°, length %s; with <b>Ctrl</b> to snap angle"));
1231 } else if ( pc->npoints == 5 ) {
1232 pc->p[4] = p;
1233 sp_canvas_item_show(pc->c0);
1234 sp_canvas_item_show(pc->cl0);
1235 bool is_symm = false;
1236 if ( ( ( pc->mode == SP_PEN_CONTEXT_MODE_CLICK ) && ( state & GDK_CONTROL_MASK ) ) ||
1237 ( ( pc->mode == SP_PEN_CONTEXT_MODE_DRAG ) && !( state & GDK_SHIFT_MASK ) ) ) {
1238 NR::Point delta = p - pc->p[3];
1239 pc->p[2] = pc->p[3] - delta;
1240 is_symm = true;
1241 pc->red_curve->reset();
1242 pc->red_curve->moveto(pc->p[0]);
1243 pc->red_curve->curveto(pc->p[1], pc->p[2], pc->p[3]);
1244 sp_canvas_bpath_set_bpath(SP_CANVAS_BPATH(pc->red_bpath), pc->red_curve);
1245 }
1246 SP_CTRL(pc->c0)->moveto(pc->p[2]);
1247 sp_ctrlline_set_coords(SP_CTRLLINE(pc->cl0), pc->p[3], pc->p[2]);
1248 SP_CTRL(pc->c1)->moveto(pc->p[4]);
1249 sp_ctrlline_set_coords(SP_CTRLLINE(pc->cl1), pc->p[3], pc->p[4]);
1251 gchar *message = is_symm ?
1252 _("<b>Curve handle, symmetric</b>: angle %3.2f°, length %s; with <b>Ctrl</b> to snap angle, with <b>Shift</b> to move this handle only") :
1253 _("<b>Curve handle</b>: angle %3.2f°, length %s; with <b>Ctrl</b> to snap angle, with <b>Shift</b> to move this handle only");
1254 spdc_pen_set_angle_distance_status_message(pc, p, 3, message);
1255 } else {
1256 g_warning("Something bad happened - npoints is %d", pc->npoints);
1257 }
1258 }
1260 static void
1261 spdc_pen_finish_segment(SPPenContext *const pc, NR::Point const /*p*/, guint const /*state*/)
1262 {
1263 if (!pc->red_curve->is_empty()) {
1264 pc->green_curve->append_continuous(pc->red_curve, 0.0625);
1265 SPCurve *curve = pc->red_curve->copy();
1266 /// \todo fixme:
1267 SPCanvasItem *cshape = sp_canvas_bpath_new(sp_desktop_sketch(pc->desktop), curve);
1268 curve->unref();
1269 sp_canvas_bpath_set_stroke(SP_CANVAS_BPATH(cshape), pc->green_color, 1.0, SP_STROKE_LINEJOIN_MITER, SP_STROKE_LINECAP_BUTT);
1271 pc->green_bpaths = g_slist_prepend(pc->green_bpaths, cshape);
1273 pc->p[0] = pc->p[3];
1274 pc->p[1] = pc->p[4];
1275 pc->npoints = 2;
1277 pc->red_curve->reset();
1278 }
1279 }
1281 static void
1282 spdc_pen_finish(SPPenContext *const pc, gboolean const closed)
1283 {
1284 if (pc->expecting_clicks_for_LPE > 1) {
1285 // don't let the path be finished before we have collected the required number of mouse clicks
1286 return;
1287 }
1289 pen_disable_events(pc);
1291 SPDesktop *const desktop = pc->desktop;
1292 pc->_message_context->clear();
1293 desktop->messageStack()->flash(Inkscape::NORMAL_MESSAGE, _("Drawing finished"));
1295 pc->red_curve->reset();
1296 spdc_concat_colors_and_flush(pc, closed);
1297 pc->sa = NULL;
1298 pc->ea = NULL;
1300 pc->npoints = 0;
1301 pc->state = SP_PEN_CONTEXT_POINT;
1303 sp_canvas_item_hide(pc->c0);
1304 sp_canvas_item_hide(pc->c1);
1305 sp_canvas_item_hide(pc->cl0);
1306 sp_canvas_item_hide(pc->cl1);
1308 if (pc->green_anchor) {
1309 pc->green_anchor = sp_draw_anchor_destroy(pc->green_anchor);
1310 }
1313 sp_canvas_end_forced_full_redraws(pc->desktop->canvas);
1315 pen_enable_events(pc);
1316 }
1318 static void
1319 pen_disable_events(SPPenContext *const pc) {
1320 pc->events_disabled++;
1321 }
1323 static void
1324 pen_enable_events(SPPenContext *const pc) {
1325 g_return_if_fail(pc->events_disabled != 0);
1327 pc->events_disabled--;
1328 }
1330 void
1331 sp_pen_context_wait_for_LPE_mouse_clicks(SPPenContext *pc, Inkscape::LivePathEffect::EffectType effect_type,
1332 unsigned int num_clicks, bool use_polylines)
1333 {
1334 g_print ("Now waiting for %s to be applied\n",
1335 Inkscape::LivePathEffect::LPETypeConverter.get_label(effect_type).c_str());
1336 pc->expecting_clicks_for_LPE = num_clicks;
1337 pc->polylines_only = use_polylines;
1338 pc->waiting_LPE_type = effect_type;
1339 }
1341 /*
1342 Local Variables:
1343 mode:c++
1344 c-file-style:"stroustrup"
1345 c-file-offsets:((innamespace . 0)(inline-open . 0)(case-label . +))
1346 indent-tabs-mode:nil
1347 fill-column:99
1348 End:
1349 */
1350 // vim: filetype=cpp:expandtab:shiftwidth=4:tabstop=8:softtabstop=4:encoding=utf-8:textwidth=99 :