Code

Remove now obsolete 'edit on canvas' button for PointParams
[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     oncanvas_editable = true;
40     knot_shape = SP_KNOT_SHAPE_SQUARE;
41     knot_mode  = SP_KNOT_MODE_XOR;
42     knot_color = 0x00ff0000;
43     handle_tip = g_strdup(htip);
44 }
46 PointParam::~PointParam()
47 {
48     if (handle_tip)
49         g_free(handle_tip);
50 }
52 void
53 PointParam::param_set_default()
54 {
55     param_setValue(defvalue);
56 }
58 bool
59 PointParam::param_readSVGValue(const gchar * strvalue)
60 {
61     gchar ** strarray = g_strsplit(strvalue, ",", 2);
62     double newx, newy;
63     unsigned int success = sp_svg_number_read_d(strarray[0], &newx);
64     success += sp_svg_number_read_d(strarray[1], &newy);
65     g_strfreev (strarray);
66     if (success == 2) {
67         param_setValue( Geom::Point(newx, newy) );
68         return true;
69     }
70     return false;
71 }
73 gchar *
74 PointParam::param_getSVGValue() const
75 {
76     Inkscape::SVGOStringStream os;
77     os << *dynamic_cast<Geom::Point const *>( this );
78     gchar * str = g_strdup(os.str().c_str());
79     return str;
80 }
82 Gtk::Widget *
83 PointParam::param_newWidget(Gtk::Tooltips * tooltips)
84 {
85     Inkscape::UI::Widget::RegisteredTransformedPoint * pointwdg = Gtk::manage(
86         new Inkscape::UI::Widget::RegisteredTransformedPoint( param_label,
87                                                               param_tooltip,
88                                                               param_key,
89                                                               *param_wr,
90                                                               param_effect->getRepr(),
91                                                               param_effect->getSPDoc() ) );
92     // TODO: fix to get correct desktop (don't use SP_ACTIVE_DESKTOP)
93     SPDesktop *desktop = SP_ACTIVE_DESKTOP;
94     Geom::Matrix transf = to_2geom(desktop->doc2dt());
95     pointwdg->setTransform(transf);
96     pointwdg->setValue( *this );
97     pointwdg->clearProgrammatically();
98     pointwdg->set_undo_parameters(SP_VERB_DIALOG_LIVE_PATH_EFFECT, _("Change point parameter"));
100     Gtk::HBox * hbox = Gtk::manage( new Gtk::HBox() );
101     static_cast<Gtk::HBox*>(hbox)->pack_start(*pointwdg, true, true);
102     static_cast<Gtk::HBox*>(hbox)->show_all_children();
104     return dynamic_cast<Gtk::Widget *> (hbox);
107 void
108 PointParam::param_setValue(Geom::Point newpoint)
110     *dynamic_cast<Geom::Point *>( this ) = newpoint;
113 void
114 PointParam::param_set_and_write_new_value (Geom::Point newpoint)
116     Inkscape::SVGOStringStream os;
117     os << newpoint;
118     gchar * str = g_strdup(os.str().c_str());
119     param_write_to_repr(str);
120     g_free(str);
123 void
124 PointParam::param_editOncanvas(SPItem * item, SPDesktop * dt)
126     // If not already in nodecontext, goto it!
127     if (!tools_isactive(dt, TOOLS_NODES)) {
128         tools_switch_current(TOOLS_NODES);
129     }
131     PointParamKnotHolder * kh =  new PointParamKnotHolder(dt, SP_OBJECT(param_effect->getLPEObj()), param_key.c_str(), item);
132     if (kh) {
133         kh->add_knot(* dynamic_cast<Geom::Point *>( this ), NULL, knot_shape, knot_mode, knot_color, param_getTooltip()->c_str() );
135         ShapeEditor * shape_editor = SP_NODE_CONTEXT( dt->event_context )->shape_editor;
136         shape_editor->set_knotholder(kh);
137     }
142 void
143 PointParam::param_transform_multiply(Geom::Matrix const& postmul, bool /*set*/)
145     param_set_and_write_new_value( (*this) * postmul );
149 void
150 PointParam::set_oncanvas_looks(SPKnotShapeType shape, SPKnotModeType mode, guint32 color)
152     knot_shape = shape;
153     knot_mode  = mode;
154     knot_color = color;
157 void
158 PointParam::knot_set(NR::Point const &p, NR::Point const &origin, guint state)
160     param_setValue(p.to_2geom());
161     sp_lpe_item_update_patheffect(SP_LPE_ITEM(item), false, false);
164 NR::Point
165 PointParam::knot_get()
167     return *this;
170 void
171 PointParam::knot_click(guint state)
173     g_print ("This is the handle associated to the parameter '%s'\n", param_key.c_str());
176 } /* namespace LivePathEffect */
178 } /* namespace Inkscape */
180 /*
181   Local Variables:
182   mode:c++
183   c-file-style:"stroustrup"
184   c-file-offsets:((innamespace . 0)(inline-open . 0)(case-label . +))
185   indent-tabs-mode:nil
186   fill-column:99
187   End:
188 */
189 // vim: filetype=cpp:expandtab:shiftwidth=4:tabstop=8:softtabstop=4 :