From: cilix42 Date: Sun, 8 Jun 2008 17:56:04 +0000 (+0000) Subject: Better way to add LPE knotholder handles; now it happens semi-automatically in a... X-Git-Url: https://git.tokkee.org/?a=commitdiff_plain;h=5be124ad592f5c71eca838ad2eaac9ffa953605f;p=inkscape.git Better way to add LPE knotholder handles; now it happens semi-automatically in a similar way as adding LPE parameters. --- diff --git a/src/live_effects/effect.cpp b/src/live_effects/effect.cpp index db395c81b..b08077e79 100644 --- a/src/live_effects/effect.cpp +++ b/src/live_effects/effect.cpp @@ -321,14 +321,26 @@ Effect::registerParameter(Parameter * param) param_vector.push_back(param); } -// TODO: Does it still make sense to use this? E.g., should we keep a list of knotholder entities -// in the effect itself and add them here in a semi-automatic manner (similarly to how it is -// done with parameters) instead of adding each one separately in the overloaded function -// addKnotHolderHandles()? +// TODO: should we provide a way to alter the handle's appearance? void -Effect::registerKnotHolderHandle(SPKnotHolderSetFunc set_func, SPKnotHolderGetFunc get_func) +Effect::registerKnotHolderHandle(KnotHolderEntity* entity, const char* descr) { - //knotholder_func_vector.push_back(std::make_pair(set_func, get_func)); + kh_entity_vector.push_back(std::make_pair(entity, descr)); +} + +/** + * Add all registered LPE knotholder handles to the knotholder + */ +void +Effect::addHandles(KnotHolder *knotholder, SPDesktop *desktop, SPItem *item) { + std::vector >::iterator i; + for (i = kh_entity_vector.begin(); i != kh_entity_vector.end(); ++i) { + KnotHolderEntity *entity = i->first; + const char *descr = i->second; + + entity->create(desktop, item, knotholder, descr); + knotholder->add(entity); + } } void @@ -346,14 +358,6 @@ Effect::addPointParamHandles(KnotHolder *knotholder, SPDesktop *desktop, SPItem } } -/** - * Virtual method to add knotholder handles for LPE items - */ -void -Effect::addKnotHolderHandles(KnotHolder *knotholder, SPDesktop *desktop, SPItem *item) -{ -} - /** * This *creates* a new widget, management of deletion should be done by the caller */ diff --git a/src/live_effects/effect.h b/src/live_effects/effect.h index c46c145b5..a990a858d 100644 --- a/src/live_effects/effect.h +++ b/src/live_effects/effect.h @@ -102,8 +102,7 @@ public: virtual void transform_multiply(Geom::Matrix const& postmul, bool set); virtual bool providesKnotholder() { return false; } - void addPointParamHandles(KnotHolder *knotholder, SPDesktop *desktop, SPItem *item); - virtual void addKnotHolderHandles(KnotHolder *knotholder, SPDesktop *desktop, SPItem *item); + void addHandles(KnotHolder *knotholder, SPDesktop *desktop, SPItem *item); Glib::ustring getName(); Inkscape::XML::Node * getRepr(); @@ -132,10 +131,12 @@ protected: doEffect_pwd2 (Geom::Piecewise > const & pwd2_in); void registerParameter(Parameter * param); - void registerKnotHolderHandle(SPKnotHolderSetFunc set_func, SPKnotHolderGetFunc get_func); + void registerKnotHolderHandle(KnotHolderEntity* entity, const char* descr); + void addPointParamHandles(KnotHolder *knotholder, SPDesktop *desktop, SPItem *item); Parameter * getNextOncanvasEditableParam(); std::vector param_vector; + std::vector > kh_entity_vector; int oncanvasedit_it; BoolParam is_visible; @@ -157,3 +158,14 @@ private: } //namespace Inkscape #endif + +/* + Local Variables: + mode:c++ + c-file-style:"stroustrup" + c-file-offsets:((innamespace . 0)(inline-open . 0)(case-label . +)) + indent-tabs-mode:nil + fill-column:99 + End: +*/ +// vim: filetype=cpp:expandtab:shiftwidth=4:tabstop=8:softtabstop=4 : diff --git a/src/live_effects/lpe-perp_bisector.cpp b/src/live_effects/lpe-perp_bisector.cpp index 39423df8b..139ca21bf 100644 --- a/src/live_effects/lpe-perp_bisector.cpp +++ b/src/live_effects/lpe-perp_bisector.cpp @@ -138,10 +138,12 @@ LPEPerpBisector::LPEPerpBisector(LivePathEffectObject *lpeobject) : registerParameter( dynamic_cast(&length_left) ); registerParameter( dynamic_cast(&length_right) ); +/** registerKnotHolderHandle(path_start_set, path_start_get); registerKnotHolderHandle(path_end_set, path_end_get); registerKnotHolderHandle(bisector_left_end_set, bisector_left_end_get); registerKnotHolderHandle(bisector_right_end_set, bisector_right_end_get); +**/ } LPEPerpBisector::~LPEPerpBisector() diff --git a/src/live_effects/lpe-tangent_to_curve.cpp b/src/live_effects/lpe-tangent_to_curve.cpp index b61a078a4..02d34f312 100644 --- a/src/live_effects/lpe-tangent_to_curve.cpp +++ b/src/live_effects/lpe-tangent_to_curve.cpp @@ -27,6 +27,36 @@ namespace Inkscape { namespace LivePathEffect { +class KnotHolderEntityAttachPt : public KnotHolderEntity +{ +public: + virtual bool isLPEParam() { return true; } + + virtual void knot_set(NR::Point const &p, NR::Point const &origin, guint state); + virtual NR::Point knot_get(); + virtual void onKnotUngrabbed(); +}; + +class KnotHolderEntityLeftEnd : public KnotHolderEntity +{ +public: + virtual bool isLPEParam() { return true; } + + virtual void knot_set(NR::Point const &p, NR::Point const &origin, guint state); + virtual NR::Point knot_get(); + virtual void onKnotUngrabbed(); +}; + +class KnotHolderEntityRightEnd : public KnotHolderEntity +{ +public: + virtual bool isLPEParam() { return true; } + + virtual void knot_set(NR::Point const &p, NR::Point const &origin, guint state); + virtual NR::Point knot_get(); + virtual void onKnotUngrabbed(); +}; + LPETangentToCurve::LPETangentToCurve(LivePathEffectObject *lpeobject) : Effect(lpeobject), angle(_("Angle"), _("Additional angle between tangent and curve"), "angle", &wr, this, 0.0), @@ -38,6 +68,10 @@ LPETangentToCurve::LPETangentToCurve(LivePathEffectObject *lpeobject) : registerParameter( dynamic_cast(&t_attach) ); registerParameter( dynamic_cast(&length_left) ); registerParameter( dynamic_cast(&length_right) ); + + registerKnotHolderHandle(new KnotHolderEntityAttachPt(), _("Adjust the \"left\" end of the tangent")); + registerKnotHolderHandle(new KnotHolderEntityLeftEnd(), _("Adjust the \"right\" end of the tangent")); + registerKnotHolderHandle(new KnotHolderEntityRightEnd(), _("Adjust the point of attachment of the tangent")); } LPETangentToCurve::~LPETangentToCurve() @@ -65,55 +99,6 @@ LPETangentToCurve::doEffect_pwd2 (Geom::Piecewise > const return output; } -class KnotHolderEntityAttachPt : public KnotHolderEntity -{ -public: - virtual bool isLPEParam() { return true; } - - virtual void knot_set(NR::Point const &p, NR::Point const &origin, guint state); - virtual NR::Point knot_get(); - virtual void onKnotUngrabbed(); -}; - -class KnotHolderEntityLeftEnd : public KnotHolderEntity -{ -public: - virtual bool isLPEParam() { return true; } - - virtual void knot_set(NR::Point const &p, NR::Point const &origin, guint state); - virtual NR::Point knot_get(); - virtual void onKnotUngrabbed(); -}; - -class KnotHolderEntityRightEnd : public KnotHolderEntity -{ -public: - virtual bool isLPEParam() { return true; } - - virtual void knot_set(NR::Point const &p, NR::Point const &origin, guint state); - virtual NR::Point knot_get(); - virtual void onKnotUngrabbed(); -}; - -void -LPETangentToCurve::addKnotHolderHandles(KnotHolder *knotholder, SPDesktop *desktop, SPItem *item) -{ - KnotHolderEntityLeftEnd *entity_left_end = new KnotHolderEntityLeftEnd(); - KnotHolderEntityRightEnd *entity_right_end = new KnotHolderEntityRightEnd(); - KnotHolderEntityAttachPt *entity_attach_pt = new KnotHolderEntityAttachPt(); - - entity_left_end->create(desktop, item, knotholder, - _("Adjust the \"left\" end of the tangent")); - entity_right_end->create(desktop, item, knotholder, - _("Adjust the \"right\" end of the tangent")); - entity_attach_pt->create(desktop, item, knotholder, - _("Adjust the point of attachment of the tangent")); - - knotholder->add(entity_left_end); - knotholder->add(entity_right_end); - knotholder->add(entity_attach_pt); -} - static LPETangentToCurve * get_effect(SPItem *item) { diff --git a/src/live_effects/lpe-tangent_to_curve.h b/src/live_effects/lpe-tangent_to_curve.h index 0de2baf56..678c32c36 100644 --- a/src/live_effects/lpe-tangent_to_curve.h +++ b/src/live_effects/lpe-tangent_to_curve.h @@ -29,7 +29,6 @@ public: virtual ~LPETangentToCurve(); bool providesKnotholder() { return true; } - virtual void addKnotHolderHandles(KnotHolder *knotholder, SPDesktop *desktop, SPItem *item); virtual Geom::Piecewise > doEffect_pwd2 (Geom::Piecewise > const & pwd2_in); diff --git a/src/object-edit.cpp b/src/object-edit.cpp index 8d8be4b85..de7fbccec 100644 --- a/src/object-edit.cpp +++ b/src/object-edit.cpp @@ -57,7 +57,7 @@ static KnotHolder *sp_lpe_knot_holder(SPItem *item, SPDesktop *desktop) Inkscape::LivePathEffect::Effect *effect = sp_lpe_item_get_current_lpe(SP_LPE_ITEM(item)); // effect->addPointParamHandles(knot_holder, desktop, item); - effect->addKnotHolderHandles(knot_holder, desktop, item); + effect->addHandles(knot_holder, desktop, item); return knot_holder; }