Code

remove many unnecessary to_2geom and from_2geom calls
[inkscape.git] / src / draw-context.cpp
1 #define __SP_DRAW_CONTEXT_C__
3 /*
4  * Generic drawing context
5  *
6  * Author:
7  *   Lauris Kaplinski <lauris@kaplinski.com>
8  *
9  * Copyright (C) 2000 Lauris Kaplinski
10  * Copyright (C) 2000-2001 Ximian, Inc.
11  * Copyright (C) 2002 Lauris Kaplinski
12  *
13  * Released under GNU GPL, read the file 'COPYING' for more information
14  */
16 #define DRAW_VERBOSE
18 #ifdef HAVE_CONFIG_H
19 # include "config.h"
20 #endif
21 #include <gdk/gdkkeysyms.h>
23 #include "display/canvas-bpath.h"
24 #include "xml/repr.h"
25 #include "svg/svg.h"
26 #include <glibmm/i18n.h>
27 #include "display/curve.h"
28 #include "desktop.h"
29 #include "desktop-affine.h"
30 #include "desktop-handles.h"
31 #include "desktop-style.h"
32 #include "document.h"
33 #include "draw-anchor.h"
34 #include "macros.h"
35 #include "message-stack.h"
36 #include "pen-context.h"
37 #include "prefs-utils.h"
38 #include "selection.h"
39 #include "selection-chemistry.h"
40 #include "snap.h"
41 #include "sp-path.h"
42 #include "sp-namedview.h"
43 #include "live_effects/lpe-patternalongpath.h"
44 #include "style.h"
46 static void sp_draw_context_class_init(SPDrawContextClass *klass);
47 static void sp_draw_context_init(SPDrawContext *dc);
48 static void sp_draw_context_dispose(GObject *object);
50 static void sp_draw_context_setup(SPEventContext *ec);
51 static void sp_draw_context_set(SPEventContext *ec, gchar const *key, gchar const *value);
52 static void sp_draw_context_finish(SPEventContext *ec);
54 static gint sp_draw_context_root_handler(SPEventContext *event_context, GdkEvent *event);
56 static void spdc_selection_changed(Inkscape::Selection *sel, SPDrawContext *dc);
57 static void spdc_selection_modified(Inkscape::Selection *sel, guint flags, SPDrawContext *dc);
59 static void spdc_attach_selection(SPDrawContext *dc, Inkscape::Selection *sel);
61 static void spdc_flush_white(SPDrawContext *dc, SPCurve *gc);
63 static void spdc_reset_white(SPDrawContext *dc);
64 static void spdc_free_colors(SPDrawContext *dc);
67 static SPEventContextClass *draw_parent_class;
70 GType
71 sp_draw_context_get_type(void)
72 {
73     static GType type = 0;
74     if (!type) {
75         GTypeInfo info = {
76             sizeof(SPDrawContextClass),
77             NULL, NULL,
78             (GClassInitFunc) sp_draw_context_class_init,
79             NULL, NULL,
80             sizeof(SPDrawContext),
81             4,
82             (GInstanceInitFunc) sp_draw_context_init,
83             NULL,   /* value_table */
84         };
85         type = g_type_register_static(SP_TYPE_EVENT_CONTEXT, "SPDrawContext", &info, (GTypeFlags)0);
86     }
87     return type;
88 }
90 static void
91 sp_draw_context_class_init(SPDrawContextClass *klass)
92 {
93     GObjectClass *object_class;
94     SPEventContextClass *ec_class;
96     object_class = (GObjectClass *)klass;
97     ec_class = (SPEventContextClass *) klass;
99     draw_parent_class = (SPEventContextClass*)g_type_class_peek_parent(klass);
101     object_class->dispose = sp_draw_context_dispose;
103     ec_class->setup = sp_draw_context_setup;
104     ec_class->set = sp_draw_context_set;
105     ec_class->finish = sp_draw_context_finish;
106     ec_class->root_handler = sp_draw_context_root_handler;
109 static void
110 sp_draw_context_init(SPDrawContext *dc)
112     dc->attach = FALSE;
114     dc->red_color = 0xff00007f;
115     dc->blue_color = 0x0000ff7f;
116     dc->green_color = 0x00ff007f;
117     dc->red_curve_is_valid = false;
119     dc->waiting_LPE_type = Inkscape::LivePathEffect::INVALID_LPE;
121     new (&dc->sel_changed_connection) sigc::connection();
122     new (&dc->sel_modified_connection) sigc::connection();
125 static void
126 sp_draw_context_dispose(GObject *object)
128     SPDrawContext *dc = SP_DRAW_CONTEXT(object);
130     dc->sel_changed_connection.~connection();
131     dc->sel_modified_connection.~connection();
133     if (dc->grab) {
134         sp_canvas_item_ungrab(dc->grab, GDK_CURRENT_TIME);
135         dc->grab = NULL;
136     }
138     if (dc->selection) {
139         dc->selection = NULL;
140     }
142     dc->waiting_LPE_type = Inkscape::LivePathEffect::INVALID_LPE;
144     spdc_free_colors(dc);
146     G_OBJECT_CLASS(draw_parent_class)->dispose(object);
149 static void
150 sp_draw_context_setup(SPEventContext *ec)
152     SPDrawContext *dc = SP_DRAW_CONTEXT(ec);
153     SPDesktop *dt = ec->desktop;
155     if (((SPEventContextClass *) draw_parent_class)->setup) {
156         ((SPEventContextClass *) draw_parent_class)->setup(ec);
157     }
159     dc->selection = sp_desktop_selection(dt);
161     /* Connect signals to track selection changes */
162     dc->sel_changed_connection = dc->selection->connectChanged(
163         sigc::bind(sigc::ptr_fun(&spdc_selection_changed), dc)
164     );
165     dc->sel_modified_connection = dc->selection->connectModified(
166         sigc::bind(sigc::ptr_fun(&spdc_selection_modified), dc)
167     );
169     /* Create red bpath */
170     dc->red_bpath = sp_canvas_bpath_new(sp_desktop_sketch(ec->desktop), NULL);
171     sp_canvas_bpath_set_stroke(SP_CANVAS_BPATH(dc->red_bpath), dc->red_color, 1.0, SP_STROKE_LINEJOIN_MITER, SP_STROKE_LINECAP_BUTT);
172     /* Create red curve */
173     dc->red_curve = new SPCurve();
175     /* Create blue bpath */
176     dc->blue_bpath = sp_canvas_bpath_new(sp_desktop_sketch(ec->desktop), NULL);
177     sp_canvas_bpath_set_stroke(SP_CANVAS_BPATH(dc->blue_bpath), dc->blue_color, 1.0, SP_STROKE_LINEJOIN_MITER, SP_STROKE_LINECAP_BUTT);
178     /* Create blue curve */
179     dc->blue_curve = new SPCurve();
181     /* Create green curve */
182     dc->green_curve = new SPCurve();
183     /* No green anchor by default */
184     dc->green_anchor = NULL;
185     dc->green_closed = FALSE;
187     dc->attach = TRUE;
188     spdc_attach_selection(dc, dc->selection);
191 static void
192 sp_draw_context_finish(SPEventContext *ec)
194     SPDrawContext *dc = SP_DRAW_CONTEXT(ec);
196     dc->sel_changed_connection.disconnect();
197     dc->sel_modified_connection.disconnect();
199     if (dc->grab) {
200         sp_canvas_item_ungrab(dc->grab, GDK_CURRENT_TIME);
201     }
203     if (dc->selection) {
204         dc->selection = NULL;
205     }
207     spdc_free_colors(dc);
210 static void
211 sp_draw_context_set(SPEventContext */*ec*/, const gchar */*key*/, const gchar */*value*/)
215 gint
216 sp_draw_context_root_handler(SPEventContext *ec, GdkEvent *event)
218     gint ret = FALSE;
220     switch (event->type) {
221         case GDK_KEY_PRESS:
222             switch (get_group0_keyval (&event->key)) {
223                 case GDK_Up:
224                 case GDK_Down:
225                 case GDK_KP_Up:
226                 case GDK_KP_Down:
227                     // prevent the zoom field from activation
228                     if (!MOD__CTRL_ONLY) {
229                         ret = TRUE;
230                     }
231                     break;
232                 default:
233             break;
234         }
235         break;
236     default:
237         break;
238     }
240     if (!ret) {
241         if (((SPEventContextClass *) draw_parent_class)->root_handler) {
242             ret = ((SPEventContextClass *) draw_parent_class)->root_handler(ec, event);
243         }
244     }
246     return ret;
249 static char const *
250 tool_name(SPDrawContext *dc)
252     return ( SP_IS_PEN_CONTEXT(dc)
253              ? "tools.freehand.pen"
254              : "tools.freehand.pencil" );
257 static void
258 spdc_paste_curve_as_freehand_shape(const SPCurve *c, SPDrawContext *dc, SPItem *item)
260     using namespace Inkscape::LivePathEffect;
262     // TODO: Don't paste path if nothing is on the clipboard
264     Effect::createAndApply(Inkscape::LivePathEffect::FREEHAND_SHAPE, dc->desktop->doc(), item);
265     Effect* lpe = sp_lpe_item_get_current_lpe(SP_LPE_ITEM(item));
266     gchar *svgd = sp_svg_write_path(c->get_pathvector());
267     static_cast<LPEPatternAlongPath*>(lpe)->pattern.paste_param_path(svgd);
270 /*
271  * If we have an item and a waiting LPE, apply the effect to the item
272  * (spiro spline mode is treated separately)
273  */
274 void
275 spdc_check_for_and_apply_waiting_LPE(SPDrawContext *dc, SPItem *item)
277     using namespace Inkscape::LivePathEffect;
279     if (item && SP_IS_LPE_ITEM(item)) {
280         if (prefs_get_int_attribute(tool_name(dc), "freehand-mode", 0) == 1) {
281             Effect::createAndApply(SPIRO, dc->desktop->doc(), item);
282         }
284         int shape = prefs_get_int_attribute(tool_name(dc), "shape", 0);
285         bool shape_applied = false;
286         SPCSSAttr *css_item = sp_css_attr_from_object (SP_OBJECT(item), SP_STYLE_FLAG_ALWAYS);
287         const char *cstroke = sp_repr_css_property(css_item, "stroke", "none");
289 #define SHAPE_LENGTH 100
290 #define SHAPE_HEIGHT 10
292         switch (shape) {
293             case 0:
294                 // don't apply any shape
295                 break;
296             case 1:
297             {
298                 // "triangle in"
299                 // TODO: this is only for illustration (we create a "decrescendo"-shaped path
300                 //       manually; eventually we should read the path from a separate file)
301                 SPCurve *c = new SPCurve();
302                 c->moveto(0,0);
303                 c->lineto(0, SHAPE_HEIGHT);
304                 c->lineto(SHAPE_LENGTH, SHAPE_HEIGHT/2);
305                 c->closepath();
306                 spdc_paste_curve_as_freehand_shape(c, dc, item);
307                 c->unref();
309                 shape_applied = true;
310                 break;
311             }
312             case 2:
313             {
314                 // "triangle out"
315                 SPCurve *c = new SPCurve();
316                 c->moveto(0, SHAPE_HEIGHT/2);
317                 c->lineto(SHAPE_LENGTH, SHAPE_HEIGHT);
318                 c->lineto(SHAPE_LENGTH, 0);
319                 c->closepath();
320                 spdc_paste_curve_as_freehand_shape(c, dc, item);
321                 c->unref();
323                 shape_applied = true;
324                 break;
325             }
326             case 3:
327             {
328                 // "ellipse"
329                 SPCurve *c = new SPCurve();
330                 const double C1 = 0.552;
331                 c->moveto(0, SHAPE_HEIGHT/2);
332                 c->curveto(0, (1 - C1) * SHAPE_HEIGHT/2, (1 - C1) * SHAPE_LENGTH/2, 0, SHAPE_LENGTH/2, 0);
333                 c->curveto((1 + C1) * SHAPE_LENGTH/2, 0, SHAPE_LENGTH, (1 - C1) * SHAPE_HEIGHT/2, SHAPE_LENGTH, SHAPE_HEIGHT/2);
334                 c->curveto(SHAPE_LENGTH, (1 + C1) * SHAPE_HEIGHT/2, (1 + C1) * SHAPE_LENGTH/2, SHAPE_HEIGHT, SHAPE_LENGTH/2, SHAPE_HEIGHT);
335                 c->curveto((1 - C1) * SHAPE_LENGTH/2, SHAPE_HEIGHT, 0, (1 + C1) * SHAPE_HEIGHT/2, 0, SHAPE_HEIGHT/2);
336                 c->closepath();
337                 spdc_paste_curve_as_freehand_shape(c, dc, item);
338                 c->unref();
339                 shape_applied = true;
340                 break;
341             }
342             case 4:
343             {
344                 // take shape from clipboard; TODO: catch the case where clipboard is empty
345                 Effect::createAndApply(FREEHAND_SHAPE, dc->desktop->doc(), item);
346                 Effect* lpe = sp_lpe_item_get_current_lpe(SP_LPE_ITEM(item));
347                 static_cast<LPEPatternAlongPath*>(lpe)->pattern.on_paste_button_click();
349                 shape_applied = true;
350                 break;
351             }
352             default:
353                 break;
354         }
355         if (shape_applied) {
356             // apply original stroke color as fill and unset stroke; then return
357             SPCSSAttr *css = sp_repr_css_attr_new();
358             sp_repr_css_set_property (css, "fill", cstroke);
359             sp_repr_css_set_property (css, "stroke", "none");
360             sp_desktop_apply_css_recursive(SP_OBJECT(item), css, true);
361             sp_repr_css_attr_unref(css);
362             return;
363         }
365         if (dc->waiting_LPE_type != INVALID_LPE) {
366             Effect::createAndApply(dc->waiting_LPE_type, dc->desktop->doc(), item);
367             dc->waiting_LPE_type = INVALID_LPE;
368         }
369         if (SP_IS_PEN_CONTEXT(dc)) {
370             sp_pen_context_set_polyline_mode(SP_PEN_CONTEXT(dc));
371         }
372     }
375 /*
376  * Selection handlers
377  */
379 static void
380 spdc_selection_changed(Inkscape::Selection *sel, SPDrawContext *dc)
382     if (dc->attach) {
383         spdc_attach_selection(dc, sel);
384     }
387 /* fixme: We have to ensure this is not delayed (Lauris) */
389 static void
390 spdc_selection_modified(Inkscape::Selection *sel, guint /*flags*/, SPDrawContext *dc)
392     if (dc->attach) {
393         spdc_attach_selection(dc, sel);
394     }
397 static void
398 spdc_attach_selection(SPDrawContext *dc, Inkscape::Selection */*sel*/)
400     /* We reset white and forget white/start/end anchors */
401     spdc_reset_white(dc);
402     dc->sa = NULL;
403     dc->ea = NULL;
405     SPItem *item = dc->selection ? dc->selection->singleItem() : NULL;
407     if ( item && SP_IS_PATH(item) ) {
408         /* Create new white data */
409         /* Item */
410         dc->white_item = item;
411         /* Curve list */
412         /* We keep it in desktop coordinates to eliminate calculation errors */
413         SPCurve *norm = sp_path_get_curve_for_edit (SP_PATH(item));
414         norm->transform(sp_item_i2d_affine(dc->white_item));
415         g_return_if_fail( norm != NULL );
416         dc->white_curves = g_slist_reverse(norm->split());
417         norm->unref();
418         /* Anchor list */
419         for (GSList *l = dc->white_curves; l != NULL; l = l->next) {
420             SPCurve *c;
421             c = (SPCurve*)l->data;
422             g_return_if_fail( c->get_segment_count() > 0 );
423             if ( !c->is_closed() ) {
424                 SPDrawAnchor *a;
425                 a = sp_draw_anchor_new(dc, c, TRUE, c->first_point());
426                 dc->white_anchors = g_slist_prepend(dc->white_anchors, a);
427                 a = sp_draw_anchor_new(dc, c, FALSE, c->last_point());
428                 dc->white_anchors = g_slist_prepend(dc->white_anchors, a);
429             }
430         }
431         /* fixme: recalculate active anchor? */
432     }
436 /**
437  *  Snaps node or handle to PI/rotationsnapsperpi degree increments.
438  *
439  *  \param dc draw context
440  *  \param p cursor point (to be changed by snapping)
441  *  \param o origin point
442  *  \param state  keyboard state to check if ctrl was pressed
443 */
445 void spdc_endpoint_snap_rotation(SPEventContext const *const ec, NR::Point &p, NR::Point const &o,
446                                  guint state)
448     unsigned const snaps = abs(prefs_get_int_attribute("options.rotationsnapsperpi", "value", 12));
449     /* 0 means no snapping. */
451     /* mirrored by fabs, so this corresponds to 15 degrees */
452     NR::Point best; /* best solution */
453     double bn = NR_HUGE; /* best normal */
454     double bdot = 0;
455     NR::Point v = NR::Point(0, 1);
456     double const r00 = cos(M_PI / snaps), r01 = sin(M_PI / snaps);
457     double const r10 = -r01, r11 = r00;
459     NR::Point delta = p - o;
461     for (unsigned i = 0; i < snaps; i++) {
462         double const ndot = fabs(dot(v,NR::rot90(delta)));
463         NR::Point t(r00*v[NR::X] + r01*v[NR::Y],
464                     r10*v[NR::X] + r11*v[NR::Y]);
465         if (ndot < bn) {
466             /* I think it is better numerically to use the normal, rather than the dot product
467              * to assess solutions, but I haven't proven it. */
468             bn = ndot;
469             best = v;
470             bdot = dot(v, delta);
471         }
472         v = t;
473     }
475     if (fabs(bdot) > 0) {
476         p = o + bdot * best;
478         if (!(state & GDK_SHIFT_MASK)) { //SHIFT disables all snapping, except the angular snapping above
479                                          //After all, the user explicitely asked for angular snapping by
480                                          //pressing CTRL
481             /* Snap it along best vector */
482             SnapManager &m = SP_EVENT_CONTEXT_DESKTOP(ec)->namedview->snap_manager;
483             m.setup(SP_EVENT_CONTEXT_DESKTOP(ec), NULL);
484             m.constrainedSnapReturnByRef( Inkscape::Snapper::SNAPPOINT_NODE, p, Inkscape::Snapper::ConstraintLine(best));
485         }
486     }
490 void spdc_endpoint_snap_free(SPEventContext const * const ec, NR::Point& p, guint const /*state*/)
492     SnapManager &m = SP_EVENT_CONTEXT_DESKTOP(ec)->namedview->snap_manager;
493     m.setup(SP_EVENT_CONTEXT_DESKTOP(ec), NULL);
494     m.freeSnapReturnByRef(Inkscape::Snapper::SNAPPOINT_NODE, p);
497 static SPCurve *
498 reverse_then_unref(SPCurve *orig)
500     SPCurve *ret = orig->create_reverse();
501     orig->unref();
502     return ret;
505 /**
506  * Concats red, blue and green.
507  * If any anchors are defined, process these, optionally removing curves from white list
508  * Invoke _flush_white to write result back to object.
509  */
510 void
511 spdc_concat_colors_and_flush(SPDrawContext *dc, gboolean forceclosed)
513     /* Concat RBG */
514     SPCurve *c = dc->green_curve;
516     /* Green */
517     dc->green_curve = new SPCurve();
518     while (dc->green_bpaths) {
519         gtk_object_destroy(GTK_OBJECT(dc->green_bpaths->data));
520         dc->green_bpaths = g_slist_remove(dc->green_bpaths, dc->green_bpaths->data);
521     }
522     /* Blue */
523     c->append_continuous(dc->blue_curve, 0.0625);
524     dc->blue_curve->reset();
525     sp_canvas_bpath_set_bpath(SP_CANVAS_BPATH(dc->blue_bpath), NULL);
526     /* Red */
527     if (dc->red_curve_is_valid) {
528         c->append_continuous(dc->red_curve, 0.0625);
529     }
530     dc->red_curve->reset();
531     sp_canvas_bpath_set_bpath(SP_CANVAS_BPATH(dc->red_bpath), NULL);
533     if (c->is_empty()) {
534         c->unref();
535         return;
536     }
538     /* Step A - test, whether we ended on green anchor */
539     if ( forceclosed || ( dc->green_anchor && dc->green_anchor->active ) ) {
540         // We hit green anchor, closing Green-Blue-Red
541         SP_EVENT_CONTEXT_DESKTOP(dc)->messageStack()->flash(Inkscape::NORMAL_MESSAGE, _("Path is closed."));
542         c->closepath_current();
543         /* Closed path, just flush */
544         spdc_flush_white(dc, c);
545         c->unref();
546         return;
547     }
549     /* Step B - both start and end anchored to same curve */
550     if ( dc->sa && dc->ea
551          && ( dc->sa->curve == dc->ea->curve )
552          && ( ( dc->sa != dc->ea )
553               || dc->sa->curve->is_closed() ) )
554     {
555         // We hit bot start and end of single curve, closing paths
556         SP_EVENT_CONTEXT_DESKTOP(dc)->messageStack()->flash(Inkscape::NORMAL_MESSAGE, _("Closing path."));
557         if (dc->sa->start && !(dc->sa->curve->is_closed()) ) {
558             c = reverse_then_unref(c);
559         }
560         dc->sa->curve->append_continuous(c, 0.0625);
561         c->unref();
562         dc->sa->curve->closepath_current();
563         spdc_flush_white(dc, NULL);
564         return;
565     }
567     /* Step C - test start */
568     if (dc->sa) {
569         SPCurve *s = dc->sa->curve;
570         dc->white_curves = g_slist_remove(dc->white_curves, s);
571         if (dc->sa->start) {
572             s = reverse_then_unref(s);
573         }
574         s->append_continuous(c, 0.0625);
575         c->unref();
576         c = s;
577     } else /* Step D - test end */ if (dc->ea) {
578         SPCurve *e = dc->ea->curve;
579         dc->white_curves = g_slist_remove(dc->white_curves, e);
580         if (!dc->ea->start) {
581             e = reverse_then_unref(e);
582         }
583         c->append_continuous(e, 0.0625);
584         e->unref();
585     }
588     spdc_flush_white(dc, c);
590     c->unref();
593 /*
594  * Flushes white curve(s) and additional curve into object
595  *
596  * No cleaning of colored curves - this has to be done by caller
597  * No rereading of white data, so if you cannot rely on ::modified, do it in caller
598  *
599  */
601 static void
602 spdc_flush_white(SPDrawContext *dc, SPCurve *gc)
604     SPCurve *c;
606     if (dc->white_curves) {
607         g_assert(dc->white_item);
608         c = SPCurve::concat(dc->white_curves);
609         g_slist_free(dc->white_curves);
610         dc->white_curves = NULL;
611         if (gc) {
612             c->append(gc, FALSE);
613         }
614     } else if (gc) {
615         c = gc;
616         c->ref();
617     } else {
618         return;
619     }
621     /* Now we have to go back to item coordinates at last */
622     c->transform( dc->white_item
623                             ? sp_item_dt2i_affine(dc->white_item)
624                             : to_2geom(sp_desktop_dt2root_affine(SP_EVENT_CONTEXT_DESKTOP(dc))) );
626     SPDesktop *desktop = SP_EVENT_CONTEXT_DESKTOP(dc);
627     SPDocument *doc = sp_desktop_document(desktop);
628     Inkscape::XML::Document *xml_doc = sp_document_repr_doc(doc);
630     if ( c && !c->is_empty() ) {
631         /* We actually have something to write */
633         bool has_lpe = false;
634         Inkscape::XML::Node *repr;
635         if (dc->white_item) {
636             repr = SP_OBJECT_REPR(dc->white_item);
637             has_lpe = sp_lpe_item_has_path_effect_recursive(SP_LPE_ITEM(dc->white_item));
638         } else {
639             repr = xml_doc->createElement("svg:path");
640             /* Set style */
641             sp_desktop_apply_style_tool(desktop, repr, tool_name(dc), false);
642         }
644         gchar *str = sp_svg_write_path( c->get_pathvector() );
645         g_assert( str != NULL );
646         if (has_lpe)
647             repr->setAttribute("inkscape:original-d", str);
648         else
649             repr->setAttribute("d", str);
650         g_free(str);
652         if (!dc->white_item) {
653             /* Attach repr */
654             SPItem *item = SP_ITEM(desktop->currentLayer()->appendChildRepr(repr));
655             dc->selection->set(repr);
656             Inkscape::GC::release(repr);
657             item->transform = i2i_affine(desktop->currentRoot(), desktop->currentLayer());
658             item->updateRepr();
659         }
662         // we finished the path; now apply any waiting LPEs or freehand shapes
663         // FIXME: placing this here seems to cause issues with undo!
664         spdc_check_for_and_apply_waiting_LPE(dc, dc->selection->singleItem());
666         sp_document_done(doc, SP_IS_PEN_CONTEXT(dc)? SP_VERB_CONTEXT_PEN : SP_VERB_CONTEXT_PENCIL, 
667                          _("Draw path"));
669         // When quickly drawing several subpaths with Shift, the next subpath may be finished and
670         // flushed before the selection_modified signal is fired by the previous change, which
671         // results in the tool losing all of the selected path's curve except that last subpath. To
672         // fix this, we force the selection_modified callback now, to make sure the tool's curve is
673         // in sync immediately.
674         spdc_selection_modified(sp_desktop_selection(desktop), 0, dc);
675     }
677     c->unref();
679     /* Flush pending updates */
680     sp_document_ensure_up_to_date(doc);
683 /**
684  * Returns FIRST active anchor (the activated one).
685  */
686 SPDrawAnchor *
687 spdc_test_inside(SPDrawContext *dc, NR::Point p)
689     SPDrawAnchor *active = NULL;
691     /* Test green anchor */
692     if (dc->green_anchor) {
693         active = sp_draw_anchor_test(dc->green_anchor, p, TRUE);
694     }
696     for (GSList *l = dc->white_anchors; l != NULL; l = l->next) {
697         SPDrawAnchor *na = sp_draw_anchor_test((SPDrawAnchor *) l->data, p, !active);
698         if ( !active && na ) {
699             active = na;
700         }
701     }
703     return active;
706 static void
707 spdc_reset_white(SPDrawContext *dc)
709     if (dc->white_item) {
710         /* We do not hold refcount */
711         dc->white_item = NULL;
712     }
713     while (dc->white_curves) {
714         reinterpret_cast<SPCurve *>(dc->white_curves->data)->unref();
715         dc->white_curves = g_slist_remove(dc->white_curves, dc->white_curves->data);
716     }
717     while (dc->white_anchors) {
718         sp_draw_anchor_destroy((SPDrawAnchor *) dc->white_anchors->data);
719         dc->white_anchors = g_slist_remove(dc->white_anchors, dc->white_anchors->data);
720     }
723 static void
724 spdc_free_colors(SPDrawContext *dc)
726     /* Red */
727     if (dc->red_bpath) {
728         gtk_object_destroy(GTK_OBJECT(dc->red_bpath));
729         dc->red_bpath = NULL;
730     }
731     if (dc->red_curve) {
732         dc->red_curve = dc->red_curve->unref();
733     }
734     /* Blue */
735     if (dc->blue_bpath) {
736         gtk_object_destroy(GTK_OBJECT(dc->blue_bpath));
737         dc->blue_bpath = NULL;
738     }
739     if (dc->blue_curve) {
740         dc->blue_curve = dc->blue_curve->unref();
741     }
742     /* Green */
743     while (dc->green_bpaths) {
744         gtk_object_destroy(GTK_OBJECT(dc->green_bpaths->data));
745         dc->green_bpaths = g_slist_remove(dc->green_bpaths, dc->green_bpaths->data);
746     }
747     if (dc->green_curve) {
748         dc->green_curve = dc->green_curve->unref();
749     }
750     if (dc->green_anchor) {
751         dc->green_anchor = sp_draw_anchor_destroy(dc->green_anchor);
752     }
753     /* White */
754     if (dc->white_item) {
755         /* We do not hold refcount */
756         dc->white_item = NULL;
757     }
758     while (dc->white_curves) {
759         reinterpret_cast<SPCurve *>(dc->white_curves->data)->unref();
760         dc->white_curves = g_slist_remove(dc->white_curves, dc->white_curves->data);
761     }
762     while (dc->white_anchors) {
763         sp_draw_anchor_destroy((SPDrawAnchor *) dc->white_anchors->data);
764         dc->white_anchors = g_slist_remove(dc->white_anchors, dc->white_anchors->data);
765     }
769 /*
770   Local Variables:
771   mode:c++
772   c-file-style:"stroustrup"
773   c-file-offsets:((innamespace . 0)(inline-open . 0)(case-label . +))
774   indent-tabs-mode:nil
775   fill-column:99
776   End:
777 */
778 // vim: filetype=cpp:expandtab:shiftwidth=4:tabstop=8:softtabstop=4:encoding=utf-8:textwidth=99 :