diff options
| author | Andrew Higginson <at.higginson@gmail.com> | 2011-12-27 21:04:47 +0000 |
|---|---|---|
| committer | Andrew <at.higginson@gmail.com> | 2011-12-27 21:04:47 +0000 |
| commit | 80960b623a99aae1402ab651b2974ef544ed3b03 (patch) | |
| tree | ba49d42c2789e9e11f805e2d5263e10f9fedeef8 /src/live_effects/parameter/powerstrokepointarray.cpp | |
| parent | try to fix bug (diff) | |
| parent | GDL: Cherry-pick upstream patch 73852 (2011-03-23) - Add missing return value. (diff) | |
| download | inkscape-80960b623a99aae1402ab651b2974ef544ed3b03.tar.gz inkscape-80960b623a99aae1402ab651b2974ef544ed3b03.zip | |
merged with trunk so I can build again...
(bzr r10092.1.36)
Diffstat (limited to 'src/live_effects/parameter/powerstrokepointarray.cpp')
| -rw-r--r-- | src/live_effects/parameter/powerstrokepointarray.cpp | 77 |
1 files changed, 67 insertions, 10 deletions
diff --git a/src/live_effects/parameter/powerstrokepointarray.cpp b/src/live_effects/parameter/powerstrokepointarray.cpp index 9d43e8447..fccbad7e5 100644 --- a/src/live_effects/parameter/powerstrokepointarray.cpp +++ b/src/live_effects/parameter/powerstrokepointarray.cpp @@ -70,13 +70,48 @@ PowerStrokePointArrayParam::param_newWidget(Gtk::Tooltips * /*tooltips*/) } -void -PowerStrokePointArrayParam::param_transform_multiply(Geom::Affine const& postmul, bool /*set*/) +void PowerStrokePointArrayParam::param_transform_multiply(Geom::Affine const& /*postmul*/, bool /*set*/) { // param_set_and_write_new_value( (*this) * postmul ); } +/** call this method to recalculate the controlpoints such that they stay at the same location relative to the new path. Useful after adding/deleting nodes to the path.*/ +void +PowerStrokePointArrayParam::recalculate_controlpoints_for_new_pwd2(Geom::Piecewise<Geom::D2<Geom::SBasis> > const & pwd2_in) +{ + if (!last_pwd2.empty()) { + if (last_pwd2.size() > pwd2_in.size()) { + // Path has become shorter: rescale offsets + double factor = (double)pwd2_in.size() / (double)last_pwd2.size(); + for (unsigned int i = 0; i < _vector.size(); ++i) { + _vector[i][Geom::X] *= factor; + } + } else if (last_pwd2.size() < pwd2_in.size()) { + // Path has become longer: probably node added, maintain position of knots + Geom::Piecewise<Geom::D2<Geom::SBasis> > normal = rot90(unitVector(derivative(pwd2_in))); + for (unsigned int i = 0; i < _vector.size(); ++i) { + Geom::Point pt = _vector[i]; + Geom::Point position = last_pwd2.valueAt(pt[Geom::X]) + pt[Geom::Y] * last_pwd2_normal.valueAt(pt[Geom::X]); + + double t = nearest_point(position, pwd2_in); + double offset = dot(position - pwd2_in.valueAt(t), normal.valueAt(t)); + _vector[i] = Geom::Point(t, offset); + } + } + + write_to_SVG(); + } +} + +void +PowerStrokePointArrayParam::set_pwd2(Geom::Piecewise<Geom::D2<Geom::SBasis> > const & pwd2_in, Geom::Piecewise<Geom::D2<Geom::SBasis> > const & pwd2_normal_in) +{ + last_pwd2 = pwd2_in; + last_pwd2_normal = pwd2_normal_in; +} + + void PowerStrokePointArrayParam::set_oncanvas_looks(SPKnotShapeType shape, SPKnotModeType mode, guint32 color) { @@ -94,6 +129,11 @@ public: virtual Geom::Point knot_get(); virtual void knot_click(guint state); + /** Checks whether the index falls within the size of the parameter's vector */ + bool valid_index(unsigned int index) { + return (_pparam->_vector.size() > index); + }; + private: PowerStrokePointArrayParam *_pparam; unsigned int _index; @@ -108,8 +148,13 @@ PowerStrokePointArrayParamKnotHolderEntity::PowerStrokePointArrayParamKnotHolder void PowerStrokePointArrayParamKnotHolderEntity::knot_set(Geom::Point const &p, Geom::Point const &/*origin*/, guint /*state*/) { -/// @todo how about item transforms??? using namespace Geom; + + if (!valid_index(_index)) { + return; + } + + /// @todo how about item transforms??? Piecewise<D2<SBasis> > const & pwd2 = _pparam->get_pwd2(); Piecewise<D2<SBasis> > const & n = _pparam->get_pwd2_normal(); @@ -124,6 +169,11 @@ Geom::Point PowerStrokePointArrayParamKnotHolderEntity::knot_get() { using namespace Geom; + + if (!valid_index(_index)) { + return Geom::Point(infinity(), infinity()); + } + Piecewise<D2<SBasis> > const & pwd2 = _pparam->get_pwd2(); Piecewise<D2<SBasis> > const & n = _pparam->get_pwd2_normal(); @@ -136,15 +186,22 @@ PowerStrokePointArrayParamKnotHolderEntity::knot_get() void PowerStrokePointArrayParamKnotHolderEntity::knot_click(guint state) { - g_print ("This is the %d handle associated to parameter '%s'\n", _index, _pparam->param_key.c_str()); +//g_print ("This is the %d handle associated to parameter '%s'\n", _index, _pparam->param_key.c_str()); if (state & GDK_CONTROL_MASK) { - std::vector<Geom::Point> & vec = _pparam->_vector; - vec.insert(vec.begin() + _index, 1, vec.at(_index)); - _pparam->param_set_and_write_new_value(vec); - g_print ("Added handle %d associated to parameter '%s'\n", _index, _pparam->param_key.c_str()); - /// @todo this BUGS ! the knot stuff should be reloaded when adding a new node! - } + if (state & GDK_MOD1_MASK) { + // delete the clicked knot + std::vector<Geom::Point> & vec = _pparam->_vector; + vec.erase(vec.begin() + _index); + _pparam->param_set_and_write_new_value(vec); + } else { + // add a knot + std::vector<Geom::Point> & vec = _pparam->_vector; + vec.insert(vec.begin() + _index, 1, vec.at(_index)); + _pparam->param_set_and_write_new_value(vec); + } + } + } void |
