diff options
| author | Johan B. C. Engelen <jbc.engelen@swissonline.ch> | 2011-11-04 21:07:55 +0000 |
|---|---|---|
| committer | Johan Engelen <goejendaagh@zonnet.nl> | 2011-11-04 21:07:55 +0000 |
| commit | faf187547d7028652e2940ed4fbd14ffe930b40c (patch) | |
| tree | f9a0025610257b96abe7f17e5b8e8774dafad13a | |
| parent | reduce scope of some variables (diff) | |
| download | inkscape-faf187547d7028652e2940ed4fbd14ffe930b40c.tar.gz inkscape-faf187547d7028652e2940ed4fbd14ffe930b40c.zip | |
Powerstroke: add erasing of knots with ctrl+alt (LPE parameter editing on-canvas code is seriously flawed)
(bzr r10719)
| -rw-r--r-- | src/live_effects/parameter/powerstrokepointarray.cpp | 38 |
1 files changed, 30 insertions, 8 deletions
diff --git a/src/live_effects/parameter/powerstrokepointarray.cpp b/src/live_effects/parameter/powerstrokepointarray.cpp index 66337fd8f..5139f0e41 100644 --- a/src/live_effects/parameter/powerstrokepointarray.cpp +++ b/src/live_effects/parameter/powerstrokepointarray.cpp @@ -93,6 +93,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; @@ -107,8 +112,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(); @@ -123,6 +133,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(); @@ -135,15 +150,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 |
