diff options
| -rw-r--r-- | src/live_effects/lpe-powerstroke.cpp | 61 | ||||
| -rw-r--r-- | src/ui/toolbar/pencil-toolbar.cpp | 7 | ||||
| -rw-r--r-- | src/ui/tools/freehand-base.cpp | 8 | ||||
| -rw-r--r-- | src/ui/tools/pencil-tool.cpp | 62 |
4 files changed, 76 insertions, 62 deletions
diff --git a/src/live_effects/lpe-powerstroke.cpp b/src/live_effects/lpe-powerstroke.cpp index d0f6f1fda..55ef2aaa7 100644 --- a/src/live_effects/lpe-powerstroke.cpp +++ b/src/live_effects/lpe-powerstroke.cpp @@ -215,39 +215,42 @@ LPEPowerStroke::doOnApply(SPLPEItem const* lpeitem) std::vector<Geom::Point> points; Geom::PathVector const &pathv = pathv_to_linear_and_cubic_beziers(SP_SHAPE(lpeitem)->_curve->get_pathvector()); double width = (lpeitem && lpeitem->style) ? lpeitem->style->stroke_width.computed / 2 : 1.; - - SPCSSAttr *css = sp_repr_css_attr_new (); - if (lpeitem->style) { - if (lpeitem->style->stroke.isPaintserver()) { - SPPaintServer * server = lpeitem->style->getStrokePaintServer(); - if (server) { - Glib::ustring str; - str += "url(#"; - str += server->getId(); - str += ")"; - sp_repr_css_set_property (css, "fill", str.c_str()); + Inkscape::Preferences *prefs = Inkscape::Preferences::get(); + Glib::ustring pref_path_ps = "/live_effects/powerstroke/powerpencilstyle"; + Glib::ustring pref_path_pp = "/live_effects/powerstroke/powerpencil"; + bool powerpencil = prefs->getBool(pref_path_pp, false); + bool powerpencilstyle = prefs->getBool(pref_path_ps, false); + if (!powerpencilstyle) { + SPCSSAttr *css = sp_repr_css_attr_new (); + if (lpeitem->style) { + if (lpeitem->style->stroke.isPaintserver()) { + SPPaintServer * server = lpeitem->style->getStrokePaintServer(); + if (server) { + Glib::ustring str; + str += "url(#"; + str += server->getId(); + str += ")"; + sp_repr_css_set_property (css, "fill", str.c_str()); + } + } else if (lpeitem->style->stroke.isColor()) { + gchar c[64]; + sp_svg_write_color (c, sizeof(c), lpeitem->style->stroke.value.color.toRGBA32(SP_SCALE24_TO_FLOAT(lpeitem->style->stroke_opacity.value))); + sp_repr_css_set_property (css, "fill", c); + } else { + sp_repr_css_set_property (css, "fill", "none"); } - } else if (lpeitem->style->stroke.isColor()) { - gchar c[64]; - sp_svg_write_color (c, sizeof(c), lpeitem->style->stroke.value.color.toRGBA32(SP_SCALE24_TO_FLOAT(lpeitem->style->stroke_opacity.value))); - sp_repr_css_set_property (css, "fill", c); } else { - sp_repr_css_set_property (css, "fill", "none"); + sp_repr_css_unset_property (css, "fill"); } - } else { - sp_repr_css_unset_property (css, "fill"); - } - sp_repr_css_set_property(css, "fill-rule", "nonzero"); - sp_repr_css_set_property(css, "stroke", "none"); - - sp_desktop_apply_css_recursive(item, css, true); - sp_repr_css_attr_unref (css); - - item->updateRepr(); - Inkscape::Preferences *prefs = Inkscape::Preferences::get(); - Glib::ustring pref_path_pp = "/live_effects/powerstroke/powerpencil"; - bool powerpencil = prefs->getBool(pref_path_pp, false); + sp_repr_css_set_property(css, "fill-rule", "nonzero"); + sp_repr_css_set_property(css, "stroke", "none"); + + sp_desktop_apply_css_recursive(item, css, true); + sp_repr_css_attr_unref (css); + + item->updateRepr(); + } if (!powerpencil) { if (pathv.empty()) { points.emplace_back(0.2,width ); diff --git a/src/ui/toolbar/pencil-toolbar.cpp b/src/ui/toolbar/pencil-toolbar.cpp index 5d7fabe4a..3ef896ccf 100644 --- a/src/ui/toolbar/pencil-toolbar.cpp +++ b/src/ui/toolbar/pencil-toolbar.cpp @@ -209,9 +209,10 @@ PencilToolbar::PencilToolbar(SPDesktop *desktop, if (freehandMode == 2 || !prefs->getInt("/tools/freehand/pencil/simplify", 0)) { _flatten_simplify->set_visible(false); } - - /* Advanced shape options */ - _shape_item->set_visible(!prefs->getBool("/tools/freehand/pencil/pressure", false)); + if (!prefs->getBool(freehand_tool_name() + "/pressure", false)) { + /* Advanced shape options */ + _shape_item->set_visible(!prefs->getBool("/tools/freehand/pencil/pressure", false)); + } } } diff --git a/src/ui/tools/freehand-base.cpp b/src/ui/tools/freehand-base.cpp index c6f99db92..0c82b4dec 100644 --- a/src/ui/tools/freehand-base.cpp +++ b/src/ui/tools/freehand-base.cpp @@ -243,7 +243,7 @@ static void spdc_apply_powerstroke_shape(std::vector<Geom::Point> points, Freeha item->transform = transform_coordinate; SPShape *sp_shape = dynamic_cast<SPShape *>(item); if (sp_shape) { - SPCurve * c = sp_shape->getCurve(); + SPCurve *c = sp_shape->getCurve(); if (!c) { return; } @@ -285,8 +285,12 @@ static void spdc_apply_powerstroke_shape(std::vector<Geom::Point> points, Freeha Geom::Path path = c->get_pathvector()[0]; if (!path.empty()) { pt->powerStrokeInterpolate(path); - } + } + bool transform_stroke = prefs->getBool("/options/transform/stroke", true); + prefs->setBool("/options/transform/stroke", true); ps->offset_points.param_set_and_write_new_value(pt->points); + ps->offset_points.param_transform_multiply(transform_coordinate.inverse(), false); + prefs->setBool("/options/transform/stroke", transform_stroke); } prefs->setBool(pref_path_pp, false); return; diff --git a/src/ui/tools/pencil-tool.cpp b/src/ui/tools/pencil-tool.cpp index 276ce411e..00e5dee46 100644 --- a/src/ui/tools/pencil-tool.cpp +++ b/src/ui/tools/pencil-tool.cpp @@ -734,6 +734,12 @@ PencilTool::removePowerStrokePreview() } } +static inline double +square(double const x) +{ + return x * x; +} + void PencilTool::addPowerStrokePencil() { @@ -746,15 +752,6 @@ PencilTool::addPowerStrokePencil() if (min > max){ min = max; } - if (!green_curve->is_unset()) { - this->_curve = green_curve->copy(); - if (!red_curve->is_unset()) { - this->_curve->append_continuous( red_curve, 0.0625); - } - } - if (!this->_curve || this->_curve->is_unset()) { - this->_curve = nullptr; - } double dezoomify_factor = 0.05 * 1000/SP_EVENT_CONTEXT(this)->desktop->current_zoom();//\/100 we want 100% = 1; double last_pressure = this->_wps.back(); double pressure_shrunk = (last_pressure * (max - min)) + min; @@ -775,11 +772,21 @@ PencilTool::addPowerStrokePencil() if (this->_curve && this->ps.size() > 1) { std::future_status status; - if (future.valid()) { + bool stop = false; + bool nofuture = false; + try { status = future.wait_for(std::chrono::seconds(0)); + } catch (const std::future_error& e) { + stop = true; + if (e.code() == std::future_errc::no_state) { + nofuture = true; + } else { + std::cout << "Caught a future_error with code \"" << e.code() + << nofuture << future.valid() << "\"\nMessage: \"" << e.what() << "\"\n"; + } } - if (!future.valid() || status == std::future_status::ready) { - if (status == std::future_status::ready) { + if (nofuture || status == std::future_status::ready) { + if (!stop && status == std::future_status::ready) { const gchar *tmpid = "tmp_power_stroke_preview"; const gchar *id = "power_stroke_preview"; SPDocument * document = SP_ACTIVE_DOCUMENT; @@ -791,10 +798,8 @@ PencilTool::addPowerStrokePencil() using namespace Inkscape::LivePathEffect; if (tmpelemref) { bool failed = true; - if (elemref) { - if (SP_SHAPE(elemref)->getCurve() != SP_SHAPE(elemref)->getCurveBeforeLPE()) { - failed = false; - } + if (elemref->getRepr()->attribute("style") != "opacity:0") { + failed = false; } SPObject *toremove = failed ? elemref : tmpelemref; SPObject *toretain = !failed ? elemref : tmpelemref; @@ -814,14 +819,14 @@ PencilTool::addPowerStrokePencil() } } Inkscape::Preferences *prefs = Inkscape::Preferences::get(); - SPCurve *curve; + SPCurve *curve = new SPCurve(); double tol = prefs->getDoubleLimited("/tools/freehand/pencil/tolerance", 10.0, 1.0, 100.0) * 0.4; bool simplify = prefs->getInt("/tools/freehand/pencil/simplify", 0); if(simplify){ double tol2 = prefs->getDoubleLimited("/tools/freehand/pencil/base-simplify", 25.0, 1.0, 100.0) * 0.4; tol = std::min(tol,tol2); } - double tolerance_sq = 0.02 ;// * square(this->desktop->w2d().descrim() * tol) * exp(0.2 * tol - 2); + double tolerance_sq = 0.02 * square(this->desktop->w2d().descrim() * tol) * exp(0.2 * tol - 2); int n_points = this->ps.size(); // worst case gives us a segment per point int max_segs = 4 * n_points; @@ -835,12 +840,13 @@ PencilTool::addPowerStrokePencil() } } Geom::Path path = curve->get_pathvector()[0]; + delete curve; if (!path.empty()) { Geom::Affine transform_coordinate = SP_ITEM(SP_ACTIVE_DESKTOP->currentLayer())->i2dt_affine().inverse(); path *= transform_coordinate; powerStrokeInterpolate(path); std::vector<Geom::Point> points_preview = this->points; - //points_preview.push_back(Geom::Point(path.size() - 1, points_preview[points_preview.size()-1][Geom::Y])); + points_preview.push_back(Geom::Point(path.size() - 1, points_preview[points_preview.size()-1][Geom::Y])); future = std::async(std::launch::async, [path, points_preview] { using namespace Inkscape::LivePathEffect; SPDocument * document = SP_ACTIVE_DOCUMENT; @@ -854,19 +860,21 @@ PencilTool::addPowerStrokePencil() gchar * pvector_str = sp_svg_write_path(path); if (pvector_str) { pp->setAttribute("d" , pvector_str); + pp->setAttribute("style", "opacity:0"); g_free(pvector_str); } pp->setAttribute("id", "power_stroke_preview"); Inkscape::GC::release(pp); - SPShape * powerpreview = SP_SHAPE(SP_ITEM(SP_ACTIVE_DESKTOP->currentLayer())->appendChildRepr(pp)); - sp_desktop_apply_style_tool(SP_ACTIVE_DESKTOP, pp, Glib::ustring("/tools/freehand/pencil").data(), false); + SPShape *powerpreview = SP_SHAPE(SP_ITEM(SP_ACTIVE_DESKTOP->currentLayer())->appendChildRepr(pp)); SPLPEItem *lpeitem = dynamic_cast<SPLPEItem *>(powerpreview); if (!lpeitem) { return true; } Inkscape::Preferences *prefs = Inkscape::Preferences::get(); Glib::ustring pref_path_pp = "/live_effects/powerstroke/powerpencil"; + Glib::ustring pref_path_ps = "/live_effects/powerstroke/powerpencilstyle"; prefs->setBool(pref_path_pp, true); + prefs->setBool(pref_path_ps, true); Effect::createAndApply(POWERSTROKE, SP_ACTIVE_DESKTOP->doc(), lpeitem); Effect* lpe = lpeitem->getCurrentLPE(); Inkscape::LivePathEffect::LPEPowerStroke *pspreview = static_cast<LPEPowerStroke*>(lpe); @@ -881,11 +889,15 @@ PencilTool::addPowerStrokePencil() pspreview->offset_points.param_set_and_write_new_value(points_preview); sp_lpe_item_enable_path_effects(lpeitem, true); } + if (powerpreview->getCurve() != powerpreview->getCurveBeforeLPE()) { + pp->setAttribute("style", "fill:#888888;opacity:0.7;fill-rule:nonzero;stroke:none;"); + } prefs->setBool(pref_path_pp, false); + prefs->setBool(pref_path_ps, false); return true; }); } else { - //std::cout << "stopped" << std::endl; + std::cout << "stopped" << std::endl; } } @@ -917,12 +929,6 @@ void PencilTool::_addFreehandPoint(Geom::Point const &p, guint /*state*/) { } } -static inline double -square(double const x) -{ - return x * x; -} - void PencilTool::powerStrokeInterpolate(Geom::Path path) { size_t ps_size = this->ps.size(); |
