summary | shortlog | log | commit | commitdiff | tree
raw | patch | inline | side by side (parent: 04d3bcf)
raw | patch | inline | side by side (parent: 04d3bcf)
author | cilix42 <cilix42@users.sourceforge.net> | |
Wed, 2 Jul 2008 16:52:42 +0000 (16:52 +0000) | ||
committer | cilix42 <cilix42@users.sourceforge.net> | |
Wed, 2 Jul 2008 16:52:42 +0000 (16:52 +0000) |
src/live_effects/lpe-perspective_path.cpp | patch | blob | history | |
src/live_effects/lpe-perspective_path.h | patch | blob | history |
index 9e7b5d8ea799d0ef5031a8c890919de90bd19987..785d7a245ccdbbf473cbc4028500adc2418864c1 100644 (file)
#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:
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 */
index 02dcf23258b1156fc1884bb28c02bd203f4054b2..62589e8756a6344506b211c639d3f6a4e9f7f76c 100644 (file)
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);
virtual Geom::Piecewise<Geom::D2<Geom::SBasis> > doEffect_pwd2 (Geom::Piecewise<Geom::D2<Geom::SBasis> > 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&);