summaryrefslogtreecommitdiffstats
path: root/src/live_effects
diff options
context:
space:
mode:
authorJabier Arraiza <jabier.arraiza@marker.es>2017-08-27 10:55:26 +0000
committerJabier Arraiza <jabier.arraiza@marker.es>2017-08-27 10:55:26 +0000
commitbbde5dbeeb06611e99f9fa7f73dafe3bf70df01c (patch)
tree8f2aba648ca0b2ae7519903c2270d56039e4a6a9 /src/live_effects
parentStarting with powerpencil (diff)
downloadinkscape-bbde5dbeeb06611e99f9fa7f73dafe3bf70df01c.tar.gz
inkscape-bbde5dbeeb06611e99f9fa7f73dafe3bf70df01c.zip
Working on preview over powerpencil
Diffstat (limited to 'src/live_effects')
-rw-r--r--src/live_effects/lpe-powerstroke.cpp31
-rw-r--r--src/live_effects/lpe-powerstroke.h3
-rw-r--r--src/live_effects/parameter/powerstrokepointarray.cpp4
-rw-r--r--src/live_effects/parameter/powerstrokepointarray.h3
4 files changed, 33 insertions, 8 deletions
diff --git a/src/live_effects/lpe-powerstroke.cpp b/src/live_effects/lpe-powerstroke.cpp
index 05ce3b7bd..ae2ce1e65 100644
--- a/src/live_effects/lpe-powerstroke.cpp
+++ b/src/live_effects/lpe-powerstroke.cpp
@@ -167,6 +167,7 @@ LPEPowerStroke::LPEPowerStroke(LivePathEffectObject *lpeobject) :
sort_points(_("Sort points"), _("Sort offset points according to their time value along the curve"), "sort_points", &wr, this, true),
interpolator_type(_("Interpolator type:"), _("Determines which kind of interpolator will be used to interpolate between stroke width along the path"), "interpolator_type", InterpolatorTypeConverter, &wr, this, Geom::Interpolate::INTERP_CUBICBEZIER),
interpolator_beta(_("Smoothness:"), _("Sets the smoothness for the CubicBezierJohan interpolator; 0 = linear interpolation, 1 = smooth"), "interpolator_beta", &wr, this, 0.2),
+ scale_width(_("Width scale:"), _("Width scale all points"), "scale_width", &wr, this, 1.0),
start_linecap_type(_("Start cap:"), _("Determines the shape of the path's start"), "start_linecap_type", LineCapTypeConverter, &wr, this, LINECAP_BUTT),
linejoin_type(_("Join:"), _("Determines the shape of the path's corners"), "linejoin_type", LineJoinTypeConverter, &wr, this, LINEJOIN_EXTRP_MITER_ARC),
miter_limit(_("Miter limit:"), _("Maximum length of the miter (in units of stroke width)"), "miter_limit", &wr, this, 4.),
@@ -186,14 +187,22 @@ LPEPowerStroke::LPEPowerStroke(LivePathEffectObject *lpeobject) :
registerParameter(&start_linecap_type);
registerParameter(&linejoin_type);
registerParameter(&miter_limit);
+ registerParameter(&scale_width);
registerParameter(&end_linecap_type);
+ scale_width.param_set_range(0.0, Geom::infinity());
+ scale_width.param_set_increments(1, 1);
+ scale_width.param_set_digits(4);
}
LPEPowerStroke::~LPEPowerStroke()
{
}
-
+void
+LPEPowerStroke::doBeforeEffect(SPLPEItem const *lpeItem)
+{
+ offset_points.set_scale_width(scale_width);
+}
void
LPEPowerStroke::doOnApply(SPLPEItem const* lpeitem)
{
@@ -247,6 +256,7 @@ LPEPowerStroke::doOnApply(SPLPEItem const* lpeitem)
points.push_back( Geom::Point(size - 0.2,width) );
}
}
+ offset_points.set_scale_width(scale_width);
offset_points.param_set_and_write_new_value(points);
} else {
if (!SP_IS_SHAPE(lpeitem)) {
@@ -559,7 +569,7 @@ LPEPowerStroke::doEffect_path (Geom::PathVector const & path_in)
Geom::Piecewise<Geom::D2<Geom::SBasis> > pwd2_in = pathv[0].toPwSb();
Piecewise<D2<SBasis> > der = derivative(pwd2_in);
Piecewise<D2<SBasis> > n = unitVector(der,0.0001);
- if (!n.size()) {
+ if (!n.size() || !pwd2_in.size() || !n.size()) {
return path_in;
}
n = rot90(n);
@@ -568,10 +578,15 @@ LPEPowerStroke::doEffect_path (Geom::PathVector const & path_in)
LineCapType end_linecap = static_cast<LineCapType>(end_linecap_type.get_value());
LineCapType start_linecap = static_cast<LineCapType>(start_linecap_type.get_value());
- std::vector<Geom::Point> ts = offset_points.data();
- if (ts.empty()) {
+ std::vector<Geom::Point> ts_no_scale = offset_points.data();
+ if (ts_no_scale.empty()) {
return path_out;
}
+ std::vector<Geom::Point> ts;
+ for (std::vector<Geom::Point>::iterator tsp = ts_no_scale.begin(); tsp != ts_no_scale.end(); ++tsp) {
+ Geom::Point p = Geom::Point((*tsp)[Geom::X], (*tsp)[Geom::Y] * scale_width);
+ ts.push_back(p);
+ }
if (sort_points) {
sort(ts.begin(), ts.end(), compare_offsets);
}
@@ -625,10 +640,16 @@ LPEPowerStroke::doEffect_path (Geom::PathVector const & path_in)
LineJoinType jointype = static_cast<LineJoinType>(linejoin_type.get_value());
+ if (!x.size() || !y.size()) {
+ return path_in;
+ }
Piecewise<D2<SBasis> > pwd2_out_1 = compose(pwd2_in,x);
Piecewise<D2<SBasis> > pwd2_out_2 = y*compose(n,x);
+ if (!pwd2_out_1.size() || !pwd2_out_2.size()) {
+ return path_in;
+ }
Piecewise<D2<SBasis> > pwd2_out = pwd2_out_1 + pwd2_out_2;
- Piecewise<D2<SBasis> > mirrorpath = reverse(compose(pwd2_in,x) - y*compose(n,x));
+ Piecewise<D2<SBasis> > mirrorpath = reverse( pwd2_out_1 - pwd2_out_2);
Geom::Path fixed_path = path_from_piecewise_fix_cusps( pwd2_out, y, jointype, miter_limit, LPE_CONVERSION_TOLERANCE);
Geom::Path fixed_mirrorpath = path_from_piecewise_fix_cusps( mirrorpath, reverse(y), jointype, miter_limit, LPE_CONVERSION_TOLERANCE);
diff --git a/src/live_effects/lpe-powerstroke.h b/src/live_effects/lpe-powerstroke.h
index 135d39274..4a0eda75a 100644
--- a/src/live_effects/lpe-powerstroke.h
+++ b/src/live_effects/lpe-powerstroke.h
@@ -27,7 +27,7 @@ public:
virtual Geom::PathVector doEffect_path (Geom::PathVector const & path_in);
-
+ virtual void doBeforeEffect(SPLPEItem const *lpeItem);
virtual void doOnApply(SPLPEItem const* lpeitem);
virtual void doOnRemove(SPLPEItem const* lpeitem);
@@ -40,6 +40,7 @@ private:
BoolParam sort_points;
EnumParam<unsigned> interpolator_type;
ScalarParam interpolator_beta;
+ ScalarParam scale_width;
EnumParam<unsigned> start_linecap_type;
EnumParam<unsigned> linejoin_type;
ScalarParam miter_limit;
diff --git a/src/live_effects/parameter/powerstrokepointarray.cpp b/src/live_effects/parameter/powerstrokepointarray.cpp
index 25639b406..bc06e42ca 100644
--- a/src/live_effects/parameter/powerstrokepointarray.cpp
+++ b/src/live_effects/parameter/powerstrokepointarray.cpp
@@ -163,7 +163,7 @@ PowerStrokePointArrayParamKnotHolderEntity::knot_set(Geom::Point const &p, Geom:
Geom::Point const s = snap_knot_position(p, state);
double t = nearest_time(s, pwd2);
double offset = dot(s - pwd2.valueAt(t), n.valueAt(t));
- _pparam->_vector.at(_index) = Geom::Point(t, offset);
+ _pparam->_vector.at(_index) = Geom::Point(t, offset/_pparam->_scale_width);
if (_pparam->_vector.size() == 1 ) {
Inkscape::Preferences *prefs = Inkscape::Preferences::get();
prefs->setDouble("/live_effect/power_stroke/width", offset);
@@ -188,7 +188,7 @@ PowerStrokePointArrayParamKnotHolderEntity::knot_get() const
g_warning("Broken powerstroke point at %f, I won't try to add that", offset_point[X]);
return Geom::Point(infinity(), infinity());
}
- Point canvas_point = pwd2.valueAt(offset_point[X]) + offset_point[Y] * n.valueAt(offset_point[X]);
+ Point canvas_point = pwd2.valueAt(offset_point[X]) + (offset_point[Y] * _pparam->_scale_width) * n.valueAt(offset_point[X]);
return canvas_point;
}
diff --git a/src/live_effects/parameter/powerstrokepointarray.h b/src/live_effects/parameter/powerstrokepointarray.h
index a34163ca1..621d3b969 100644
--- a/src/live_effects/parameter/powerstrokepointarray.h
+++ b/src/live_effects/parameter/powerstrokepointarray.h
@@ -35,6 +35,7 @@ public:
void set_oncanvas_looks(SPKnotShapeType shape, SPKnotModeType mode, guint32 color);
+
float median_width();
virtual bool providesKnotHolderEntities() const { return true; }
@@ -46,6 +47,8 @@ public:
Geom::Piecewise<Geom::D2<Geom::SBasis> > const & get_pwd2_normal() const { return last_pwd2_normal; }
void recalculate_controlpoints_for_new_pwd2(Geom::Piecewise<Geom::D2<Geom::SBasis> > const & pwd2_in);
+ void set_scale_width(double scale_width){_scale_width = scale_width;};
+ double _scale_width;
friend class PowerStrokePointArrayParamKnotHolderEntity;
private: