From: cilix42 Date: Tue, 29 Jul 2008 14:49:40 +0000 (+0000) Subject: LPE knotholder refactoring: PointParams are not knotholder entities any more; instead... X-Git-Url: https://git.tokkee.org/?a=commitdiff_plain;h=797bee69297bbdd86c5cff2e0771a71d1e2ac69d;p=inkscape.git LPE knotholder refactoring: PointParams are not knotholder entities any more; instead, every parameter type can now return entities (and then forget about them) --- diff --git a/src/knot-holder-entity.h b/src/knot-holder-entity.h index a29b71f4d..9cdc908de 100644 --- a/src/knot-holder-entity.h +++ b/src/knot-holder-entity.h @@ -43,6 +43,7 @@ public: /* derived classes like PointParam for LPEs use this, e.g., to indicate that we must not call delete on their pointer when a knotholder is destroyed */ + // TODO: purge this now that PointParams are not KnotHolderEntities any more! virtual bool isLPEParam() { return false; } /* the get/set/click handlers are virtual functions; each handler class for a knot diff --git a/src/live_effects/effect.cpp b/src/live_effects/effect.cpp index 289d22172..c4bbc31e1 100644 --- a/src/live_effects/effect.cpp +++ b/src/live_effects/effect.cpp @@ -422,6 +422,9 @@ Effect::registerKnotHolderHandle(KnotHolderEntity* entity, const char* descr) */ void Effect::addHandles(KnotHolder *knotholder, SPDesktop *desktop, SPItem *item) { + using namespace Inkscape::LivePathEffect; + + // add handles provided by the effect itself std::vector >::iterator i; for (i = kh_entity_vector.begin(); i != kh_entity_vector.end(); ++i) { KnotHolderEntity *entity = i->first; @@ -430,18 +433,10 @@ Effect::addHandles(KnotHolder *knotholder, SPDesktop *desktop, SPItem *item) { entity->create(desktop, item, knotholder, descr); knotholder->add(entity); } -} -void -Effect::addPointParamHandles(KnotHolder *knotholder, SPDesktop *desktop, SPItem *item) { - using namespace Inkscape::LivePathEffect; + // add handles provided by the effect's parameters (if any) for (std::vector::iterator p = param_vector.begin(); p != param_vector.end(); ++p) { - if ( Inkscape::LivePathEffect::PointParam *pparam = dynamic_cast(*p) ) { - KnotHolderEntity *e = dynamic_cast(*p); - e->create(desktop, item, knotholder, pparam->handleTip(), - pparam->knotShape(), pparam->knotMode(), pparam->knotColor()); - knotholder->add(e); - } + (*p)->addKnotHolderEntities(knotholder, desktop, item); } } @@ -612,6 +607,7 @@ Effect::transform_multiply(Geom::Matrix const& postmul, bool set) } } +// TODO: take _all_ parameters into account, not only PointParams bool Effect::providesKnotholder() { diff --git a/src/live_effects/parameter/parameter.h b/src/live_effects/parameter/parameter.h index 3b3b14673..02d520fe4 100644 --- a/src/live_effects/parameter/parameter.h +++ b/src/live_effects/parameter/parameter.h @@ -12,6 +12,7 @@ #include #include <2geom/forward.h> +class KnotHolder; struct SPDesktop; struct SPItem; @@ -56,6 +57,8 @@ public: virtual Glib::ustring * param_getTooltip() { return ¶m_tooltip; }; + virtual void addKnotHolderEntities(KnotHolder *knotholder, SPDesktop *desktop, SPItem *item) {} + virtual void param_editOncanvas(SPItem * /*item*/, SPDesktop * /*dt*/) {}; virtual void param_setup_nodepath(Inkscape::NodePath::Path */*np*/) {}; diff --git a/src/live_effects/parameter/point.cpp b/src/live_effects/parameter/point.cpp index 69e2520c2..7889bf164 100644 --- a/src/live_effects/parameter/point.cpp +++ b/src/live_effects/parameter/point.cpp @@ -152,23 +152,46 @@ PointParam::set_oncanvas_looks(SPKnotShapeType shape, SPKnotModeType mode, guint knot_color = color; } +class PointParamKnotHolderEntity : public KnotHolderEntity { +public: + PointParamKnotHolderEntity(PointParam *p) { this->pparam = p; } + virtual ~PointParamKnotHolderEntity() {} + + virtual void knot_set(NR::Point const &p, NR::Point const &origin, guint state); + virtual NR::Point knot_get(); + virtual void knot_click(guint state); + +private: + PointParam *pparam; +}; + void -PointParam::knot_set(NR::Point const &p, NR::Point const &/*origin*/, guint /*state*/) +PointParamKnotHolderEntity::knot_set(NR::Point const &p, NR::Point const &/*origin*/, guint /*state*/) { - param_setValue(p.to_2geom()); + pparam->param_setValue(p.to_2geom()); sp_lpe_item_update_patheffect(SP_LPE_ITEM(item), false, false); } NR::Point -PointParam::knot_get() +PointParamKnotHolderEntity::knot_get() +{ + return *pparam; +} + +void +PointParamKnotHolderEntity::knot_click(guint /*state*/) { - return *this; + g_print ("This is the handle associated to parameter '%s'\n", pparam->param_key.c_str()); } void -PointParam::knot_click(guint /*state*/) +PointParam::addKnotHolderEntities(KnotHolder *knotholder, SPDesktop *desktop, SPItem *item) { - g_print ("This is the handle associated to the parameter '%s'\n", param_key.c_str()); + PointParamKnotHolderEntity *e = new PointParamKnotHolderEntity(this); + // TODO: can we ditch handleTip() etc. because we have access to handle_tip etc. itself??? + e->create(desktop, item, knotholder, handleTip(), knotShape(), knotMode(), knotColor()); + knotholder->add(e); + } } /* namespace LivePathEffect */ diff --git a/src/live_effects/parameter/point.h b/src/live_effects/parameter/point.h index 90c318b5e..0334db7e0 100644 --- a/src/live_effects/parameter/point.h +++ b/src/live_effects/parameter/point.h @@ -23,7 +23,7 @@ namespace Inkscape { namespace LivePathEffect { -class PointParam : public Geom::Point, public Parameter, public KnotHolderEntity { +class PointParam : public Geom::Point, public Parameter { public: PointParam( const Glib::ustring& label, const Glib::ustring& tip, @@ -45,6 +45,7 @@ public: void param_set_and_write_new_value(Geom::Point newpoint); + // TODO: ditch this virtual void param_editOncanvas(SPItem * item, SPDesktop * dt); virtual void param_transform_multiply(Geom::Matrix const& /*postmul*/, bool /*set*/); @@ -54,11 +55,9 @@ public: SPKnotModeType knotMode() { return knot_mode; } guint32 knotColor() { return knot_color; } - /* these are overloaded from KnotHolderEntity */ - virtual void knot_set(NR::Point const &p, NR::Point const &origin, guint state); - virtual NR::Point knot_get(); - virtual void knot_click(guint state); + virtual void addKnotHolderEntities(KnotHolder *knotholder, SPDesktop *desktop, SPItem *item); + // TODO: ditch this! virtual bool isLPEParam() { return true; } private: diff --git a/src/object-edit.cpp b/src/object-edit.cpp index 9245166ca..52c5d42cc 100644 --- a/src/object-edit.cpp +++ b/src/object-edit.cpp @@ -56,7 +56,6 @@ static KnotHolder *sp_lpe_knot_holder(SPItem *item, SPDesktop *desktop) KnotHolder *knot_holder = new KnotHolder(desktop, item, NULL); Inkscape::LivePathEffect::Effect *effect = sp_lpe_item_get_current_lpe(SP_LPE_ITEM(item)); - effect->addPointParamHandles(knot_holder, desktop, item); effect->addHandles(knot_holder, desktop, item); return knot_holder;