diff options
| author | Johan B. C. Engelen <jbc.engelen@swissonline.ch> | 2012-04-07 14:09:58 +0000 |
|---|---|---|
| committer | Johan B. C. Engelen <j.b.c.engelen@alumnus.utwente.nl> | 2012-04-07 14:09:58 +0000 |
| commit | 7867b2ae755a4217c14365e3b1b18484ba98712b (patch) | |
| tree | b5ee8094b54c44d0357bcada0699d06726739aa0 /src/live_effects/lpe-parallel.cpp | |
| parent | powerstrokepointarray : add todo comment. do not derive from LPEKnotHolderEnt... (diff) | |
| download | inkscape-7867b2ae755a4217c14365e3b1b18484ba98712b.tar.gz inkscape-7867b2ae755a4217c14365e3b1b18484ba98712b.zip | |
cleanup knotholder code for LPEs
(bzr r11170)
Diffstat (limited to 'src/live_effects/lpe-parallel.cpp')
| -rw-r--r-- | src/live_effects/lpe-parallel.cpp | 59 |
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; } |
