X-Git-Url: https://git.tokkee.org/?a=blobdiff_plain;f=src%2Flive_effects%2Flpe-perspective_path.cpp;h=2eef0cd5b21b5cecb855150ec4424ae363865667;hb=a9b9dd25c265c8a187f7ae93f946d829e04271a5;hp=cf6d1cecd91ce583f588ed013239abd98d840196;hpb=0563fd55cbad59e8a878e6d4cbbdd8e47f74488d;p=inkscape.git diff --git a/src/live_effects/lpe-perspective_path.cpp b/src/live_effects/lpe-perspective_path.cpp index cf6d1cecd..2eef0cd5b 100644 --- a/src/live_effects/lpe-perspective_path.cpp +++ b/src/live_effects/lpe-perspective_path.cpp @@ -30,12 +30,22 @@ #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 LPEKnotHolderEntity +{ +public: + virtual void knot_set(Geom::Point const &p, Geom::Point const &origin, guint state); + virtual Geom::Point knot_get(); +}; + +} // namespace PP + LPEPerspectivePath::LPEPerspectivePath(LivePathEffectObject *lpeobject) : Effect(lpeobject), // initialise your parameters here: @@ -52,6 +62,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()); @@ -69,7 +81,7 @@ LPEPerspectivePath::~LPEPerspectivePath() void LPEPerspectivePath::doBeforeEffect (SPLPEItem *lpeitem) { - original_bbox(lpeitem, true); + original_bbox(lpeitem, true); } Geom::Piecewise > @@ -83,17 +95,16 @@ LPEPerspectivePath::doEffect_pwd2 (Geom::Piecewise > cons // remove this once we have unified coordinate systems path_a_pw = path_a_pw + Geom::Point(offsetx, -offsety); - D2 > B = make_cuts_independant(path_a_pw); + D2 > B = make_cuts_independent(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]); @@ -128,7 +139,7 @@ LPEPerspectivePath::doEffect_pwd2 (Geom::Piecewise > cons + preimage[2] * tmat[j][2] + tmat[j][3]; } - D2 > result(divide(res[0],res[2], 3), + D2 > result(divide(res[0],res[2], 3), divide(res[1],res[2], 3)); Piecewise > output = sectionize(result); @@ -136,7 +147,44 @@ 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(Geom::Point const &p, Geom::Point const &origin, guint /*state*/) +{ + using namespace Geom; + + LPEPerspectivePath* lpe = get_effect(item); + + Geom::Point const s = snap_knot_position(p); + + lpe->offsetx.param_set_value((s - origin)[Geom::X]); + lpe->offsety.param_set_value(-(s - origin)[Geom::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); +} + +Geom::Point +KnotHolderEntityOffset::knot_get() +{ + LPEPerspectivePath* lpe = get_effect(item); + return lpe->orig + Geom::Point(lpe->offsetx, -lpe->offsety); +} + +} // namespace PP } //namespace LivePathEffect } /* namespace Inkscape */