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 int shape = prefs_get_int_attribute("tools.freehand", "shape", 0);
275 bool shape_applied = false;
276 SPCSSAttr *css_item = sp_css_attr_from_object (SP_OBJECT(item), SP_STYLE_FLAG_ALWAYS);
277 const char *cstroke = sp_repr_css_property(css_item, "stroke", "none");
279 switch (shape) {
280 case 0:
281 // don't apply any shape
282 break;
283 case 1:
284 {
285 // take shape from clipboard; TODO: catch the case where clipboard is empty
286 Effect::createAndApply(PATTERN_ALONG_PATH, dc->desktop->doc(), item);
287 Effect* lpe = sp_lpe_item_get_current_lpe(SP_LPE_ITEM(item));
288 static_cast<LPEPatternAlongPath*>(lpe)->pattern.on_paste_button_click();
290 shape_applied = true;
291 break;
292 }
293 case 2:
294 {
295 // "crescendo"
296 // TODO: this is only for illustration (we create a "crescendo"-shaped path
297 // manually; eventually we should read the path from a separate file)
298 SPCurve *c = new SPCurve();
299 c->moveto(0,5);
300 c->lineto(200,10);
301 c->lineto(200,0);
302 c->closepath();
303 spdc_paste_curve_as_param_path(c, dc, item);
304 c->unref();
306 shape_applied = true;
307 break;
308 }
309 case 3:
310 {
311 // "decrescendo"
312 // TODO: this is only for illustration (we create a "decrescendo"-shaped path
313 // manually; eventually we should read the path from a separate file)
314 SPCurve *c = new SPCurve();
315 c->moveto(0,0);
316 c->lineto(0,10);
317 c->lineto(200,5);
318 c->closepath();
319 spdc_paste_curve_as_param_path(c, dc, item);
320 c->unref();
322 shape_applied = true;
323 break;
324 }
325 default:
326 break;
327 }
328 if (shape_applied) {
329 // apply original stroke color as fill and unset stroke; then return
330 SPCSSAttr *css = sp_repr_css_attr_new();
331 sp_repr_css_set_property (css, "fill", cstroke);
332 sp_repr_css_set_property (css, "stroke", "none");
333 sp_desktop_apply_css_recursive(SP_OBJECT(item), css, true);
334 sp_repr_css_attr_unref(css);
335 return;
336 }
338 if (prefs_get_int_attribute("tools.freehand", "spiro-spline-mode", 0)) {
339 Effect::createAndApply(SPIRO, dc->desktop->doc(), item);
340 return;
341 }
342 if (dc->waiting_LPE_type != INVALID_LPE) {
343 Effect::createAndApply(dc->waiting_LPE_type, dc->desktop->doc(), item);
344 dc->waiting_LPE_type = INVALID_LPE;
345 }
346 if (SP_IS_PEN_CONTEXT(dc)) {
347 SP_PEN_CONTEXT(dc)->polylines_only = false;
348 }
349 }
350 }
352 /*
353 * Selection handlers
354 */
356 static void
357 spdc_selection_changed(Inkscape::Selection *sel, SPDrawContext *dc)
358 {
359 // note: in draw context, selection_changed() is only called with a valid item as argument when
360 // a new item was created; otherwise the following function call would yield wrong results
361 spdc_check_for_and_apply_waiting_LPE(dc, sel->singleItem());
363 if (dc->attach) {
364 spdc_attach_selection(dc, sel);
365 }
366 }
368 /* fixme: We have to ensure this is not delayed (Lauris) */
370 static void
371 spdc_selection_modified(Inkscape::Selection *sel, guint /*flags*/, SPDrawContext *dc)
372 {
373 if (dc->attach) {
374 spdc_attach_selection(dc, sel);
375 }
376 }
378 static void
379 spdc_attach_selection(SPDrawContext *dc, Inkscape::Selection */*sel*/)
380 {
381 /* We reset white and forget white/start/end anchors */
382 spdc_reset_white(dc);
383 dc->sa = NULL;
384 dc->ea = NULL;
386 SPItem *item = dc->selection ? dc->selection->singleItem() : NULL;
388 if ( item && SP_IS_PATH(item) ) {
389 /* Create new white data */
390 /* Item */
391 dc->white_item = item;
392 /* Curve list */
393 /* We keep it in desktop coordinates to eliminate calculation errors */
394 SPCurve *norm = sp_path_get_curve_for_edit (SP_PATH(item));
395 norm->transform(from_2geom(sp_item_i2d_affine(dc->white_item)));
396 g_return_if_fail( norm != NULL );
397 dc->white_curves = g_slist_reverse(norm->split());
398 norm->unref();
399 /* Anchor list */
400 for (GSList *l = dc->white_curves; l != NULL; l = l->next) {
401 SPCurve *c;
402 c = (SPCurve*)l->data;
403 g_return_if_fail( c->get_length() > 1 );
404 if ( !c->is_closed() ) {
405 SPDrawAnchor *a;
406 a = sp_draw_anchor_new(dc, c, TRUE, c->first_point());
407 dc->white_anchors = g_slist_prepend(dc->white_anchors, a);
408 a = sp_draw_anchor_new(dc, c, FALSE, c->last_point());
409 dc->white_anchors = g_slist_prepend(dc->white_anchors, a);
410 }
411 }
412 /* fixme: recalculate active anchor? */
413 }
414 }
417 /**
418 * Snaps node or handle to PI/rotationsnapsperpi degree increments.
419 *
420 * \param dc draw context
421 * \param p cursor point (to be changed by snapping)
422 * \param o origin point
423 * \param state keyboard state to check if ctrl was pressed
424 */
426 void spdc_endpoint_snap_rotation(SPEventContext const *const ec, NR::Point &p, NR::Point const o,
427 guint state)
428 {
429 /* Control must be down for this snap to work */
430 if ((state & GDK_CONTROL_MASK) == 0) {
431 return;
432 }
434 unsigned const snaps = abs(prefs_get_int_attribute("options.rotationsnapsperpi", "value", 12));
435 /* 0 means no snapping. */
437 /* mirrored by fabs, so this corresponds to 15 degrees */
438 NR::Point best; /* best solution */
439 double bn = NR_HUGE; /* best normal */
440 double bdot = 0;
441 NR::Point v = NR::Point(0, 1);
442 double const r00 = cos(M_PI / snaps), r01 = sin(M_PI / snaps);
443 double const r10 = -r01, r11 = r00;
445 NR::Point delta = p - o;
447 for (unsigned i = 0; i < snaps; i++) {
448 double const ndot = fabs(dot(v,NR::rot90(delta)));
449 NR::Point t(r00*v[NR::X] + r01*v[NR::Y],
450 r10*v[NR::X] + r11*v[NR::Y]);
451 if (ndot < bn) {
452 /* I think it is better numerically to use the normal, rather than the dot product
453 * to assess solutions, but I haven't proven it. */
454 bn = ndot;
455 best = v;
456 bdot = dot(v, delta);
457 }
458 v = t;
459 }
461 if (fabs(bdot) > 0) {
462 p = o + bdot * best;
464 /* Snap it along best vector */
465 SnapManager &m = SP_EVENT_CONTEXT_DESKTOP(ec)->namedview->snap_manager;
466 m.setup(SP_EVENT_CONTEXT_DESKTOP(ec), NULL);
467 m.constrainedSnapReturnByRef( Inkscape::Snapper::SNAPPOINT_NODE, p, Inkscape::Snapper::ConstraintLine(best));
468 }
469 }
472 void spdc_endpoint_snap_free(SPEventContext const * const ec, NR::Point& p, guint const state)
473 {
474 /* Shift disables this snap */
475 if (state & GDK_SHIFT_MASK) {
476 return;
477 }
479 SnapManager &m = SP_EVENT_CONTEXT_DESKTOP(ec)->namedview->snap_manager;
480 m.setup(SP_EVENT_CONTEXT_DESKTOP(ec), NULL);
481 m.freeSnapReturnByRef(Inkscape::Snapper::SNAPPOINT_NODE, p);
482 }
484 static SPCurve *
485 reverse_then_unref(SPCurve *orig)
486 {
487 SPCurve *ret = orig->create_reverse();
488 orig->unref();
489 return ret;
490 }
492 /**
493 * Concats red, blue and green.
494 * If any anchors are defined, process these, optionally removing curves from white list
495 * Invoke _flush_white to write result back to object.
496 */
497 void
498 spdc_concat_colors_and_flush(SPDrawContext *dc, gboolean forceclosed)
499 {
500 /* Concat RBG */
501 SPCurve *c = dc->green_curve;
503 /* Green */
504 dc->green_curve = new SPCurve(64);
505 while (dc->green_bpaths) {
506 gtk_object_destroy(GTK_OBJECT(dc->green_bpaths->data));
507 dc->green_bpaths = g_slist_remove(dc->green_bpaths, dc->green_bpaths->data);
508 }
509 /* Blue */
510 c->append_continuous(dc->blue_curve, 0.0625);
511 dc->blue_curve->reset();
512 sp_canvas_bpath_set_bpath(SP_CANVAS_BPATH(dc->blue_bpath), NULL);
513 /* Red */
514 if (dc->red_curve_is_valid) {
515 c->append_continuous(dc->red_curve, 0.0625);
516 }
517 dc->red_curve->reset();
518 sp_canvas_bpath_set_bpath(SP_CANVAS_BPATH(dc->red_bpath), NULL);
520 if (c->is_empty()) {
521 c->unref();
522 return;
523 }
525 /* Step A - test, whether we ended on green anchor */
526 if ( forceclosed || ( dc->green_anchor && dc->green_anchor->active ) ) {
527 // We hit green anchor, closing Green-Blue-Red
528 SP_EVENT_CONTEXT_DESKTOP(dc)->messageStack()->flash(Inkscape::NORMAL_MESSAGE, _("Path is closed."));
529 c->closepath_current();
530 /* Closed path, just flush */
531 spdc_flush_white(dc, c);
532 c->unref();
533 return;
534 }
536 /* Step B - both start and end anchored to same curve */
537 if ( dc->sa && dc->ea
538 && ( dc->sa->curve == dc->ea->curve )
539 && ( ( dc->sa != dc->ea )
540 || dc->sa->curve->is_closed() ) )
541 {
542 // We hit bot start and end of single curve, closing paths
543 SP_EVENT_CONTEXT_DESKTOP(dc)->messageStack()->flash(Inkscape::NORMAL_MESSAGE, _("Closing path."));
544 if (dc->sa->start && !(dc->sa->curve->is_closed()) ) {
545 c = reverse_then_unref(c);
546 }
547 dc->sa->curve->append_continuous(c, 0.0625);
548 c->unref();
549 dc->sa->curve->closepath_current();
550 spdc_flush_white(dc, NULL);
551 return;
552 }
554 /* Step C - test start */
555 if (dc->sa) {
556 SPCurve *s = dc->sa->curve;
557 dc->white_curves = g_slist_remove(dc->white_curves, s);
558 if (dc->sa->start) {
559 s = reverse_then_unref(s);
560 }
561 s->append_continuous(c, 0.0625);
562 c->unref();
563 c = s;
564 } else /* Step D - test end */ if (dc->ea) {
565 SPCurve *e = dc->ea->curve;
566 dc->white_curves = g_slist_remove(dc->white_curves, e);
567 if (!dc->ea->start) {
568 e = reverse_then_unref(e);
569 }
570 c->append_continuous(e, 0.0625);
571 e->unref();
572 }
575 spdc_flush_white(dc, c);
577 c->unref();
578 }
580 static char const *
581 tool_name(SPDrawContext *dc)
582 {
583 return ( SP_IS_PEN_CONTEXT(dc)
584 ? "tools.freehand.pen"
585 : "tools.freehand.pencil" );
586 }
588 /*
589 * Flushes white curve(s) and additional curve into object
590 *
591 * No cleaning of colored curves - this has to be done by caller
592 * No rereading of white data, so if you cannot rely on ::modified, do it in caller
593 *
594 */
596 static void
597 spdc_flush_white(SPDrawContext *dc, SPCurve *gc)
598 {
599 SPCurve *c;
601 if (dc->white_curves) {
602 g_assert(dc->white_item);
603 c = SPCurve::concat(dc->white_curves);
604 g_slist_free(dc->white_curves);
605 dc->white_curves = NULL;
606 if (gc) {
607 c->append(gc, FALSE);
608 }
609 } else if (gc) {
610 c = gc;
611 c->ref();
612 } else {
613 return;
614 }
616 /* Now we have to go back to item coordinates at last */
617 c->transform(( dc->white_item
618 ? from_2geom(sp_item_dt2i_affine(dc->white_item))
619 : sp_desktop_dt2root_affine(SP_EVENT_CONTEXT_DESKTOP(dc)) ));
621 SPDesktop *desktop = SP_EVENT_CONTEXT_DESKTOP(dc);
622 SPDocument *doc = sp_desktop_document(desktop);
623 Inkscape::XML::Document *xml_doc = sp_document_repr_doc(doc);
625 if ( c && !c->is_empty() ) {
626 /* We actually have something to write */
628 bool has_lpe = false;
629 Inkscape::XML::Node *repr;
630 if (dc->white_item) {
631 repr = SP_OBJECT_REPR(dc->white_item);
632 has_lpe = sp_lpe_item_has_path_effect_recursive(SP_LPE_ITEM(dc->white_item));
633 } else {
634 repr = xml_doc->createElement("svg:path");
635 /* Set style */
636 sp_desktop_apply_style_tool(desktop, repr, tool_name(dc), false);
637 }
639 gchar *str = sp_svg_write_path( c->get_pathvector() );
640 g_assert( str != NULL );
641 if (has_lpe)
642 repr->setAttribute("inkscape:original-d", str);
643 else
644 repr->setAttribute("d", str);
645 g_free(str);
647 if (!dc->white_item) {
648 /* Attach repr */
649 SPItem *item = SP_ITEM(desktop->currentLayer()->appendChildRepr(repr));
650 dc->selection->set(repr);
651 Inkscape::GC::release(repr);
652 item->transform = from_2geom(i2i_affine(desktop->currentRoot(), desktop->currentLayer()));
653 item->updateRepr();
654 }
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);
671 }
673 /**
674 * Returns FIRST active anchor (the activated one).
675 */
676 SPDrawAnchor *
677 spdc_test_inside(SPDrawContext *dc, NR::Point p)
678 {
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;
694 }
696 static void
697 spdc_reset_white(SPDrawContext *dc)
698 {
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 }
711 }
713 static void
714 spdc_free_colors(SPDrawContext *dc)
715 {
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 }
756 }
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 :