99c32720729876935d9b32a38665720188287b57
1 #define INKSCAPE_LIVEPATHEFFECT_POWERSTROKE_POINT_ARRAY_CPP
3 /*
4 * Copyright (C) Johan Engelen 2007 <j.b.c.engelen@utwente.nl>
5 *
6 * Released under GNU GPL, read the file 'COPYING' for more information
7 */
9 #include "live_effects/parameter/powerstrokepointarray.h"
11 #include "live_effects/effect.h"
12 #include "svg/svg.h"
13 #include "svg/stringstream.h"
14 #include <gtkmm.h>
15 #include "ui/widget/point.h"
16 #include "widgets/icon.h"
17 #include "ui/widget/registered-widget.h"
18 #include "inkscape.h"
19 #include "verbs.h"
20 #include "knotholder.h"
22 // needed for on-canvas editting:
23 #include "desktop.h"
25 namespace Inkscape {
27 namespace LivePathEffect {
29 PowerStrokePointArrayParam::PowerStrokePointArrayParam( const Glib::ustring& label, const Glib::ustring& tip,
30 const Glib::ustring& key, Inkscape::UI::Widget::Registry* wr,
31 Effect* effect, const gchar *htip)
32 : ArrayParam<Geom::Point>(label, tip, key, wr, effect, 0)
33 {
34 knot_shape = SP_KNOT_SHAPE_DIAMOND;
35 knot_mode = SP_KNOT_MODE_XOR;
36 knot_color = 0xff00ff00;
37 handle_tip = g_strdup(htip);
38 }
40 PowerStrokePointArrayParam::~PowerStrokePointArrayParam()
41 {
42 if (handle_tip)
43 g_free(handle_tip);
44 }
46 Gtk::Widget *
47 PowerStrokePointArrayParam::param_newWidget(Gtk::Tooltips * /*tooltips*/)
48 {
49 return NULL;
50 /*
51 Inkscape::UI::Widget::RegisteredTransformedPoint * pointwdg = Gtk::manage(
52 new Inkscape::UI::Widget::RegisteredTransformedPoint( param_label,
53 param_tooltip,
54 param_key,
55 *param_wr,
56 param_effect->getRepr(),
57 param_effect->getSPDoc() ) );
58 // TODO: fix to get correct desktop (don't use SP_ACTIVE_DESKTOP)
59 SPDesktop *desktop = SP_ACTIVE_DESKTOP;
60 Geom::Matrix transf = desktop->doc2dt();
61 pointwdg->setTransform(transf);
62 pointwdg->setValue( *this );
63 pointwdg->clearProgrammatically();
64 pointwdg->set_undo_parameters(SP_VERB_DIALOG_LIVE_PATH_EFFECT, _("Change point parameter"));
66 Gtk::HBox * hbox = Gtk::manage( new Gtk::HBox() );
67 static_cast<Gtk::HBox*>(hbox)->pack_start(*pointwdg, true, true);
68 static_cast<Gtk::HBox*>(hbox)->show_all_children();
70 return dynamic_cast<Gtk::Widget *> (hbox);
71 */
72 }
75 void
76 PowerStrokePointArrayParam::param_transform_multiply(Geom::Matrix const& postmul, bool /*set*/)
77 {
78 // param_set_and_write_new_value( (*this) * postmul );
79 }
82 void
83 PowerStrokePointArrayParam::set_oncanvas_looks(SPKnotShapeType shape, SPKnotModeType mode, guint32 color)
84 {
85 knot_shape = shape;
86 knot_mode = mode;
87 knot_color = color;
88 }
90 class PowerStrokePointArrayParamKnotHolderEntity : public LPEKnotHolderEntity {
91 public:
92 PowerStrokePointArrayParamKnotHolderEntity(PowerStrokePointArrayParam *p, unsigned int index);
93 virtual ~PowerStrokePointArrayParamKnotHolderEntity() {}
95 virtual void knot_set(Geom::Point const &p, Geom::Point const &origin, guint state);
96 virtual Geom::Point knot_get();
97 virtual void knot_click(guint state);
99 private:
100 PowerStrokePointArrayParam *_pparam;
101 unsigned int _index;
102 };
104 PowerStrokePointArrayParamKnotHolderEntity::PowerStrokePointArrayParamKnotHolderEntity(PowerStrokePointArrayParam *p, unsigned int index)
105 : _pparam(p),
106 _index(index)
107 {
108 }
110 void
111 PowerStrokePointArrayParamKnotHolderEntity::knot_set(Geom::Point const &p, Geom::Point const &/*origin*/, guint /*state*/)
112 {
113 Geom::Point const s = snap_knot_position(p);
114 _pparam->_vector.at(_index) = s;
115 // _pparam->param_set_and_write_new_value(_pparam->_vector);
116 sp_lpe_item_update_patheffect(SP_LPE_ITEM(item), false, false);
117 }
119 Geom::Point
120 PowerStrokePointArrayParamKnotHolderEntity::knot_get()
121 {
122 Geom::Point canvas_point = _pparam->_vector.at(_index);
123 return canvas_point;
124 }
126 void
127 PowerStrokePointArrayParamKnotHolderEntity::knot_click(guint state)
128 {
129 g_print ("This is the %d handle associated to parameter '%s'\n", _index, _pparam->param_key.c_str());
131 if (state & GDK_CONTROL_MASK) {
132 std::vector<Geom::Point> & vec = _pparam->_vector;
133 vec.insert(vec.begin() + _index, 1, vec.at(_index));
134 _pparam->param_set_and_write_new_value(vec);
135 g_print ("Added handle %d associated to parameter '%s'\n", _index, _pparam->param_key.c_str());
136 /// @todo this BUGS ! the knot stuff should be reloaded when adding a new node!
137 }
138 }
140 void
141 PowerStrokePointArrayParam::addKnotHolderEntities(KnotHolder *knotholder, SPDesktop *desktop, SPItem *item)
142 {
143 for (unsigned int i = 0; i < _vector.size(); ++i) {
144 PowerStrokePointArrayParamKnotHolderEntity *e = new PowerStrokePointArrayParamKnotHolderEntity(this, i);
145 e->create(desktop, item, knotholder, handle_tip, knot_shape, knot_mode, knot_color);
146 knotholder->add(e);
147 }
148 }
150 } /* namespace LivePathEffect */
152 } /* namespace Inkscape */
154 /*
155 Local Variables:
156 mode:c++
157 c-file-style:"stroustrup"
158 c-file-offsets:((innamespace . 0)(inline-open . 0)(case-label . +))
159 indent-tabs-mode:nil
160 fill-column:99
161 End:
162 */
163 // vim: filetype=cpp:expandtab:shiftwidth=4:tabstop=8:softtabstop=4 :