From 7867b2ae755a4217c14365e3b1b18484ba98712b Mon Sep 17 00:00:00 2001 From: "Johan B. C. Engelen" Date: Sat, 7 Apr 2012 16:09:58 +0200 Subject: cleanup knotholder code for LPEs (bzr r11170) --- src/live_effects/lpe-parallel.cpp | 59 ++++++++++++++++++++++----------------- 1 file changed, 33 insertions(+), 26 deletions(-) (limited to 'src/live_effects/lpe-parallel.cpp') 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 + * Copyright (C) Johan Engelen 2007-2012 * Copyright (C) Maximilian Albert 2008 * * 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(&offset_pt)); registerParameter( dynamic_cast(&length_left) ); registerParameter( dynamic_cast(&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 > 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(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(_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(_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(_effect); return lpe->C; } Geom::Point KnotHolderEntityRightEnd::knot_get() { - LPEParallel *lpe = get_effect(item); + LPEParallel *lpe = dynamic_cast(_effect); return lpe->D; } -- cgit v1.2.3