Code

Merge from trunk.
[inkscape.git] / src / live_effects / lpe-perspective_path.cpp
index 9aa26e05d0097e08714aea16ca5cd9bdfcdee308..58efe4ef51f7822b3229a667f30a6ef5e01905e2 100644 (file)
@@ -1,22 +1,11 @@
-#define INKSCAPE_LPE_PERSPECTIVE_PATH_CPP
-/** \file
- * LPE <perspective_path> 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/PERSPECTIVE_PATH/YOURNAME/g
- *   :%s/PerspectivePath/Yourname/g
- *   :%s/perspective_path/yourname/g
+/** @file
+ * @brief LPE perspective path effect implementation.
  */
-/*
- * Authors:
- *   Johan Engelen
- *   Maximilian Albert
+/* Authors:
+ *   Maximilian Albert <maximilian.albert@gmail.com>
+ *   Johan Engelen <j.b.c.engelen@utwente.nl>
  *
- * Copyright (C) Johan Engelen 2007 <j.b.c.engelen@utwente.nl>
- * Copyright (C) Maximilian Albert 2008 <maximilian.albert@gmail.com>
+ * Copyright (C) 2007-2008 Authors
  *
  * Released under GNU GPL, read the file 'COPYING' for more information
  */
@@ -27,6 +16,7 @@
 
 #include "live_effects/lpe-perspective_path.h"
 #include "sp-item-group.h"
+#include "knot-holder-entity.h"
 
 #include "inkscape.h"
 
@@ -37,13 +27,11 @@ namespace LivePathEffect {
 
 namespace PP {
 
-class KnotHolderEntityOffset : public KnotHolderEntity
+class KnotHolderEntityOffset : public LPEKnotHolderEntity
 {
 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();
+    virtual void knot_set(Geom::Point const &p, Geom::Point const &origin, guint state);
+    virtual Geom::Point knot_get();
 };
 
 } // namespace PP
@@ -70,7 +58,7 @@ LPEPerspectivePath::LPEPerspectivePath(LivePathEffectObject *lpeobject) :
 
     Persp3D *persp = persp3d_document_first_persp(inkscape_active_document());
 
-    Proj::TransfMat3x4 pmat = persp->tmat;
+    Proj::TransfMat3x4 pmat = persp->perspective_impl->tmat;
 
     pmat.copy_tmat(tmat);
 }
@@ -164,20 +152,22 @@ get_effect(SPItem *item)
 }
 
 void
-KnotHolderEntityOffset::knot_set(NR::Point const &p, NR::Point const &origin, guint /*state*/)
+KnotHolderEntityOffset::knot_set(Geom::Point const &p, Geom::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
+    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);
 }
 
-NR::Point
+Geom::Point
 KnotHolderEntityOffset::knot_get()
 {
     LPEPerspectivePath* lpe = get_effect(item);
@@ -198,4 +188,4 @@ KnotHolderEntityOffset::knot_get()
   fill-column:99
   End:
 */
-// vim: filetype=cpp:expandtab:shiftwidth=4:tabstop=8:softtabstop=4 :
+// vim: filetype=cpp:expandtab:shiftwidth=4:tabstop=8:softtabstop=4:fileencoding=utf-8:textwidth=99 :