1 #define INKSCAPE_LIVEPATHEFFECT_PARAMETER_POINT_CPP\r
2 \r
3 /*\r
4 * Copyright (C) Johan Engelen 2007 <j.b.c.engelen@utwente.nl>\r
5 *\r
6 * Released under GNU GPL, read the file 'COPYING' for more information\r
7 */\r
8 \r
9 #include "live_effects/parameter/point.h"\r
10 #include "live_effects/effect.h"\r
11 #include "svg/svg.h"\r
12 #include "svg/stringstream.h"\r
13 #include <gtkmm.h>\r
14 #include "ui/widget/point.h"\r
15 #include "widgets/icon.h"\r
16 \r
17 #include "knot.h"\r
18 #include "inkscape.h"\r
19 #include "verbs.h"\r
20 \r
21 #define noLPEPOINTPARAM_DEBUG\r
22 \r
23 #define PRM_KNOT_COLOR_NORMAL 0xffffff00\r
24 #define PRM_KNOT_COLOR_SELECTED 0x0000ff00\r
25 \r
26 namespace Inkscape {\r
27 \r
28 namespace LivePathEffect {\r
29 \r
30 PointParam::PointParam( const Glib::ustring& label, const Glib::ustring& tip,\r
31 const Glib::ustring& key, Inkscape::UI::Widget::Registry* wr,\r
32 Effect* effect )\r
33 : Geom::Point(0,0), Parameter(label, tip, key, wr, effect)\r
34 {\r
35 _widget = NULL;\r
36 pointwdg = NULL;\r
37 knot = NULL;\r
38 _tooltips = NULL;\r
39 }\r
40 \r
41 PointParam::~PointParam()\r
42 {\r
43 if (pointwdg)\r
44 delete pointwdg;\r
45 if (_tooltips)\r
46 delete _tooltips;\r
47 \r
48 if (knot)\r
49 g_object_unref (G_OBJECT (knot));\r
50 }\r
51 \r
52 bool\r
53 PointParam::param_readSVGValue(const gchar * strvalue)\r
54 {\r
55 gchar ** strarray = g_strsplit(strvalue, ",", 2);\r
56 double newx, newy;\r
57 unsigned int success = sp_svg_number_read_d(strarray[0], &newx);\r
58 success += sp_svg_number_read_d(strarray[1], &newy);\r
59 g_strfreev (strarray);\r
60 if (success == 2) {\r
61 *dynamic_cast<Geom::Point *>( this ) = Geom::Point(newx, newy);\r
62 return true;\r
63 }\r
64 return false;\r
65 }\r
66 \r
67 gchar *\r
68 PointParam::param_writeSVGValue() const\r
69 {\r
70 Inkscape::SVGOStringStream os;\r
71 os << pointwdg->getPoint()->getXValue() << "," << pointwdg->getPoint()->getYValue();\r
72 gchar * str = g_strdup(os.str().c_str());\r
73 return str;\r
74 }\r
75 \r
76 Gtk::Widget *\r
77 PointParam::param_getWidget()\r
78 {\r
79 if (!_widget) {\r
80 pointwdg = new Inkscape::UI::Widget::RegisteredPoint();\r
81 pointwdg->init(param_label, param_tooltip, param_key, *param_wr, param_effect->getRepr(), param_effect->getSPDoc());\r
82 pointwdg->setValue(0.1, 0.2);\r
83 pointwdg->set_undo_parameters(SP_VERB_DIALOG_LIVE_PATH_EFFECT, _("Change point parameter"));\r
84 \r
85 Gtk::Widget* pIcon = Gtk::manage( sp_icon_get_icon( "draw_node", Inkscape::ICON_SIZE_BUTTON) );\r
86 Gtk::Button * pButton = Gtk::manage(new Gtk::Button());\r
87 pButton->set_relief(Gtk::RELIEF_NONE);\r
88 pIcon->show();\r
89 pButton->add(*pIcon);\r
90 pButton->show();\r
91 pButton->signal_clicked().connect(sigc::mem_fun(*this, &PointParam::on_button_click));\r
92 #ifndef LPEPOINTPARAM_DEBUG\r
93 pButton->set_sensitive(false);\r
94 #endif\r
95 \r
96 _widget = Gtk::manage( new Gtk::HBox() );\r
97 static_cast<Gtk::HBox*>(_widget)->pack_start(*pButton, true, true);\r
98 static_cast<Gtk::HBox*>(_widget)->pack_start(*(pointwdg->getPoint()), true, true);\r
99 static_cast<Gtk::HBox*>(_widget)->show_all_children();\r
100 \r
101 _tooltips = new Gtk::Tooltips();\r
102 _tooltips->set_tip(*pButton, _("Edit on-canvas"));\r
103 }\r
104 return dynamic_cast<Gtk::Widget *> (_widget);\r
105 }\r
106 \r
107 void\r
108 PointParam::param_setValue(Geom::Point newpoint)\r
109 {\r
110 *dynamic_cast<Geom::Point *>( this ) = newpoint;\r
111 pointwdg->setValue(newpoint[0], newpoint[1]);\r
112 }\r
113 \r
114 \r
115 // CALLBACKS:\r
116 \r
117 void\r
118 PointParam::on_button_click()\r
119 {\r
120 g_message("add knot to canvas on correct location :S");\r
121 \r
122 if (!knot) {\r
123 // create the knot\r
124 knot = sp_knot_new (SP_ACTIVE_DESKTOP, NULL);\r
125 knot->setMode(SP_KNOT_MODE_XOR);\r
126 knot->setFill(PRM_KNOT_COLOR_NORMAL, PRM_KNOT_COLOR_NORMAL, PRM_KNOT_COLOR_NORMAL);\r
127 knot->setStroke(0x000000ff, 0x000000ff, 0x000000ff);\r
128 sp_knot_update_ctrl(knot);\r
129 \r
130 // move knot to the given point\r
131 sp_knot_set_position (knot, &NR::Point((*this)[0], (*this)[1]), SP_KNOT_STATE_NORMAL);\r
132 sp_knot_show (knot);\r
133 /*\r
134 // connect knot's signals\r
135 if ( (draggable) // it can be NULL if a node in unsnapped (eg. focus point unsnapped from center)\r
136 // luckily, midstops never snap to other nodes so are never unsnapped...\r
137 && ( (draggable->point_type == POINT_LG_MID)\r
138 || (draggable->point_type == POINT_RG_MID1)\r
139 || (draggable->point_type == POINT_RG_MID2) ) )\r
140 {\r
141 this->handler_id = g_signal_connect (G_OBJECT (this->knot), "moved", G_CALLBACK (gr_knot_moved_midpoint_handler), this);\r
142 } else {\r
143 this->handler_id = g_signal_connect (G_OBJECT (this->knot), "moved", G_CALLBACK (gr_knot_moved_handler), this);\r
144 }\r
145 g_signal_connect (G_OBJECT (this->knot), "clicked", G_CALLBACK (gr_knot_clicked_handler), this);\r
146 g_signal_connect (G_OBJECT (this->knot), "doubleclicked", G_CALLBACK (gr_knot_doubleclicked_handler), this);\r
147 g_signal_connect (G_OBJECT (this->knot), "grabbed", G_CALLBACK (gr_knot_grabbed_handler), this);\r
148 g_signal_connect (G_OBJECT (this->knot), "ungrabbed", G_CALLBACK (gr_knot_ungrabbed_handler), this);\r
149 */\r
150 }\r
151 }\r
152 \r
153 }; /* namespace LivePathEffect */\r
154 \r
155 }; /* namespace Inkscape */\r
156 \r
157 /*\r
158 Local Variables:\r
159 mode:c++\r
160 c-file-style:"stroustrup"\r
161 c-file-offsets:((innamespace . 0)(inline-open . 0)(case-label . +))\r
162 indent-tabs-mode:nil\r
163 fill-column:99\r
164 End:\r
165 */\r
166 // vim: filetype=cpp:expandtab:shiftwidth=4:tabstop=8:softtabstop=4 :\r