Code

cmake: EOL of cmakelists.txt in subdirs
[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, 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 }
45 PointParam::~PointParam()
46 {
47 }
49 void
50 PointParam::param_set_default()
51 {
52     param_setValue(defvalue);
53 }
55 bool
56 PointParam::param_readSVGValue(const gchar * strvalue)
57 {
58     gchar ** strarray = g_strsplit(strvalue, ",", 2);
59     double newx, newy;
60     unsigned int success = sp_svg_number_read_d(strarray[0], &newx);
61     success += sp_svg_number_read_d(strarray[1], &newy);
62     g_strfreev (strarray);
63     if (success == 2) {
64         param_setValue( Geom::Point(newx, newy) );
65         return true;
66     }
67     return false;
68 }
70 gchar *
71 PointParam::param_writeSVGValue() const
72 {
73     Inkscape::SVGOStringStream os;
74     os << *dynamic_cast<Geom::Point const *>( this );
75     gchar * str = g_strdup(os.str().c_str());
76     return str;
77 }
79 Gtk::Widget *
80 PointParam::param_newWidget(Gtk::Tooltips * tooltips)
81 {
82     Inkscape::UI::Widget::RegisteredTransformedPoint * pointwdg = Gtk::manage(
83         new Inkscape::UI::Widget::RegisteredTransformedPoint( param_label,
84                                                               param_tooltip,
85                                                               param_key,
86                                                               *param_wr,
87                                                               param_effect->getRepr(),
88                                                               param_effect->getSPDoc() ) );
89     // TODO: fix to get correct desktop (don't use SP_ACTIVE_DESKTOP)
90     SPDesktop *desktop = SP_ACTIVE_DESKTOP;
91     Geom::Matrix transf = to_2geom(desktop->doc2dt());
92     pointwdg->setTransform(transf);
93     pointwdg->setValue( *this );
94     pointwdg->clearProgrammatically();
95     pointwdg->set_undo_parameters(SP_VERB_DIALOG_LIVE_PATH_EFFECT, _("Change point parameter"));
97     Gtk::Widget*  pIcon = Gtk::manage( sp_icon_get_icon( "draw_node", Inkscape::ICON_SIZE_BUTTON) );
98     Gtk::Button * pButton = Gtk::manage(new Gtk::Button());
99     pButton->set_relief(Gtk::RELIEF_NONE);
100     pIcon->show();
101     pButton->add(*pIcon);
102     pButton->show();
103     pButton->signal_clicked().connect(sigc::mem_fun(*this, &PointParam::on_button_click));
105     Gtk::HBox * hbox = Gtk::manage( new Gtk::HBox() );
106     static_cast<Gtk::HBox*>(hbox)->pack_start(*pButton, true, true);
107     static_cast<Gtk::HBox*>(hbox)->pack_start(*pointwdg, true, true);
108     static_cast<Gtk::HBox*>(hbox)->show_all_children();
110     tooltips->set_tip(*pButton, _("Edit on-canvas"));
112     return dynamic_cast<Gtk::Widget *> (hbox);
115 void
116 PointParam::param_setValue(Geom::Point newpoint)
118     *dynamic_cast<Geom::Point *>( this ) = newpoint;
121 void
122 PointParam::param_set_and_write_new_value (Geom::Point newpoint)
124     Inkscape::SVGOStringStream os;
125     os << newpoint;
126     gchar * str = g_strdup(os.str().c_str());
127     param_write_to_repr(str);
128     g_free(str);
131 void
132 PointParam::param_editOncanvas(SPItem * item, SPDesktop * dt)
134     // If not already in nodecontext, goto it!
135     if (!tools_isactive(dt, TOOLS_NODES)) {
136         tools_switch_current(TOOLS_NODES);
137     }
139     PointParamKnotHolder * kh =  pointparam_knot_holder_new( dt, SP_OBJECT(param_effect->getLPEObj()), param_key.c_str(), item);
140     if (kh) {
141         kh->add_knot(* dynamic_cast<Geom::Point *>( this ), NULL, knot_shape, knot_mode, knot_color, param_getTooltip()->c_str() );
143         ShapeEditor * shape_editor = SP_NODE_CONTEXT( dt->event_context )->shape_editor;
144         shape_editor->set_knotholder(kh);
145     }
150 void
151 PointParam::param_transform_multiply(Geom::Matrix const& postmul, bool /*set*/)
153     param_set_and_write_new_value( (*this) * postmul );
157 void
158 PointParam::set_oncanvas_looks(SPKnotShapeType shape, SPKnotModeType mode, guint32 color)
160     knot_shape = shape;
161     knot_mode  = mode;
162     knot_color = color;
166 // CALLBACKS:
168 void
169 PointParam::on_button_click()
171     SPDesktop *desktop = SP_ACTIVE_DESKTOP;
172     SPItem * item = sp_desktop_selection(desktop)->singleItem();
173     if (item != NULL) {
174         param_editOncanvas(item, desktop);
175     }
178 } /* namespace LivePathEffect */
180 } /* namespace Inkscape */
182 /*
183   Local Variables:
184   mode:c++
185   c-file-style:"stroustrup"
186   c-file-offsets:((innamespace . 0)(inline-open . 0)(case-label . +))
187   indent-tabs-mode:nil
188   fill-column:99
189   End:
190 */
191 // vim: filetype=cpp:expandtab:shiftwidth=4:tabstop=8:softtabstop=4 :