diff --git a/src/knotholder.cpp b/src/knotholder.cpp
index b589d18c5bf65baadda28edfe2c3f3ec1cbf718c..55a171414e58ee59144961b62c4cfd3e1f0734e9 100644 (file)
--- a/src/knotholder.cpp
+++ b/src/knotholder.cpp
#include "box3d.h"
#include "sp-pattern.h"
#include "style.h"
#include "box3d.h"
#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 "xml/repr.h" // for debugging only
-#include <libnr/nr-matrix-div.h>
#include <glibmm/i18n.h>
class SPDesktop;
#include <glibmm/i18n.h>
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;
KnotHolder::KnotHolder(SPDesktop *desktop, SPItem *item, SPKnotHolderReleasedFunc relhandler)
{
Inkscape::XML::Node *repr = SP_OBJECT(item)->repr;
@@ -57,22 +55,26 @@ KnotHolder::KnotHolder(SPDesktop *desktop, SPItem *item, SPKnotHolderReleasedFun
this->repr = repr;
this->local_change = FALSE;
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) {
}
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->isDeletable()) {
+ delete (*i);
+ } else {
+ // 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?
}
}
-/** TODO: is this still needed?
-void sp_knot_holder_destroy(SPKnotHolder *kh) {
- g_object_unref(kh);
- }
-**/
-
/**
* \param p In desktop coordinates.
*/
/**
* \param p In desktop coordinates.
*/
void
KnotHolder::update_knots()
{
void
KnotHolder::update_knots()
{
- NR::Matrix const i2d(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;
for(std::list<KnotHolderEntity *>::iterator i = entity.begin(); i != entity.end(); ++i) {
KnotHolderEntity *e = *i;
void
KnotHolder::knot_clicked_handler(SPKnot *knot, guint state)
{
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;
if (e->knot == knot) {
// no need to test whether knot_click exists since it's virtual now
for(std::list<KnotHolderEntity *>::iterator i = knot_holder->entity.begin(); i != knot_holder->entity.end(); ++i) {
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;
}
}
break;
}
}
}
// for drag, this is done by ungrabbed_handler, but for click we must do it here
}
// 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
_("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) {
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 / sp_item_i2d_affine(item);
- e->knot_set_func(q, e->knot->drag_origin / 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;
}
}
break;
}
}
}
void
}
void
-KnotHolder::knot_ungrabbed_handler()
+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;
this->released(this->item);
} else {
SPObject *object = (SPObject *) this->item;
- object->updateRepr(object->repr, SP_OBJECT_WRITE_EXT);
+
+ // Caution: this call involves a screen update, which may process events, and as a
+ // result the knotholder may be destructed. So, after the updateRepr, we cannot use any
+ // fields of this knotholder (such as this->item), but only values we have saved beforehand
+ // (such as object).
+ 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(object)) {
+ // This writes all parameters to SVG. Is this sufficiently efficient or should we only
+ // write the ones that were changed?
+
+ Inkscape::LivePathEffect::Effect *lpe = sp_lpe_item_get_current_lpe(SP_LPE_ITEM(object));
+ if (lpe) {
+ LivePathEffectObject *lpeobj = lpe->getLPEObj();
+ SP_OBJECT(lpeobj)->updateRepr();
+ }
+ }
unsigned int object_verb = SP_VERB_NONE;
unsigned int object_verb = SP_VERB_NONE;
else
object_verb = SP_VERB_SELECTION_DYNAMIC_OFFSET;
}
else
object_verb = SP_VERB_SELECTION_DYNAMIC_OFFSET;
}
-
+
sp_document_done(SP_OBJECT_DOCUMENT (object), object_verb,
_("Move handle"));
}
}
sp_document_done(SP_OBJECT_DOCUMENT (object), object_verb,
_("Move handle"));
}
}
+void
+KnotHolder::add(KnotHolderEntity *e)
+{
+ entity.push_back(e);
+}
+
void
KnotHolder::add_pattern_knotholder()
{
void
KnotHolder::add_pattern_knotholder()
{
// TRANSLATORS: This refers to the pattern that's inside the object
_("<b>Move</b> the pattern fill inside the object"),
SP_KNOT_SHAPE_CROSS);
// TRANSLATORS: This refers to the pattern that's inside the object
_("<b>Move</b> the pattern fill inside the object"),
SP_KNOT_SHAPE_CROSS);
- entity_angle->create(desktop, item, this,
+ entity_scale->create(desktop, item, this,
_("<b>Scale</b> the pattern fill uniformly"),
SP_KNOT_SHAPE_SQUARE, SP_KNOT_MODE_XOR);
_("<b>Scale</b> the pattern fill uniformly"),
SP_KNOT_SHAPE_SQUARE, SP_KNOT_MODE_XOR);
- entity_scale->create(desktop, item, this,
+ entity_angle->create(desktop, item, this,
_("<b>Rotate</b> the pattern fill; with <b>Ctrl</b> to snap angle"),
SP_KNOT_SHAPE_CIRCLE, SP_KNOT_MODE_XOR);
entity.push_back(entity_xy);
_("<b>Rotate</b> the pattern fill; with <b>Ctrl</b> to snap angle"),
SP_KNOT_SHAPE_CIRCLE, SP_KNOT_MODE_XOR);
entity.push_back(entity_xy);