summaryrefslogtreecommitdiffstats
path: root/src/live_effects/lpe-parallel.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'src/live_effects/lpe-parallel.cpp')
-rw-r--r--src/live_effects/lpe-parallel.cpp59
1 files changed, 33 insertions, 26 deletions
diff --git a/src/live_effects/lpe-parallel.cpp b/src/live_effects/lpe-parallel.cpp
index 5b373442b..4d15bf13e 100644
--- a/src/live_effects/lpe-parallel.cpp
+++ b/src/live_effects/lpe-parallel.cpp
@@ -6,7 +6,7 @@
* Authors:
* Maximilian Albert
*
- * Copyright (C) Johan Engelen 2007 <j.b.c.engelen@utwente.nl>
+ * Copyright (C) Johan Engelen 2007-2012 <j.b.c.engelen@alumnus.utwente.nl>
* Copyright (C) Maximilian Albert 2008 <maximilian.albert@gmail.com>
*
* Released under GNU GPL, read the file 'COPYING' for more information
@@ -19,21 +19,24 @@
#include <2geom/path.h>
#include <2geom/transforms.h>
+#include "knot-holder-entity.h"
+#include "knotholder.h"
+
namespace Inkscape {
namespace LivePathEffect {
namespace Pl {
-class KnotHolderEntityLeftEnd : public LPEKnotHolderEntity
-{
+class KnotHolderEntityLeftEnd : public LPEKnotHolderEntity {
public:
+ KnotHolderEntityLeftEnd(LPEParallel *effect) : LPEKnotHolderEntity(effect) {};
virtual void knot_set(Geom::Point const &p, Geom::Point const &origin, guint state);
virtual Geom::Point knot_get();
};
-class KnotHolderEntityRightEnd : public LPEKnotHolderEntity
-{
+class KnotHolderEntityRightEnd : public LPEKnotHolderEntity {
public:
+ KnotHolderEntityRightEnd(LPEParallel *effect) : LPEKnotHolderEntity(effect) {};
virtual void knot_set(Geom::Point const &p, Geom::Point const &origin, guint state);
virtual Geom::Point knot_get();
};
@@ -48,13 +51,11 @@ LPEParallel::LPEParallel(LivePathEffectObject *lpeobject) :
length_right(_("Length right"), _("Specifies the right end of the parallel"), "length-right", &wr, this, 150)
{
show_orig_path = true;
+ _provides_knotholder_entities = true;
registerParameter(dynamic_cast<Parameter *>(&offset_pt));
registerParameter( dynamic_cast<Parameter *>(&length_left) );
registerParameter( dynamic_cast<Parameter *>(&length_right) );
-
- registerKnotHolderHandle(new Pl::KnotHolderEntityLeftEnd(), _("Adjust the \"left\" end of the parallel"));
- registerKnotHolderHandle(new Pl::KnotHolderEntityRightEnd(), _("Adjust the \"right\" end of the parallel"));
}
LPEParallel::~LPEParallel()
@@ -93,27 +94,33 @@ LPEParallel::doEffect_pwd2 (Geom::Piecewise<Geom::D2<Geom::SBasis> > const & pwd
return output + dir;
}
-namespace Pl {
-
-// TODO: make this more generic
-static LPEParallel *
-get_effect(SPItem *item)
-{
- Effect *effect = sp_lpe_item_get_current_lpe(SP_LPE_ITEM(item));
- if (effect->effectType() != PARALLEL) {
- g_print ("Warning: Effect is not of type LPEParallel!\n");
- return NULL;
+void
+LPEParallel::addKnotHolderEntities(KnotHolder *knotholder, SPDesktop *desktop, SPItem *item) {
+ {
+ KnotHolderEntity *e = new Pl::KnotHolderEntityLeftEnd(this);
+ e->create( desktop, item, knotholder,
+ _("Adjust the \"left\" end of the parallel")
+ /*optional: knot_shape, knot_mode, knot_color*/);
+ knotholder->add(e);
}
- return static_cast<LPEParallel *>(effect);
-}
+ {
+ KnotHolderEntity *e = new Pl::KnotHolderEntityRightEnd(this);
+ e->create( desktop, item, knotholder,
+ _("Adjust the \"right\" end of the parallel")
+ /*optional: knot_shape, knot_mode, knot_color*/);
+ knotholder->add(e);
+ }
+};
+
+namespace Pl {
void
KnotHolderEntityLeftEnd::knot_set(Geom::Point const &p, Geom::Point const &/*origin*/, guint /*state*/)
{
using namespace Geom;
- LPEParallel *lpe = get_effect(item);
-
+ LPEParallel *lpe = dynamic_cast<LPEParallel *>(_effect);
+
Geom::Point const s = snap_knot_position(p);
double lambda = L2(s - lpe->offset_pt) * sgn(dot(s - lpe->offset_pt, lpe->dir));
@@ -127,8 +134,8 @@ KnotHolderEntityRightEnd::knot_set(Geom::Point const &p, Geom::Point const &/*or
{
using namespace Geom;
- LPEParallel *lpe = get_effect(item);
-
+ LPEParallel *lpe = dynamic_cast<LPEParallel *>(_effect);
+
Geom::Point const s = snap_knot_position(p);
double lambda = L2(s - lpe->offset_pt) * sgn(dot(s - lpe->offset_pt, lpe->dir));
@@ -140,14 +147,14 @@ KnotHolderEntityRightEnd::knot_set(Geom::Point const &p, Geom::Point const &/*or
Geom::Point
KnotHolderEntityLeftEnd::knot_get()
{
- LPEParallel *lpe = get_effect(item);
+ LPEParallel *lpe = dynamic_cast<LPEParallel *>(_effect);
return lpe->C;
}
Geom::Point
KnotHolderEntityRightEnd::knot_get()
{
- LPEParallel *lpe = get_effect(item);
+ LPEParallel *lpe = dynamic_cast<LPEParallel *>(_effect);
return lpe->D;
}