Code

Better way to add LPE knotholder handles; now it happens semi-automatically in a...
authorcilix42 <cilix42@users.sourceforge.net>
Sun, 8 Jun 2008 17:56:04 +0000 (17:56 +0000)
committercilix42 <cilix42@users.sourceforge.net>
Sun, 8 Jun 2008 17:56:04 +0000 (17:56 +0000)
src/live_effects/effect.cpp
src/live_effects/effect.h
src/live_effects/lpe-perp_bisector.cpp
src/live_effects/lpe-tangent_to_curve.cpp
src/live_effects/lpe-tangent_to_curve.h
src/object-edit.cpp

index db395c81b51c6b7684f49d965cffa99d21f13396..b08077e795050b11275748281085bdbdcff4f638 100644 (file)
@@ -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<std::pair<KnotHolderEntity*, const char*> >::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
  */
index c46c145b58afcf8c6455104f2f0c1f10f09c13c0..a990a858d2afaeb6fe42d93fc61940056c18e578 100644 (file)
@@ -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<Geom::D2<Geom::SBasis> > 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<Parameter *> param_vector;
+    std::vector<std::pair<KnotHolderEntity*, const char*> > 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 :
index 39423df8b6a6fec4ec838c3add1f0fb4cf89642a..139ca21bf5e9d30c0d8178026786aa34a1792db6 100644 (file)
@@ -138,10 +138,12 @@ LPEPerpBisector::LPEPerpBisector(LivePathEffectObject *lpeobject) :
     registerParameter( dynamic_cast<Parameter *>(&length_left) );
     registerParameter( dynamic_cast<Parameter *>(&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()
index b61a078a4562cc4e24e60847b99fe7b34cb191b7..02d34f31204e5862c65d0468e2b5027bb8d90e58 100644 (file)
 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<Parameter *>(&t_attach) );
     registerParameter( dynamic_cast<Parameter *>(&length_left) );
     registerParameter( dynamic_cast<Parameter *>(&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<Geom::D2<Geom::SBasis> > 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)
 {
index 0de2baf5624834b11fa5e717bbb5b56fcfcfee46..678c32c3696130dbf5cbb21108c44c9606b828cb 100644 (file)
@@ -29,7 +29,6 @@ public:
     virtual ~LPETangentToCurve();
 
     bool providesKnotholder() { return true; }
-    virtual void addKnotHolderHandles(KnotHolder *knotholder, SPDesktop *desktop, SPItem *item);
 
     virtual Geom::Piecewise<Geom::D2<Geom::SBasis> >
       doEffect_pwd2 (Geom::Piecewise<Geom::D2<Geom::SBasis> > const & pwd2_in);
index 8d8be4b85752a073d3fa0107f6d871d8d19881d1..de7fbccec296adbf4f77a4d20396234ac6b8a230 100644 (file)
@@ -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;
 }