Code

forgot to commit the two essential files! sorry to break the build for a second
authorjohanengelen <johanengelen@users.sourceforge.net>
Thu, 20 Mar 2008 23:24:17 +0000 (23:24 +0000)
committerjohanengelen <johanengelen@users.sourceforge.net>
Thu, 20 Mar 2008 23:24:17 +0000 (23:24 +0000)
src/live_effects/parameter/pointparam-knotholder.cpp [new file with mode: 0644]
src/live_effects/parameter/pointparam-knotholder.h [new file with mode: 0644]

diff --git a/src/live_effects/parameter/pointparam-knotholder.cpp b/src/live_effects/parameter/pointparam-knotholder.cpp
new file mode 100644 (file)
index 0000000..df8c18d
--- /dev/null
@@ -0,0 +1,267 @@
+#define INKSCAPE_LPE_POINTPARAM_KNOTHOLDER_C\r
+\r
+/*\r
+ * Container for PointParamKnotHolder visual handles\r
+ *\r
+ * Authors:\r
+ *   Johan Engelen <goejendaagh@zonnet.nl>\r
+ *\r
+ * Copyright (C) 2008 authors\r
+ *\r
+ * Released under GNU GPL, read the file 'COPYING' for more information\r
+ */\r
+\r
+#include "live_effects/parameter/pointparam-knotholder.h"\r
+#include "live_effects/lpeobject.h"\r
+#include "document.h"\r
+#include "sp-shape.h"\r
+#include "knot.h"\r
+#include "knotholder.h"\r
+#include "knot-holder-entity.h"\r
+\r
+#include <libnr/nr-matrix-div.h>\r
+#include <glibmm/i18n.h>\r
+#include <2geom/point.h>\r
+#include <2geom/matrix.h>\r
+#include "svg/stringstream.h"\r
+#include "xml/repr.h"\r
+\r
+class SPDesktop;\r
+\r
+static void pointparam_knot_clicked_handler (SPKnot *knot, guint state, gpointer data);\r
+static void pointparam_knot_moved_handler(SPKnot *knot, NR::Point const *p, guint state, gpointer data);\r
+static void pointparam_knot_ungrabbed_handler (SPKnot *knot, unsigned int state, PointParamKnotHolder *kh);\r
+static void pointparam_knot_holder_class_init(PointParamKnotHolderClass *klass);\r
+\r
+void pointparam_knot_holder_dispose(GObject *object);\r
+\r
+static SPKnotHolderClass *parent_class;\r
+\r
+/**\r
+ * Registers SPKnotHolder class and returns its type number.\r
+ */\r
+GType pointparam_knot_holder_get_type()\r
+{\r
+    static GType type = 0;\r
+    if (!type) {\r
+        GTypeInfo info = {\r
+            sizeof(PointParamKnotHolderClass),\r
+            NULL,      /* base_init */\r
+            NULL,      /* base_finalize */\r
+            (GClassInitFunc) pointparam_knot_holder_class_init,\r
+            NULL,      /* class_finalize */\r
+            NULL,      /* class_data */\r
+            sizeof (PointParamKnotHolder),\r
+            16,        /* n_preallocs */\r
+            NULL,\r
+            NULL\r
+        };\r
+        type = g_type_register_static (G_TYPE_OBJECT, "InkscapePointParamKnotHolder", &info, (GTypeFlags) 0);\r
+    }\r
+    return type;\r
+}\r
+\r
+/**\r
+ * PointParamKnotHolder vtable initialization.\r
+ */\r
+static void pointparam_knot_holder_class_init(PointParamKnotHolderClass *klass)\r
+{\r
+    GObjectClass *gobject_class;\r
+    gobject_class = (GObjectClass *) klass;\r
+\r
+    parent_class = (SPKnotHolderClass*) g_type_class_peek_parent(klass);\r
+    gobject_class->dispose = pointparam_knot_holder_dispose;\r
+}\r
+\r
+PointParamKnotHolder *pointparam_knot_holder_new(SPDesktop *desktop, SPObject *lpeobject, const gchar * key, SPItem *item)\r
+{\r
+    g_return_val_if_fail(desktop != NULL, NULL);\r
+    g_return_val_if_fail(item != NULL, NULL);\r
+    g_return_val_if_fail(SP_IS_ITEM(item), NULL);\r
+\r
+    PointParamKnotHolder *knot_holder = (PointParamKnotHolder*)g_object_new (INKSCAPE_TYPE_POINTPARAM_KNOT_HOLDER, 0);\r
+    knot_holder->desktop = desktop;\r
+    knot_holder->item = item;\r
+    knot_holder->lpeobject = LIVEPATHEFFECT(lpeobject);\r
+    g_object_ref(G_OBJECT(item));\r
+    g_object_ref(G_OBJECT(lpeobject));\r
+    knot_holder->entity = NULL;\r
+\r
+    knot_holder->released = NULL;\r
+\r
+    knot_holder->repr = lpeobject->repr;\r
+    knot_holder->repr_key = key;\r
+\r
+    knot_holder->local_change = FALSE;\r
+\r
+    return knot_holder;\r
+}\r
+\r
+void pointparam_knot_holder_dispose(GObject *object) {\r
+    PointParamKnotHolder *kh = G_TYPE_CHECK_INSTANCE_CAST((object), INKSCAPE_TYPE_POINTPARAM_KNOT_HOLDER, PointParamKnotHolder);\r
+\r
+    g_object_unref(G_OBJECT(kh->item));\r
+    g_object_unref(G_OBJECT(kh->lpeobject));\r
+    while (kh->entity) {\r
+        SPKnotHolderEntity *e = (SPKnotHolderEntity *) kh->entity->data;\r
+        g_signal_handler_disconnect(e->knot, e->_click_handler_id);\r
+        g_signal_handler_disconnect(e->knot, e->_ungrab_handler_id);\r
+        /* unref should call destroy */\r
+        g_object_unref(e->knot);\r
+        g_free(e);\r
+        kh->entity = g_slist_remove(kh->entity, e);\r
+    }\r
+}\r
+\r
+void pointparam_knot_holder_destroy(PointParamKnotHolder *kh) {\r
+    g_object_unref(kh);\r
+}\r
+\r
+void pointparam_knot_holder_add_full(\r
+    PointParamKnotHolder *knot_holder,\r
+    Geom::Point         & p,\r
+    void (* knot_click) (SPItem *item, guint state),\r
+    SPKnotShapeType     shape,\r
+    SPKnotModeType      mode,\r
+    guint32             color,\r
+    const gchar *tip )\r
+{\r
+    g_return_if_fail(knot_holder != NULL);\r
+\r
+    SPItem *item = SP_ITEM(knot_holder->item);\r
+\r
+    /* create new SPKnotHolderEntry */\r
+    SPKnotHolderEntity *e = g_new(SPKnotHolderEntity, 1);\r
+    e->knot = sp_knot_new(knot_holder->desktop, tip);\r
+    e->knot_set = NULL;\r
+    e->knot_get = NULL;\r
+    if (knot_click) {\r
+        e->knot_click = knot_click;\r
+    } else {\r
+        e->knot_click = NULL;\r
+    }\r
+\r
+    g_object_set(G_OBJECT (e->knot->item), "shape", shape, NULL);\r
+    g_object_set(G_OBJECT (e->knot->item), "mode", mode, NULL);\r
+\r
+    e->knot->fill [SP_KNOT_STATE_NORMAL] = color;\r
+    g_object_set (G_OBJECT (e->knot->item), "fill_color", color, NULL);\r
+\r
+    knot_holder->entity = g_slist_append(knot_holder->entity, e);\r
+\r
+    /* Move to current point. */\r
+    NR::Point dp = p * sp_item_i2d_affine(item);\r
+    sp_knot_set_position(e->knot, &dp, SP_KNOT_STATE_NORMAL);\r
+\r
+    e->handler_id = g_signal_connect(e->knot, "moved", G_CALLBACK(pointparam_knot_moved_handler), knot_holder);\r
+    e->_click_handler_id = g_signal_connect(e->knot, "clicked", G_CALLBACK(pointparam_knot_clicked_handler), knot_holder);\r
+    e->_ungrab_handler_id = g_signal_connect(e->knot, "ungrabbed", G_CALLBACK(pointparam_knot_ungrabbed_handler), knot_holder);\r
+\r
+    sp_knot_show(e->knot);\r
+}\r
+\r
+/**\r
+ * \param p In desktop coordinates.\r
+ */\r
+\r
+ // don't write to XML yet...\r
+//static\r
+void pointparam_knotholder_update_knots(PointParamKnotHolder *knot_holder, SPItem *item)\r
+{\r
+\r
+    NR::Matrix const i2d(sp_item_i2d_affine(item));\r
+/*\r
+    for (GSList *el = knot_holder->entity; el; el = el->next) {\r
+        SPKnotHolderEntity *e = (SPKnotHolderEntity *) el->data;\r
+        GObject *kob = e->knot;\r
+\r
+        NR::Point dp( e->knot_get(item) * i2d );\r
+        g_signal_handler_block(kob, e->handler_id);\r
+        sp_knot_set_position(e->knot, &dp, SP_KNOT_STATE_NORMAL);\r
+        g_signal_handler_unblock(kob, e->handler_id);\r
+    }\r
+    \r
+    knot_holder->lpeobject->lpe->setParameter(np->repr_key, svgpath);\r
+\r
+    knot_holder->lpeobject->requestModified(SP_OBJECT_MODIFIED_FLAG);\r
+*/\r
+}\r
+\r
+static void pointparam_knot_clicked_handler(SPKnot *knot, guint state, gpointer data)\r
+{\r
+\r
+    SPKnotHolder *knot_holder = (SPKnotHolder *) data;\r
+    SPItem *item  = SP_ITEM (knot_holder->item);\r
+/*\r
+    g_object_ref(knot_holder);\r
+    for (GSList *el = knot_holder->entity; el; el = el->next) {\r
+        SPKnotHolderEntity *e = (SPKnotHolderEntity *) el->data;\r
+        if (e->knot == knot) {\r
+            if (e->knot_click) {\r
+                e->knot_click(item, state);\r
+            }\r
+            break;\r
+        }\r
+    }\r
+\r
+    if (SP_IS_SHAPE(item)) {\r
+        sp_shape_set_shape(SP_SHAPE(item));\r
+    }\r
+\r
+    knotholder_update_knots(knot_holder, item);\r
+    g_object_unref(knot_holder);\r
+\r
+    // for drag, this is done by ungrabbed_handler, but for click we must do it here\r
+    sp_document_done(SP_OBJECT_DOCUMENT(knot_holder->item), SP_VERB_CONTEXT_LPE, \r
+                     _("Change LPE point parameter"));\r
+*/\r
+}\r
+\r
+static void pointparam_knot_moved_handler(SPKnot *knot, NR::Point const *p, guint state, gpointer data)\r
+{\r
+\r
+    SPKnotHolder *knot_holder = (SPKnotHolder *) data;\r
+    SPItem *item  = SP_ITEM (knot_holder->item);\r
+/*    // this was a local change and the knotholder does not need to be recreated:\r
+    knot_holder->local_change = TRUE;\r
+\r
+    for (GSList *el = knot_holder->entity; el; el = el->next) {\r
+        SPKnotHolderEntity *e = (SPKnotHolderEntity *) el->data;\r
+        if (e->knot == knot) {\r
+            NR::Point const q = *p / sp_item_i2d_affine(item);\r
+            e->knot_set(item, q, e->knot->drag_origin / sp_item_i2d_affine(item), state);\r
+            break;\r
+        }\r
+    }\r
+\r
+    if (SP_IS_SHAPE (item)) {\r
+        sp_shape_set_shape(SP_SHAPE (item));\r
+    }\r
+\r
+    knotholder_update_knots(knot_holder, item);\r
+*/\r
+}\r
+\r
+static void pointparam_knot_ungrabbed_handler(SPKnot *knot, unsigned int /*state*/, PointParamKnotHolder *kh)\r
+{\r
+    NR::Matrix const i2d(sp_item_i2d_affine(kh->item));\r
+    NR::Point pos = sp_knot_position(knot) / i2d;\r
+\r
+    Inkscape::SVGOStringStream os;\r
+    os << pos[0] << "," << pos[1];\r
+\r
+    kh->repr->setAttribute(kh->repr_key , os.str().c_str());\r
+\r
+    sp_document_done(SP_OBJECT_DOCUMENT (kh->lpeobject), SP_VERB_CONTEXT_LPE, _("Change LPE point parameter"));\r
+}\r
+\r
+/*\r
+  Local Variables:\r
+  mode:c++\r
+  c-file-style:"stroustrup"\r
+  c-file-offsets:((innamespace . 0)(inline-open . 0)(case-label . +))\r
+  indent-tabs-mode:nil\r
+  fill-column:99\r
+  End:\r
+*/\r
+// vim: filetype=cpp:expandtab:shiftwidth=4:tabstop=8:softtabstop=4:encoding=utf-8:textwidth=99 :\r
diff --git a/src/live_effects/parameter/pointparam-knotholder.h b/src/live_effects/parameter/pointparam-knotholder.h
new file mode 100644 (file)
index 0000000..d18b75e
--- /dev/null
@@ -0,0 +1,76 @@
+#ifndef INKSCAPE_LPE_POINTPARAM_KNOTHOLDER_H\r
+#define INKSCAPE_LPE_POINTPARAM_KNOTHOLDER_H\r
+\r
+/*\r
+ * PointParamKnotHolder - Hold SPKnot list and manage signals for LPE PointParam\r
+ *\r
+ * Author:\r
+ *   Johan Engelen <goejendaagh@zonnet.nl>\r
+ *\r
+ * Copyright (C) 2008 Johan Engelen\r
+ *\r
+ * Released under GNU GPL\r
+ *\r
+ */\r
+\r
+#include "knotholder.h"\r
+#include <glib/gtypes.h>\r
+#include "knot-enums.h"\r
+#include "forward.h"\r
+#include "libnr/nr-forward.h"\r
+#include <2geom/point.h>\r
+#include "live_effects/lpeobject.h"\r
+\r
+namespace Inkscape {\r
+namespace XML {\r
+class Node;\r
+}\r
+}\r
+\r
+\r
+typedef void (* SPKnotHolderSetFunc) (SPItem *item, NR::Point const &p, NR::Point const &origin, guint state);\r
+typedef NR::Point (* SPKnotHolderGetFunc) (SPItem *item);\r
+/* fixme: Think how to make callbacks most sensitive (Lauris) */\r
+typedef void (* SPKnotHolderReleasedFunc) (SPItem *item);\r
+\r
+struct PointParamKnotHolder : public SPKnotHolder {\r
+    LivePathEffectObject * lpeobject;\r
+    Inkscape::XML::Node  * repr;\r
+    const gchar          * repr_key;\r
+};\r
+\r
+struct PointParamKnotHolderClass : SPKnotHolderClass {\r
+};\r
+\r
+/* fixme: As a temporary solution, if released is NULL knotholder flushes undo itself (Lauris) */\r
+PointParamKnotHolder *pointparam_knot_holder_new(SPDesktop *desktop, SPObject *lpeobject, const gchar * key, SPItem *item);\r
+\r
+void pointparam_knot_holder_destroy(PointParamKnotHolder *knots);\r
+\r
+void pointparam_knot_holder_add_full(PointParamKnotHolder *knot_holder,\r
+                             Geom::Point &p,\r
+                             void (* knot_click) (SPItem *item, guint state),\r
+                             SPKnotShapeType shape,\r
+                             SPKnotModeType mode,\r
+                             guint32 color,\r
+                             gchar const *tip);\r
+\r
+GType pointparam_knot_holder_get_type();\r
+\r
+// FIXME: see knotholder.h\r
+void pointparam_knotholder_update_knots(SPKnotHolder *knot_holder, SPItem *item);\r
+\r
+#define INKSCAPE_TYPE_POINTPARAM_KNOT_HOLDER      (pointparam_knot_holder_get_type())\r
+\r
+#endif /* INKSCAPE_LPE_POINTPARAM_KNOTHOLDER_H */\r
+\r
+/*\r
+  Local Variables:\r
+  mode:c++\r
+  c-file-style:"stroustrup"\r
+  c-file-offsets:((innamespace . 0)(inline-open . 0)(case-label . +))\r
+  indent-tabs-mode:nil\r
+  fill-column:99\r
+  End:\r
+*/\r
+// vim: filetype=cpp:expandtab:shiftwidth=4:tabstop=8:softtabstop=4:encoding=utf-8:textwidth=99 :\r