06e527ffd56585a48c1f5403f33ed1568ff809bb
1 #define INKSCAPE_LPE_POINTPARAM_KNOTHOLDER_C
3 /*
4 * Container for PointParamKnotHolder visual handles
5 *
6 * Authors:
7 * Johan Engelen <goejendaagh@zonnet.nl>
8 *
9 * Copyright (C) 2008 authors
10 *
11 * Released under GNU GPL, read the file 'COPYING' for more information
12 */
14 #include "live_effects/parameter/pointparam-knotholder.h"
15 #include "live_effects/lpeobject.h"
16 #include "document.h"
17 #include "sp-shape.h"
18 #include "knot.h"
19 #include "knotholder.h"
20 #include "knot-holder-entity.h"
22 #include <libnr/nr-matrix-div.h>
23 #include <glibmm/i18n.h>
24 #include <2geom/point.h>
25 #include <2geom/matrix.h>
26 #include "svg/stringstream.h"
27 #include "xml/repr.h"
29 class SPDesktop;
31 namespace Inkscape {
33 static void pointparam_knot_clicked_handler (SPKnot *knot, guint state, PointParamKnotHolder *kh);
34 static void pointparam_knot_moved_handler(SPKnot *knot, NR::Point const *p, guint state, PointParamKnotHolder *kh);
35 static void pointparam_knot_ungrabbed_handler (SPKnot *knot, unsigned int state, PointParamKnotHolder *kh);
37 PointParamKnotHolder::PointParamKnotHolder(SPDesktop *desktop, SPObject *lpeobject, const gchar * key, SPItem *item)
38 {
39 if (!desktop || !item || !SP_IS_ITEM(item)) {
40 g_print ("Error! Throw an exception, please!\n");
41 }
43 this->desktop = desktop;
44 this->item = item;
45 this->lpeobject = LIVEPATHEFFECT(lpeobject);
46 g_object_ref(G_OBJECT(item));
47 g_object_ref(G_OBJECT(lpeobject));
49 this->released = NULL;
51 this->repr = lpeobject->repr;
52 this->repr_key = key;
54 this->local_change = FALSE;
55 }
57 PointParamKnotHolder::~PointParamKnotHolder()
58 {
59 g_object_unref(G_OBJECT(this->item));
60 g_object_unref(G_OBJECT(this->lpeobject));
61 }
63 class KnotHolderEntityPointParam : public KnotHolderEntity {
64 public:
65 virtual NR::Point knot_get();
66 virtual void knot_set(NR::Point const &p, NR::Point const &origin, guint state);
67 };
69 NR::Point
70 KnotHolderEntityPointParam::knot_get() {
71 return NR::Point(0,0);
72 }
74 void
75 KnotHolderEntityPointParam::knot_set(NR::Point const &/*p*/, NR::Point const &/*origin*/, guint /*state*/) {
76 }
78 void
79 PointParamKnotHolder::add_knot (
80 Geom::Point & p,
81 // TODO: check if knot_click being ignored is bad:
82 PointParamKnotHolderClickedFunc knot_click,
83 SPKnotShapeType shape,
84 SPKnotModeType mode,
85 guint32 color,
86 const gchar *tip )
87 {
88 /* create new SPKnotHolderEntry */
89 KnotHolderEntity *e = new KnotHolderEntityPointParam();
90 e->create(this->desktop, this->item, this, tip, shape, mode, color);
92 entity.push_back(e);
94 // Move to current point.
95 NR::Point dp = p * from_2geom(sp_item_i2d_affine(item));
96 sp_knot_set_position(e->knot, &dp, SP_KNOT_STATE_NORMAL);
98 e->handler_id = g_signal_connect(e->knot, "moved", G_CALLBACK(pointparam_knot_moved_handler), this);
99 e->_click_handler_id = g_signal_connect(e->knot, "clicked", G_CALLBACK(pointparam_knot_clicked_handler), this);
100 e->_ungrab_handler_id = g_signal_connect(e->knot, "ungrabbed", G_CALLBACK(pointparam_knot_ungrabbed_handler), this);
102 sp_knot_show(e->knot);
103 }
105 static void pointparam_knot_clicked_handler(SPKnot */*knot*/, guint /*state*/, PointParamKnotHolder */*kh*/)
106 {
108 }
110 /**
111 * \param p In desktop coordinates.
112 * This function does not write to XML, but tries to write directly to the PointParam to quickly live update the effect
113 */
114 static void pointparam_knot_moved_handler(SPKnot */*knot*/, NR::Point const *p, guint /*state*/, PointParamKnotHolder *kh)
115 {
116 NR::Matrix const i2d(from_2geom(sp_item_i2d_affine(kh->getItem())));
117 NR::Point pos = (*p) / i2d;
119 Inkscape::SVGOStringStream os;
120 os << pos.to_2geom();
122 kh->lpeobject->lpe->setParameter(kh->repr_key, os.str().c_str());
123 }
125 static void pointparam_knot_ungrabbed_handler(SPKnot *knot, unsigned int /*state*/, PointParamKnotHolder *kh)
126 {
127 NR::Matrix const i2d(from_2geom(sp_item_i2d_affine(kh->getItem())));
128 NR::Point pos = sp_knot_position(knot) / i2d;
130 Inkscape::SVGOStringStream os;
131 os << pos.to_2geom();
133 kh->repr->setAttribute(kh->repr_key , os.str().c_str());
135 sp_document_done(SP_OBJECT_DOCUMENT (kh->lpeobject), SP_VERB_CONTEXT_LPE, _("Change LPE point parameter"));
136 }
138 } // namespace Inkscape
140 /*
141 Local Variables:
142 mode:c++
143 c-file-style:"stroustrup"
144 c-file-offsets:((innamespace . 0)(inline-open . 0)(case-label . +))
145 indent-tabs-mode:nil
146 fill-column:99
147 End:
148 */
149 // vim: filetype=cpp:expandtab:shiftwidth=4:tabstop=8:softtabstop=4:encoding=utf-8:textwidth=99 :