Code

powerstroke: arbitrary number of control points.
authorJohan Engelen <goejendaagh@zonnet.nl>
Tue, 27 Jul 2010 19:56:51 +0000 (21:56 +0200)
committerJohan Engelen <goejendaagh@zonnet.nl>
Tue, 27 Jul 2010 19:56:51 +0000 (21:56 +0200)
src/live_effects/lpe-powerstroke.cpp
src/live_effects/lpe-powerstroke.h
src/live_effects/parameter/array.h
src/live_effects/parameter/powerstrokepointarray.cpp
src/live_effects/parameter/powerstrokepointarray.h

index b349f9aa6c5b0b1958fc50b23c0df4d7d446a234..da2b9d6a92c96a1b74fbbad1d7b68270e25243f1 100644 (file)
@@ -26,16 +26,10 @@ namespace LivePathEffect {
 
 LPEPowerStroke::LPEPowerStroke(LivePathEffectObject *lpeobject) :
     Effect(lpeobject),
-    offset_1(_("Start Offset"), _("Handle to control the distance of the offset from the curve"), "offset_1", &wr, this),
-    offset_2(_("End Offset"), _("Handle to control the distance of the offset from the curve"), "offset_2", &wr, this),
-    offset_3(_("End Offset"), _("Handle to control the distance of the offset from the curve"), "offset_3", &wr, this),
     offset_points(_("Offset points"), _("Offset points"), "offset_points", &wr, this)
 {
     show_orig_path = true;
 
-    registerParameter( dynamic_cast<Parameter *>(&offset_1) );
-    registerParameter( dynamic_cast<Parameter *>(&offset_2) );
-    registerParameter( dynamic_cast<Parameter *>(&offset_3) );
     registerParameter( dynamic_cast<Parameter *>(&offset_points) );
 }
 
@@ -48,9 +42,12 @@ LPEPowerStroke::~LPEPowerStroke()
 void
 LPEPowerStroke::doOnApply(SPLPEItem *lpeitem)
 {
-    offset_1.param_set_and_write_new_value(*(SP_SHAPE(lpeitem)->curve->first_point()));
-    offset_2.param_set_and_write_new_value(*(SP_SHAPE(lpeitem)->curve->last_point()));
-    offset_3.param_set_and_write_new_value(*(SP_SHAPE(lpeitem)->curve->last_point()));
+    std::vector<Geom::Point> points;
+    points.push_back( *(SP_SHAPE(lpeitem)->curve->first_point()) );
+    Geom::Path const *path = SP_SHAPE(lpeitem)->curve->first_path();
+    points.push_back( path->pointAt(path->size()/2) );
+    points.push_back( *(SP_SHAPE(lpeitem)->curve->last_point()) );
+    offset_points.param_set_and_write_new_value(points);
 }
 
 static void append_half_circle(Geom::Piecewise<Geom::D2<Geom::SBasis> > &pwd2,
@@ -68,38 +65,27 @@ LPEPowerStroke::doEffect_pwd2 (Geom::Piecewise<Geom::D2<Geom::SBasis> > const &
 {
     using namespace Geom;
 
-    double t1 = nearest_point(offset_1, pwd2_in);
-    double offset1 = L2(pwd2_in.valueAt(t1) - offset_1);
+    std::vector<Geom::Point> ts(offset_points.data().size());
 
-    double t2 = nearest_point(offset_2, pwd2_in);
-    double offset2 = L2(pwd2_in.valueAt(t2) - offset_2);
-
-    double t3 = nearest_point(offset_3, pwd2_in);
-    double offset3 = L2(pwd2_in.valueAt(t3) - offset_3);
-
-    /*
-    unsigned number_of_points = offset_points.data.size();
-    double* t = new double[number_of_points];
-    Point*  offset = new double[number_of_points];
-    for (unsigned i = 0; i < number_of_points; ++i) {
-        t[i] = nearest_point(offset_points.data[i], pwd2_in);
-        Point A = pwd2_in.valueAt(t[i]);
-        offset[i] = L2(A - offset_points.data[i]);
+    for (unsigned int i; i < ts.size(); ++i) {
+        double t = nearest_point(offset_points.data().at(i), pwd2_in);
+        double offset = L2(pwd2_in.valueAt(t) - offset_points.data().at(i));
+        ts.at(i) = Geom::Point(t, offset);
     }
-    */
 
     // create stroke path where points (x,y) = (t, offset)
     Path strokepath;
     strokepath.start( Point(pwd2_in.domain().min(),0) );
-    strokepath.appendNew<Geom::LineSegment>( Point(t1, offset1) );
-    strokepath.appendNew<Geom::LineSegment>( Point(t2, offset2) );
-    strokepath.appendNew<Geom::LineSegment>( Point(t3, offset3) );
+    for (unsigned int i = 0 ; i < ts.size(); ++i) {
+        strokepath.appendNew<Geom::LineSegment>(ts.at(i));
+    }
     strokepath.appendNew<Geom::LineSegment>( Point(pwd2_in.domain().max(), 0) );
-    strokepath.appendNew<Geom::LineSegment>( Point(t3, -offset3) );
-    strokepath.appendNew<Geom::LineSegment>( Point(t2, -offset2) );
-    strokepath.appendNew<Geom::LineSegment>( Point(t1, -offset1) );
+    for (unsigned int i = 0; i < ts.size(); ++i) {
+        Geom::Point temp = ts.at(ts.size() - 1 - i);
+        strokepath.appendNew<Geom::LineSegment>( Geom::Point(temp[X], - temp[Y]) );
+    }
     strokepath.close();
-    
+
     D2<Piecewise<SBasis> > patternd2 = make_cuts_independent(strokepath.toPwSb());
     Piecewise<SBasis> x = Piecewise<SBasis>(patternd2[0]);
     Piecewise<SBasis> y = Piecewise<SBasis>(patternd2[1]);
index 811c63259e345251a74988e61b06fa19461f0eb4..66b2ab89fcf351adde321603afa31318ab0f7b41 100644 (file)
@@ -29,9 +29,6 @@ public:
     virtual void doOnApply(SPLPEItem *lpeitem);
 
 private:
-    PointParam offset_1;
-    PointParam offset_2;
-    PointParam offset_3;
     PowerStrokePointArrayParam offset_points;
 
     LPEPowerStroke(const LPEPowerStroke&);
index e5f230111003d1d757311c6d0e6a45e20917f8fb..89c344594f6750863e6a02a66905ce4c5d9604da 100644 (file)
@@ -85,10 +85,7 @@ public:
         g_free(str);
     }
 
-private:
-    ArrayParam(const ArrayParam&);
-    ArrayParam& operator=(const ArrayParam&);
-
+protected:
     std::vector<StorageType> _vector;
     size_t _default_size;
 
@@ -103,6 +100,10 @@ private:
     }
 
     StorageType readsvg(const gchar * str);
+
+private:
+    ArrayParam(const ArrayParam&);
+    ArrayParam& operator=(const ArrayParam&);
 };
 
 
index 923266a94c7e9a9a3de9f2b3257350948efc71aa..49ef05319e22dcb9b7682ca323c3b00c62f3b1a1 100644 (file)
@@ -33,7 +33,7 @@ PowerStrokePointArrayParam::PowerStrokePointArrayParam( const Glib::ustring& lab
 {
     knot_shape = SP_KNOT_SHAPE_DIAMOND;
     knot_mode  = SP_KNOT_MODE_XOR;
-    knot_color = 0xffffff00;
+    knot_color = 0xff00ff00;
     handle_tip = g_strdup(htip);
 }
 
@@ -110,15 +110,16 @@ PowerStrokePointArrayParamKnotHolderEntity::PowerStrokePointArrayParamKnotHolder
 void
 PowerStrokePointArrayParamKnotHolderEntity::knot_set(Geom::Point const &p, Geom::Point const &/*origin*/, guint /*state*/)
 {
-//    Geom::Point const s = snap_knot_position(p);
-//    pparam->param_setValue(s);
-//    sp_lpe_item_update_patheffect(SP_LPE_ITEM(item), false, false);
+    Geom::Point const s = snap_knot_position(p);
+    _pparam->_vector.at(_index) = s;
+//    _pparam->param_set_and_write_new_value(_pparam->_vector);
+    sp_lpe_item_update_patheffect(SP_LPE_ITEM(item), false, false);
 }
 
 Geom::Point
 PowerStrokePointArrayParamKnotHolderEntity::knot_get()
 {
-    Geom::Point canvas_point;
+    Geom::Point canvas_point = _pparam->_vector.at(_index);
     return canvas_point;
 }
 
@@ -131,11 +132,11 @@ PowerStrokePointArrayParamKnotHolderEntity::knot_click(guint /*state*/)
 void
 PowerStrokePointArrayParam::addKnotHolderEntities(KnotHolder *knotholder, SPDesktop *desktop, SPItem *item)
 {
-    //PowerStrokePointArrayParamKnotHolderEntity *e = new PowerStrokePointArrayParamKnotHolderEntity(this);
-    // TODO: can we ditch handleTip() etc. because we have access to handle_tip etc. itself???
-    //e->create(desktop, item, knotholder, handleTip(), knot_shape, knot_mode, knot_color);
-    //knotholder->add(e);
-
+    for (unsigned int i = 0; i < _vector.size(); ++i) {
+        PowerStrokePointArrayParamKnotHolderEntity *e = new PowerStrokePointArrayParamKnotHolderEntity(this, i);
+        e->create(desktop, item, knotholder, handle_tip, knot_shape, knot_mode, knot_color);
+        knotholder->add(e);
+    }
 }
 
 } /* namespace LivePathEffect */
index 0a33c0369a14346bed3455752ccc7b7378b1f924..66eb3c9877fa78053e9e8e37c736fff0cdddde87 100644 (file)
@@ -22,6 +22,8 @@ namespace Inkscape {
 
 namespace LivePathEffect {
 
+class PowerStrokePointArrayParamKnotHolderEntity;
+
 class PowerStrokePointArrayParam : public ArrayParam<Geom::Point> {
 public:
     PowerStrokePointArrayParam( const Glib::ustring& label,
@@ -41,6 +43,8 @@ public:
     virtual bool providesKnotHolderEntities() { return true; }
     virtual void addKnotHolderEntities(KnotHolder *knotholder, SPDesktop *desktop, SPItem *item);
 
+    friend class PowerStrokePointArrayParamKnotHolderEntity;
+
 private:
     PowerStrokePointArrayParam(const PowerStrokePointArrayParam&);
     PowerStrokePointArrayParam& operator=(const PowerStrokePointArrayParam&);