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;
108 }
110 static void
111 sp_draw_context_init(SPDrawContext *dc)
112 {
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();
124 }
126 static void
127 sp_draw_context_dispose(GObject *object)
128 {
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);
148 }
150 static void
151 sp_draw_context_setup(SPEventContext *ec)
152 {
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);
190 }
192 static void
193 sp_draw_context_finish(SPEventContext *ec)
194 {
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);
209 }
211 static void
212 sp_draw_context_set(SPEventContext */*ec*/, const gchar */*key*/, const gchar */*value*/)
213 {
214 }
216 gint
217 sp_draw_context_root_handler(SPEventContext *ec, GdkEvent *event)
218 {
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;
248 }
250 static void
251 spdc_paste_curve_as_param_path(const SPCurve *c, SPDrawContext *dc, SPItem *item)
252 {
253 using namespace Inkscape::LivePathEffect;
255 // TODO: Don't paste path if nothing is on the clipboard
257 Effect::createAndApply(Inkscape::LivePathEffect::PATTERN_ALONG_PATH, 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);
261 }
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)
269 {
270 using namespace Inkscape::LivePathEffect;
272 if (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(PATTERN_ALONG_PATH, 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_param_path(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_param_path(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 }
349 }
351 /*
352 * Selection handlers
353 */
355 static void
356 spdc_selection_changed(Inkscape::Selection *sel, SPDrawContext *dc)
357 {
358 // note: in draw context, selection_changed() is only called with a valid item as argument when
359 // a new item was created; otherwise the following function call would yield wrong results
360 spdc_check_for_and_apply_waiting_LPE(dc, sel->singleItem());
362 if (dc->attach) {
363 spdc_attach_selection(dc, sel);
364 }
365 }
367 /* fixme: We have to ensure this is not delayed (Lauris) */
369 static void
370 spdc_selection_modified(Inkscape::Selection *sel, guint /*flags*/, SPDrawContext *dc)
371 {
372 if (dc->attach) {
373 spdc_attach_selection(dc, sel);
374 }
375 }
377 static void
378 spdc_attach_selection(SPDrawContext *dc, Inkscape::Selection */*sel*/)
379 {
380 /* We reset white and forget white/start/end anchors */
381 spdc_reset_white(dc);
382 dc->sa = NULL;
383 dc->ea = NULL;
385 SPItem *item = dc->selection ? dc->selection->singleItem() : NULL;
387 if ( item && SP_IS_PATH(item) ) {
388 /* Create new white data */
389 /* Item */
390 dc->white_item = item;
391 /* Curve list */
392 /* We keep it in desktop coordinates to eliminate calculation errors */
393 SPCurve *norm = sp_path_get_curve_for_edit (SP_PATH(item));
394 norm->transform(from_2geom(sp_item_i2d_affine(dc->white_item)));
395 g_return_if_fail( norm != NULL );
396 dc->white_curves = g_slist_reverse(norm->split());
397 norm->unref();
398 /* Anchor list */
399 for (GSList *l = dc->white_curves; l != NULL; l = l->next) {
400 SPCurve *c;
401 c = (SPCurve*)l->data;
402 g_return_if_fail( c->get_length() > 1 );
403 if ( !c->is_closed() ) {
404 SPDrawAnchor *a;
405 a = sp_draw_anchor_new(dc, c, TRUE, c->first_point());
406 dc->white_anchors = g_slist_prepend(dc->white_anchors, a);
407 a = sp_draw_anchor_new(dc, c, FALSE, c->last_point());
408 dc->white_anchors = g_slist_prepend(dc->white_anchors, a);
409 }
410 }
411 /* fixme: recalculate active anchor? */
412 }
413 }
416 /**
417 * Snaps node or handle to PI/rotationsnapsperpi degree increments.
418 *
419 * \param dc draw context
420 * \param p cursor point (to be changed by snapping)
421 * \param o origin point
422 * \param state keyboard state to check if ctrl was pressed
423 */
425 void spdc_endpoint_snap_rotation(SPEventContext const *const ec, NR::Point &p, NR::Point const o,
426 guint state)
427 {
428 /* Control must be down for this snap to work */
429 if ((state & GDK_CONTROL_MASK) == 0) {
430 return;
431 }
433 unsigned const snaps = abs(prefs_get_int_attribute("options.rotationsnapsperpi", "value", 12));
434 /* 0 means no snapping. */
436 /* mirrored by fabs, so this corresponds to 15 degrees */
437 NR::Point best; /* best solution */
438 double bn = NR_HUGE; /* best normal */
439 double bdot = 0;
440 NR::Point v = NR::Point(0, 1);
441 double const r00 = cos(M_PI / snaps), r01 = sin(M_PI / snaps);
442 double const r10 = -r01, r11 = r00;
444 NR::Point delta = p - o;
446 for (unsigned i = 0; i < snaps; i++) {
447 double const ndot = fabs(dot(v,NR::rot90(delta)));
448 NR::Point t(r00*v[NR::X] + r01*v[NR::Y],
449 r10*v[NR::X] + r11*v[NR::Y]);
450 if (ndot < bn) {
451 /* I think it is better numerically to use the normal, rather than the dot product
452 * to assess solutions, but I haven't proven it. */
453 bn = ndot;
454 best = v;
455 bdot = dot(v, delta);
456 }
457 v = t;
458 }
460 if (fabs(bdot) > 0) {
461 p = o + bdot * best;
463 /* Snap it along best vector */
464 SnapManager &m = SP_EVENT_CONTEXT_DESKTOP(ec)->namedview->snap_manager;
465 m.setup(SP_EVENT_CONTEXT_DESKTOP(ec), NULL);
466 m.constrainedSnapReturnByRef( Inkscape::Snapper::SNAPPOINT_NODE, p, Inkscape::Snapper::ConstraintLine(best));
467 }
468 }
471 void spdc_endpoint_snap_free(SPEventContext const * const ec, NR::Point& p, guint const state)
472 {
473 /* Shift disables this snap */
474 if (state & GDK_SHIFT_MASK) {
475 return;
476 }
478 SnapManager &m = SP_EVENT_CONTEXT_DESKTOP(ec)->namedview->snap_manager;
479 m.setup(SP_EVENT_CONTEXT_DESKTOP(ec), NULL);
480 m.freeSnapReturnByRef(Inkscape::Snapper::SNAPPOINT_NODE, p);
481 }
483 static SPCurve *
484 reverse_then_unref(SPCurve *orig)
485 {
486 SPCurve *ret = orig->create_reverse();
487 orig->unref();
488 return ret;
489 }
491 /**
492 * Concats red, blue and green.
493 * If any anchors are defined, process these, optionally removing curves from white list
494 * Invoke _flush_white to write result back to object.
495 */
496 void
497 spdc_concat_colors_and_flush(SPDrawContext *dc, gboolean forceclosed)
498 {
499 /* Concat RBG */
500 SPCurve *c = dc->green_curve;
502 /* Green */
503 dc->green_curve = new SPCurve(64);
504 while (dc->green_bpaths) {
505 gtk_object_destroy(GTK_OBJECT(dc->green_bpaths->data));
506 dc->green_bpaths = g_slist_remove(dc->green_bpaths, dc->green_bpaths->data);
507 }
508 /* Blue */
509 c->append_continuous(dc->blue_curve, 0.0625);
510 dc->blue_curve->reset();
511 sp_canvas_bpath_set_bpath(SP_CANVAS_BPATH(dc->blue_bpath), NULL);
512 /* Red */
513 if (dc->red_curve_is_valid) {
514 c->append_continuous(dc->red_curve, 0.0625);
515 }
516 dc->red_curve->reset();
517 sp_canvas_bpath_set_bpath(SP_CANVAS_BPATH(dc->red_bpath), NULL);
519 if (c->is_empty()) {
520 c->unref();
521 return;
522 }
524 /* Step A - test, whether we ended on green anchor */
525 if ( forceclosed || ( dc->green_anchor && dc->green_anchor->active ) ) {
526 // We hit green anchor, closing Green-Blue-Red
527 SP_EVENT_CONTEXT_DESKTOP(dc)->messageStack()->flash(Inkscape::NORMAL_MESSAGE, _("Path is closed."));
528 c->closepath_current();
529 /* Closed path, just flush */
530 spdc_flush_white(dc, c);
531 c->unref();
532 return;
533 }
535 /* Step B - both start and end anchored to same curve */
536 if ( dc->sa && dc->ea
537 && ( dc->sa->curve == dc->ea->curve )
538 && ( ( dc->sa != dc->ea )
539 || dc->sa->curve->is_closed() ) )
540 {
541 // We hit bot start and end of single curve, closing paths
542 SP_EVENT_CONTEXT_DESKTOP(dc)->messageStack()->flash(Inkscape::NORMAL_MESSAGE, _("Closing path."));
543 if (dc->sa->start && !(dc->sa->curve->is_closed()) ) {
544 c = reverse_then_unref(c);
545 }
546 dc->sa->curve->append_continuous(c, 0.0625);
547 c->unref();
548 dc->sa->curve->closepath_current();
549 spdc_flush_white(dc, NULL);
550 return;
551 }
553 /* Step C - test start */
554 if (dc->sa) {
555 SPCurve *s = dc->sa->curve;
556 dc->white_curves = g_slist_remove(dc->white_curves, s);
557 if (dc->sa->start) {
558 s = reverse_then_unref(s);
559 }
560 s->append_continuous(c, 0.0625);
561 c->unref();
562 c = s;
563 } else /* Step D - test end */ if (dc->ea) {
564 SPCurve *e = dc->ea->curve;
565 dc->white_curves = g_slist_remove(dc->white_curves, e);
566 if (!dc->ea->start) {
567 e = reverse_then_unref(e);
568 }
569 c->append_continuous(e, 0.0625);
570 e->unref();
571 }
574 spdc_flush_white(dc, c);
576 c->unref();
577 }
579 static char const *
580 tool_name(SPDrawContext *dc)
581 {
582 return ( SP_IS_PEN_CONTEXT(dc)
583 ? "tools.freehand.pen"
584 : "tools.freehand.pencil" );
585 }
587 /*
588 * Flushes white curve(s) and additional curve into object
589 *
590 * No cleaning of colored curves - this has to be done by caller
591 * No rereading of white data, so if you cannot rely on ::modified, do it in caller
592 *
593 */
595 static void
596 spdc_flush_white(SPDrawContext *dc, SPCurve *gc)
597 {
598 SPCurve *c;
600 if (dc->white_curves) {
601 g_assert(dc->white_item);
602 c = SPCurve::concat(dc->white_curves);
603 g_slist_free(dc->white_curves);
604 dc->white_curves = NULL;
605 if (gc) {
606 c->append(gc, FALSE);
607 }
608 } else if (gc) {
609 c = gc;
610 c->ref();
611 } else {
612 return;
613 }
615 /* Now we have to go back to item coordinates at last */
616 c->transform(( dc->white_item
617 ? from_2geom(sp_item_dt2i_affine(dc->white_item))
618 : sp_desktop_dt2root_affine(SP_EVENT_CONTEXT_DESKTOP(dc)) ));
620 SPDesktop *desktop = SP_EVENT_CONTEXT_DESKTOP(dc);
621 SPDocument *doc = sp_desktop_document(desktop);
622 Inkscape::XML::Document *xml_doc = sp_document_repr_doc(doc);
624 if ( c && !c->is_empty() ) {
625 /* We actually have something to write */
627 bool has_lpe = false;
628 Inkscape::XML::Node *repr;
629 if (dc->white_item) {
630 repr = SP_OBJECT_REPR(dc->white_item);
631 has_lpe = sp_lpe_item_has_path_effect_recursive(SP_LPE_ITEM(dc->white_item));
632 } else {
633 repr = xml_doc->createElement("svg:path");
634 /* Set style */
635 sp_desktop_apply_style_tool(desktop, repr, tool_name(dc), false);
636 }
638 gchar *str = sp_svg_write_path( c->get_pathvector() );
639 g_assert( str != NULL );
640 if (has_lpe)
641 repr->setAttribute("inkscape:original-d", str);
642 else
643 repr->setAttribute("d", str);
644 g_free(str);
646 if (!dc->white_item) {
647 /* Attach repr */
648 SPItem *item = SP_ITEM(desktop->currentLayer()->appendChildRepr(repr));
649 dc->selection->set(repr);
650 Inkscape::GC::release(repr);
651 item->transform = from_2geom(i2i_affine(desktop->currentRoot(), desktop->currentLayer()));
652 item->updateRepr();
653 }
655 sp_document_done(doc, SP_IS_PEN_CONTEXT(dc)? SP_VERB_CONTEXT_PEN : SP_VERB_CONTEXT_PENCIL,
656 _("Draw path"));
658 // When quickly drawing several subpaths with Shift, the next subpath may be finished and
659 // flushed before the selection_modified signal is fired by the previous change, which
660 // results in the tool losing all of the selected path's curve except that last subpath. To
661 // fix this, we force the selection_modified callback now, to make sure the tool's curve is
662 // in sync immediately.
663 spdc_selection_modified(sp_desktop_selection(desktop), 0, dc);
664 }
666 c->unref();
668 /* Flush pending updates */
669 sp_document_ensure_up_to_date(doc);
670 }
672 /**
673 * Returns FIRST active anchor (the activated one).
674 */
675 SPDrawAnchor *
676 spdc_test_inside(SPDrawContext *dc, NR::Point p)
677 {
678 SPDrawAnchor *active = NULL;
680 /* Test green anchor */
681 if (dc->green_anchor) {
682 active = sp_draw_anchor_test(dc->green_anchor, p, TRUE);
683 }
685 for (GSList *l = dc->white_anchors; l != NULL; l = l->next) {
686 SPDrawAnchor *na = sp_draw_anchor_test((SPDrawAnchor *) l->data, p, !active);
687 if ( !active && na ) {
688 active = na;
689 }
690 }
692 return active;
693 }
695 static void
696 spdc_reset_white(SPDrawContext *dc)
697 {
698 if (dc->white_item) {
699 /* We do not hold refcount */
700 dc->white_item = NULL;
701 }
702 while (dc->white_curves) {
703 reinterpret_cast<SPCurve *>(dc->white_curves->data)->unref();
704 dc->white_curves = g_slist_remove(dc->white_curves, dc->white_curves->data);
705 }
706 while (dc->white_anchors) {
707 sp_draw_anchor_destroy((SPDrawAnchor *) dc->white_anchors->data);
708 dc->white_anchors = g_slist_remove(dc->white_anchors, dc->white_anchors->data);
709 }
710 }
712 static void
713 spdc_free_colors(SPDrawContext *dc)
714 {
715 /* Red */
716 if (dc->red_bpath) {
717 gtk_object_destroy(GTK_OBJECT(dc->red_bpath));
718 dc->red_bpath = NULL;
719 }
720 if (dc->red_curve) {
721 dc->red_curve = dc->red_curve->unref();
722 }
723 /* Blue */
724 if (dc->blue_bpath) {
725 gtk_object_destroy(GTK_OBJECT(dc->blue_bpath));
726 dc->blue_bpath = NULL;
727 }
728 if (dc->blue_curve) {
729 dc->blue_curve = dc->blue_curve->unref();
730 }
731 /* Green */
732 while (dc->green_bpaths) {
733 gtk_object_destroy(GTK_OBJECT(dc->green_bpaths->data));
734 dc->green_bpaths = g_slist_remove(dc->green_bpaths, dc->green_bpaths->data);
735 }
736 if (dc->green_curve) {
737 dc->green_curve = dc->green_curve->unref();
738 }
739 if (dc->green_anchor) {
740 dc->green_anchor = sp_draw_anchor_destroy(dc->green_anchor);
741 }
742 /* White */
743 if (dc->white_item) {
744 /* We do not hold refcount */
745 dc->white_item = NULL;
746 }
747 while (dc->white_curves) {
748 reinterpret_cast<SPCurve *>(dc->white_curves->data)->unref();
749 dc->white_curves = g_slist_remove(dc->white_curves, dc->white_curves->data);
750 }
751 while (dc->white_anchors) {
752 sp_draw_anchor_destroy((SPDrawAnchor *) dc->white_anchors->data);
753 dc->white_anchors = g_slist_remove(dc->white_anchors, dc->white_anchors->data);
754 }
755 }
758 /*
759 Local Variables:
760 mode:c++
761 c-file-style:"stroustrup"
762 c-file-offsets:((innamespace . 0)(inline-open . 0)(case-label . +))
763 indent-tabs-mode:nil
764 fill-column:99
765 End:
766 */
767 // vim: filetype=cpp:expandtab:shiftwidth=4:tabstop=8:softtabstop=4:encoding=utf-8:textwidth=99 :