diff options
| author | Denis Declara <declara91@gmail.com> | 2012-04-15 12:29:45 +0000 |
|---|---|---|
| committer | Denis Declara <declara91@gmail.com> | 2012-04-15 12:29:45 +0000 |
| commit | 6b5ff661a46ea1779c86f6947006c5ed32926117 (patch) | |
| tree | a5b170f0830854e99ad065055ee2a3996933e614 /src/live_effects/lpe-angle_bisector.cpp | |
| parent | Improved User interface. (diff) | |
| parent | i18n. Fix for Bug #980518 (Please use c-format). (diff) | |
| download | inkscape-6b5ff661a46ea1779c86f6947006c5ed32926117.tar.gz inkscape-6b5ff661a46ea1779c86f6947006c5ed32926117.zip | |
Trunk merge
(bzr r11073.1.15)
Diffstat (limited to 'src/live_effects/lpe-angle_bisector.cpp')
| -rw-r--r-- | src/live_effects/lpe-angle_bisector.cpp | 72 |
1 files changed, 34 insertions, 38 deletions
diff --git a/src/live_effects/lpe-angle_bisector.cpp b/src/live_effects/lpe-angle_bisector.cpp index aee4f48a1..99110c51e 100644 --- a/src/live_effects/lpe-angle_bisector.cpp +++ b/src/live_effects/lpe-angle_bisector.cpp @@ -1,47 +1,38 @@ #define INKSCAPE_LPE_ANGLE_BISECTOR_CPP -/** \file - * LPE <angle_bisector> implementation, used as an example for a base starting class - * when implementing new LivePathEffects. - * - * In vi, three global search-and-replaces will let you rename everything - * in this and the .h file: - * - * :%s/ANGLE_BISECTOR/YOURNAME/g - * :%s/AngleBisector/Yourname/g - * :%s/angle_bisector/yourname/g - */ /* * Authors: - * Johan Engelen + * Maximilian Albert <maximilian.albert@gmail.com> + * Johan Engelen <j.b.c.engelen@alumnus.utwente.nl> * - * Copyright (C) Johan Engelen 2007 <j.b.c.engelen@utwente.nl> + * Copyright (C) Authors 2007-2012 * * Released under GNU GPL, read the file 'COPYING' for more information */ #include "live_effects/lpe-angle_bisector.h" -// You might need to include other 2geom files. You can add them here: #include <2geom/path.h> #include <2geom/sbasis-to-bezier.h> #include "sp-lpe-item.h" +#include "knot-holder-entity.h" +#include "knotholder.h" namespace Inkscape { namespace LivePathEffect { namespace AB { -class KnotHolderEntityLeftEnd : public LPEKnotHolderEntity -{ +class KnotHolderEntityLeftEnd : public LPEKnotHolderEntity { public: + KnotHolderEntityLeftEnd(LPEAngleBisector* 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(LPEAngleBisector* effect) : LPEKnotHolderEntity(effect) {}; virtual void knot_set(Geom::Point const &p, Geom::Point const &origin, guint state); virtual Geom::Point knot_get(); }; @@ -54,12 +45,10 @@ LPEAngleBisector::LPEAngleBisector(LivePathEffectObject *lpeobject) : length_right(_("Length right"), _("Specifies the right end of the bisector"), "length-right", &wr, this, 250) { show_orig_path = true; + _provides_knotholder_entities = true; registerParameter( dynamic_cast<Parameter *>(&length_left) ); registerParameter( dynamic_cast<Parameter *>(&length_right) ); - - registerKnotHolderHandle(new AB::KnotHolderEntityLeftEnd(), _("Adjust the \"left\" end of the bisector")); - registerKnotHolderHandle(new AB::KnotHolderEntityRightEnd(), _("Adjust the \"right\" of the bisector")); } LPEAngleBisector::~LPEAngleBisector() @@ -89,25 +78,32 @@ LPEAngleBisector::doEffect_path (std::vector<Geom::Path> const & path_in) return path_from_piecewise(output, LPE_CONVERSION_TOLERANCE); } -namespace AB { -// TODO: make this more generic -static LPEAngleBisector * -get_effect(SPItem *item) -{ - Effect *effect = sp_lpe_item_get_current_lpe(SP_LPE_ITEM(item)); - if (effect->effectType() != ANGLE_BISECTOR) { - g_print ("Warning: Effect is not of type LPEAngleBisector!\n"); - return NULL; +void +LPEAngleBisector::addKnotHolderEntities(KnotHolder *knotholder, SPDesktop *desktop, SPItem *item) { + { + KnotHolderEntity *e = new AB::KnotHolderEntityLeftEnd(this); + e->create( desktop, item, knotholder, + _("Adjust the \"left\" end of the bisector") + /*optional: knot_shape, knot_mode, knot_color*/); + knotholder->add(e); } - return static_cast<LPEAngleBisector *>(effect); -} + { + KnotHolderEntity *e = new AB::KnotHolderEntityRightEnd(this); + e->create( desktop, item, knotholder, + _("Adjust the \"right\" of the bisector") + /*optional: knot_shape, knot_mode, knot_color*/); + knotholder->add(e); + } +}; + +namespace AB { void KnotHolderEntityLeftEnd::knot_set(Geom::Point const &p, Geom::Point const &/*origin*/, guint /*state*/) { - LPEAngleBisector *lpe = get_effect(item); - + LPEAngleBisector *lpe = dynamic_cast<LPEAngleBisector *>(_effect); + Geom::Point const s = snap_knot_position(p); double lambda = Geom::nearest_point(s, lpe->ptA, lpe->dir); @@ -119,8 +115,8 @@ KnotHolderEntityLeftEnd::knot_set(Geom::Point const &p, Geom::Point const &/*ori void KnotHolderEntityRightEnd::knot_set(Geom::Point const &p, Geom::Point const &/*origin*/, guint /*state*/) { - LPEAngleBisector *lpe = get_effect(item); - + LPEAngleBisector *lpe = dynamic_cast<LPEAngleBisector *>(_effect); + Geom::Point const s = snap_knot_position(p); double lambda = Geom::nearest_point(s, lpe->ptA, lpe->dir); @@ -132,14 +128,14 @@ KnotHolderEntityRightEnd::knot_set(Geom::Point const &p, Geom::Point const &/*or Geom::Point KnotHolderEntityLeftEnd::knot_get() { - LPEAngleBisector *lpe = get_effect(item); + LPEAngleBisector *lpe = dynamic_cast<LPEAngleBisector *>(_effect); return lpe->ptA - lpe->dir * lpe->length_left; } Geom::Point KnotHolderEntityRightEnd::knot_get() { - LPEAngleBisector *lpe = get_effect(item); + LPEAngleBisector *lpe = dynamic_cast<LPEAngleBisector *>(_effect); return lpe->ptA + lpe->dir * lpe->length_right; } |
