diff options
| author | Jabier Arraiza Cenoz <jabier.arraiza@marker.es> | 2014-03-20 00:48:37 +0000 |
|---|---|---|
| committer | Jabiertxof <jtx@jtx.marker.es> | 2014-03-20 00:48:37 +0000 |
| commit | 67a180fdd31fd8dd06be4df75356509001295458 (patch) | |
| tree | faec7c3bc12ac848068262cdbe2f0e92dd3664c2 /src | |
| parent | update to trunk (diff) | |
| download | inkscape-67a180fdd31fd8dd06be4df75356509001295458.tar.gz inkscape-67a180fdd31fd8dd06be4df75356509001295458.zip | |
Refactor of anchors
(bzr r11950.1.306)
Diffstat (limited to 'src')
| -rw-r--r-- | src/ui/tools/freehand-base.cpp | 97 | ||||
| -rw-r--r-- | src/ui/tools/freehand-base.h | 2 | ||||
| -rw-r--r-- | src/ui/tools/pen-tool.cpp | 18 |
3 files changed, 50 insertions, 67 deletions
diff --git a/src/ui/tools/freehand-base.cpp b/src/ui/tools/freehand-base.cpp index d34ca2142..5897ce0ee 100644 --- a/src/ui/tools/freehand-base.cpp +++ b/src/ui/tools/freehand-base.cpp @@ -492,17 +492,7 @@ void spdc_concat_colors_and_flush(FreehandBase *dc, gboolean forceclosed) dc->red_curve->reset(); sp_canvas_bpath_set_bpath(SP_CANVAS_BPATH(dc->red_bpath), NULL); - // Blue2 - dc->blue2_curve->reset(); - sp_canvas_bpath_set_bpath(SP_CANVAS_BPATH(dc->blue2_bpath), NULL); - - /* if c is empty, it might be that the user was trying to continue an existing curve and cancelled. - if this is the case and we are in bspline or spirolive the previous curve needs to be selected again because - we modify it when continuing through an anchor. */ if (c->is_empty()) { - if(prefs->getInt(tool_name(dc) + "/freehand-mode", 0) == 1 || prefs->getInt(tool_name(dc) + "/freehand-mode", 0) == 2){ - spdc_selection_modified(sp_desktop_selection(dc->desktop), 0, dc); - } c->unref(); return; } @@ -526,50 +516,43 @@ void spdc_concat_colors_and_flush(FreehandBase *dc, gboolean forceclosed) { // We hit bot start and end of single curve, closing paths dc->desktop->messageStack()->flash(Inkscape::NORMAL_MESSAGE, _("Closing path.")); - - /* if we are in bspline or spirolive mode, the continuation and ending curve are updated when continuing or ending the curve in an anchor. - this causes that the original function doesn't detect if it's the same curve in case the curves have multiples parts -shift- and - close incorrectly one of the parts */ + if (dc->sa->start && !(dc->sa->curve->is_closed()) ) { + c = reverse_then_unref(c); + } if(prefs->getInt(tool_name(dc) + "/freehand-mode", 0) == 1 || - prefs->getInt(tool_name(dc) + "/freehand-mode", 0) == 2){ - if (dc->sa->start && !(dc->sa->curve->is_closed()) ) { - dc->sa->curve = reverse_then_unref(dc->sa->curve); - } - dc->sa->curve->append_continuous(c, 0.0625); + prefs->getInt(tool_name(dc) + "/freehand-mode", 0) == 2){ + dc->sc->append_continuous(c, 0.0625); c->unref(); - if(Geom::are_near(dc->sa->curve->first_path()->initialPoint(), dc->ea->dp)){ - dc->sa->curve->closepath_current(); - } - - // if the curve has an bspline or spiro LPE, we execute - // spdc_flush_white, passing the necessary starting curve. - dc->white_curves = g_slist_remove(dc->white_curves, dc->sa->curve); - spdc_flush_white(dc, dc->sa->curve); + dc->sc->closepath_current(); }else{ - if (dc->sa->start && !(dc->sa->curve->is_closed()) ) { - c = reverse_then_unref(c); - } dc->sa->curve->append_continuous(c, 0.0625); c->unref(); dc->sa->curve->closepath_current(); - spdc_flush_white(dc, NULL); } - + spdc_flush_white(dc, NULL); return; } // Step C - test start if (dc->sa) { SPCurve *s = dc->sa->curve; + if(prefs->getInt(tool_name(dc) + "/freehand-mode", 0) == 1 || + prefs->getInt(tool_name(dc) + "/freehand-mode", 0) == 2){ + s = dc->sc; + } dc->white_curves = g_slist_remove(dc->white_curves, s); if (dc->sa->start) { s = reverse_then_unref(s); } s->append_continuous(c, 0.0625); - c->reset(); + c->unref(); c = s; } else /* Step D - test end */ if (dc->ea) { SPCurve *e = dc->ea->curve; + if(prefs->getInt(tool_name(dc) + "/freehand-mode", 0) == 1 || + prefs->getInt(tool_name(dc) + "/freehand-mode", 0) == 2){ + e = dc->ec; + } dc->white_curves = g_slist_remove(dc->white_curves, e); if (!dc->ea->start) { e = reverse_then_unref(e); @@ -577,16 +560,30 @@ void spdc_concat_colors_and_flush(FreehandBase *dc, gboolean forceclosed) c->append_continuous(e, 0.0625); e->unref(); } + + spdc_flush_white(dc, c); + c->unref(); } static void spdc_flush_white(FreehandBase *dc, SPCurve *gc) { SPCurve *c; - + Inkscape::Preferences *prefs = Inkscape::Preferences::get(); if (dc->white_curves) { g_assert(dc->white_item); + if(prefs->getInt(tool_name(dc) + "/freehand-mode", 0) == 1 || + prefs->getInt(tool_name(dc) + "/freehand-mode", 0) == 2){ + if(dc->sa){ + dc->white_curves = g_slist_remove(dc->white_curves, dc->sa->curve); + dc->white_curves = g_slist_append(dc->white_curves, dc->sc); + } + if(dc->ea){ + dc->white_curves = g_slist_remove(dc->white_curves, dc->ea->curve); + dc->white_curves = g_slist_append(dc->white_curves, dc->ec); + } + } c = SPCurve::concat(dc->white_curves); g_slist_free(dc->white_curves); dc->white_curves = NULL; @@ -615,17 +612,6 @@ static void spdc_flush_white(FreehandBase *dc, SPCurve *gc) bool has_lpe = false; Inkscape::XML::Node *repr; - /* if we are in bspline or spirolive the anchors curves, if exist, needs to be selected again because - we modify it when continuing through an anchor. */ - Inkscape::Preferences *prefs = Inkscape::Preferences::get(); - if ( ((dc->sa && !dc->sa->curve->is_empty()) || - (dc->ea && !dc->ea->curve->is_empty())) && - (prefs->getInt(tool_name(dc) + "/freehand-mode", 0) == 1 || - prefs->getInt(tool_name(dc) + "/freehand-mode", 0) == 2) - ) { - spdc_selection_modified(sp_desktop_selection(dc->desktop), 0, dc); - } - if (dc->white_item) { repr = dc->white_item->getRepr(); has_lpe = SP_LPE_ITEM(dc->white_item)->hasPathEffectRecursive(); @@ -689,19 +675,6 @@ SPDrawAnchor *spdc_test_inside(FreehandBase *dc, Geom::Point p) active = na; } } - - /* modify the anchoring curve so it is equal to the starting curve. - this curve is modified when it's modified and we need them to be equal to the closing curve */ - Inkscape::Preferences *prefs = Inkscape::Preferences::get(); - if((prefs->getInt(tool_name(dc) + "/freehand-mode", 0) == 1 || - prefs->getInt(tool_name(dc) + "/freehand-mode", 0) == 2) && - dc->sa && !dc->red_curve->is_empty() && !dc->green_anchor){ - if(active){ - active->curve = dc->sa->curve; - active->curve->ref(); - } - } - return active; } @@ -750,6 +723,14 @@ static void spdc_free_colors(FreehandBase *dc) dc->blue2_curve = dc->blue2_curve->unref(); } + if (dc->sc) { + dc->sc = dc->sc->unref(); + } + + if (dc->ec) { + dc->ec = dc->ec->unref(); + } + // Green while (dc->green_bpaths) { sp_canvas_item_destroy(SP_CANVAS_ITEM(dc->green_bpaths->data)); diff --git a/src/ui/tools/freehand-base.h b/src/ui/tools/freehand-base.h index d5c2fc9ba..266e22783 100644 --- a/src/ui/tools/freehand-base.h +++ b/src/ui/tools/freehand-base.h @@ -74,9 +74,11 @@ public: // Start anchor SPDrawAnchor *sa; + SPCurve * sc; // End anchor SPDrawAnchor *ea; + SPCurve * ec; /* type of the LPE that is to be applied automatically to a finished path (if any) */ Inkscape::LivePathEffect::EffectType waiting_LPE_type; diff --git a/src/ui/tools/pen-tool.cpp b/src/ui/tools/pen-tool.cpp index 75dd6a32b..1701cf5d9 100644 --- a/src/ui/tools/pen-tool.cpp +++ b/src/ui/tools/pen-tool.cpp @@ -1516,8 +1516,8 @@ void PenTool::_bspline_spiro_start_anchor_on() if (this->sa->start) { tmpCurve = tmpCurve->create_reverse(); } - this->sa->curve->reset(); - this->sa->curve = tmpCurve; + this->sc->reset(); + this->sc = tmpCurve; } void PenTool::_bspline_spiro_start_anchor_off() @@ -1542,8 +1542,8 @@ void PenTool::_bspline_spiro_start_anchor_off() if (this->sa->start) { tmpCurve = tmpCurve->create_reverse(); } - this->sa->curve->reset(); - this->sa->curve = tmpCurve; + this->sc->reset(); + this->sc = tmpCurve; } } @@ -1677,8 +1677,8 @@ void PenTool::_bspline_spiro_end_anchor_on() if (!this->sa->start) { tmpCurve = tmpCurve->create_reverse(); } - this->sa->curve->reset(); - this->sa->curve = tmpCurve; + this->sc->reset(); + this->sc = tmpCurve; } } @@ -1726,8 +1726,8 @@ void PenTool::_bspline_spiro_end_anchor_off() if (!this->sa->start) { tmpCurve = tmpCurve->create_reverse(); } - this->sa->curve->reset(); - this->sa->curve = tmpCurve; + this->sc->reset(); + this->sc = tmpCurve; } } } @@ -1742,7 +1742,7 @@ void PenTool::_bspline_spiro_build() SPCurve *curve = new SPCurve(); //If we continuate the existing curve we add it at the start if(this->sa && !this->sa->curve->is_empty()){ - curve = this->sa->curve->copy(); + curve = this->sc->copy(); if (this->sa->start) { curve = curve->create_reverse(); } |
