From 36285e420d3124dfe8cd2c5a8ac5a76bf7cdd4c6 Mon Sep 17 00:00:00 2001 From: cilix42 Date: Wed, 2 Jul 2008 16:52:42 +0000 Subject: [PATCH] Handle for PerspectivePath LPE to adjust offset (not ideal yet but better than entering values by hand) --- src/live_effects/lpe-perspective_path.cpp | 58 +++++++++++++++++++++-- src/live_effects/lpe-perspective_path.h | 11 +++++ 2 files changed, 64 insertions(+), 5 deletions(-) diff --git a/src/live_effects/lpe-perspective_path.cpp b/src/live_effects/lpe-perspective_path.cpp index 9e7b5d8ea..785d7a245 100644 --- a/src/live_effects/lpe-perspective_path.cpp +++ b/src/live_effects/lpe-perspective_path.cpp @@ -30,12 +30,24 @@ #include "inkscape.h" -// You might need to include other 2geom files. You can add them here: #include <2geom/path.h> namespace Inkscape { namespace LivePathEffect { +namespace PP { + +class KnotHolderEntityOffset : public KnotHolderEntity +{ +public: + virtual bool isLPEParam() { return true; } + + virtual void knot_set(NR::Point const &p, NR::Point const &origin, guint state); + virtual NR::Point knot_get(); +}; + +} // namespace PP + LPEPerspectivePath::LPEPerspectivePath(LivePathEffectObject *lpeobject) : Effect(lpeobject), // initialise your parameters here: @@ -52,6 +64,8 @@ LPEPerspectivePath::LPEPerspectivePath(LivePathEffectObject *lpeobject) : registerParameter( dynamic_cast(&offsety) ); registerParameter( dynamic_cast(&uses_plane_xy) ); + registerKnotHolderHandle(new PP::KnotHolderEntityOffset(), _("Adjust the origin")); + concatenate_before_pwd2 = true; // don't split the path into its subpaths Persp3D *persp = persp3d_document_first_persp(inkscape_active_document()); @@ -86,14 +100,13 @@ LPEPerspectivePath::doEffect_pwd2 (Geom::Piecewise > cons D2 > B = make_cuts_independant(path_a_pw); Piecewise preimage[4]; - Geom::Point orig = Geom::Point(uses_plane_xy ? boundingbox_X.max() : boundingbox_X.min(), - boundingbox_Y.middle()); - //Geom::Point orig = Geom::Point(bounds_X.min(), bounds_Y.middle()); //orig = Geom::Point(orig[X], sp_document_height(inkscape_active_document()) - orig[Y]); //double offset = uses_plane_xy ? boundingbox_X.extent() : 0.0; + orig = Point(uses_plane_xy ? boundingbox_X.max() : boundingbox_X.min(), boundingbox_Y.middle()); + /** g_print ("Orig: (%8.2f, %8.2f)\n", orig[X], orig[Y]); @@ -136,7 +149,42 @@ LPEPerspectivePath::doEffect_pwd2 (Geom::Piecewise > cons return output; } -/* ######################## */ +namespace PP { + +// TODO: make this more generic +static LPEPerspectivePath * +get_effect(SPItem *item) +{ + Effect *effect = sp_lpe_item_get_current_lpe(SP_LPE_ITEM(item)); + if (effect->effectType() != PERSPECTIVE_PATH) { + g_print ("Warning: Effect is not of type LPEPerspectivePath!\n"); + return NULL; + } + return static_cast(effect); +} + +void +KnotHolderEntityOffset::knot_set(NR::Point const &p, NR::Point const &origin, guint /*state*/) +{ + using namespace Geom; + + LPEPerspectivePath* lpe = get_effect(item); + + lpe->offsetx.param_set_value((p - origin)[NR::X]); + lpe->offsety.param_set_value(-(p - origin)[NR::Y]); // additional minus sign is due to coordinate system flipping + + // FIXME: this should not directly ask for updating the item. It should write to SVG, which triggers updating. + sp_lpe_item_update_patheffect (SP_LPE_ITEM(item), false, true); +} + +NR::Point +KnotHolderEntityOffset::knot_get() +{ + LPEPerspectivePath* lpe = get_effect(item); + return lpe->orig + Geom::Point(lpe->offsetx, -lpe->offsety); +} + +} // namespace PP } //namespace LivePathEffect } /* namespace Inkscape */ diff --git a/src/live_effects/lpe-perspective_path.h b/src/live_effects/lpe-perspective_path.h index 02dcf2325..62589e875 100644 --- a/src/live_effects/lpe-perspective_path.h +++ b/src/live_effects/lpe-perspective_path.h @@ -25,6 +25,11 @@ namespace Inkscape { namespace LivePathEffect { +namespace PP { + // we need a separate namespace to avoid clashes with other LPEs + class KnotHolderEntityOffset; +} + class LPEPerspectivePath : public Effect, GroupBBoxEffect { public: LPEPerspectivePath(LivePathEffectObject *lpeobject); @@ -34,15 +39,21 @@ public: virtual Geom::Piecewise > doEffect_pwd2 (Geom::Piecewise > const & pwd2_in); + /* the knotholder entity classes must be declared friends */ + friend class PP::KnotHolderEntityOffset; + private: // add the parameters for your effect here: ScalarParam scalex; ScalarParam scaley; + // TODO: rewrite this using a PointParam instead of two ScalarParams ScalarParam offsetx; ScalarParam offsety; BoolParam uses_plane_xy; // there are all kinds of parameters. Check the /live_effects/parameter directory which types exist! + Geom::Point orig; + LPEPerspectivePath(const LPEPerspectivePath&); LPEPerspectivePath& operator=(const LPEPerspectivePath&); -- 2.30.2