Code

Remove oncanvas_editable attribute for PointParams; use their internal shape settings...
[inkscape.git] / src / live_effects / parameter / point.cpp
1 #define INKSCAPE_LIVEPATHEFFECT_PARAMETER_POINT_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/point.h"
10 #include "live_effects/parameter/pointparam-knotholder.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"
21 // needed for on-canvas editting:
22 #include "tools-switch.h"
23 #include "node-context.h"
24 #include "shape-editor.h"
25 #include "desktop.h"
26 #include "selection.h"
27 #include "libnr/nr-convert2geom.h"
29 namespace Inkscape {
31 namespace LivePathEffect {
33 PointParam::PointParam( const Glib::ustring& label, const Glib::ustring& tip,
34                         const Glib::ustring& key, Inkscape::UI::Widget::Registry* wr,
35                         Effect* effect, const gchar *htip, Geom::Point default_value)
36     : Geom::Point(default_value), Parameter(label, tip, key, wr, effect), defvalue(default_value)
37 {
38     knot_shape = SP_KNOT_SHAPE_DIAMOND;
39     knot_mode  = SP_KNOT_MODE_XOR;
40     knot_color = 0xffffff00;
41     handle_tip = g_strdup(htip);
42 }
44 PointParam::~PointParam()
45 {
46     if (handle_tip)
47         g_free(handle_tip);
48 }
50 void
51 PointParam::param_set_default()
52 {
53     param_setValue(defvalue);
54 }
56 bool
57 PointParam::param_readSVGValue(const gchar * strvalue)
58 {
59     gchar ** strarray = g_strsplit(strvalue, ",", 2);
60     double newx, newy;
61     unsigned int success = sp_svg_number_read_d(strarray[0], &newx);
62     success += sp_svg_number_read_d(strarray[1], &newy);
63     g_strfreev (strarray);
64     if (success == 2) {
65         param_setValue( Geom::Point(newx, newy) );
66         return true;
67     }
68     return false;
69 }
71 gchar *
72 PointParam::param_getSVGValue() const
73 {
74     Inkscape::SVGOStringStream os;
75     os << *dynamic_cast<Geom::Point const *>( this );
76     gchar * str = g_strdup(os.str().c_str());
77     return str;
78 }
80 Gtk::Widget *
81 PointParam::param_newWidget(Gtk::Tooltips * tooltips)
82 {
83     Inkscape::UI::Widget::RegisteredTransformedPoint * pointwdg = Gtk::manage(
84         new Inkscape::UI::Widget::RegisteredTransformedPoint( param_label,
85                                                               param_tooltip,
86                                                               param_key,
87                                                               *param_wr,
88                                                               param_effect->getRepr(),
89                                                               param_effect->getSPDoc() ) );
90     // TODO: fix to get correct desktop (don't use SP_ACTIVE_DESKTOP)
91     SPDesktop *desktop = SP_ACTIVE_DESKTOP;
92     Geom::Matrix transf = to_2geom(desktop->doc2dt());
93     pointwdg->setTransform(transf);
94     pointwdg->setValue( *this );
95     pointwdg->clearProgrammatically();
96     pointwdg->set_undo_parameters(SP_VERB_DIALOG_LIVE_PATH_EFFECT, _("Change point parameter"));
98     Gtk::HBox * hbox = Gtk::manage( new Gtk::HBox() );
99     static_cast<Gtk::HBox*>(hbox)->pack_start(*pointwdg, true, true);
100     static_cast<Gtk::HBox*>(hbox)->show_all_children();
102     return dynamic_cast<Gtk::Widget *> (hbox);
105 void
106 PointParam::param_setValue(Geom::Point newpoint)
108     *dynamic_cast<Geom::Point *>( this ) = newpoint;
111 void
112 PointParam::param_set_and_write_new_value (Geom::Point newpoint)
114     Inkscape::SVGOStringStream os;
115     os << newpoint;
116     gchar * str = g_strdup(os.str().c_str());
117     param_write_to_repr(str);
118     g_free(str);
121 void
122 PointParam::param_editOncanvas(SPItem * item, SPDesktop * dt)
124     // If not already in nodecontext, goto it!
125     if (!tools_isactive(dt, TOOLS_NODES)) {
126         tools_switch_current(TOOLS_NODES);
127     }
129     PointParamKnotHolder * kh =  new PointParamKnotHolder(dt, SP_OBJECT(param_effect->getLPEObj()), param_key.c_str(), item);
130     if (kh) {
131         kh->add_knot(* dynamic_cast<Geom::Point *>( this ), NULL, knot_shape, knot_mode, knot_color, param_getTooltip()->c_str() );
133         ShapeEditor * shape_editor = SP_NODE_CONTEXT( dt->event_context )->shape_editor;
134         shape_editor->set_knotholder(kh);
135     }
140 void
141 PointParam::param_transform_multiply(Geom::Matrix const& postmul, bool /*set*/)
143     param_set_and_write_new_value( (*this) * postmul );
147 void
148 PointParam::set_oncanvas_looks(SPKnotShapeType shape, SPKnotModeType mode, guint32 color)
150     knot_shape = shape;
151     knot_mode  = mode;
152     knot_color = color;
155 void
156 PointParam::knot_set(NR::Point const &p, NR::Point const &origin, guint state)
158     param_setValue(p.to_2geom());
159     sp_lpe_item_update_patheffect(SP_LPE_ITEM(item), false, false);
162 NR::Point
163 PointParam::knot_get()
165     return *this;
168 void
169 PointParam::knot_click(guint state)
171     g_print ("This is the handle associated to the parameter '%s'\n", param_key.c_str());
174 } /* namespace LivePathEffect */
176 } /* namespace Inkscape */
178 /*
179   Local Variables:
180   mode:c++
181   c-file-style:"stroustrup"
182   c-file-offsets:((innamespace . 0)(inline-open . 0)(case-label . +))
183   indent-tabs-mode:nil
184   fill-column:99
185   End:
186 */
187 // vim: filetype=cpp:expandtab:shiftwidth=4:tabstop=8:softtabstop=4 :