Code

remove flashing test indicator on pointparam.
[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/effect.h"
11 #include "svg/svg.h"
12 #include "svg/stringstream.h"
13 #include <gtkmm.h>
14 #include "ui/widget/point.h"
15 #include "widgets/icon.h"
16 #include "ui/widget/registered-widget.h"
17 #include "inkscape.h"
18 #include "verbs.h"
20 // needed for on-canvas editting:
21 #include "tools-switch.h"
22 #include "node-context.h"
23 #include "shape-editor.h"
24 #include "desktop.h"
25 #include "selection.h"
27 #define LPEPOINTPARAM_DEBUG // undefine to disable all on-canvas editing code for PointParam
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, Geom::Point default_value )
36     : Geom::Point(default_value), Parameter(label, tip, key, wr, effect), defvalue(default_value)
37 {
38 #ifdef LPEPOINTPARAM_DEBUG
39     oncanvas_editable = true;
40 #endif
41 }
43 PointParam::~PointParam()
44 {
45 }
47 void
48 PointParam::param_set_default()
49 {
50     param_setValue(defvalue);
51 }
53 bool
54 PointParam::param_readSVGValue(const gchar * strvalue)
55 {
56     gchar ** strarray = g_strsplit(strvalue, ",", 2);
57     double newx, newy;
58     unsigned int success = sp_svg_number_read_d(strarray[0], &newx);
59     success += sp_svg_number_read_d(strarray[1], &newy);
60     g_strfreev (strarray);
61     if (success == 2) {
62         param_setValue( Geom::Point(newx, newy) );
63         return true;
64     }
65     return false;
66 }
68 gchar *
69 PointParam::param_writeSVGValue() const
70 {
71     Inkscape::SVGOStringStream os;
72     os << (*this)[0] << "," << (*this)[1];
73     gchar * str = g_strdup(os.str().c_str());
74     return str;
75 }
77 Gtk::Widget *
78 PointParam::param_newWidget(Gtk::Tooltips * tooltips)
79 {
80     Inkscape::UI::Widget::RegisteredPoint * pointwdg = Gtk::manage(
81         new Inkscape::UI::Widget::RegisteredPoint( param_label,
82                                                    param_tooltip,
83                                                    param_key,
84                                                    *param_wr,
85                                                    param_effect->getRepr(),
86                                                    param_effect->getSPDoc() ) );
87     pointwdg->setValue( (*this)[0], (*this)[1] );
88     pointwdg->clearProgrammatically();
89     pointwdg->set_undo_parameters(SP_VERB_DIALOG_LIVE_PATH_EFFECT, _("Change point parameter"));
91     Gtk::Widget*  pIcon = Gtk::manage( sp_icon_get_icon( "draw_node", Inkscape::ICON_SIZE_BUTTON) );
92     Gtk::Button * pButton = Gtk::manage(new Gtk::Button());
93     pButton->set_relief(Gtk::RELIEF_NONE);
94     pIcon->show();
95     pButton->add(*pIcon);
96     pButton->show();
97     pButton->signal_clicked().connect(sigc::mem_fun(*this, &PointParam::on_button_click));
98 #ifndef LPEPOINTPARAM_DEBUG
99     pButton->set_sensitive(false);
100 #endif
102     Gtk::HBox * hbox = Gtk::manage( new Gtk::HBox() );
103     static_cast<Gtk::HBox*>(hbox)->pack_start(*pButton, true, true);
104     static_cast<Gtk::HBox*>(hbox)->pack_start(*pointwdg, true, true);
105     static_cast<Gtk::HBox*>(hbox)->show_all_children();
107     tooltips->set_tip(*pButton, _("Edit on-canvas"));
109     return dynamic_cast<Gtk::Widget *> (hbox);
112 void
113 PointParam::param_setValue(Geom::Point newpoint)
115     *dynamic_cast<Geom::Point *>( this ) = newpoint;
118 void
119 PointParam::param_set_and_write_new_value (Geom::Point newpoint)
121     Inkscape::SVGOStringStream os;
122     os << newpoint[0] << "," << newpoint[1];
123     gchar * str = g_strdup(os.str().c_str());
124     param_write_to_repr(str);
125     g_free(str);
128 void
129 PointParam::param_editOncanvas(SPItem * item, SPDesktop * dt)
131     // If not already in nodecontext, goto it!
132     if (!tools_isactive(dt, TOOLS_NODES)) {
133         tools_switch_current(TOOLS_NODES);
134     }
136     ShapeEditor * shape_editor = SP_NODE_CONTEXT( dt->event_context )->shape_editor;
137     shape_editor->set_item_lpe_point_parameter(item, SP_OBJECT(param_effect->getLPEObj()), param_key.c_str());
142 void
143 PointParam::param_transform_multiply(Geom::Matrix const& postmul, bool /*set*/)
145     param_set_and_write_new_value( (*this) * postmul );
149 // CALLBACKS:
151 void
152 PointParam::on_button_click()
154     SPDesktop *desktop = SP_ACTIVE_DESKTOP;
155     SPItem * item = sp_desktop_selection(desktop)->singleItem();
156     if (item != NULL) {
157         param_editOncanvas(item, desktop);
158     }
161 } /* namespace LivePathEffect */
163 } /* namespace Inkscape */
165 /*
166   Local Variables:
167   mode:c++
168   c-file-style:"stroustrup"
169   c-file-offsets:((innamespace . 0)(inline-open . 0)(case-label . +))
170   indent-tabs-mode:nil
171   fill-column:99
172   End:
173 */
174 // vim: filetype=cpp:expandtab:shiftwidth=4:tabstop=8:softtabstop=4 :