Code

New LPE FreehandShape derived from PatternAlongPath (for the shapes in pen/pencil...
[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 "libnr/n-art-bpath.h"
28 #include "display/curve.h"
29 #include "desktop.h"
30 #include "desktop-affine.h"
31 #include "desktop-handles.h"
32 #include "desktop-style.h"
33 #include "document.h"
34 #include "draw-anchor.h"
35 #include "macros.h"
36 #include "message-stack.h"
37 #include "pen-context.h"
38 #include "prefs-utils.h"
39 #include "selection.h"
40 #include "selection-chemistry.h"
41 #include "snap.h"
42 #include "sp-path.h"
43 #include "sp-namedview.h"
44 #include "live_effects/lpe-patternalongpath.h"
45 #include "style.h"
47 static void sp_draw_context_class_init(SPDrawContextClass *klass);
48 static void sp_draw_context_init(SPDrawContext *dc);
49 static void sp_draw_context_dispose(GObject *object);
51 static void sp_draw_context_setup(SPEventContext *ec);
52 static void sp_draw_context_set(SPEventContext *ec, gchar const *key, gchar const *value);
53 static void sp_draw_context_finish(SPEventContext *ec);
55 static gint sp_draw_context_root_handler(SPEventContext *event_context, GdkEvent *event);
57 static void spdc_selection_changed(Inkscape::Selection *sel, SPDrawContext *dc);
58 static void spdc_selection_modified(Inkscape::Selection *sel, guint flags, SPDrawContext *dc);
60 static void spdc_attach_selection(SPDrawContext *dc, Inkscape::Selection *sel);
62 static void spdc_flush_white(SPDrawContext *dc, SPCurve *gc);
64 static void spdc_reset_white(SPDrawContext *dc);
65 static void spdc_free_colors(SPDrawContext *dc);
68 static SPEventContextClass *draw_parent_class;
71 GType
72 sp_draw_context_get_type(void)
73 {
74     static GType type = 0;
75     if (!type) {
76         GTypeInfo info = {
77             sizeof(SPDrawContextClass),
78             NULL, NULL,
79             (GClassInitFunc) sp_draw_context_class_init,
80             NULL, NULL,
81             sizeof(SPDrawContext),
82             4,
83             (GInstanceInitFunc) sp_draw_context_init,
84             NULL,   /* value_table */
85         };
86         type = g_type_register_static(SP_TYPE_EVENT_CONTEXT, "SPDrawContext", &info, (GTypeFlags)0);
87     }
88     return type;
89 }
91 static void
92 sp_draw_context_class_init(SPDrawContextClass *klass)
93 {
94     GObjectClass *object_class;
95     SPEventContextClass *ec_class;
97     object_class = (GObjectClass *)klass;
98     ec_class = (SPEventContextClass *) klass;
100     draw_parent_class = (SPEventContextClass*)g_type_class_peek_parent(klass);
102     object_class->dispose = sp_draw_context_dispose;
104     ec_class->setup = sp_draw_context_setup;
105     ec_class->set = sp_draw_context_set;
106     ec_class->finish = sp_draw_context_finish;
107     ec_class->root_handler = sp_draw_context_root_handler;
110 static void
111 sp_draw_context_init(SPDrawContext *dc)
113     dc->attach = FALSE;
115     dc->red_color = 0xff00007f;
116     dc->blue_color = 0x0000ff7f;
117     dc->green_color = 0x00ff007f;
118     dc->red_curve_is_valid = false;
120     dc->waiting_LPE_type = Inkscape::LivePathEffect::INVALID_LPE;
122     new (&dc->sel_changed_connection) sigc::connection();
123     new (&dc->sel_modified_connection) sigc::connection();
126 static void
127 sp_draw_context_dispose(GObject *object)
129     SPDrawContext *dc = SP_DRAW_CONTEXT(object);
131     dc->sel_changed_connection.~connection();
132     dc->sel_modified_connection.~connection();
134     if (dc->grab) {
135         sp_canvas_item_ungrab(dc->grab, GDK_CURRENT_TIME);
136         dc->grab = NULL;
137     }
139     if (dc->selection) {
140         dc->selection = NULL;
141     }
143     dc->waiting_LPE_type = Inkscape::LivePathEffect::INVALID_LPE;
145     spdc_free_colors(dc);
147     G_OBJECT_CLASS(draw_parent_class)->dispose(object);
150 static void
151 sp_draw_context_setup(SPEventContext *ec)
153     SPDrawContext *dc = SP_DRAW_CONTEXT(ec);
154     SPDesktop *dt = ec->desktop;
156     if (((SPEventContextClass *) draw_parent_class)->setup) {
157         ((SPEventContextClass *) draw_parent_class)->setup(ec);
158     }
160     dc->selection = sp_desktop_selection(dt);
162     /* Connect signals to track selection changes */
163     dc->sel_changed_connection = dc->selection->connectChanged(
164         sigc::bind(sigc::ptr_fun(&spdc_selection_changed), dc)
165     );
166     dc->sel_modified_connection = dc->selection->connectModified(
167         sigc::bind(sigc::ptr_fun(&spdc_selection_modified), dc)
168     );
170     /* Create red bpath */
171     dc->red_bpath = sp_canvas_bpath_new(sp_desktop_sketch(ec->desktop), NULL);
172     sp_canvas_bpath_set_stroke(SP_CANVAS_BPATH(dc->red_bpath), dc->red_color, 1.0, SP_STROKE_LINEJOIN_MITER, SP_STROKE_LINECAP_BUTT);
173     /* Create red curve */
174     dc->red_curve = new SPCurve(4);
176     /* Create blue bpath */
177     dc->blue_bpath = sp_canvas_bpath_new(sp_desktop_sketch(ec->desktop), NULL);
178     sp_canvas_bpath_set_stroke(SP_CANVAS_BPATH(dc->blue_bpath), dc->blue_color, 1.0, SP_STROKE_LINEJOIN_MITER, SP_STROKE_LINECAP_BUTT);
179     /* Create blue curve */
180     dc->blue_curve = new SPCurve(8);
182     /* Create green curve */
183     dc->green_curve = new SPCurve(64);
184     /* No green anchor by default */
185     dc->green_anchor = NULL;
186     dc->green_closed = FALSE;
188     dc->attach = TRUE;
189     spdc_attach_selection(dc, dc->selection);
192 static void
193 sp_draw_context_finish(SPEventContext *ec)
195     SPDrawContext *dc = SP_DRAW_CONTEXT(ec);
197     dc->sel_changed_connection.disconnect();
198     dc->sel_modified_connection.disconnect();
200     if (dc->grab) {
201         sp_canvas_item_ungrab(dc->grab, GDK_CURRENT_TIME);
202     }
204     if (dc->selection) {
205         dc->selection = NULL;
206     }
208     spdc_free_colors(dc);
211 static void
212 sp_draw_context_set(SPEventContext */*ec*/, const gchar */*key*/, const gchar */*value*/)
216 gint
217 sp_draw_context_root_handler(SPEventContext *ec, GdkEvent *event)
219     gint ret = FALSE;
221     switch (event->type) {
222         case GDK_KEY_PRESS:
223             switch (get_group0_keyval (&event->key)) {
224                 case GDK_Up:
225                 case GDK_Down:
226                 case GDK_KP_Up:
227                 case GDK_KP_Down:
228                     // prevent the zoom field from activation
229                     if (!MOD__CTRL_ONLY) {
230                         ret = TRUE;
231                     }
232                     break;
233                 default:
234             break;
235         }
236         break;
237     default:
238         break;
239     }
241     if (!ret) {
242         if (((SPEventContextClass *) draw_parent_class)->root_handler) {
243             ret = ((SPEventContextClass *) draw_parent_class)->root_handler(ec, event);
244         }
245     }
247     return ret;
250 static void
251 spdc_paste_curve_as_freehand_shape(const SPCurve *c, SPDrawContext *dc, SPItem *item)
253     using namespace Inkscape::LivePathEffect;
255     // TODO: Don't paste path if nothing is on the clipboard
257     Effect::createAndApply(Inkscape::LivePathEffect::FREEHAND_SHAPE, dc->desktop->doc(), item);
258     Effect* lpe = sp_lpe_item_get_current_lpe(SP_LPE_ITEM(item));
259     gchar *svgd = sp_svg_write_path(c->get_pathvector());
260     static_cast<LPEPatternAlongPath*>(lpe)->pattern.paste_param_path(svgd);
263 /*
264  * If we have an item and a waiting LPE, apply the effect to the item
265  * (spiro spline mode is treated separately)
266  */
267 void
268 spdc_check_for_and_apply_waiting_LPE(SPDrawContext *dc, SPItem *item)
270     using namespace Inkscape::LivePathEffect;
272     if (item && SP_IS_LPE_ITEM(item)) {
273         if (prefs_get_int_attribute("tools.freehand", "spiro-spline-mode", 0)) {
274             Effect::createAndApply(SPIRO, dc->desktop->doc(), item);
275         }
277         int shape = prefs_get_int_attribute("tools.freehand", "shape", 0);
278         bool shape_applied = false;
279         SPCSSAttr *css_item = sp_css_attr_from_object (SP_OBJECT(item), SP_STYLE_FLAG_ALWAYS);
280         const char *cstroke = sp_repr_css_property(css_item, "stroke", "none");
282         switch (shape) {
283             case 0:
284                 // don't apply any shape
285                 break;
286             case 1:
287             {
288                 // take shape from clipboard; TODO: catch the case where clipboard is empty
289                 Effect::createAndApply(FREEHAND_SHAPE, dc->desktop->doc(), item);
290                 Effect* lpe = sp_lpe_item_get_current_lpe(SP_LPE_ITEM(item));
291                 static_cast<LPEPatternAlongPath*>(lpe)->pattern.on_paste_button_click();
293                 shape_applied = true;
294                 break;
295             }
296             case 2:
297             {
298                 // "crescendo"
299                 // TODO: this is only for illustration (we create a "crescendo"-shaped path
300                 //       manually; eventually we should read the path from a separate file)
301                 SPCurve *c = new SPCurve();
302                 c->moveto(0,5);
303                 c->lineto(200,10);
304                 c->lineto(200,0);
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 3:
313             {
314                 // "decrescendo"
315                 // TODO: this is only for illustration (we create a "decrescendo"-shaped path
316                 //       manually; eventually we should read the path from a separate file)
317                 SPCurve *c = new SPCurve();
318                 c->moveto(0,0);
319                 c->lineto(0,10);
320                 c->lineto(200,5);
321                 c->closepath();
322                 spdc_paste_curve_as_freehand_shape(c, dc, item);
323                 c->unref();
325                 shape_applied = true;
326                 break;
327             }
328             default:
329                 break;
330         }
331         if (shape_applied) {
332             // apply original stroke color as fill and unset stroke; then return
333             SPCSSAttr *css = sp_repr_css_attr_new();
334             sp_repr_css_set_property (css, "fill", cstroke);
335             sp_repr_css_set_property (css, "stroke", "none");
336             sp_desktop_apply_css_recursive(SP_OBJECT(item), css, true);
337             sp_repr_css_attr_unref(css);
338             return;
339         }
341         if (dc->waiting_LPE_type != INVALID_LPE) {
342             Effect::createAndApply(dc->waiting_LPE_type, dc->desktop->doc(), item);
343             dc->waiting_LPE_type = INVALID_LPE;
344         }
345         if (SP_IS_PEN_CONTEXT(dc)) {
346             SP_PEN_CONTEXT(dc)->polylines_only = false;
347         }
348     }
351 /*
352  * Selection handlers
353  */
355 static void
356 spdc_selection_changed(Inkscape::Selection *sel, SPDrawContext *dc)
358     if (dc->attach) {
359         spdc_attach_selection(dc, sel);
360     }
363 /* fixme: We have to ensure this is not delayed (Lauris) */
365 static void
366 spdc_selection_modified(Inkscape::Selection *sel, guint /*flags*/, SPDrawContext *dc)
368     if (dc->attach) {
369         spdc_attach_selection(dc, sel);
370     }
373 static void
374 spdc_attach_selection(SPDrawContext *dc, Inkscape::Selection */*sel*/)
376     /* We reset white and forget white/start/end anchors */
377     spdc_reset_white(dc);
378     dc->sa = NULL;
379     dc->ea = NULL;
381     SPItem *item = dc->selection ? dc->selection->singleItem() : NULL;
383     if ( item && SP_IS_PATH(item) ) {
384         /* Create new white data */
385         /* Item */
386         dc->white_item = item;
387         /* Curve list */
388         /* We keep it in desktop coordinates to eliminate calculation errors */
389         SPCurve *norm = sp_path_get_curve_for_edit (SP_PATH(item));
390         norm->transform(from_2geom(sp_item_i2d_affine(dc->white_item)));
391         g_return_if_fail( norm != NULL );
392         dc->white_curves = g_slist_reverse(norm->split());
393         norm->unref();
394         /* Anchor list */
395         for (GSList *l = dc->white_curves; l != NULL; l = l->next) {
396             SPCurve *c;
397             c = (SPCurve*)l->data;
398             g_return_if_fail( c->get_segment_count() > 0 );
399             if ( !c->is_closed() ) {
400                 SPDrawAnchor *a;
401                 a = sp_draw_anchor_new(dc, c, TRUE, c->first_point());
402                 dc->white_anchors = g_slist_prepend(dc->white_anchors, a);
403                 a = sp_draw_anchor_new(dc, c, FALSE, c->last_point());
404                 dc->white_anchors = g_slist_prepend(dc->white_anchors, a);
405             }
406         }
407         /* fixme: recalculate active anchor? */
408     }
412 /**
413  *  Snaps node or handle to PI/rotationsnapsperpi degree increments.
414  *
415  *  \param dc draw context
416  *  \param p cursor point (to be changed by snapping)
417  *  \param o origin point
418  *  \param state  keyboard state to check if ctrl was pressed
419 */
421 void spdc_endpoint_snap_rotation(SPEventContext const *const ec, NR::Point &p, NR::Point const o,
422                                  guint state)
424     /* Control must be down for this snap to work */
425     if ((state & GDK_CONTROL_MASK) == 0) {
426         return;
427     }
429     unsigned const snaps = abs(prefs_get_int_attribute("options.rotationsnapsperpi", "value", 12));
430     /* 0 means no snapping. */
432     /* mirrored by fabs, so this corresponds to 15 degrees */
433     NR::Point best; /* best solution */
434     double bn = NR_HUGE; /* best normal */
435     double bdot = 0;
436     NR::Point v = NR::Point(0, 1);
437     double const r00 = cos(M_PI / snaps), r01 = sin(M_PI / snaps);
438     double const r10 = -r01, r11 = r00;
440     NR::Point delta = p - o;
442     for (unsigned i = 0; i < snaps; i++) {
443         double const ndot = fabs(dot(v,NR::rot90(delta)));
444         NR::Point t(r00*v[NR::X] + r01*v[NR::Y],
445                     r10*v[NR::X] + r11*v[NR::Y]);
446         if (ndot < bn) {
447             /* I think it is better numerically to use the normal, rather than the dot product
448              * to assess solutions, but I haven't proven it. */
449             bn = ndot;
450             best = v;
451             bdot = dot(v, delta);
452         }
453         v = t;
454     }
456     if (fabs(bdot) > 0) {
457         p = o + bdot * best;
459         /* Snap it along best vector */
460         SnapManager &m = SP_EVENT_CONTEXT_DESKTOP(ec)->namedview->snap_manager;
461         m.setup(SP_EVENT_CONTEXT_DESKTOP(ec), NULL);
462         m.constrainedSnapReturnByRef( Inkscape::Snapper::SNAPPOINT_NODE, p, Inkscape::Snapper::ConstraintLine(best));
463     }
467 void spdc_endpoint_snap_free(SPEventContext const * const ec, NR::Point& p, guint const state)
469     /* Shift disables this snap */
470     if (state & GDK_SHIFT_MASK) {
471         return;
472     }
474     SnapManager &m = SP_EVENT_CONTEXT_DESKTOP(ec)->namedview->snap_manager;
475     m.setup(SP_EVENT_CONTEXT_DESKTOP(ec), NULL);
476     m.freeSnapReturnByRef(Inkscape::Snapper::SNAPPOINT_NODE, p);
479 static SPCurve *
480 reverse_then_unref(SPCurve *orig)
482     SPCurve *ret = orig->create_reverse();
483     orig->unref();
484     return ret;
487 /**
488  * Concats red, blue and green.
489  * If any anchors are defined, process these, optionally removing curves from white list
490  * Invoke _flush_white to write result back to object.
491  */
492 void
493 spdc_concat_colors_and_flush(SPDrawContext *dc, gboolean forceclosed)
495     /* Concat RBG */
496     SPCurve *c = dc->green_curve;
498     /* Green */
499     dc->green_curve = new SPCurve(64);
500     while (dc->green_bpaths) {
501         gtk_object_destroy(GTK_OBJECT(dc->green_bpaths->data));
502         dc->green_bpaths = g_slist_remove(dc->green_bpaths, dc->green_bpaths->data);
503     }
504     /* Blue */
505     c->append_continuous(dc->blue_curve, 0.0625);
506     dc->blue_curve->reset();
507     sp_canvas_bpath_set_bpath(SP_CANVAS_BPATH(dc->blue_bpath), NULL);
508     /* Red */
509     if (dc->red_curve_is_valid) {
510         c->append_continuous(dc->red_curve, 0.0625);
511     }
512     dc->red_curve->reset();
513     sp_canvas_bpath_set_bpath(SP_CANVAS_BPATH(dc->red_bpath), NULL);
515     if (c->is_empty()) {
516         c->unref();
517         return;
518     }
520     /* Step A - test, whether we ended on green anchor */
521     if ( forceclosed || ( dc->green_anchor && dc->green_anchor->active ) ) {
522         // We hit green anchor, closing Green-Blue-Red
523         SP_EVENT_CONTEXT_DESKTOP(dc)->messageStack()->flash(Inkscape::NORMAL_MESSAGE, _("Path is closed."));
524         c->closepath_current();
525         /* Closed path, just flush */
526         spdc_flush_white(dc, c);
527         c->unref();
528         return;
529     }
531     /* Step B - both start and end anchored to same curve */
532     if ( dc->sa && dc->ea
533          && ( dc->sa->curve == dc->ea->curve )
534          && ( ( dc->sa != dc->ea )
535               || dc->sa->curve->is_closed() ) )
536     {
537         // We hit bot start and end of single curve, closing paths
538         SP_EVENT_CONTEXT_DESKTOP(dc)->messageStack()->flash(Inkscape::NORMAL_MESSAGE, _("Closing path."));
539         if (dc->sa->start && !(dc->sa->curve->is_closed()) ) {
540             c = reverse_then_unref(c);
541         }
542         dc->sa->curve->append_continuous(c, 0.0625);
543         c->unref();
544         dc->sa->curve->closepath_current();
545         spdc_flush_white(dc, NULL);
546         return;
547     }
549     /* Step C - test start */
550     if (dc->sa) {
551         SPCurve *s = dc->sa->curve;
552         dc->white_curves = g_slist_remove(dc->white_curves, s);
553         if (dc->sa->start) {
554             s = reverse_then_unref(s);
555         }
556         s->append_continuous(c, 0.0625);
557         c->unref();
558         c = s;
559     } else /* Step D - test end */ if (dc->ea) {
560         SPCurve *e = dc->ea->curve;
561         dc->white_curves = g_slist_remove(dc->white_curves, e);
562         if (!dc->ea->start) {
563             e = reverse_then_unref(e);
564         }
565         c->append_continuous(e, 0.0625);
566         e->unref();
567     }
570     spdc_flush_white(dc, c);
572     c->unref();
575 static char const *
576 tool_name(SPDrawContext *dc)
578     return ( SP_IS_PEN_CONTEXT(dc)
579              ? "tools.freehand.pen"
580              : "tools.freehand.pencil" );
583 /*
584  * Flushes white curve(s) and additional curve into object
585  *
586  * No cleaning of colored curves - this has to be done by caller
587  * No rereading of white data, so if you cannot rely on ::modified, do it in caller
588  *
589  */
591 static void
592 spdc_flush_white(SPDrawContext *dc, SPCurve *gc)
594     SPCurve *c;
596     if (dc->white_curves) {
597         g_assert(dc->white_item);
598         c = SPCurve::concat(dc->white_curves);
599         g_slist_free(dc->white_curves);
600         dc->white_curves = NULL;
601         if (gc) {
602             c->append(gc, FALSE);
603         }
604     } else if (gc) {
605         c = gc;
606         c->ref();
607     } else {
608         return;
609     }
611     /* Now we have to go back to item coordinates at last */
612     c->transform(( dc->white_item
613                             ? from_2geom(sp_item_dt2i_affine(dc->white_item))
614                             : sp_desktop_dt2root_affine(SP_EVENT_CONTEXT_DESKTOP(dc)) ));
616     SPDesktop *desktop = SP_EVENT_CONTEXT_DESKTOP(dc);
617     SPDocument *doc = sp_desktop_document(desktop);
618     Inkscape::XML::Document *xml_doc = sp_document_repr_doc(doc);
620     if ( c && !c->is_empty() ) {
621         /* We actually have something to write */
623         bool has_lpe = false;
624         Inkscape::XML::Node *repr;
625         if (dc->white_item) {
626             repr = SP_OBJECT_REPR(dc->white_item);
627             has_lpe = sp_lpe_item_has_path_effect_recursive(SP_LPE_ITEM(dc->white_item));
628         } else {
629             repr = xml_doc->createElement("svg:path");
630             /* Set style */
631             sp_desktop_apply_style_tool(desktop, repr, tool_name(dc), false);
632         }
634         gchar *str = sp_svg_write_path( c->get_pathvector() );
635         g_assert( str != NULL );
636         if (has_lpe)
637             repr->setAttribute("inkscape:original-d", str);
638         else
639             repr->setAttribute("d", str);
640         g_free(str);
642         if (!dc->white_item) {
643             /* Attach repr */
644             SPItem *item = SP_ITEM(desktop->currentLayer()->appendChildRepr(repr));
645             dc->selection->set(repr);
646             Inkscape::GC::release(repr);
647             item->transform = from_2geom(i2i_affine(desktop->currentRoot(), desktop->currentLayer()));
648             item->updateRepr();
649         }
652         // we finished the path; now apply any waiting LPEs or freehand shapes
653         // FIXME: placing this here seems to cause issues with undo!
654         spdc_check_for_and_apply_waiting_LPE(dc, dc->selection->singleItem());
656         sp_document_done(doc, SP_IS_PEN_CONTEXT(dc)? SP_VERB_CONTEXT_PEN : SP_VERB_CONTEXT_PENCIL, 
657                          _("Draw path"));
659         // When quickly drawing several subpaths with Shift, the next subpath may be finished and
660         // flushed before the selection_modified signal is fired by the previous change, which
661         // results in the tool losing all of the selected path's curve except that last subpath. To
662         // fix this, we force the selection_modified callback now, to make sure the tool's curve is
663         // in sync immediately.
664         spdc_selection_modified(sp_desktop_selection(desktop), 0, dc);
665     }
667     c->unref();
669     /* Flush pending updates */
670     sp_document_ensure_up_to_date(doc);
673 /**
674  * Returns FIRST active anchor (the activated one).
675  */
676 SPDrawAnchor *
677 spdc_test_inside(SPDrawContext *dc, NR::Point p)
679     SPDrawAnchor *active = NULL;
681     /* Test green anchor */
682     if (dc->green_anchor) {
683         active = sp_draw_anchor_test(dc->green_anchor, p, TRUE);
684     }
686     for (GSList *l = dc->white_anchors; l != NULL; l = l->next) {
687         SPDrawAnchor *na = sp_draw_anchor_test((SPDrawAnchor *) l->data, p, !active);
688         if ( !active && na ) {
689             active = na;
690         }
691     }
693     return active;
696 static void
697 spdc_reset_white(SPDrawContext *dc)
699     if (dc->white_item) {
700         /* We do not hold refcount */
701         dc->white_item = NULL;
702     }
703     while (dc->white_curves) {
704         reinterpret_cast<SPCurve *>(dc->white_curves->data)->unref();
705         dc->white_curves = g_slist_remove(dc->white_curves, dc->white_curves->data);
706     }
707     while (dc->white_anchors) {
708         sp_draw_anchor_destroy((SPDrawAnchor *) dc->white_anchors->data);
709         dc->white_anchors = g_slist_remove(dc->white_anchors, dc->white_anchors->data);
710     }
713 static void
714 spdc_free_colors(SPDrawContext *dc)
716     /* Red */
717     if (dc->red_bpath) {
718         gtk_object_destroy(GTK_OBJECT(dc->red_bpath));
719         dc->red_bpath = NULL;
720     }
721     if (dc->red_curve) {
722         dc->red_curve = dc->red_curve->unref();
723     }
724     /* Blue */
725     if (dc->blue_bpath) {
726         gtk_object_destroy(GTK_OBJECT(dc->blue_bpath));
727         dc->blue_bpath = NULL;
728     }
729     if (dc->blue_curve) {
730         dc->blue_curve = dc->blue_curve->unref();
731     }
732     /* Green */
733     while (dc->green_bpaths) {
734         gtk_object_destroy(GTK_OBJECT(dc->green_bpaths->data));
735         dc->green_bpaths = g_slist_remove(dc->green_bpaths, dc->green_bpaths->data);
736     }
737     if (dc->green_curve) {
738         dc->green_curve = dc->green_curve->unref();
739     }
740     if (dc->green_anchor) {
741         dc->green_anchor = sp_draw_anchor_destroy(dc->green_anchor);
742     }
743     /* White */
744     if (dc->white_item) {
745         /* We do not hold refcount */
746         dc->white_item = NULL;
747     }
748     while (dc->white_curves) {
749         reinterpret_cast<SPCurve *>(dc->white_curves->data)->unref();
750         dc->white_curves = g_slist_remove(dc->white_curves, dc->white_curves->data);
751     }
752     while (dc->white_anchors) {
753         sp_draw_anchor_destroy((SPDrawAnchor *) dc->white_anchors->data);
754         dc->white_anchors = g_slist_remove(dc->white_anchors, dc->white_anchors->data);
755     }
759 /*
760   Local Variables:
761   mode:c++
762   c-file-style:"stroustrup"
763   c-file-offsets:((innamespace . 0)(inline-open . 0)(case-label . +))
764   indent-tabs-mode:nil
765   fill-column:99
766   End:
767 */
768 // vim: filetype=cpp:expandtab:shiftwidth=4:tabstop=8:softtabstop=4:encoding=utf-8:textwidth=99 :