X-Git-Url: https://git.tokkee.org/?a=blobdiff_plain;f=src%2Fdraw-context.cpp;h=50799b55fe45f2b19c9c1a95e708bf6675976e50;hb=5209a05743e62584a7ec6afe050ffb0223f899f8;hp=30b2e612c40281b751541f04367a5a4807798e71;hpb=351ca2a8e90bf74b86c939f81f8948f8416a97f2;p=inkscape.git diff --git a/src/draw-context.cpp b/src/draw-context.cpp index 30b2e612c..50799b55f 100644 --- a/src/draw-context.cpp +++ b/src/draw-context.cpp @@ -25,6 +25,7 @@ #include "svg/svg.h" #include #include "libnr/n-art-bpath.h" +#include "display/curve.h" #include "desktop.h" #include "desktop-affine.h" #include "desktop-handles.h" @@ -164,16 +165,16 @@ sp_draw_context_setup(SPEventContext *ec) dc->red_bpath = sp_canvas_bpath_new(sp_desktop_sketch(ec->desktop), NULL); sp_canvas_bpath_set_stroke(SP_CANVAS_BPATH(dc->red_bpath), dc->red_color, 1.0, SP_STROKE_LINEJOIN_MITER, SP_STROKE_LINECAP_BUTT); /* Create red curve */ - dc->red_curve = sp_curve_new_sized(4); + dc->red_curve = new SPCurve(4); /* Create blue bpath */ dc->blue_bpath = sp_canvas_bpath_new(sp_desktop_sketch(ec->desktop), NULL); sp_canvas_bpath_set_stroke(SP_CANVAS_BPATH(dc->blue_bpath), dc->blue_color, 1.0, SP_STROKE_LINEJOIN_MITER, SP_STROKE_LINECAP_BUTT); /* Create blue curve */ - dc->blue_curve = sp_curve_new_sized(8); + dc->blue_curve = new SPCurve(8); /* Create green curve */ - dc->green_curve = sp_curve_new_sized(64); + dc->green_curve = new SPCurve(64); /* No green anchor by default */ dc->green_anchor = NULL; dc->green_closed = FALSE; @@ -202,7 +203,7 @@ sp_draw_context_finish(SPEventContext *ec) } static void -sp_draw_context_set(SPEventContext *ec, const gchar *key, const gchar *value) +sp_draw_context_set(SPEventContext */*ec*/, const gchar */*key*/, const gchar */*value*/) { } @@ -256,7 +257,7 @@ spdc_selection_changed(Inkscape::Selection *sel, SPDrawContext *dc) /* fixme: We have to ensure this is not delayed (Lauris) */ static void -spdc_selection_modified(Inkscape::Selection *sel, guint flags, SPDrawContext *dc) +spdc_selection_modified(Inkscape::Selection *sel, guint /*flags*/, SPDrawContext *dc) { if (dc->attach) { spdc_attach_selection(dc, sel); @@ -264,7 +265,7 @@ spdc_selection_modified(Inkscape::Selection *sel, guint flags, SPDrawContext *dc } static void -spdc_attach_selection(SPDrawContext *dc, Inkscape::Selection *sel) +spdc_attach_selection(SPDrawContext *dc, Inkscape::Selection */*sel*/) { /* We reset white and forget white/start/end anchors */ spdc_reset_white(dc); @@ -279,21 +280,21 @@ spdc_attach_selection(SPDrawContext *dc, Inkscape::Selection *sel) dc->white_item = item; /* Curve list */ /* We keep it in desktop coordinates to eliminate calculation errors */ - SPCurve *norm = sp_shape_get_curve(SP_SHAPE(item)); - sp_curve_transform(norm, sp_item_i2d_affine(dc->white_item)); + SPCurve *norm = sp_path_get_curve_for_edit (SP_PATH(item)); + norm->transform(sp_item_i2d_affine(dc->white_item)); g_return_if_fail( norm != NULL ); - dc->white_curves = g_slist_reverse(sp_curve_split(norm)); - sp_curve_unref(norm); + dc->white_curves = g_slist_reverse(norm->split()); + norm->unref(); /* Anchor list */ for (GSList *l = dc->white_curves; l != NULL; l = l->next) { SPCurve *c; c = (SPCurve*)l->data; - g_return_if_fail( c->end > 1 ); + g_return_if_fail( c->_end > 1 ); if ( SP_CURVE_BPATH(c)->code == NR_MOVETO_OPEN ) { NArtBpath *s, *e; SPDrawAnchor *a; - s = sp_curve_first_bpath(c); - e = sp_curve_last_bpath(c); + s = c->first_bpath(); + e = c->last_bpath(); a = sp_draw_anchor_new(dc, c, TRUE, NR::Point(s->x3, s->y3)); dc->white_anchors = g_slist_prepend(dc->white_anchors, a); a = sp_draw_anchor_new(dc, c, FALSE, NR::Point(e->x3, e->y3)); @@ -353,9 +354,11 @@ void spdc_endpoint_snap_rotation(SPEventContext const *const ec, NR::Point &p, N p = o + bdot * best; /* Snap it along best vector */ - SnapManager const &m = SP_EVENT_CONTEXT_DESKTOP(ec)->namedview->snap_manager; - p = m.constrainedSnap(Inkscape::Snapper::SNAP_POINT | Inkscape::Snapper::BBOX_POINT, - p, Inkscape::Snapper::ConstraintLine(best), NULL).getPoint(); + SnapManager &m = SP_EVENT_CONTEXT_DESKTOP(ec)->namedview->snap_manager; + m.setup(SP_EVENT_CONTEXT_DESKTOP(ec), NULL); + Inkscape::SnappedPoint const s = m.constrainedSnap( Inkscape::Snapper::SNAPPOINT_NODE, + p, Inkscape::Snapper::ConstraintLine(best)); + p = s.getPoint(); } } @@ -367,16 +370,17 @@ void spdc_endpoint_snap_free(SPEventContext const * const ec, NR::Point& p, guin return; } - /* FIXME: this should be doing bbox snap as well */ - SnapManager const &m = SP_EVENT_CONTEXT_DESKTOP(ec)->namedview->snap_manager; - p = m.freeSnap(Inkscape::Snapper::BBOX_POINT | Inkscape::Snapper::SNAP_POINT, p, NULL).getPoint(); + SnapManager &m = SP_EVENT_CONTEXT_DESKTOP(ec)->namedview->snap_manager; + m.setup(SP_EVENT_CONTEXT_DESKTOP(ec), NULL); + Inkscape::SnappedPoint const s = m.freeSnap(Inkscape::Snapper::SNAPPOINT_NODE, p); + p = s.getPoint(); } static SPCurve * reverse_then_unref(SPCurve *orig) { - SPCurve *ret = sp_curve_reverse(orig); - sp_curve_unref(orig); + SPCurve *ret = orig->create_reverse(); + orig->unref(); return ret; } @@ -392,24 +396,24 @@ spdc_concat_colors_and_flush(SPDrawContext *dc, gboolean forceclosed) SPCurve *c = dc->green_curve; /* Green */ - dc->green_curve = sp_curve_new_sized(64); + dc->green_curve = new SPCurve(64); while (dc->green_bpaths) { gtk_object_destroy(GTK_OBJECT(dc->green_bpaths->data)); dc->green_bpaths = g_slist_remove(dc->green_bpaths, dc->green_bpaths->data); } /* Blue */ - sp_curve_append_continuous(c, dc->blue_curve, 0.0625); - sp_curve_reset(dc->blue_curve); + c->append_continuous(dc->blue_curve, 0.0625); + dc->blue_curve->reset(); sp_canvas_bpath_set_bpath(SP_CANVAS_BPATH(dc->blue_bpath), NULL); /* Red */ if (dc->red_curve_is_valid) { - sp_curve_append_continuous(c, dc->red_curve, 0.0625); + c->append_continuous(dc->red_curve, 0.0625); } - sp_curve_reset(dc->red_curve); + dc->red_curve->reset(); sp_canvas_bpath_set_bpath(SP_CANVAS_BPATH(dc->red_bpath), NULL); - if (sp_curve_empty(c)) { - sp_curve_unref(c); + if (c->is_empty()) { + c->unref(); return; } @@ -417,10 +421,10 @@ spdc_concat_colors_and_flush(SPDrawContext *dc, gboolean forceclosed) if ( forceclosed || ( dc->green_anchor && dc->green_anchor->active ) ) { // We hit green anchor, closing Green-Blue-Red SP_EVENT_CONTEXT_DESKTOP(dc)->messageStack()->flash(Inkscape::NORMAL_MESSAGE, _("Path is closed.")); - sp_curve_closepath_current(c); + c->closepath_current(); /* Closed path, just flush */ spdc_flush_white(dc, c); - sp_curve_unref(c); + c->unref(); return; } @@ -428,16 +432,16 @@ spdc_concat_colors_and_flush(SPDrawContext *dc, gboolean forceclosed) if ( dc->sa && dc->ea && ( dc->sa->curve == dc->ea->curve ) && ( ( dc->sa != dc->ea ) - || dc->sa->curve->closed ) ) + || dc->sa->curve->is_closed() ) ) { // We hit bot start and end of single curve, closing paths SP_EVENT_CONTEXT_DESKTOP(dc)->messageStack()->flash(Inkscape::NORMAL_MESSAGE, _("Closing path.")); - if (dc->sa->start && !(dc->sa->curve->closed) ) { + if (dc->sa->start && !(dc->sa->curve->is_closed()) ) { c = reverse_then_unref(c); } - sp_curve_append_continuous(dc->sa->curve, c, 0.0625); - sp_curve_unref(c); - sp_curve_closepath_current(dc->sa->curve); + dc->sa->curve->append_continuous(c, 0.0625); + c->unref(); + dc->sa->curve->closepath_current(); spdc_flush_white(dc, NULL); return; } @@ -449,8 +453,8 @@ spdc_concat_colors_and_flush(SPDrawContext *dc, gboolean forceclosed) if (dc->sa->start) { s = reverse_then_unref(s); } - sp_curve_append_continuous(s, c, 0.0625); - sp_curve_unref(c); + s->append_continuous(c, 0.0625); + c->unref(); c = s; } else /* Step D - test end */ if (dc->ea) { SPCurve *e = dc->ea->curve; @@ -458,14 +462,14 @@ spdc_concat_colors_and_flush(SPDrawContext *dc, gboolean forceclosed) if (!dc->ea->start) { e = reverse_then_unref(e); } - sp_curve_append_continuous(c, e, 0.0625); - sp_curve_unref(e); + c->append_continuous(e, 0.0625); + e->unref(); } spdc_flush_white(dc, c); - sp_curve_unref(c); + c->unref(); } static char const * @@ -491,21 +495,21 @@ spdc_flush_white(SPDrawContext *dc, SPCurve *gc) if (dc->white_curves) { g_assert(dc->white_item); - c = sp_curve_concat(dc->white_curves); + c = SPCurve::concat(dc->white_curves); g_slist_free(dc->white_curves); dc->white_curves = NULL; if (gc) { - sp_curve_append(c, gc, FALSE); + c->append(gc, FALSE); } } else if (gc) { c = gc; - sp_curve_ref(c); + c->ref(); } else { return; } /* Now we have to go back to item coordinates at last */ - sp_curve_transform(c, ( dc->white_item + c->transform(( dc->white_item ? sp_item_dt2i_affine(dc->white_item) : sp_desktop_dt2root_affine(SP_EVENT_CONTEXT_DESKTOP(dc)) )); @@ -513,12 +517,14 @@ spdc_flush_white(SPDrawContext *dc, SPCurve *gc) SPDocument *doc = sp_desktop_document(desktop); Inkscape::XML::Document *xml_doc = sp_document_repr_doc(doc); - if ( c && !sp_curve_empty(c) ) { + if ( c && !c->is_empty() ) { /* We actually have something to write */ + bool has_lpe = false; Inkscape::XML::Node *repr; if (dc->white_item) { repr = SP_OBJECT_REPR(dc->white_item); + has_lpe = sp_lpe_item_has_path_effect_recursive(SP_LPE_ITEM(dc->white_item)); } else { repr = xml_doc->createElement("svg:path"); /* Set style */ @@ -527,7 +533,10 @@ spdc_flush_white(SPDrawContext *dc, SPCurve *gc) gchar *str = sp_svg_write_path(SP_CURVE_BPATH(c)); g_assert( str != NULL ); - repr->setAttribute("d", str); + if (has_lpe) + repr->setAttribute("inkscape:original-d", str); + else + repr->setAttribute("d", str); g_free(str); if (!dc->white_item) { @@ -541,9 +550,16 @@ spdc_flush_white(SPDrawContext *dc, SPCurve *gc) sp_document_done(doc, SP_IS_PEN_CONTEXT(dc)? SP_VERB_CONTEXT_PEN : SP_VERB_CONTEXT_PENCIL, _("Draw path")); + + // When quickly drawing several subpaths with Shift, the next subpath may be finished and + // flushed before the selection_modified signal is fired by the previous change, which + // results in the tool losing all of the selected path's curve except that last subpath. To + // fix this, we force the selection_modified callback now, to make sure the tool's curve is + // in sync immediately. + spdc_selection_modified(sp_desktop_selection(desktop), 0, dc); } - sp_curve_unref(c); + c->unref(); /* Flush pending updates */ sp_document_ensure_up_to_date(doc); @@ -580,7 +596,7 @@ spdc_reset_white(SPDrawContext *dc) dc->white_item = NULL; } while (dc->white_curves) { - sp_curve_unref((SPCurve *) dc->white_curves->data); + reinterpret_cast(dc->white_curves->data)->unref(); dc->white_curves = g_slist_remove(dc->white_curves, dc->white_curves->data); } while (dc->white_anchors) { @@ -598,7 +614,7 @@ spdc_free_colors(SPDrawContext *dc) dc->red_bpath = NULL; } if (dc->red_curve) { - dc->red_curve = sp_curve_unref(dc->red_curve); + dc->red_curve = dc->red_curve->unref(); } /* Blue */ if (dc->blue_bpath) { @@ -606,7 +622,7 @@ spdc_free_colors(SPDrawContext *dc) dc->blue_bpath = NULL; } if (dc->blue_curve) { - dc->blue_curve = sp_curve_unref(dc->blue_curve); + dc->blue_curve = dc->blue_curve->unref(); } /* Green */ while (dc->green_bpaths) { @@ -614,7 +630,7 @@ spdc_free_colors(SPDrawContext *dc) dc->green_bpaths = g_slist_remove(dc->green_bpaths, dc->green_bpaths->data); } if (dc->green_curve) { - dc->green_curve = sp_curve_unref(dc->green_curve); + dc->green_curve = dc->green_curve->unref(); } if (dc->green_anchor) { dc->green_anchor = sp_draw_anchor_destroy(dc->green_anchor); @@ -625,7 +641,7 @@ spdc_free_colors(SPDrawContext *dc) dc->white_item = NULL; } while (dc->white_curves) { - sp_curve_unref((SPCurve *) dc->white_curves->data); + reinterpret_cast(dc->white_curves->data)->unref(); dc->white_curves = g_slist_remove(dc->white_curves, dc->white_curves->data); } while (dc->white_anchors) {