Code

Cleanup of out-of-sync tests
[inkscape.git] / src / knotholder.cpp
index f2bbbfbc06803e4932137d3f6d8c4b97d82cd1c1..5f749cfee6a7a4c48fc40b854d58983d2dfd3c7c 100644 (file)
 #include "sp-pattern.h"
 #include "style.h"
 #include "live_effects/lpeobject.h"
+#include "desktop.h"
+#include "display/sp-canvas.h"
 
 #include "xml/repr.h" // for debugging only
 
-#include <libnr/nr-matrix-div.h>
 #include <glibmm/i18n.h>
 
 class SPDesktop;
@@ -54,23 +55,24 @@ KnotHolder::KnotHolder(SPDesktop *desktop, SPItem *item, SPKnotHolderReleasedFun
 
     this->repr = repr;
     this->local_change = FALSE;
+
+    this->dragging = false;
 }
 
 KnotHolder::~KnotHolder() {
     g_object_unref(G_OBJECT(item));
     for(std::list<KnotHolderEntity *>::iterator i = entity.begin(); i != entity.end(); ++i) {
         KnotHolderEntity* e = (*i);
-        if (!e->isLPEParam()) {
-            // knotholder entity may be deleted
+        if (e->isDeletable()) {
             delete (*i);
         } else {
-            // we must not delete the entity since it's an LPE parameter,
+            // we must not delete the entity (since it's attached to an LPE parameter),
             // but the handle should be destroyed
             g_object_unref(e->knot);
         }
         (*i) = NULL;
     }
-    entity.clear(); // this shouldn't be necessary, though
+    entity.clear(); // is this necessary?
 }
 
 /**
@@ -80,7 +82,7 @@ KnotHolder::~KnotHolder() {
 void
 KnotHolder::update_knots()
 {
-    NR::Matrix const i2d(from_2geom(sp_item_i2d_affine(item)));
+    Geom::Matrix const i2d(sp_item_i2d_affine(item));
 
     for(std::list<KnotHolderEntity *>::iterator i = entity.begin(); i != entity.end(); ++i) {
         KnotHolderEntity *e = *i;
@@ -91,7 +93,7 @@ KnotHolder::update_knots()
 void
 KnotHolder::knot_clicked_handler(SPKnot *knot, guint state)
 {
-    KnotHolder *knot_holder = this;
+       KnotHolder *knot_holder = this;
 
     for(std::list<KnotHolderEntity *>::iterator i = knot_holder->entity.begin(); i != knot_holder->entity.end(); ++i) {
         KnotHolderEntity *e = *i;
@@ -128,21 +130,25 @@ KnotHolder::knot_clicked_handler(SPKnot *knot, guint state)
     }
 
     // for drag, this is done by ungrabbed_handler, but for click we must do it here
-    sp_document_done(SP_OBJECT_DOCUMENT(item), object_verb, 
+    sp_document_done(SP_OBJECT_DOCUMENT(item), object_verb,
                      _("Change handle"));
 }
 
 void
-KnotHolder::knot_moved_handler(SPKnot *knot, NR::Point const *p, guint state)
+KnotHolder::knot_moved_handler(SPKnot *knot, Geom::Point const &p, guint state)
 {
-    // this was a local change and the knotholder does not need to be recreated:
+    if (this->dragging == false) {
+       this->dragging = true;
+    }
+
+       // this was a local change and the knotholder does not need to be recreated:
     this->local_change = TRUE;
 
     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 / from_2geom(sp_item_i2d_affine(item));
-            e->knot_set(q, e->knot->drag_origin / from_2geom(sp_item_i2d_affine(item)), state);
+            Geom::Point const q = p * sp_item_i2d_affine(item).inverse();
+            e->knot_set(q, e->knot->drag_origin * sp_item_i2d_affine(item).inverse(), state);
             break;
         }
     }
@@ -155,9 +161,11 @@ KnotHolder::knot_moved_handler(SPKnot *knot, NR::Point const *p, guint state)
 }
 
 void
-KnotHolder::knot_ungrabbed_handler(SPKnot *knot)
+KnotHolder::knot_ungrabbed_handler(SPKnot */*knot*/)
 {
-    if (this->released) {
+       this->dragging = false;
+
+       if (this->released) {
         this->released(this->item);
     } else {
         SPObject *object = (SPObject *) this->item;
@@ -200,7 +208,7 @@ KnotHolder::knot_ungrabbed_handler(SPKnot *knot)
             else
                 object_verb = SP_VERB_SELECTION_DYNAMIC_OFFSET;
         }
-        
+
         sp_document_done(SP_OBJECT_DOCUMENT (object), object_verb,
                          _("Move handle"));
     }
@@ -226,7 +234,7 @@ KnotHolder::add_pattern_knotholder()
                           _("<b>Move</b> the pattern fill inside the object"),
                           SP_KNOT_SHAPE_CROSS);
         entity_scale->create(desktop, item, this,
-                             _("<b>Scale</b> the pattern fill uniformly"),
+                             _("<b>Scale</b> the pattern fill; uniformly if with <b>Ctrl</b>"),
                              SP_KNOT_SHAPE_SQUARE, SP_KNOT_MODE_XOR);
         entity_angle->create(desktop, item, this,
                              _("<b>Rotate</b> the pattern fill; with <b>Ctrl</b> to snap angle"),