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"
17 #include "knot.h"
18 #include "inkscape.h"
19 #include "verbs.h"
21 #define noLPEPOINTPARAM_DEBUG
23 #define PRM_KNOT_COLOR_NORMAL 0xffffff00
24 #define PRM_KNOT_COLOR_SELECTED 0x0000ff00
26 namespace Inkscape {
28 namespace LivePathEffect {
30 PointParam::PointParam( const Glib::ustring& label, const Glib::ustring& tip,
31 const Glib::ustring& key, Inkscape::UI::Widget::Registry* wr,
32 Effect* effect, Geom::Point default_value )
33 : Geom::Point(default_value), Parameter(label, tip, key, wr, effect), defvalue(default_value)
34 {
35 _widget = NULL;
36 pointwdg = NULL;
37 knot = NULL;
38 _tooltips = NULL;
39 }
41 PointParam::~PointParam()
42 {
43 if (pointwdg)
44 delete pointwdg;
45 if (_tooltips)
46 delete _tooltips;
48 if (knot)
49 g_object_unref (G_OBJECT (knot));
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_writeSVGValue() const
75 {
76 Inkscape::SVGOStringStream os;
77 os << (*this)[0] << "," << (*this)[1];
78 gchar * str = g_strdup(os.str().c_str());
79 return str;
80 }
82 Gtk::Widget *
83 PointParam::param_getWidget()
84 {
85 if (!_widget) {
86 pointwdg = new Inkscape::UI::Widget::RegisteredPoint();
87 pointwdg->init(param_label, param_tooltip, param_key, *param_wr, param_effect->getRepr(), param_effect->getSPDoc());
88 pointwdg->setValue( (*this)[0], (*this)[1] );
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 _widget = Gtk::manage( new Gtk::HBox() );
103 static_cast<Gtk::HBox*>(_widget)->pack_start(*pButton, true, true);
104 static_cast<Gtk::HBox*>(_widget)->pack_start(*(pointwdg->getPoint()), true, true);
105 static_cast<Gtk::HBox*>(_widget)->show_all_children();
107 _tooltips = new Gtk::Tooltips();
108 _tooltips->set_tip(*pButton, _("Edit on-canvas"));
109 }
110 return dynamic_cast<Gtk::Widget *> (_widget);
111 }
113 void
114 PointParam::param_setValue(Geom::Point newpoint)
115 {
116 *dynamic_cast<Geom::Point *>( this ) = newpoint;
117 if (pointwdg)
118 pointwdg->setValue(newpoint[0], newpoint[1]);
119 }
122 // CALLBACKS:
124 void
125 PointParam::on_button_click()
126 {
127 g_message("add knot to canvas on correct location :S");
129 if (!knot) {
130 // create the knot
131 knot = sp_knot_new (SP_ACTIVE_DESKTOP, NULL);
132 knot->setMode(SP_KNOT_MODE_XOR);
133 knot->setFill(PRM_KNOT_COLOR_NORMAL, PRM_KNOT_COLOR_NORMAL, PRM_KNOT_COLOR_NORMAL);
134 knot->setStroke(0x000000ff, 0x000000ff, 0x000000ff);
135 sp_knot_update_ctrl(knot);
137 // move knot to the given point
138 sp_knot_set_position (knot, &NR::Point(*static_cast<Geom::Point*>(this)), SP_KNOT_STATE_NORMAL);
139 sp_knot_show (knot);
140 /*
141 // connect knot's signals
142 if ( (draggable) // it can be NULL if a node in unsnapped (eg. focus point unsnapped from center)
143 // luckily, midstops never snap to other nodes so are never unsnapped...
144 && ( (draggable->point_type == POINT_LG_MID)
145 || (draggable->point_type == POINT_RG_MID1)
146 || (draggable->point_type == POINT_RG_MID2) ) )
147 {
148 this->handler_id = g_signal_connect (G_OBJECT (this->knot), "moved", G_CALLBACK (gr_knot_moved_midpoint_handler), this);
149 } else {
150 this->handler_id = g_signal_connect (G_OBJECT (this->knot), "moved", G_CALLBACK (gr_knot_moved_handler), this);
151 }
152 g_signal_connect (G_OBJECT (this->knot), "clicked", G_CALLBACK (gr_knot_clicked_handler), this);
153 g_signal_connect (G_OBJECT (this->knot), "doubleclicked", G_CALLBACK (gr_knot_doubleclicked_handler), this);
154 g_signal_connect (G_OBJECT (this->knot), "grabbed", G_CALLBACK (gr_knot_grabbed_handler), this);
155 g_signal_connect (G_OBJECT (this->knot), "ungrabbed", G_CALLBACK (gr_knot_ungrabbed_handler), this);
156 */
157 }
158 }
160 } /* namespace LivePathEffect */
162 } /* namespace Inkscape */
164 /*
165 Local Variables:
166 mode:c++
167 c-file-style:"stroustrup"
168 c-file-offsets:((innamespace . 0)(inline-open . 0)(case-label . +))
169 indent-tabs-mode:nil
170 fill-column:99
171 End:
172 */
173 // vim: filetype=cpp:expandtab:shiftwidth=4:tabstop=8:softtabstop=4 :