Inkscape
Vector Graphics Editor
Loading...
Searching...
No Matches
transformedpoint.cpp
Go to the documentation of this file.
1// SPDX-License-Identifier: GPL-2.0-or-later
2/*
3 * Copyright (C) Theodore Janeczko 2012 <flutterguy317@gmail.com>
4 *
5 * Released under GNU GPL v2+, read the file 'COPYING' for more information.
6 */
7
8#include "transformedpoint.h"
9
10#include <glibmm/i18n.h>
11
12#include "desktop.h"
13
14#include "live_effects/effect.h"
15#include "object/sp-lpe-item.h"
16#include "svg/stringstream.h"
17#include "svg/svg.h"
18#include "ui/icon-names.h"
20#include "ui/knot/knot-holder.h"
21#include "ui/pack.h"
23
24namespace Inkscape {
25namespace LivePathEffect {
26
27TransformedPointParam::TransformedPointParam( const Glib::ustring& label, const Glib::ustring& tip,
28 const Glib::ustring& key, Inkscape::UI::Widget::Registry* wr,
29 Effect* effect, Geom::Point default_vector,
30 bool dontTransform)
31 : Parameter(label, tip, key, wr, effect),
32 defvalue(default_vector),
33 vector(default_vector),
34 noTransform(dontTransform)
35{
36}
37
39
40void
46
47bool
49{
50 gchar ** strarray = g_strsplit(strvalue, ",", 4);
51 if (!strarray) {
52 return false;
53 }
54 double val[4];
55 unsigned int i = 0;
56 while (i < 4 && strarray[i]) {
57 if (sp_svg_number_read_d(strarray[i], &val[i]) != 0) {
58 i++;
59 } else {
60 break;
61 }
62 }
63 g_strfreev (strarray);
64 if (i == 4) {
65 setOrigin( Geom::Point(val[0], val[1]) );
66 setVector( Geom::Point(val[2], val[3]) );
67 return true;
68 }
69 return false;
70}
71
72Glib::ustring
74{
76 os << origin << " , " << vector;
77 return os.str();
78}
79
80Glib::ustring
87
88void
90{
91 defvalue = default_point;
92}
93
94void
96{
97 gchar ** strarray = g_strsplit(default_point, ",", 2);
98 double newx, newy;
99 unsigned int success = sp_svg_number_read_d(strarray[0], &newx);
100 success += sp_svg_number_read_d(strarray[1], &newy);
101 g_strfreev (strarray);
102 if (success == 2) {
103 param_update_default( Geom::Point(newx, newy) );
104 }
105}
106
107Gtk::Widget *
109{
110 auto const pointwdg = Gtk::make_managed<UI::Widget::RegisteredVector>( param_label,
112 param_key,
113 *param_wr,
116 pointwdg->setPolarCoords();
117 pointwdg->setValue( vector, origin );
118 pointwdg->clearProgrammatically();
119 pointwdg->set_undo_parameters(_("Change vector parameter"), INKSCAPE_ICON("dialog-path-effects"));
120
121 auto const hbox = Gtk::make_managed<Gtk::Box>(Gtk::Orientation::HORIZONTAL);
122 UI::pack_start(*hbox, *pointwdg, true, true);
123 return hbox;
124}
125
126void
128{
129 setValues(new_origin, new_vector);
131}
132
133void
135{
136 if (!noTransform) {
137 set_and_write_new_values( origin * postmul, vector * postmul.withoutTranslation() );
138 }
139}
140
142{
143 vec_knot_shape = shape;
144 vec_knot_color = color;
145}
146
147void
152
153class TransformedPointParamKnotHolderEntity_Vector : public KnotHolderEntity {
154public:
155 TransformedPointParamKnotHolderEntity_Vector(TransformedPointParam *p) : param(p) { }
156 ~TransformedPointParamKnotHolderEntity_Vector() override = default;
157
158 void knot_set(Geom::Point const &p, Geom::Point const &/*origin*/, guint /*state*/) override {
159 Geom::Point const s = p - param->origin;
161 param->setVector(s);
162 param->set_and_write_new_values(param->origin, param->vector);
163 sp_lpe_item_update_patheffect(cast<SPLPEItem>(item), false, false);
164 };
165 void knot_ungrabbed(Geom::Point const &p, Geom::Point const &origin, guint state) override
166 {
167 param->param_effect->makeUndoDone(_("Move handle"));
168 };
169 Geom::Point knot_get() const override{
170 return param->origin + param->vector;
171 };
172 void knot_click(guint /*state*/) override{
173 g_message ("This is the vector handle associated to parameter '%s'", param->param_key.c_str());
174 };
175
176private:
177 TransformedPointParam *param;
178};
179
180void
188
189} /* namespace LivePathEffect */
190} /* namespace Inkscape */
191
192/*
193 Local Variables:
194 mode:c++
195 c-file-style:"stroustrup"
196 c-file-offsets:((innamespace . 0)(inline-open . 0)(case-label . +))
197 indent-tabs-mode:nil
198 fill-column:99
199 End:
200*/
201// vim: filetype=cpp:expandtab:shiftwidth=4:tabstop=8:softtabstop=4 :
Point origin
Definition aa.cpp:227
3x3 matrix representing an affine transformation.
Definition affine.h:70
Two-dimensional point that doubles as a vector.
Definition point.h:66
Inkscape::XML::Node * getRepr()
Definition effect.cpp:1928
Inkscape::UI::Widget::Registry * param_wr
Definition parameter.h:99
void param_write_to_repr(const char *svgd)
Definition parameter.cpp:52
Inkscape::CanvasItemCtrlShape vec_knot_shape
The looks of the vector and origin knots oncanvas.
bool param_readSVGValue(const gchar *strvalue) override
Glib::ustring param_getDefaultSVGValue() const override
void setValues(Geom::Point const &new_origin, Geom::Point const &new_vector)
void param_update_default(Geom::Point default_point)
virtual void addKnotHolderEntities(KnotHolder *knotholder, SPDesktop *desktop, SPItem *item)
void set_and_write_new_values(Geom::Point const &new_origin, Geom::Point const &new_vector)
TransformedPointParam(const Glib::ustring &label, const Glib::ustring &tip, const Glib::ustring &key, Inkscape::UI::Widget::Registry *wr, Effect *effect, Geom::Point default_vector=Geom::Point(1, 0), bool dontTransform=false)
void set_vector_oncanvas_looks(CanvasItemCtrlShape shape, uint32_t color)
void setOrigin(Geom::Point const &new_origin)
void setVector(Geom::Point const &new_vector)
void param_transform_multiply(Geom::Affine const &postmul, bool set) override
std::string str() const
KnotHolderEntity definition.
virtual void knot_click(unsigned)
void add(KnotHolderEntity *e)
To do: update description of desktop.
Definition desktop.h:149
Base class for visual SVG elements.
Definition sp-item.h:109
Editable view implementation.
unsigned int guint32
Macro for icon names used in Inkscape.
SPItem * item
Glib::ustring label
void pack_start(Gtk::Box &box, Gtk::Widget &child, bool const expand, bool const fill, unsigned const padding)
Adds child to box, packed with reference to the start of box.
Definition pack.cpp:141
Helper class to stream background task notifications as a series of messages.
@ CANVAS_ITEM_CTRL_TYPE_LPE
static cairo_user_data_key_t key
Helpers for using Gtk::Boxes, encapsulating large changes between GTK3 & GTK4.
void sp_lpe_item_update_patheffect(SPLPEItem *lpeitem, bool wholetree, bool write, bool with_satellites)
Calls any registered handlers for the update_patheffect action.
Base class for live path effect items.
unsigned int sp_svg_number_read_d(gchar const *str, double *val)
TODO: insert short description here.
SPDesktop * desktop