Code

add commentary about temporary canvas items.
[inkscape.git] / src / knotholder.cpp
index b589d18c5bf65baadda28edfe2c3f3ec1cbf718c..eeddf2eb083d8d57fc87eccd53f4fd4d866d5c44 100644 (file)
@@ -29,6 +29,7 @@
 #include "box3d.h"
 #include "sp-pattern.h"
 #include "style.h"
+#include "live_effects/lpeobject.h"
 
 #include "xml/repr.h" // for debugging only
 
 
 class SPDesktop;
 
-//static void knot_clicked_handler (SPKnot *knot, guint state, gpointer data);
-//static void knot_moved_handler(SPKnot *knot, NR::Point const *p, guint state, gpointer data);
-//static void knot_ungrabbed_handler (SPKnot *knot, unsigned int state, KnotHolder *kh);
-
 KnotHolder::KnotHolder(SPDesktop *desktop, SPItem *item, SPKnotHolderReleasedFunc relhandler)
 {
     Inkscape::XML::Node *repr = SP_OBJECT(item)->repr;
@@ -62,17 +59,20 @@ KnotHolder::KnotHolder(SPDesktop *desktop, SPItem *item, SPKnotHolderReleasedFun
 KnotHolder::~KnotHolder() {
     g_object_unref(G_OBJECT(item));
     for(std::list<KnotHolderEntity *>::iterator i = entity.begin(); i != entity.end(); ++i) {
-        delete *i;
+        KnotHolderEntity* e = (*i);
+        if (!e->isLPEParam()) {
+            // knotholder entity may be deleted
+            delete (*i);
+        } else {
+            // we must not delete the entity since it's an LPE parameter,
+            // but the handle should be destroyed
+            g_object_unref(e->knot);
+        }
+        (*i) = NULL;
     }
     entity.clear(); // this shouldn't be necessary, though
 }
 
-/** TODO: is this still needed?
-void sp_knot_holder_destroy(SPKnotHolder *kh) {
-    g_object_unref(kh);
-    }
-**/
-
 /**
  * \param p In desktop coordinates.
  */
@@ -80,7 +80,7 @@ void sp_knot_holder_destroy(SPKnotHolder *kh) {
 void
 KnotHolder::update_knots()
 {
-    NR::Matrix const i2d(sp_item_i2d_affine(item));
+    NR::Matrix const i2d(from_2geom(sp_item_i2d_affine(item)));
 
     for(std::list<KnotHolderEntity *>::iterator i = entity.begin(); i != entity.end(); ++i) {
         KnotHolderEntity *e = *i;
@@ -97,7 +97,7 @@ KnotHolder::knot_clicked_handler(SPKnot *knot, guint state)
         KnotHolderEntity *e = *i;
         if (e->knot == knot) {
             // no need to test whether knot_click exists since it's virtual now
-            e->knot_click_func(state);
+            e->knot_click(state);
             break;
         }
     }
@@ -141,8 +141,8 @@ KnotHolder::knot_moved_handler(SPKnot *knot, NR::Point const *p, guint state)
     for(std::list<KnotHolderEntity *>::iterator i = this->entity.begin(); i != this->entity.end(); ++i) {
         KnotHolderEntity *e = *i;
         if (e->knot == knot) {
-            NR::Point const q = *p / sp_item_i2d_affine(item);
-            e->knot_set_func(q, e->knot->drag_origin / sp_item_i2d_affine(item), state);
+            NR::Point const q = *p / from_2geom(sp_item_i2d_affine(item));
+            e->knot_set(q, e->knot->drag_origin / from_2geom(sp_item_i2d_affine(item)), state);
             break;
         }
     }
@@ -155,13 +155,34 @@ KnotHolder::knot_moved_handler(SPKnot *knot, NR::Point const *p, guint state)
 }
 
 void
-KnotHolder::knot_ungrabbed_handler()
+KnotHolder::knot_ungrabbed_handler(SPKnot *knot)
 {
     if (this->released) {
         this->released(this->item);
     } else {
         SPObject *object = (SPObject *) this->item;
-        object->updateRepr(object->repr, SP_OBJECT_WRITE_EXT);
+        object->updateRepr();
+
+        /* do cleanup tasks (e.g., for LPE items write the parameter values
+         * that were changed by dragging the handle to SVG)
+         */
+        if (SP_IS_LPE_ITEM(item)) {
+            // This writes all parameters to SVG. Is this sufficiently efficient or should we only write
+            // the ones that were changed (e.g., via the individual handles' onKnotUngrabbed() method?            
+            Inkscape::LivePathEffect::Effect *lpe = sp_lpe_item_get_current_lpe(SP_LPE_ITEM(item));
+            if (lpe) {
+                LivePathEffectObject *lpeobj = lpe->getLPEObj();
+                SP_OBJECT(lpeobj)->updateRepr();
+            }
+        }
+        // this was once used to write individual parameter values to SVG but this is now done globally above;
+        // we leave the calls to onKnotUngrabbed, anyway, in case any other cleanup tasks need to be done
+        for(std::list<KnotHolderEntity *>::iterator i = this->entity.begin(); i != this->entity.end(); ++i) {
+            KnotHolderEntity *e = *i;
+            if (e->knot == knot) {
+                e->onKnotUngrabbed(); // for most KnotHolderEntitys this does nothing
+            }
+        }
 
         unsigned int object_verb = SP_VERB_NONE;
 
@@ -187,6 +208,12 @@ KnotHolder::knot_ungrabbed_handler()
     }
 }
 
+void
+KnotHolder::add(KnotHolderEntity *e)
+{
+    entity.push_back(e);
+}
+
 void
 KnotHolder::add_pattern_knotholder()
 {