Code

fixing wrong includes
[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 "knot.h"
18 #include "inkscape.h"
19 #include "verbs.h"
21 // needed for on-canvas editting:
22 #include "tools-switch.h"
23 #include "shape-editor.h"
24 #include "node-context.h"
25 #include "desktop-handles.h"
26 #include "selection.h"
27 #include "desktop.h"
29 #define LPEPOINTPARAM_DEBUG // undefine to disable all on-canvas editing code for PointParam
31 #define PRM_KNOT_COLOR_NORMAL 0xffffff00
32 #define PRM_KNOT_COLOR_SELECTED 0x0000ff00
34 namespace Inkscape {
36 namespace LivePathEffect {
38 PointParam::PointParam( const Glib::ustring& label, const Glib::ustring& tip,
39                         const Glib::ustring& key, Inkscape::UI::Widget::Registry* wr,
40                         Effect* effect, Geom::Point default_value )
41     : Geom::Point(default_value), Parameter(label, tip, key, wr, effect), defvalue(default_value)
42 {
43     knot = NULL;
44 #ifdef LPEPOINTPARAM_DEBUG
45     oncanvas_editable = true;
46 #endif
47 }
49 PointParam::~PointParam()
50 {
51     if (knot)
52         g_object_unref (G_OBJECT (knot));
53 }
55 void
56 PointParam::param_set_default()
57 {
58     param_setValue(defvalue);
59 }
61 bool
62 PointParam::param_readSVGValue(const gchar * strvalue)
63 {
64     gchar ** strarray = g_strsplit(strvalue, ",", 2);
65     double newx, newy;
66     unsigned int success = sp_svg_number_read_d(strarray[0], &newx);
67     success += sp_svg_number_read_d(strarray[1], &newy);
68     g_strfreev (strarray);
69     if (success == 2) {
70         param_setValue( Geom::Point(newx, newy) );
71         return true;
72     }
73     return false;
74 }
76 gchar *
77 PointParam::param_writeSVGValue() const
78 {
79     Inkscape::SVGOStringStream os;
80     os << (*this)[0] << "," << (*this)[1];
81     gchar * str = g_strdup(os.str().c_str());
82     return str;
83 }
85 Gtk::Widget *
86 PointParam::param_newWidget(Gtk::Tooltips * tooltips)
87 {
88     Inkscape::UI::Widget::RegisteredPoint * pointwdg = Gtk::manage(
89         new Inkscape::UI::Widget::RegisteredPoint( param_label,
90                                                    param_tooltip,
91                                                    param_key,
92                                                    *param_wr,
93                                                    param_effect->getRepr(),
94                                                    param_effect->getSPDoc() ) );
95     pointwdg->setValue( (*this)[0], (*this)[1] );
96     pointwdg->set_undo_parameters(SP_VERB_DIALOG_LIVE_PATH_EFFECT, _("Change point parameter"));
98     Gtk::Widget*  pIcon = Gtk::manage( sp_icon_get_icon( "draw_node", Inkscape::ICON_SIZE_BUTTON) );
99     Gtk::Button * pButton = Gtk::manage(new Gtk::Button());
100     pButton->set_relief(Gtk::RELIEF_NONE);
101     pIcon->show();
102     pButton->add(*pIcon);
103     pButton->show();
104     pButton->signal_clicked().connect(sigc::mem_fun(*this, &PointParam::on_button_click));
105 #ifndef LPEPOINTPARAM_DEBUG
106     pButton->set_sensitive(false);
107 #endif
109     Gtk::HBox * hbox = Gtk::manage( new Gtk::HBox() );
110     static_cast<Gtk::HBox*>(hbox)->pack_start(*pButton, true, true);
111     static_cast<Gtk::HBox*>(hbox)->pack_start(*pointwdg, true, true);
112     static_cast<Gtk::HBox*>(hbox)->show_all_children();
114     tooltips->set_tip(*pButton, _("Edit on-canvas"));
116     return dynamic_cast<Gtk::Widget *> (hbox);
119 void
120 PointParam::param_setValue(Geom::Point newpoint)
122     *dynamic_cast<Geom::Point *>( this ) = newpoint;
125 void
126 PointParam::param_set_and_write_new_value (Geom::Point newpoint)
128     Inkscape::SVGOStringStream os;
129     os << newpoint[0] << "," << newpoint[1];
130     gchar * str = g_strdup(os.str().c_str());
131     param_write_to_repr(str);
132     g_free(str);
135 void
136 PointParam::param_editOncanvas(SPItem * item, SPDesktop * dt)
138     // If not already in nodecontext, goto it!
139     if (!tools_isactive(dt, TOOLS_NODES)) {
140         tools_switch_current(TOOLS_NODES);
141     }
143     ShapeEditor * shape_editor = SP_NODE_CONTEXT( dt->event_context )->shape_editor;
144     shape_editor->set_item_lpe_point_parameter(item, SP_OBJECT(param_effect->getLPEObj()), param_key.c_str());
149 void
150 PointParam::param_transform_multiply(Geom::Matrix const& postmul, bool /*set*/)
152     param_set_and_write_new_value( (*this) * postmul );
156 // CALLBACKS:
158 void
159 PointParam::on_button_click()
161     SPItem * item = sp_desktop_selection(SP_ACTIVE_DESKTOP)->singleItem();
162     if (item != NULL) {
163         param_editOncanvas(item, SP_ACTIVE_DESKTOP);
164     }
167 } /* namespace LivePathEffect */
169 } /* namespace Inkscape */
171 /*
172   Local Variables:
173   mode:c++
174   c-file-style:"stroustrup"
175   c-file-offsets:((innamespace . 0)(inline-open . 0)(case-label . +))
176   indent-tabs-mode:nil
177   fill-column:99
178   End:
179 */
180 // vim: filetype=cpp:expandtab:shiftwidth=4:tabstop=8:softtabstop=4 :