From faf187547d7028652e2940ed4fbd14ffe930b40c Mon Sep 17 00:00:00 2001 From: "Johan B. C. Engelen" Date: Fri, 4 Nov 2011 22:07:55 +0100 Subject: Powerstroke: add erasing of knots with ctrl+alt (LPE parameter editing on-canvas code is seriously flawed) (bzr r10719) --- .../parameter/powerstrokepointarray.cpp | 38 +++++++++++++++++----- 1 file changed, 30 insertions(+), 8 deletions(-) (limited to 'src') 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 > const & pwd2 = _pparam->get_pwd2(); Piecewise > 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 > const & pwd2 = _pparam->get_pwd2(); Piecewise > 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 & 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 & vec = _pparam->_vector; + vec.erase(vec.begin() + _index); + _pparam->param_set_and_write_new_value(vec); + } else { + // add a knot + std::vector & vec = _pparam->_vector; + vec.insert(vec.begin() + _index, 1, vec.at(_index)); + _pparam->param_set_and_write_new_value(vec); + } + } + } void -- cgit v1.2.3