diff options
| author | Maximilian Albert <maximilian.albert@gmail.com> | 2008-07-02 16:52:42 +0000 |
|---|---|---|
| committer | cilix42 <cilix42@users.sourceforge.net> | 2008-07-02 16:52:42 +0000 |
| commit | 7443d7f6edeac04237e8e4bd574493601948751d (patch) | |
| tree | 18d1ea1c97c3c38dabcdd554dbfaee10aaf15096 /src/live_effects/lpe-perspective_path.cpp | |
| parent | Remove now obsolete 'edit on canvas' button for PointParams (diff) | |
| download | inkscape-7443d7f6edeac04237e8e4bd574493601948751d.tar.gz inkscape-7443d7f6edeac04237e8e4bd574493601948751d.zip | |
Handle for PerspectivePath LPE to adjust offset (not ideal yet but better than entering values by hand)
(bzr r6120)
Diffstat (limited to 'src/live_effects/lpe-perspective_path.cpp')
| -rw-r--r-- | src/live_effects/lpe-perspective_path.cpp | 58 |
1 files changed, 53 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<Parameter *>(&offsety) ); registerParameter( dynamic_cast<Parameter *>(&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<Geom::D2<Geom::SBasis> > cons D2<Piecewise<SBasis> > B = make_cuts_independant(path_a_pw); Piecewise<SBasis> 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<Geom::D2<Geom::SBasis> > 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<LPEPerspectivePath *>(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 */ |
