summaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
authorJabier Arraiza <jabier.arraiza@marker.es>2017-12-26 16:14:27 +0000
committerJabier Arraiza <jabier.arraiza@marker.es>2017-12-26 16:14:27 +0000
commitd25de3679d94cc03fdba8aba4de20fab723b4b27 (patch)
treeb5f7a1fea6f2bb2f0d3069916b023ca8b4fa325b /src
parentMerge branch 'master' into powerpencilII (diff)
downloadinkscape-d25de3679d94cc03fdba8aba4de20fab723b4b27.tar.gz
inkscape-d25de3679d94cc03fdba8aba4de20fab723b4b27.zip
Fix power stroke closed path and minor tweacks for pencil powerstroke
Diffstat (limited to 'src')
-rw-r--r--src/live_effects/lpe-powerstroke.cpp48
-rw-r--r--src/ui/dialog/inkscape-preferences.cpp2
-rw-r--r--src/ui/tools/freehand-base.cpp1
-rw-r--r--src/ui/tools/pencil-tool.cpp9
4 files changed, 35 insertions, 25 deletions
diff --git a/src/live_effects/lpe-powerstroke.cpp b/src/live_effects/lpe-powerstroke.cpp
index 995f0be35..4e937c1e4 100644
--- a/src/live_effects/lpe-powerstroke.cpp
+++ b/src/live_effects/lpe-powerstroke.cpp
@@ -599,20 +599,33 @@ LPEPowerStroke::doEffect_path (Geom::PathVector const & path_in)
if (sort_points) {
sort(ts.begin(), ts.end(), compare_offsets);
}
+ // create stroke path where points (x,y) := (t, offset)
+ Geom::Interpolate::Interpolator *interpolator = Geom::Interpolate::Interpolator::create(static_cast<Geom::Interpolate::InterpolatorType>(interpolator_type.get_value()));
+ if (Geom::Interpolate::CubicBezierJohan *johan = dynamic_cast<Geom::Interpolate::CubicBezierJohan*>(interpolator)) {
+ johan->setBeta(interpolator_beta);
+ }
+ if (Geom::Interpolate::CubicBezierSmooth *smooth = dynamic_cast<Geom::Interpolate::CubicBezierSmooth*>(interpolator)) {
+ smooth->setBeta(interpolator_beta);
+ }
if (pathv[0].closed()) {
- // add extra points for interpolation between first and last point
- Point first_point = ts.front();
- Point last_point = ts.back();
- //TODO: this is wrong we need to give a calulated Y value
- ts.insert(ts.begin(), last_point - Point(pwd2_in.domain().extent() ,0));
-// double startpercentwidth = ts.front()[Geom::X]/pwd2_in.domain().max();
-// double endpercentwidth = (pwd2_in.domain().max() - ts.back()[Geom::X])/pwd2_in.domain().max();
-// double totalwidth = endpercentwidth + startpercentwidth ;
-// double factor = endpercentwidth/totalwidth;
-// std::cout << factor << "factor" << std::endl;
-// double gap = ts.front()[Geom::Y] - ts.back()[Geom::Y];
-// ts.insert(ts.begin(), Point( pwd2_in.domain().min(), ts.back()[Geom::Y] - (gap / factor) ) );
-// ts.push_back( Point( pwd2_in.domain().max(), ts.back()[Geom::Y] - (gap / factor) ) );
+ std::vector<Geom::Point> ts_close;
+ //we have only one knot or overwrite before
+ Geom::Point start = Geom::Point( pwd2_in.domain().min(), ts.front()[Geom::Y]);
+ Geom::Point end = Geom::Point( pwd2_in.domain().max(), ts.front()[Geom::Y]);
+ if (ts.size() > 1) {
+ ts_close.push_back(ts[ts.size()-2]);
+ ts_close.push_back(ts.back());
+ ts_close.push_back(ts.front());
+ ts_close.push_back(ts[1]);
+ Geom::Path closepath = interpolator->interpolateToPath(ts_close);
+ start = closepath.pointAt(Geom::nearest_time(Geom::Point( pwd2_in.domain().min(),0), closepath));
+ start[Geom::X] = pwd2_in.domain().min();
+ end = start;
+ end[Geom::X] = pwd2_in.domain().max();
+ }
+ ts.insert(ts.begin(), start );
+ ts.push_back( end );
+ ts_close.clear();
} else {
// add width data for first and last point on the path
// depending on cap type, these first and last points have width zero or take the width from the closest width point.
@@ -629,14 +642,7 @@ LPEPowerStroke::doEffect_path (Geom::PathVector const & path_in)
for (std::size_t i = 0, e = ts.size(); i < e; ++i) {
ts[i][Geom::X] *= xcoord_scaling;
}
- // create stroke path where points (x,y) := (t, offset)
- Geom::Interpolate::Interpolator *interpolator = Geom::Interpolate::Interpolator::create(static_cast<Geom::Interpolate::InterpolatorType>(interpolator_type.get_value()));
- if (Geom::Interpolate::CubicBezierJohan *johan = dynamic_cast<Geom::Interpolate::CubicBezierJohan*>(interpolator)) {
- johan->setBeta(interpolator_beta);
- }
- if (Geom::Interpolate::CubicBezierSmooth *smooth = dynamic_cast<Geom::Interpolate::CubicBezierSmooth*>(interpolator)) {
- smooth->setBeta(interpolator_beta);
- }
+
Geom::Path strokepath = interpolator->interpolateToPath(ts);
delete interpolator;
diff --git a/src/ui/dialog/inkscape-preferences.cpp b/src/ui/dialog/inkscape-preferences.cpp
index eb4a6567e..0ac12d15c 100644
--- a/src/ui/dialog/inkscape-preferences.cpp
+++ b/src/ui/dialog/inkscape-preferences.cpp
@@ -432,7 +432,7 @@ void InkscapePreferences::initPageTools()
this->AddDotSizeSpinbutton(_page_pencil, "/tools/freehand/pencil", 3.0);
this->AddBaseSimplifySpinbutton(_page_pencil, "/tools/freehand/pencil", 25.0);
_page_pencil.add_group_header( _("Pressure sensitivity settings"));
- this->AddPencilPowerStrokePressureStep(_page_pencil, "/tools/freehand/pencil", 10);
+ this->AddPencilPowerStrokePressureStep(_page_pencil, "/tools/freehand/pencil", 5);
_page_pencil.add_group_header( _("Sketch mode"));
_page_pencil.add_line( true, "", _pencil_average_all_sketches, "",
diff --git a/src/ui/tools/freehand-base.cpp b/src/ui/tools/freehand-base.cpp
index d2ef1e00d..8a078d510 100644
--- a/src/ui/tools/freehand-base.cpp
+++ b/src/ui/tools/freehand-base.cpp
@@ -884,7 +884,6 @@ static void spdc_flush_white(FreehandBase *dc, SPCurve *gc)
if (!dc->white_item) {
dc->white_item = SP_ITEM(desktop->currentLayer()->appendChildRepr(repr));
}
- std::cout << "lololololo----------------------lololo" << std::endl;
spdc_check_for_and_apply_waiting_LPE(dc, dc->white_item, c, false);
dc->selection->set(dc->white_item);
}
diff --git a/src/ui/tools/pencil-tool.cpp b/src/ui/tools/pencil-tool.cpp
index 8d9981ae2..2f68688a1 100644
--- a/src/ui/tools/pencil-tool.cpp
+++ b/src/ui/tools/pencil-tool.cpp
@@ -771,7 +771,7 @@ PencilTool::addPowerStrokePencil()
{
using namespace Inkscape::LivePathEffect;
Inkscape::Preferences *prefs = Inkscape::Preferences::get();
- double step = prefs->getIntLimited("/tools/freehand/pencil/ps-step-pressure",10, 1, 100)/100.0;
+ double step = prefs->getIntLimited("/tools/freehand/pencil/ps-step-pressure",5, 1, 100)/100.0;
double min = prefs->getIntLimited("/tools/freehand/pencil/minpressure", 0, 1, 100) / 100.0;
double max = prefs->getIntLimited("/tools/freehand/pencil/maxpressure", 100, 1, 100) / 100.0;
Geom::Affine transform_coordinate = SP_ITEM(SP_ACTIVE_DESKTOP->currentLayer())->i2dt_affine();
@@ -790,11 +790,16 @@ PencilTool::addPowerStrokePencil()
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;
+ step = (step * (max - min)) + min;
//We need half width for power stroke
double pressure_computed = pressure_shrunk * dezoomify_factor/2.0;
this->_last_point = this->ps.back();
this->_last_point *= transform_coordinate.inverse();
- if (this->ps.size() == 1 || std::abs(_previous_pressure - pressure_shrunk) > step ) {
+ if (this->ps.size() == 1 ||
+ std::abs(_previous_pressure - pressure_shrunk) > step ||
+ _previous_pressure == 0.0 ||
+ (_previous_pressure > step && pressure_shrunk < step))
+ {
_previous_pressure = pressure_shrunk;
this->points.push_back(Geom::Point(0, pressure_computed));
this->_points_pos.push_back(this->_last_point);