Code

Merge and cleanup of GSoC C++-ification project.
[inkscape.git] / src / knot-holder-entity.h
index f0862c87483ccf44958ddc8b068f71ff4165013f..bd654616c59e775a32451cfdc0b6c0dd9667641d 100644 (file)
@@ -1,9 +1,9 @@
 #ifndef SEEN_KNOT_HOLDER_ENTITY_H
 #define SEEN_KNOT_HOLDER_ENTITY_H
 
-/** \file 
- * KnotHolderEntity definition. 
- * 
+/** \file
+ * KnotHolderEntity definition.
+ *
  * Authors:
  *   Mitsuru Oka <oka326@parkcity.ne.jp>
  *   Maximilian Albert <maximilian.albert@gmail.com>
 
 #include <glib/gtypes.h>
 #include "knot.h"
+#include <2geom/forward.h>
+#include "snapper.h"
 
 struct SPItem;
 struct SPKnot;
-namespace NR {
-class Point;
-}
 
 class SPDesktop;
 class KnotHolder;
 
-typedef void (* SPKnotHolderSetFunc) (SPItem *item, NR::Point const &p, NR::Point const &origin, guint state);
-typedef NR::Point (* SPKnotHolderGetFunc) (SPItem *item);
+typedef void (* SPKnotHolderSetFunc) (SPItem *item, Geom::Point const &p, Geom::Point const &origin, guint state);
+typedef Geom::Point (* SPKnotHolderGetFunc) (SPItem *item);
 /* fixme: Think how to make callbacks most sensitive (Lauris) */
 typedef void (* SPKnotHolderReleasedFunc) (SPItem *item);
 
@@ -38,28 +37,32 @@ class KnotHolderEntity {
 public:
     KnotHolderEntity() {}
     virtual ~KnotHolderEntity();
-    virtual void create(SPDesktop *desktop, SPItem *item, KnotHolder *parent, const gchar *tip = "", 
+    virtual void create(SPDesktop *desktop, SPItem *item, KnotHolder *parent, const gchar *tip = "",
                         SPKnotShapeType shape = SP_KNOT_SHAPE_DIAMOND,
                         SPKnotModeType mode = SP_KNOT_MODE_XOR,
                         guint32 color = 0xffffff00);
 
-    /* derived classes like PointParam for LPEs use this, e.g., to indicate that we must not call
-       delete on their pointer when a knotholder is destroyed */
-    virtual bool isLPEParam() { return false; }
+    /* derived classes used for LPE knotholder handles use this to indicate that they
+       must not be deleted when a knotholder is destroyed */
+    // TODO: it would be nice to ditch this but then we need to dynamically create instances of different
+    //       KnotHolderEntity classes in Effect::addKnotHolderEntities. How to do this???
+    virtual bool isDeletable() { return true; }
 
     /* the get/set/click handlers are virtual functions; each handler class for a knot
        should be derived from KnotHolderEntity and override these functions */
-    virtual void knot_set(NR::Point const &p, NR::Point const &origin, guint state) = 0;
-    virtual NR::Point knot_get() = 0;
+    virtual void knot_set(Geom::Point const &p, Geom::Point const &origin, guint state) = 0;
+    virtual Geom::Point knot_get() = 0;
     virtual void knot_click(guint /*state*/) {}
-    virtual void onKnotUngrabbed() {} // this is called 'manually' from KnotHolder; would it be
-                                      // more efficient to establish another signal connection?
 
     void update_knot();
 
 //private:
+    Geom::Point snap_knot_position(Geom::Point const &p);
+    Geom::Point snap_knot_position_constrained(Geom::Point const &p, Inkscape::Snapper::SnapConstraint const &constraint);
+
     SPKnot *knot;
     SPItem *item;
+    SPDesktop *desktop;
 
     KnotHolder *parent_holder;
 
@@ -78,24 +81,29 @@ public:
     sigc::connection _ungrabbed_connection;
 };
 
+// derived KnotHolderEntity class for LPEs
+class LPEKnotHolderEntity : public KnotHolderEntity {
+    virtual bool isDeletable() { return false; }
+};
+
 /* pattern manipulation */
 
 class PatternKnotHolderEntityXY : public KnotHolderEntity {
 public:
-    virtual NR::Point knot_get();
-    virtual void knot_set(NR::Point const &p, NR::Point const &origin, guint state);
+    virtual Geom::Point knot_get();
+    virtual void knot_set(Geom::Point const &p, Geom::Point const &origin, guint state);
 };
 
 class PatternKnotHolderEntityAngle : public KnotHolderEntity {
 public:
-    virtual NR::Point knot_get();
-    virtual void knot_set(NR::Point const &p, NR::Point const &origin, guint state);
+    virtual Geom::Point knot_get();
+    virtual void knot_set(Geom::Point const &p, Geom::Point const &origin, guint state);
 };
 
 class PatternKnotHolderEntityScale : public KnotHolderEntity {
 public:
-    virtual NR::Point knot_get();
-    virtual void knot_set(NR::Point const &p, NR::Point const &origin, guint state);
+    virtual Geom::Point knot_get();
+    virtual void knot_set(Geom::Point const &p, Geom::Point const &origin, guint state);
 };
 
 #endif /* !SEEN_KNOT_HOLDER_ENTITY_H */
@@ -109,4 +117,4 @@ public:
   fill-column:99
   End:
 */
-// vim: filetype=cpp:expandtab:shiftwidth=4:tabstop=8:softtabstop=4:encoding=utf-8:textwidth=99 :
+// vim: filetype=cpp:expandtab:shiftwidth=4:tabstop=8:softtabstop=4:fileencoding=utf-8:textwidth=99 :