summaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
authorJabier Arraiza <jabier.arraiza@marker.es>2019-07-18 22:02:00 +0000
committerJabier Arraiza <jabier.arraiza@marker.es>2019-07-19 21:33:23 +0000
commit6a1663ece896e790ab6de408abdddaca0d2a5e5c (patch)
treedb3f9a5c5dc781e99624e54c1b5a32073a00beb3 /src
parentImprovements finish pointed by Maren (diff)
downloadinkscape-6a1663ece896e790ab6de408abdddaca0d2a5e5c.tar.gz
inkscape-6a1663ece896e790ab6de408abdddaca0d2a5e5c.zip
Fixes for pressure pencil
Diffstat (limited to 'src')
-rw-r--r--src/live_effects/effect.cpp4
-rw-r--r--src/live_effects/effect.h2
-rw-r--r--src/live_effects/lpe-powerstroke.cpp27
-rw-r--r--src/live_effects/lpe-powerstroke.h4
-rw-r--r--src/live_effects/lpe-simplify.cpp19
-rw-r--r--src/live_effects/lpe-simplify.h2
-rw-r--r--src/live_effects/parameter/togglebutton.cpp76
-rw-r--r--src/live_effects/parameter/togglebutton.h58
-rw-r--r--src/ui/toolbar/pencil-toolbar.cpp4
-rw-r--r--src/ui/tools/freehand-base.cpp2
-rw-r--r--src/ui/tools/pencil-tool.cpp118
11 files changed, 178 insertions, 138 deletions
diff --git a/src/live_effects/effect.cpp b/src/live_effects/effect.cpp
index e547e709d..acc9dfaa9 100644
--- a/src/live_effects/effect.cpp
+++ b/src/live_effects/effect.cpp
@@ -1250,10 +1250,10 @@ void Effect::doAfterEffect (SPLPEItem const* /*lpeitem*/)
is_load = false;
}
-void Effect::doOnException (SPLPEItem const* /*lpeitem*/)
+void Effect::doOnException(SPLPEItem const * /*lpeitem*/)
{
has_exception = true;
- pathvector_after_effect = pathvector_before_effect;
+ pathvector_after_effect = pathvector_before_effect;
}
diff --git a/src/live_effects/effect.h b/src/live_effects/effect.h
index 6ef65fe3c..de237b8bb 100644
--- a/src/live_effects/effect.h
+++ b/src/live_effects/effect.h
@@ -75,7 +75,7 @@ public:
virtual void doBeforeEffect (SPLPEItem const* lpeitem);
virtual void doAfterEffect (SPLPEItem const* lpeitem);
- virtual void doOnException (SPLPEItem const* lpeitem);
+ virtual void doOnException(SPLPEItem const *lpeitem);
virtual void doOnRemove (SPLPEItem const* lpeitem);
virtual void doOnVisibilityToggled(SPLPEItem const* lpeitem);
void writeParamsToSVG();
diff --git a/src/live_effects/lpe-powerstroke.cpp b/src/live_effects/lpe-powerstroke.cpp
index 5eb5afc75..fa961c9af 100644
--- a/src/live_effects/lpe-powerstroke.cpp
+++ b/src/live_effects/lpe-powerstroke.cpp
@@ -12,8 +12,8 @@
*/
#include "live_effects/lpe-powerstroke.h"
-#include "live_effects/lpe-simplify.h"
#include "live_effects/lpe-powerstroke-interpolators.h"
+#include "live_effects/lpe-simplify.h"
#include "live_effects/lpeobject.h"
#include "svg/svg-color.h"
@@ -185,7 +185,7 @@ LPEPowerStroke::LPEPowerStroke(LivePathEffectObject *lpeobject) :
scale_width.param_set_increments(0.1, 0.1);
scale_width.param_set_digits(4);
recusion_limit = 0;
- previous_size = 0;
+ has_recursion = false;
}
LPEPowerStroke::~LPEPowerStroke() = default;
@@ -194,15 +194,13 @@ void
LPEPowerStroke::doBeforeEffect(SPLPEItem const *lpeItem)
{
offset_points.set_scale_width(scale_width);
- size_t psize = pathvector_before_effect.size();
- if (!is_load && previous_size != psize) {
+ if (has_recursion) {
+ has_recursion = false;
adjustForNewPath(pathvector_before_effect);
}
- previous_size = psize;
}
-void
-LPEPowerStroke::applyStyle(SPLPEItem *lpeitem)
+void LPEPowerStroke::applyStyle(SPLPEItem *lpeitem)
{
SPCSSAttr *css = sp_repr_css_attr_new();
if (lpeitem->style) {
@@ -765,17 +763,20 @@ LPEPowerStroke::doEffect_path (Geom::PathVector const & path_in)
return path_out;
}
-void
-LPEPowerStroke::doAfterEffect (SPLPEItem const* lpeitem){
+void LPEPowerStroke::doAfterEffect(SPLPEItem const *lpeitem)
+{
is_load = false;
if (pathvector_before_effect[0].size() == pathvector_after_effect[0].size()) {
if (recusion_limit < 6) {
- Inkscape::LivePathEffect::Effect* effect = sp_lpe_item->getPathEffectOfType(Inkscape::LivePathEffect::SIMPLIFY);
- if(effect){
- LivePathEffect::LPESimplify *simplify = dynamic_cast<LivePathEffect::LPESimplify*>(effect->getLPEObj()->get_lpe());
+ Inkscape::LivePathEffect::Effect *effect =
+ sp_lpe_item->getPathEffectOfType(Inkscape::LivePathEffect::SIMPLIFY);
+ if (effect) {
+ LivePathEffect::LPESimplify *simplify =
+ dynamic_cast<LivePathEffect::LPESimplify *>(effect->getLPEObj()->get_lpe());
double threshold = simplify->threshold * 1.2;
- simplify->threshold.param_set_value(threshold);
+ simplify->threshold.param_set_value(threshold);
simplify->threshold.write_to_SVG();
+ has_recursion = true;
}
}
++recusion_limit;
diff --git a/src/live_effects/lpe-powerstroke.h b/src/live_effects/lpe-powerstroke.h
index 4cb4e5a69..caf84b2db 100644
--- a/src/live_effects/lpe-powerstroke.h
+++ b/src/live_effects/lpe-powerstroke.h
@@ -42,7 +42,7 @@ public:
void doBeforeEffect(SPLPEItem const *lpeItem) override;
void doOnApply(SPLPEItem const* lpeitem) override;
void doOnRemove(SPLPEItem const* lpeitem) override;
- void doAfterEffect (SPLPEItem const* lpeitem) override;
+ void doAfterEffect(SPLPEItem const *lpeitem) override;
void applyStyle(SPLPEItem *lpeitem);
// methods called by path-manipulator upon edits
void adjustForNewPath(Geom::PathVector const & path_in);
@@ -59,7 +59,7 @@ private:
ScalarParam miter_limit;
EnumParam<unsigned> end_linecap_type;
size_t recusion_limit;
- size_t previous_size;
+ bool has_recursion;
};
} //namespace LivePathEffect
diff --git a/src/live_effects/lpe-simplify.cpp b/src/live_effects/lpe-simplify.cpp
index da36b184e..f101e63f2 100644
--- a/src/live_effects/lpe-simplify.cpp
+++ b/src/live_effects/lpe-simplify.cpp
@@ -19,15 +19,16 @@ namespace Inkscape {
namespace LivePathEffect {
LPESimplify::LPESimplify(LivePathEffectObject *lpeobject)
- : Effect(lpeobject),
- steps(_("Steps:"),_("Change number of simplify steps "), "steps", &wr, this,1),
- threshold(_("Roughly threshold:"), _("Roughly threshold:"), "threshold", &wr, this, 0.002),
- smooth_angles(_("Smooth angles:"), _("Max degree difference on handles to perform a smooth"), "smooth_angles", &wr, this, 0.),
- helper_size(_("Helper size:"), _("Helper size"), "helper_size", &wr, this, 5),
- simplify_individual_paths(_("Paths separately"), _("Simplifying paths (separately)"), "simplify_individual_paths", &wr, this, false,
- "", INKSCAPE_ICON("on"), INKSCAPE_ICON("off")),
- simplify_just_coalesce(_("Just coalesce"), _("Simplify just coalesce"), "simplify_just_coalesce", &wr, this, false,
- "", INKSCAPE_ICON("on"), INKSCAPE_ICON("off"))
+ : Effect(lpeobject)
+ , steps(_("Steps:"), _("Change number of simplify steps "), "steps", &wr, this, 1)
+ , threshold(_("Roughly threshold:"), _("Roughly threshold:"), "threshold", &wr, this, 0.002)
+ , smooth_angles(_("Smooth angles:"), _("Max degree difference on handles to perform a smooth"), "smooth_angles",
+ &wr, this, 0.)
+ , helper_size(_("Helper size:"), _("Helper size"), "helper_size", &wr, this, 5)
+ , simplify_individual_paths(_("Paths separately"), _("Simplifying paths (separately)"), "simplify_individual_paths",
+ &wr, this, false, "", INKSCAPE_ICON("on"), INKSCAPE_ICON("off"))
+ , simplify_just_coalesce(_("Just coalesce"), _("Simplify just coalesce"), "simplify_just_coalesce", &wr, this,
+ false, "", INKSCAPE_ICON("on"), INKSCAPE_ICON("off"))
{
registerParameter(&steps);
registerParameter(&threshold);
diff --git a/src/live_effects/lpe-simplify.h b/src/live_effects/lpe-simplify.h
index 08561b3e4..9eb3d15e9 100644
--- a/src/live_effects/lpe-simplify.h
+++ b/src/live_effects/lpe-simplify.h
@@ -37,7 +37,7 @@ public:
virtual void drawHandleLine(Geom::Point p,Geom::Point p2);
ScalarParam threshold;
-protected:
+ protected:
void addCanvasIndicators(SPLPEItem const */*lpeitem*/, std::vector<Geom::PathVector> &hp_vec) override;
private:
diff --git a/src/live_effects/parameter/togglebutton.cpp b/src/live_effects/parameter/togglebutton.cpp
index 555b1222a..06a67eae6 100644
--- a/src/live_effects/parameter/togglebutton.cpp
+++ b/src/live_effects/parameter/togglebutton.cpp
@@ -25,13 +25,17 @@ namespace Inkscape {
namespace LivePathEffect {
-ToggleButtonParam::ToggleButtonParam( const Glib::ustring& label, const Glib::ustring& tip,
- const Glib::ustring& key, Inkscape::UI::Widget::Registry* wr,
- Effect* effect, bool default_value, Glib::ustring inactive_label,
- char const * _icon_active, char const * _icon_inactive,
- Gtk::BuiltinIconSize _icon_size)
- : Parameter(label, tip, key, wr, effect), value(default_value), defvalue(default_value),
- inactive_label(std::move(inactive_label)), _icon_active(_icon_active), _icon_inactive(_icon_inactive), _icon_size(_icon_size)
+ToggleButtonParam::ToggleButtonParam(const Glib::ustring &label, const Glib::ustring &tip, const Glib::ustring &key,
+ Inkscape::UI::Widget::Registry *wr, Effect *effect, bool default_value,
+ Glib::ustring inactive_label, char const *_icon_active, char const *_icon_inactive,
+ Gtk::BuiltinIconSize _icon_size)
+ : Parameter(label, tip, key, wr, effect)
+ , value(default_value)
+ , defvalue(default_value)
+ , inactive_label(std::move(inactive_label))
+ , _icon_active(_icon_active)
+ , _icon_inactive(_icon_inactive)
+ , _icon_size(_icon_size)
{
checkwdg = nullptr;
}
@@ -95,33 +99,33 @@ ToggleButtonParam::param_newWidget()
false,
param_effect->getRepr(),
param_effect->getSPDoc()) );
- auto box_button = new Gtk::Box(Gtk::ORIENTATION_HORIZONTAL);
- box_button->set_homogeneous(false);
- Gtk::Label * label = new Gtk::Label("");
- if (!param_label.empty()) {
- if(value || inactive_label.empty()){
- label->set_text(param_label.c_str());
- }else{
- label->set_text(inactive_label.c_str());
- }
- }
- label->show();
- if ( _icon_active ) {
- if(!_icon_inactive){
- _icon_inactive = _icon_active;
- }
- box_button->show();
- Gtk::Widget *icon_button = nullptr;
- if (!value) {
- icon_button = sp_get_icon_image(_icon_inactive, _icon_size);
- } else {
- icon_button = sp_get_icon_image(_icon_active, _icon_size);
- }
- icon_button->show();
- box_button->pack_start(*icon_button, false, false, 1);
- if (!param_label.empty()) {
- box_button->pack_start (*label, false, false, 1);
- }
+ auto box_button = new Gtk::Box(Gtk::ORIENTATION_HORIZONTAL);
+ box_button->set_homogeneous(false);
+ Gtk::Label *label = new Gtk::Label("");
+ if (!param_label.empty()) {
+ if (value || inactive_label.empty()) {
+ label->set_text(param_label.c_str());
+ } else {
+ label->set_text(inactive_label.c_str());
+ }
+ }
+ label->show();
+ if (_icon_active) {
+ if (!_icon_inactive) {
+ _icon_inactive = _icon_active;
+ }
+ box_button->show();
+ Gtk::Widget *icon_button = nullptr;
+ if (!value) {
+ icon_button = sp_get_icon_image(_icon_inactive, _icon_size);
+ } else {
+ icon_button = sp_get_icon_image(_icon_active, _icon_size);
+ }
+ icon_button->show();
+ box_button->pack_start(*icon_button, false, false, 1);
+ if (!param_label.empty()) {
+ box_button->pack_start(*label, false, false, 1);
+ }
}else{
box_button->pack_start(*label, false, false, 1);
}
@@ -149,7 +153,7 @@ ToggleButtonParam::refresh_button()
if(!box_button){
return;
}
- std::vector<Gtk::Widget*> children = box_button->get_children();
+ std::vector<Gtk::Widget *> children = box_button->get_children();
if (!param_label.empty()) {
Gtk::Label *lab = dynamic_cast<Gtk::Label*>(children[children.size()-1]);
if (!lab) return;
@@ -160,7 +164,7 @@ ToggleButtonParam::refresh_button()
}
}
if ( _icon_active ) {
- Gdk::Pixbuf * icon_pixbuf = nullptr;
+ Gdk::Pixbuf *icon_pixbuf = nullptr;
Gtk::Widget *im = dynamic_cast<Gtk::Image *>(children[0]);
if (!im) return;
if (!value) {
diff --git a/src/live_effects/parameter/togglebutton.h b/src/live_effects/parameter/togglebutton.h
index d21c9ac37..b76a2d7c8 100644
--- a/src/live_effects/parameter/togglebutton.h
+++ b/src/live_effects/parameter/togglebutton.h
@@ -25,37 +25,31 @@ namespace LivePathEffect {
*/
class ToggleButtonParam : public Parameter {
public:
- ToggleButtonParam( const Glib::ustring& label,
- const Glib::ustring& tip,
- const Glib::ustring& key,
- Inkscape::UI::Widget::Registry* wr,
- Effect* effect,
- bool default_value = false,
- Glib::ustring inactive_label = "",
- char const * icon_active = nullptr,
- char const * icon_inactive = nullptr,
- Gtk::BuiltinIconSize icon_size = Gtk::ICON_SIZE_SMALL_TOOLBAR);
- ~ToggleButtonParam() override;
- ToggleButtonParam(const ToggleButtonParam&) = delete;
- ToggleButtonParam& operator=(const ToggleButtonParam&) = delete;
-
- Gtk::Widget * param_newWidget() override;
-
- bool param_readSVGValue(const gchar * strvalue) override;
- gchar * param_getSVGValue() const override;
- gchar * param_getDefaultSVGValue() const override;
-
- void param_setValue(bool newvalue);
- void param_set_default() override;
-
- bool get_value() const { return value; };
-
- inline operator bool() const { return value; };
-
- sigc::signal<void>& signal_toggled() { return _signal_toggled; }
- virtual void toggled();
- void param_update_default(bool default_value);
- void param_update_default(const gchar * default_value) override;
+ ToggleButtonParam(const Glib::ustring &label, const Glib::ustring &tip, const Glib::ustring &key,
+ Inkscape::UI::Widget::Registry *wr, Effect *effect, bool default_value = false,
+ Glib::ustring inactive_label = "", char const *icon_active = nullptr,
+ char const *icon_inactive = nullptr, Gtk::BuiltinIconSize icon_size = Gtk::ICON_SIZE_SMALL_TOOLBAR);
+ ~ToggleButtonParam() override;
+ ToggleButtonParam(const ToggleButtonParam &) = delete;
+ ToggleButtonParam &operator=(const ToggleButtonParam &) = delete;
+
+ Gtk::Widget *param_newWidget() override;
+
+ bool param_readSVGValue(const gchar *strvalue) override;
+ gchar *param_getSVGValue() const override;
+ gchar *param_getDefaultSVGValue() const override;
+
+ void param_setValue(bool newvalue);
+ void param_set_default() override;
+
+ bool get_value() const { return value; };
+
+ inline operator bool() const { return value; };
+
+ sigc::signal<void> &signal_toggled() { return _signal_toggled; }
+ virtual void toggled();
+ void param_update_default(bool default_value);
+ void param_update_default(const gchar *default_value) override;
private:
void refresh_button();
@@ -64,7 +58,7 @@ private:
const Glib::ustring inactive_label;
const char * _icon_active;
const char * _icon_inactive;
- Gtk::BuiltinIconSize _icon_size;
+ Gtk::BuiltinIconSize _icon_size;
Inkscape::UI::Widget::RegisteredToggleButton * checkwdg;
sigc::signal<void> _signal_toggled;
diff --git a/src/ui/toolbar/pencil-toolbar.cpp b/src/ui/toolbar/pencil-toolbar.cpp
index bcc3a3d2d..4b8bad506 100644
--- a/src/ui/toolbar/pencil-toolbar.cpp
+++ b/src/ui/toolbar/pencil-toolbar.cpp
@@ -341,9 +341,9 @@ PencilToolbar::use_pencil_pressure() {
_minpressure->set_visible(true);
_maxpressure->set_visible(true);
_cap_item->set_visible(true);
+ _flatten_simplify->set_visible(true);
_shape_item->set_visible(false);
_simplify->set_visible(false);
- _flatten_simplify->set_visible(false);
_flatten_spiro_bspline->set_visible(false);
for (auto button : _mode_buttons) {
button->set_sensitive(false);
@@ -354,9 +354,9 @@ PencilToolbar::use_pencil_pressure() {
_minpressure->set_visible(false);
_maxpressure->set_visible(false);
_cap_item->set_visible(false);
+ _flatten_simplify->set_visible(false);
_shape_item->set_visible(true);
_simplify->set_visible(true);
- _flatten_simplify->set_visible(true);
if (freehandMode == 1 || freehandMode == 2) {
_flatten_spiro_bspline->set_visible(true);
}
diff --git a/src/ui/tools/freehand-base.cpp b/src/ui/tools/freehand-base.cpp
index 52796b25e..c549358a7 100644
--- a/src/ui/tools/freehand-base.cpp
+++ b/src/ui/tools/freehand-base.cpp
@@ -892,7 +892,7 @@ static void spdc_flush_white(FreehandBase *dc, SPCurve *gc)
if (SP_IS_PENCIL_CONTEXT(dc) && dc->tablet_enabled) {
if (!dc->white_item) {
- dc->white_item = SP_ITEM(desktop->currentLayer()->appendChildRepr(repr));
+ dc->white_item = SP_ITEM(desktop->currentLayer()->appendChildRepr(repr));
}
spdc_check_for_and_apply_waiting_LPE(dc, dc->white_item, c, false);
}
diff --git a/src/ui/tools/pencil-tool.cpp b/src/ui/tools/pencil-tool.cpp
index bda06ad97..5a9f508ca 100644
--- a/src/ui/tools/pencil-tool.cpp
+++ b/src/ui/tools/pencil-tool.cpp
@@ -239,7 +239,7 @@ bool PencilTool::_handleButtonPress(GdkEventButton const &bevent) {
// anchor, which is handled by the sibling branch above)
selection->clear();
desktop->messageStack()->flash(Inkscape::NORMAL_MESSAGE, _("Creating new path"));
- } else if (!(bevent.state & GDK_SHIFT_MASK) ) {
+ } else if (!(bevent.state & GDK_SHIFT_MASK)) {
// This is the first click of a new curve; deselect item so that
// this curve is not combined with it (unless it is drawn from its
// anchor, which is handled by the sibling branch above)
@@ -354,7 +354,7 @@ bool PencilTool::_handleMotionNotify(GdkEventMotion const &mevent) {
// whether we're going into freehand mode or not
this->ps.push_back(this->p[0]);
if (tablet_enabled) {
- this->_wps.push_back(Geom::Point(0,0));
+ this->_wps.emplace_back(0, 0);
}
}
this->_addFreehandPoint(p, mevent.state);
@@ -705,15 +705,15 @@ static inline double square(double const x) { return x * x; }
void PencilTool::addPowerStrokePencil(bool reset)
{
gint top = 21;
- if (this->size_powerpencil > 50) {
+ if (this->size_powerpencil > 30) {
top = 41;
}
- static int pscounter = top;
+ static int pscounter = 21;
if (reset) {
pscounter = top;
return;
}
- if (pscounter > top-1) {
+ if (pscounter > top - 1) {
pscounter = 0;
} else {
pscounter++;
@@ -753,7 +753,7 @@ void PencilTool::addPowerStrokePencil(bool reset)
toremove->getRepr()->setAttribute("id", "tmp_power_stroke_preview");
}
Inkscape::Preferences *prefs = Inkscape::Preferences::get();
- double tol = (prefs->getDoubleLimited("/tools/freehand/pencil/base-simplify", 25.0, 0.0, 100.0) -10) * 0.4;
+ double tol = prefs->getDoubleLimited("/tools/freehand/pencil/base-simplify", 25.0, 0.0, 100.0) * 0.4;
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
@@ -795,22 +795,36 @@ void PencilTool::addPowerStrokePencil(bool reset)
return;
// return true;
}
-
tol = prefs->getDoubleLimited("/tools/freehand/pencil/tolerance", 10.0, 0.0, 100.0) + 30;
if (tol > 30) {
- tol = tol / (100.0 * (102.0 - tol));
- std::ostringstream threshold;
+ tol = tol / (130.0 * (132.0 - tol));
+ Inkscape::SVGOStringStream threshold;
threshold << tol;
Effect::createAndApply(SIMPLIFY, desktop->doc(), SP_ITEM(lpeitem));
Effect *lpe = lpeitem->getCurrentLPE();
- Inkscape::LivePathEffect::LPESimplify *simplify = static_cast<Inkscape::LivePathEffect::LPESimplify *>(lpe);
+ Inkscape::LivePathEffect::LPESimplify *simplify =
+ static_cast<Inkscape::LivePathEffect::LPESimplify *>(lpe);
if (simplify) {
+ sp_lpe_item_enable_path_effects(lpeitem, false);
Glib::ustring pref_path = "/live_effects/simplify/smooth_angles";
bool valid = prefs->getEntry(pref_path).isValid();
if (!valid) {
- lpe->getRepr()->setAttribute("smooth_angles", "360");
+ lpe->getRepr()->setAttribute("smooth_angles", "0");
}
- lpe->getRepr()->setAttribute("threshold", threshold.str());
+ pref_path = "/live_effects/simplify/helper_size";
+ valid = prefs->getEntry(pref_path).isValid();
+ if (!valid) {
+ lpe->getRepr()->setAttribute("helper_size", "0");
+ }
+ pref_path = "/live_effects/simplify/step";
+ valid = prefs->getEntry(pref_path).isValid();
+ if (!valid) {
+ lpe->getRepr()->setAttribute("step", "1");
+ }
+ lpe->getRepr()->setAttribute("threshold", threshold.str().c_str());
+ lpe->getRepr()->setAttribute("simplify_individual_paths", "false");
+ lpe->getRepr()->setAttribute("simplify_just_coalesce", "false");
+ sp_lpe_item_enable_path_effects(lpeitem, true);
}
sp_lpe_item_update_patheffect(lpeitem, false, true);
curvepressure = powerpreview->getCurve();
@@ -832,13 +846,18 @@ void PencilTool::addPowerStrokePencil(bool reset)
Glib::ustring pref_path = "/live_effects/powerstroke/interpolator_type";
bool valid = prefs->getEntry(pref_path).isValid();
if (!valid) {
- pspreview->getRepr()->setAttribute("interpolator_type", "CentripetalCatmullRom");
+ pspreview->getRepr()->setAttribute("interpolator_type", "CubicBezierJohan");
}
pref_path = "/live_effects/powerstroke/linejoin_type";
valid = prefs->getEntry(pref_path).isValid();
if (!valid) {
pspreview->getRepr()->setAttribute("linejoin_type", "bevel");
}
+ pref_path = "/live_effects/powerstroke/interpolator_beta";
+ valid = prefs->getEntry(pref_path).isValid();
+ if (!valid) {
+ pspreview->getRepr()->setAttribute("interpolator_beta", "0.75");
+ }
gint cap = prefs->getInt("/live_effects/powerstroke/powerpencilcap", 4);
pspreview->getRepr()->setAttribute("start_linecap_type", LineCapTypeConverter.get_key(cap));
pspreview->getRepr()->setAttribute("end_linecap_type", LineCapTypeConverter.get_key(cap));
@@ -846,6 +865,12 @@ void PencilTool::addPowerStrokePencil(bool reset)
pspreview->offset_points.param_set_and_write_new_value(this->points);
sp_lpe_item_enable_path_effects(lpeitem, true);
sp_lpe_item_update_patheffect(lpeitem, false, true);
+ if (pspreview->has_exception) {
+ sp_lpe_item_enable_path_effects(lpeitem, false);
+ pp->setAttribute("id", "delete_power_stroke_preview");
+ toremove->setAttribute("id", "power_stroke_preview");
+ toremove = powerpreview;
+ }
if (toremove) {
using namespace Inkscape::LivePathEffect;
Effect *lpe = SP_LPE_ITEM(toremove)->getCurrentLPE();
@@ -889,6 +914,10 @@ void PencilTool::_addFreehandPoint(Geom::Point const &p, guint /*state*/) {
{
this->p[this->_npoints++] = p;
this->_fitAndSplit();
+ double distance = 0;
+ if (tablet_enabled) {
+ distance = Geom::distance(p,this->ps.back()) + this->_wps.back()[Geom::X];
+ }
this->ps.push_back(p);
if (tablet_enabled) {
Inkscape::Preferences *prefs = Inkscape::Preferences::get();
@@ -901,9 +930,9 @@ void PencilTool::_addFreehandPoint(Geom::Point const &p, guint /*state*/) {
double pressure_shrunk = (((this->pressure - 0.25) * 1.25) * (max - min)) + min;
double pressure_computed = pressure_shrunk * (dezoomify_factor / 5.0);
if (this->pressure < 0.25) {
- this->_wps.push_back(Geom::Point(this->ps.size(), 0));
+ this->_wps.emplace_back(distance, 0);
} else {
- this->_wps.push_back(Geom::Point(this->ps.size(), pressure_computed));
+ this->_wps.emplace_back(distance, pressure_computed);
}
this->addPowerStrokePencil(false);
sp_canvas_bpath_set_bpath(SP_CANVAS_BPATH(this->red_bpath), nullptr);
@@ -915,51 +944,63 @@ void PencilTool::_addFreehandPoint(Geom::Point const &p, guint /*state*/) {
}
}
-void PencilTool::powerStrokeInterpolate(Geom::Path path)
+void PencilTool::powerStrokeInterpolate(Geom::Path const path)
{
size_t ps_size = this->ps.size();
if ( ps_size <= 1 ) {
return;
}
-
+
using Geom::X;
using Geom::Y;
- Inkscape::Preferences *prefs = Inkscape::Preferences::get();
- SPItem *item = selection ? selection->singleItem() : nullptr;
gint points_size = this->_wps.size();
gint path_size = path.size();
std::vector<Geom::Point> tmp_points;
Geom::Point previous = Geom::Point(Geom::infinity(), 0);
+ bool increase = false;
size_t i = 0;
- bool increase = true;
for (auto pp : this->_wps) {
- pp[Geom::X] = (path_size / (double)points_size) * i;
- if (pp[Geom::Y] == 0 || (path_size > 1 && (pp[Geom::X] < 1 || pp[Geom::X] > path_size - 2))) {
- ++i;
+ i++;
+ if (i%10) { //remove 9 of 10
continue;
}
- if (std::abs(pp[Geom::X] - previous[Geom::X]) > 0.2 && std::abs(pp[Geom::Y] - previous[Geom::Y]) > 0.5) {
- if (previous[Geom::Y] < pp[Geom::Y]) {
- if (increase && tmp_points.size() > 1) {
- tmp_points.pop_back();
- }
- increase = true;
- } else {
- if (!increase && tmp_points.size() > 1) {
- tmp_points.pop_back();
- }
- increase = false;
+ if (!this->_wps.back()[Geom::X]) {
+ continue;
+ }
+
+ pp[Geom::X] /= this->_wps.back()[Geom::X];
+ pp[Geom::X] *= path_size;
+ if (pp[Geom::Y] == 0 || path_size < 2 || pp[Geom::X] < 1) {
+ continue;
+ }
+
+ if (previous[Geom::Y] < pp[Geom::Y]) {
+ if (increase && tmp_points.size() > 1) {
+ tmp_points.pop_back();
}
- previous = pp;
tmp_points.push_back(pp);
+ increase = true;
+ } else {
+ if (!increase && tmp_points.size() > 1) {
+ tmp_points.pop_back();
+ }
+ tmp_points.push_back(pp);
+ increase = false;
}
- ++i;
+ previous = pp;
+ if (pp[Geom::X] > path.size() - 1) {
+ pp[Geom::X] = path.size() - 1;
+ break;
+ }
}
+
this->points = tmp_points;
tmp_points.clear();
- if (this->points.empty()) {
- Geom::Point one(Geom::Coord(path_size/2), this->_wps[this->_wps.size()/2][Geom::Y]);
+ if (this->points.empty() && this->_wps.size() > 1) {
+ double onepress = this->_wps[((this->_wps.size() - 1) / 2) + 1][Geom::Y];
+ double onewidth = path_size /(double)2.0;
+ Geom::Point one(onewidth, onepress);
this->points.push_back(one);
}
sp_canvas_bpath_set_bpath(SP_CANVAS_BPATH(this->red_bpath), nullptr);
@@ -970,7 +1011,6 @@ void PencilTool::_interpolate() {
if ( ps_size <= 1 ) {
return;
}
-
using Geom::X;
using Geom::Y;
Inkscape::Preferences *prefs = Inkscape::Preferences::get();