summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorJabier Arraiza <jabier.arraiza@marker.es>2019-07-17 22:57:15 +0000
committerJabier Arraiza <jabier.arraiza@marker.es>2019-07-19 21:33:23 +0000
commit44911fb71708f71feea4c853de856a14af4fbccf (patch)
tree264c3b8651b9d58915616986792cf4cd8d117dae
parentFix translations and coding style (diff)
downloadinkscape-44911fb71708f71feea4c853de856a14af4fbccf.tar.gz
inkscape-44911fb71708f71feea4c853de856a14af4fbccf.zip
Improvements finish pointed by Maren
-rw-r--r--src/live_effects/effect.cpp7
-rw-r--r--src/live_effects/effect.h1
-rw-r--r--src/live_effects/lpe-powerstroke.cpp34
-rw-r--r--src/live_effects/lpe-powerstroke.h3
-rw-r--r--src/live_effects/lpe-simplify.cpp2
-rw-r--r--src/live_effects/lpe-simplify.h2
-rw-r--r--src/live_effects/parameter/togglebutton.cpp38
-rw-r--r--src/live_effects/parameter/togglebutton.h4
-rwxr-xr-xsrc/object/sp-lpe-item.cpp2
-rw-r--r--src/ui/toolbar/pencil-toolbar.cpp2
-rw-r--r--src/ui/tools/freehand-base.cpp10
-rw-r--r--src/ui/tools/pencil-tool.cpp139
-rw-r--r--src/ui/tools/pencil-tool.h7
13 files changed, 157 insertions, 94 deletions
diff --git a/src/live_effects/effect.cpp b/src/live_effects/effect.cpp
index f5b291635..e547e709d 100644
--- a/src/live_effects/effect.cpp
+++ b/src/live_effects/effect.cpp
@@ -1250,6 +1250,13 @@ void Effect::doAfterEffect (SPLPEItem const* /*lpeitem*/)
is_load = false;
}
+void Effect::doOnException (SPLPEItem const* /*lpeitem*/)
+{
+ has_exception = true;
+ pathvector_after_effect = pathvector_before_effect;
+}
+
+
void Effect::doOnRemove (SPLPEItem const* /*lpeitem*/)
{
}
diff --git a/src/live_effects/effect.h b/src/live_effects/effect.h
index 725aae6c4..6ef65fe3c 100644
--- a/src/live_effects/effect.h
+++ b/src/live_effects/effect.h
@@ -75,6 +75,7 @@ public:
virtual void doBeforeEffect (SPLPEItem const* lpeitem);
virtual void doAfterEffect (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 0a13e4661..5eb5afc75 100644
--- a/src/live_effects/lpe-powerstroke.cpp
+++ b/src/live_effects/lpe-powerstroke.cpp
@@ -12,7 +12,9 @@
*/
#include "live_effects/lpe-powerstroke.h"
+#include "live_effects/lpe-simplify.h"
#include "live_effects/lpe-powerstroke-interpolators.h"
+#include "live_effects/lpeobject.h"
#include "svg/svg-color.h"
#include "desktop-style.h"
@@ -182,17 +184,25 @@ LPEPowerStroke::LPEPowerStroke(LivePathEffectObject *lpeobject) :
scale_width.param_set_range(0.0, Geom::infinity());
scale_width.param_set_increments(0.1, 0.1);
scale_width.param_set_digits(4);
+ recusion_limit = 0;
+ previous_size = 0;
}
-LPEPowerStroke::~LPEPowerStroke()
-= default;
+LPEPowerStroke::~LPEPowerStroke() = default;
+
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) {
+ 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) {
@@ -755,6 +765,24 @@ LPEPowerStroke::doEffect_path (Geom::PathVector const & path_in)
return path_out;
}
+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());
+ double threshold = simplify->threshold * 1.2;
+ simplify->threshold.param_set_value(threshold);
+ simplify->threshold.write_to_SVG();
+ }
+ }
+ ++recusion_limit;
+ } else {
+ recusion_limit = 0;
+ }
+}
/* ######################## */
diff --git a/src/live_effects/lpe-powerstroke.h b/src/live_effects/lpe-powerstroke.h
index 945a2ffe7..4cb4e5a69 100644
--- a/src/live_effects/lpe-powerstroke.h
+++ b/src/live_effects/lpe-powerstroke.h
@@ -42,6 +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 applyStyle(SPLPEItem *lpeitem);
// methods called by path-manipulator upon edits
void adjustForNewPath(Geom::PathVector const & path_in);
@@ -57,6 +58,8 @@ private:
EnumParam<unsigned> linejoin_type;
ScalarParam miter_limit;
EnumParam<unsigned> end_linecap_type;
+ size_t recusion_limit;
+ size_t previous_size;
};
} //namespace LivePathEffect
diff --git a/src/live_effects/lpe-simplify.cpp b/src/live_effects/lpe-simplify.cpp
index 56647e4e2..da36b184e 100644
--- a/src/live_effects/lpe-simplify.cpp
+++ b/src/live_effects/lpe-simplify.cpp
@@ -27,7 +27,7 @@ LPESimplify::LPESimplify(LivePathEffectObject *lpeobject)
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"))
+ "", 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 a04fff76c..08561b3e4 100644
--- a/src/live_effects/lpe-simplify.h
+++ b/src/live_effects/lpe-simplify.h
@@ -35,13 +35,13 @@ public:
virtual void drawHandle(Geom::Point p);
virtual void drawHandleLine(Geom::Point p,Geom::Point p2);
+ ScalarParam threshold;
protected:
void addCanvasIndicators(SPLPEItem const */*lpeitem*/, std::vector<Geom::PathVector> &hp_vec) override;
private:
ScalarParam steps;
- ScalarParam threshold;
ScalarParam smooth_angles;
ScalarParam helper_size;
ToggleButtonParam simplify_individual_paths;
diff --git a/src/live_effects/parameter/togglebutton.cpp b/src/live_effects/parameter/togglebutton.cpp
index bc275e876..555b1222a 100644
--- a/src/live_effects/parameter/togglebutton.cpp
+++ b/src/live_effects/parameter/togglebutton.cpp
@@ -29,7 +29,7 @@ ToggleButtonParam::ToggleButtonParam( const Glib::ustring& label, const Glib::us
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,
- GtkIconSize _icon_size)
+ 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)
{
@@ -95,38 +95,38 @@ ToggleButtonParam::param_newWidget()
false,
param_effect->getRepr(),
param_effect->getSPDoc()) );
- auto box_button = gtk_box_new (GTK_ORIENTATION_HORIZONTAL, 0);
- gtk_box_set_homogeneous(GTK_BOX(box_button), false);
- GtkWidget * label_button = gtk_label_new ("");
+ 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()){
- gtk_label_set_text(GTK_LABEL(label_button), param_label.c_str());
+ label->set_text(param_label.c_str());
}else{
- gtk_label_set_text(GTK_LABEL(label_button), inactive_label.c_str());
+ label->set_text(inactive_label.c_str());
}
}
- gtk_widget_show(label_button);
+ label->show();
if ( _icon_active ) {
if(!_icon_inactive){
_icon_inactive = _icon_active;
}
- gtk_widget_show(box_button);
- GtkWidget *icon_button = nullptr;
+ 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);
}
- gtk_widget_show(icon_button);
- gtk_box_pack_start (GTK_BOX(box_button), icon_button, false, false, 1);
+ icon_button->show();
+ box_button->pack_start(*icon_button, false, false, 1);
if (!param_label.empty()) {
- gtk_box_pack_start (GTK_BOX(box_button), label_button, false, false, 1);
+ box_button->pack_start (*label, false, false, 1);
}
}else{
- gtk_box_pack_start (GTK_BOX(box_button), label_button, false, false, 1);
+ box_button->pack_start(*label, false, false, 1);
}
- checkwdg->add(*Gtk::manage(Glib::wrap(box_button)));
+ checkwdg->add(*Gtk::manage(box_button));
checkwdg->setActive(value);
checkwdg->setProgrammatically = false;
checkwdg->set_undo_parameters(SP_VERB_DIALOG_LIVE_PATH_EFFECT, _("Change togglebutton parameter"));
@@ -145,11 +145,11 @@ ToggleButtonParam::refresh_button()
if(!checkwdg){
return;
}
- Gtk::Widget * box_button = checkwdg->get_child();
+ Gtk::Container *box_button = dynamic_cast<Gtk::Container *>(checkwdg->get_child());
if(!box_button){
return;
}
- std::vector<Gtk::Widget*> children = Glib::wrap(GTK_CONTAINER(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,13 +160,13 @@ ToggleButtonParam::refresh_button()
}
}
if ( _icon_active ) {
- GdkPixbuf * icon_pixbuf = nullptr;
+ Gdk::Pixbuf * icon_pixbuf = nullptr;
Gtk::Widget *im = dynamic_cast<Gtk::Image *>(children[0]);
if (!im) return;
if (!value) {
- im = Glib::wrap(sp_get_icon_image(_icon_inactive, _icon_size));
+ im = sp_get_icon_image(_icon_inactive, _icon_size);
} else {
- im = Glib::wrap(sp_get_icon_image(_icon_active, _icon_size));
+ im = sp_get_icon_image(_icon_active, _icon_size);
}
}
}
diff --git a/src/live_effects/parameter/togglebutton.h b/src/live_effects/parameter/togglebutton.h
index d1845de5b..d21c9ac37 100644
--- a/src/live_effects/parameter/togglebutton.h
+++ b/src/live_effects/parameter/togglebutton.h
@@ -34,7 +34,7 @@ public:
Glib::ustring inactive_label = "",
char const * icon_active = nullptr,
char const * icon_inactive = nullptr,
- GtkIconSize icon_size = GTK_ICON_SIZE_SMALL_TOOLBAR);
+ Gtk::BuiltinIconSize icon_size = Gtk::ICON_SIZE_SMALL_TOOLBAR);
~ToggleButtonParam() override;
ToggleButtonParam(const ToggleButtonParam&) = delete;
ToggleButtonParam& operator=(const ToggleButtonParam&) = delete;
@@ -64,7 +64,7 @@ private:
const Glib::ustring inactive_label;
const char * _icon_active;
const char * _icon_inactive;
- GtkIconSize _icon_size;
+ Gtk::BuiltinIconSize _icon_size;
Inkscape::UI::Widget::RegisteredToggleButton * checkwdg;
sigc::signal<void> _signal_toggled;
diff --git a/src/object/sp-lpe-item.cpp b/src/object/sp-lpe-item.cpp
index 6be373925..457ce65c1 100755
--- a/src/object/sp-lpe-item.cpp
+++ b/src/object/sp-lpe-item.cpp
@@ -259,7 +259,7 @@ bool SPLPEItem::performOnePathEffect(SPCurve *curve, SPShape *current, Inkscape:
SP_ACTIVE_DESKTOP->messageStack()->flash( Inkscape::WARNING_MESSAGE,
_("An exception occurred during execution of the Path Effect.") );
}
- lpe->has_exception = true;
+ lpe->doOnException(this);
return false;
}
diff --git a/src/ui/toolbar/pencil-toolbar.cpp b/src/ui/toolbar/pencil-toolbar.cpp
index e32d2c19a..bcc3a3d2d 100644
--- a/src/ui/toolbar/pencil-toolbar.cpp
+++ b/src/ui/toolbar/pencil-toolbar.cpp
@@ -146,7 +146,7 @@ PencilToolbar::PencilToolbar(SPDesktop *desktop,
_("(few nodes, smooth)") };
std::vector<double> values = { 1, 10, 20, 30, 50, 75, 100 };
auto tolerance_val = prefs->getDouble("/tools/freehand/pencil/tolerance", 3.0);
- _tolerance_adj = Gtk::Adjustment::create(tolerance_val, 1, 100.0, 0.5, 1.0);
+ _tolerance_adj = Gtk::Adjustment::create(tolerance_val, 0, 100.0, 0.5, 1.0);
auto tolerance_item =
Gtk::manage(new UI::Widget::SpinButtonToolItem("pencil-tolerance", _("Smoothing:"), _tolerance_adj, 1, 2));
tolerance_item->set_tooltip_text(_("How much smoothing (simplifying) is applied to the line"));
diff --git a/src/ui/tools/freehand-base.cpp b/src/ui/tools/freehand-base.cpp
index 961410c6b..52796b25e 100644
--- a/src/ui/tools/freehand-base.cpp
+++ b/src/ui/tools/freehand-base.cpp
@@ -890,13 +890,11 @@ static void spdc_flush_white(FreehandBase *dc, SPCurve *gc)
repr->setAttribute("d", str);
g_free(str);
- if (SP_IS_PENCIL_CONTEXT(dc)) {
- if (dc->tablet_enabled) {
- if (!dc->white_item) {
- dc->white_item = SP_ITEM(desktop->currentLayer()->appendChildRepr(repr));
- }
- spdc_check_for_and_apply_waiting_LPE(dc, dc->white_item, c, false);
+ if (SP_IS_PENCIL_CONTEXT(dc) && dc->tablet_enabled) {
+ if (!dc->white_item) {
+ dc->white_item = SP_ITEM(desktop->currentLayer()->appendChildRepr(repr));
}
+ spdc_check_for_and_apply_waiting_LPE(dc, dc->white_item, c, false);
}
if (!dc->white_item) {
// Attach repr
diff --git a/src/ui/tools/pencil-tool.cpp b/src/ui/tools/pencil-tool.cpp
index dd5ef80fd..bda06ad97 100644
--- a/src/ui/tools/pencil-tool.cpp
+++ b/src/ui/tools/pencil-tool.cpp
@@ -41,6 +41,8 @@
#include "live_effects/lpe-powerstroke-interpolators.h"
#include "live_effects/lpe-powerstroke.h"
+#include "live_effects/lpe-simplify.h"
+#include "live_effects/lpeobject.h"
#include "object/sp-lpe-item.h"
#include "object/sp-path.h"
@@ -98,6 +100,7 @@ void PencilTool::setup() {
this->_is_drawing = false;
this->anchor_statusbar = false;
+ this->size_powerpencil = 0;
}
@@ -230,7 +233,7 @@ bool PencilTool::_handleButtonPress(GdkEventButton const &bevent) {
desktop->messageStack()->flash(Inkscape::NORMAL_MESSAGE, _("Continuing selected path"));
} else {
m.setup(desktop, true);
- if (tablet_enabled && this->pressure) {
+ if (tablet_enabled) {
// 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)
@@ -351,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(0);
+ this->_wps.push_back(Geom::Point(0,0));
}
}
this->_addFreehandPoint(p, mevent.state);
@@ -475,10 +478,17 @@ bool PencilTool::_handleButtonRelease(GdkEventButton const &revent) {
this->_interpolate();
Inkscape::Preferences *prefs = Inkscape::Preferences::get();
if (tablet_enabled) {
- gint prevmode = prefs->getInt("/tools/freehand/pencil/freehand-mode", 0);
+ gint shapetype = prefs->getInt("/tools/freehand/pencil/shape", 0);
+ gint simplify = prefs->getInt("/tools/freehand/pencil/simplify", 0);
+ gint mode = prefs->getInt("/tools/freehand/pencil/freehand-mode", 0);
+ prefs->setInt("/tools/freehand/pencil/shape", 0);
+ prefs->setInt("/tools/freehand/pencil/simplify", 0);
prefs->setInt("/tools/freehand/pencil/freehand-mode", 0);
spdc_concat_colors_and_flush(this, FALSE);
- prefs->setInt("/tools/freehand/pencil/freehand-mode", prevmode);
+ prefs->setInt("/tools/freehand/pencil/freehand-mode", mode);
+ prefs->setInt("/tools/freehand/pencil/simplify", simplify);
+ prefs->setInt("/tools/freehand/pencil/shape", shapetype);
+ this->addPowerStrokePencil(true);
} else {
spdc_concat_colors_and_flush(this, FALSE);
}
@@ -487,6 +497,7 @@ bool PencilTool::_handleButtonRelease(GdkEventButton const &revent) {
this->ea = nullptr;
this->ps.clear();
this->_wps.clear();
+ this->size_powerpencil = 0;
if (this->green_anchor) {
this->green_anchor = sp_draw_anchor_destroy(this->green_anchor);
}
@@ -691,16 +702,24 @@ void PencilTool::_finishEndpoint() {
static inline double square(double const x) { return x * x; }
-void PencilTool::addPowerStrokePencil(bool force, gint tolsimplify)
+void PencilTool::addPowerStrokePencil(bool reset)
{
-
- static int pscounter = 16;
- if (pscounter > 15 || force) {
+ gint top = 21;
+ if (this->size_powerpencil > 50) {
+ top = 41;
+ }
+ static int pscounter = top;
+ if (reset) {
+ pscounter = top;
+ return;
+ }
+ if (pscounter > top-1) {
pscounter = 0;
} else {
pscounter++;
return;
}
+
using namespace Inkscape::LivePathEffect;
if (this->_curve && this->ps.size() > 1) {
@@ -734,14 +753,13 @@ void PencilTool::addPowerStrokePencil(bool force, gint tolsimplify)
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) * 0.4;
+ double tol = (prefs->getDoubleLimited("/tools/freehand/pencil/base-simplify", 25.0, 0.0, 100.0) -10) * 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
int max_segs = 4 * n_points;
std::vector<Geom::Point> b(max_segs);
SPCurve *curvepressure = new SPCurve();
-
int const n_segs = Geom::bezier_fit_cubic_r(b.data(), this->ps.data(), n_points, tolerance_sq, max_segs);
if (n_segs > 0) {
/* Fit and draw and reset state */
@@ -750,20 +768,15 @@ void PencilTool::addPowerStrokePencil(bool force, gint tolsimplify)
curvepressure->curveto(b[4 * c + 1], b[4 * c + 2], b[4 * c + 3]);
}
}
+ Geom::Affine transform_coordinate = SP_ITEM(SP_ACTIVE_DESKTOP->currentLayer())->i2dt_affine().inverse();
+ curvepressure->transform(transform_coordinate);
Geom::Path path = curvepressure->get_pathvector()[0];
int original_size = path.size();
if (!path.empty()) {
- Geom::Affine transform_coordinate = SP_ITEM(SP_ACTIVE_DESKTOP->currentLayer())->i2dt_affine().inverse();
- path *= transform_coordinate;
// 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]));
// future = std::async(std::launch::async, [path, points_preview] {
using namespace Inkscape::LivePathEffect;
- SPDocument *document = SP_ACTIVE_DOCUMENT;
- if (!document) {
- return;
- // return true;
- }
Inkscape::XML::Document *xml_doc = document->getReprDoc();
Inkscape::XML::Node *pp = nullptr;
pp = xml_doc->createElement("svg:path");
@@ -782,30 +795,37 @@ void PencilTool::addPowerStrokePencil(bool force, gint tolsimplify)
return;
// return true;
}
-
- tol = prefs->getDoubleLimited("/tools/freehand/pencil/tolerance", 10.0, 0.0, 100.0) + tolsimplify;
- tol = tol / (100.0 * (102.0 - tol));
- std::ostringstream threshold;
- threshold << tol;
- Effect::createAndApply(SIMPLIFY, desktop->doc(), SP_ITEM(lpeitem));
- Effect *lpe = lpeitem->getCurrentLPE();
- if (lpe) {
- Glib::ustring pref_path = "/live_effects/simplify/smooth_angles";
- bool valid = prefs->getEntry(pref_path).isValid();
- if (!valid) {
- lpe->getRepr()->setAttribute("smooth_angles", "0");
+
+ 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;
+ threshold << tol;
+ Effect::createAndApply(SIMPLIFY, desktop->doc(), SP_ITEM(lpeitem));
+ Effect *lpe = lpeitem->getCurrentLPE();
+ Inkscape::LivePathEffect::LPESimplify *simplify = static_cast<Inkscape::LivePathEffect::LPESimplify *>(lpe);
+ if (simplify) {
+ 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("threshold", threshold.str());
+ }
+ sp_lpe_item_update_patheffect(lpeitem, false, true);
+ curvepressure = powerpreview->getCurve();
+ if (curvepressure->is_empty()) {
+ return;
}
- lpe->getRepr()->setAttribute("threshold", threshold.str());
+ path = curvepressure->get_pathvector()[0];
}
- sp_lpe_item_update_patheffect(lpeitem, false, true);
- curvepressure = powerpreview->getCurve();
- path = curvepressure->get_pathvector()[0];
+ this->size_powerpencil = path.size();
powerStrokeInterpolate(path);
Inkscape::Preferences *prefs = Inkscape::Preferences::get();
Glib::ustring pref_path_pp = "/live_effects/powerstroke/powerpencil";
prefs->setBool(pref_path_pp, true);
Effect::createAndApply(POWERSTROKE, SP_ACTIVE_DESKTOP->doc(), lpeitem);
- lpe = lpeitem->getCurrentLPE();
+ Effect *lpe = lpeitem->getCurrentLPE();
Inkscape::LivePathEffect::LPEPowerStroke *pspreview = static_cast<LPEPowerStroke *>(lpe);
if (pspreview) {
sp_lpe_item_enable_path_effects(lpeitem, false);
@@ -814,6 +834,11 @@ void PencilTool::addPowerStrokePencil(bool force, gint tolsimplify)
if (!valid) {
pspreview->getRepr()->setAttribute("interpolator_type", "CentripetalCatmullRom");
}
+ pref_path = "/live_effects/powerstroke/linejoin_type";
+ valid = prefs->getEntry(pref_path).isValid();
+ if (!valid) {
+ pspreview->getRepr()->setAttribute("linejoin_type", "bevel");
+ }
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));
@@ -830,21 +855,20 @@ void PencilTool::addPowerStrokePencil(bool force, gint tolsimplify)
SP_OBJECT(lpeobj)->deleteObject(true);
lpeobj = nullptr;
}
- lpe = SP_LPE_ITEM(toremove)->getCurrentLPE();
- SP_LPE_ITEM(toremove)->removeCurrentPathEffect(true);
- lpeobj = lpe->getLPEObj();
- if (lpeobj) {
- SP_OBJECT(lpeobj)->deleteObject(true);
- lpeobj = nullptr;
+ tol = prefs->getDoubleLimited("/tools/freehand/pencil/tolerance", 10.0, 0.0, 100.0) + 30;
+ if (tol > 30) {
+ lpe = SP_LPE_ITEM(toremove)->getCurrentLPE();
+ SP_LPE_ITEM(toremove)->removeCurrentPathEffect(true);
+ lpeobj = lpe->getLPEObj();
+ if (lpeobj) {
+ SP_OBJECT(lpeobj)->deleteObject(true);
+ lpeobj = nullptr;
+ }
}
toremove->deleteObject(true);
toremove = nullptr;
}
- if (!pspreview->has_exception && path.size() != powerpreview->getCurve()->get_pathvector()[0].size()) {
- pp->setAttribute("style", "fill:#888888;opacity:1;fill-rule:nonzero;stroke:none;");
- } else if (tolsimplify < 61) { // run 3 times
- addPowerStrokePencil(true, tolsimplify + 10);
- }
+ pp->setAttribute("style", "fill:#888888;opacity:1;fill-rule:nonzero;stroke:none;");
}
if (curvepressure) {
curvepressure->unref();
@@ -870,19 +894,18 @@ void PencilTool::_addFreehandPoint(Geom::Point const &p, guint /*state*/) {
Inkscape::Preferences *prefs = Inkscape::Preferences::get();
double min = prefs->getIntLimited("/tools/freehand/pencil/minpressure", 10, 0, 100) / 100.0;
double max = prefs->getIntLimited("/tools/freehand/pencil/maxpressure", 40, 0, 100) / 100.0;
- Geom::Affine transform_coordinate = SP_ITEM(SP_ACTIVE_DESKTOP->currentLayer())->i2dt_affine();
if (min > max) {
min = max;
}
- if (this->pressure < 0.25) {
- this->_wps.push_back(0);
- return;
- }
double dezoomify_factor = 0.05 * 1000 / SP_EVENT_CONTEXT(this)->desktop->current_zoom();
double pressure_shrunk = (((this->pressure - 0.25) * 1.25) * (max - min)) + min;
double pressure_computed = pressure_shrunk * (dezoomify_factor / 5.0);
- this->_wps.push_back(pressure_computed);
- this->addPowerStrokePencil(false, 30);
+ if (this->pressure < 0.25) {
+ this->_wps.push_back(Geom::Point(this->ps.size(), 0));
+ } else {
+ this->_wps.push_back(Geom::Point(this->ps.size(), pressure_computed));
+ }
+ this->addPowerStrokePencil(false);
sp_canvas_bpath_set_bpath(SP_CANVAS_BPATH(this->red_bpath), nullptr);
for (auto i:this->green_bpaths) {
sp_canvas_item_destroy(i);
@@ -898,6 +921,7 @@ void PencilTool::powerStrokeInterpolate(Geom::Path path)
if ( ps_size <= 1 ) {
return;
}
+
using Geom::X;
using Geom::Y;
Inkscape::Preferences *prefs = Inkscape::Preferences::get();
@@ -907,13 +931,10 @@ void PencilTool::powerStrokeInterpolate(Geom::Path path)
std::vector<Geom::Point> tmp_points;
Geom::Point previous = Geom::Point(Geom::infinity(), 0);
size_t i = 0;
- size_t previ = 0;
bool increase = true;
- for (auto pressure : this->_wps) {
- Geom::Point pp = Geom::Point();
+ for (auto pp : this->_wps) {
pp[Geom::X] = (path_size / (double)points_size) * i;
- pp[Geom::Y] = pressure;
- if (pressure == 0 || (path_size > 1 && (pp[Geom::X] < 1 || pp[Geom::X] > path_size - 1))) {
+ if (pp[Geom::Y] == 0 || (path_size > 1 && (pp[Geom::X] < 1 || pp[Geom::X] > path_size - 2))) {
++i;
continue;
}
@@ -937,6 +958,10 @@ void PencilTool::powerStrokeInterpolate(Geom::Path path)
}
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]);
+ this->points.push_back(one);
+ }
sp_canvas_bpath_set_bpath(SP_CANVAS_BPATH(this->red_bpath), nullptr);
}
diff --git a/src/ui/tools/pencil-tool.h b/src/ui/tools/pencil-tool.h
index 60edd3f78..e30db8067 100644
--- a/src/ui/tools/pencil-tool.h
+++ b/src/ui/tools/pencil-tool.h
@@ -48,8 +48,8 @@ public:
Geom::Point p[16];
std::vector<Geom::Point> ps;
std::vector<Geom::Point> points;
- void addPowerStrokePencil(bool force, gint tolsimplify);
- void powerStrokeInterpolate(Geom::Path);
+ void addPowerStrokePencil(bool reset);
+ void powerStrokeInterpolate(Geom::Path const path);
Geom::Piecewise<Geom::D2<Geom::SBasis> > sketch_interpolation; // the current proposal from the sketched paths
unsigned sketch_n; // number of sketches done
static const std::string prefsPath;
@@ -76,12 +76,13 @@ private:
void _extinput(GdkEvent *event);
void _cancel();
void _endpointSnap(Geom::Point &p, guint const state);
- std::vector<double> _wps;
+ std::vector<Geom::Point> _wps;
SPCurve * _curve;
Geom::Point _req_tangent;
bool _is_drawing;
PencilState _state;
gint _npoints;
+ gint size_powerpencil;
// std::future<bool> future;
};