1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
|
#define INKSCAPE_LIVEPATHEFFECT_PARAMETER_VECTOR_CPP
/*
* Copyright (C) Johan Engelen 2008 <j.b.c.engelen@utwente.nl>
*
* Released under GNU GPL, read the file 'COPYING' for more information
*/
#include "live_effects/parameter/vector.h"
#include "sp-lpe-item.h"
#include "knotholder.h"
#include "svg/svg.h"
#include "svg/stringstream.h"
#include <gtkmm.h>
// needed for on-canvas editting:
class SPDesktop;
namespace Inkscape {
namespace LivePathEffect {
VectorParam::VectorParam( const Glib::ustring& label, const Glib::ustring& tip,
const Glib::ustring& key, Inkscape::UI::Widget::Registry* wr,
Effect* effect, Geom::Point default_vector)
: Parameter(label, tip, key, wr, effect),
defvalue(default_vector),
origin(0.,0.),
vector(default_vector)
{
vec_knot_shape = SP_KNOT_SHAPE_DIAMOND;
vec_knot_mode = SP_KNOT_MODE_XOR;
vec_knot_color = 0xffffb500;
ori_knot_shape = SP_KNOT_SHAPE_CIRCLE;
ori_knot_mode = SP_KNOT_MODE_XOR;
ori_knot_color = 0xffffb500;
}
VectorParam::~VectorParam()
{
}
void
VectorParam::param_set_default()
{
setOrigin(Geom::Point(0.,0.));
setVector(defvalue);
}
bool
VectorParam::param_readSVGValue(const gchar * strvalue)
{
gchar ** strarray = g_strsplit(strvalue, ",", 4);
double val[4];
unsigned int i = 0;
while (strarray[i] && i < 4) {
if (sp_svg_number_read_d(strarray[i], &val[i]) != 0) {
i++;
} else {
break;
}
}
g_strfreev (strarray);
if (i == 4) {
setOrigin( Geom::Point(val[0], val[1]) );
setVector( Geom::Point(val[2], val[3]) );
return true;
}
return false;
}
gchar *
VectorParam::param_getSVGValue() const
{
Inkscape::SVGOStringStream os;
os << origin << " , " << vector;
gchar * str = g_strdup(os.str().c_str());
return str;
}
Gtk::Widget *
VectorParam::param_newWidget(Gtk::Tooltips * /*tooltips*/)
{
/*
Inkscape::UI::Widget::RegisteredTransformedPoint * pointwdg = Gtk::manage(
new Inkscape::UI::Widget::RegisteredTransformedPoint( param_label,
param_tooltip,
param_key,
*param_wr,
param_effect->getRepr(),
param_effect->getSPDoc() ) );
// TODO: fix to get correct desktop (don't use SP_ACTIVE_DESKTOP)
SPDesktop *desktop = SP_ACTIVE_DESKTOP;
Geom::Matrix transf = desktop->doc2dt();
pointwdg->setTransform(transf);
pointwdg->setValue( *this );
pointwdg->clearProgrammatically();
pointwdg->set_undo_parameters(SP_VERB_DIALOG_LIVE_PATH_EFFECT, _("Change point parameter"));
Gtk::HBox * hbox = Gtk::manage( new Gtk::HBox() );
static_cast<Gtk::HBox*>(hbox)->pack_start(*pointwdg, true, true);
static_cast<Gtk::HBox*>(hbox)->show_all_children();
return dynamic_cast<Gtk::Widget *> (hbox);
*/ return NULL;
}
void
VectorParam::set_and_write_new_values(Geom::Point const &new_origin, Geom::Point const &new_vector)
{
setValues(new_origin, new_vector);
gchar * str = param_getSVGValue();
param_write_to_repr(str);
g_free(str);
}
void
VectorParam::param_transform_multiply(Geom::Matrix const& postmul, bool /*set*/)
{
set_and_write_new_values( origin * postmul, vector * postmul.without_translation() );
}
void
VectorParam::set_vector_oncanvas_looks(SPKnotShapeType shape, SPKnotModeType mode, guint32 color)
{
vec_knot_shape = shape;
vec_knot_mode = mode;
vec_knot_color = color;
}
void
VectorParam::set_origin_oncanvas_looks(SPKnotShapeType shape, SPKnotModeType mode, guint32 color)
{
ori_knot_shape = shape;
ori_knot_mode = mode;
ori_knot_color = color;
}
class VectorParamKnotHolderEntity_Origin : public LPEKnotHolderEntity {
public:
VectorParamKnotHolderEntity_Origin(VectorParam *p) : param(p) { }
virtual ~VectorParamKnotHolderEntity_Origin() {}
virtual void knot_set(Geom::Point const &p, Geom::Point const &/*origin*/, guint /*state*/) {
Geom::Point const s = snap_knot_position(p);
param->setOrigin(s);
sp_lpe_item_update_patheffect(SP_LPE_ITEM(item), false, false);
};
virtual Geom::Point knot_get(){
return param->origin;
};
virtual void knot_click(guint /*state*/){
g_print ("This is the origin handle associated to parameter '%s'\n", param->param_key.c_str());
};
private:
VectorParam *param;
};
class VectorParamKnotHolderEntity_Vector : public LPEKnotHolderEntity {
public:
VectorParamKnotHolderEntity_Vector(VectorParam *p) : param(p) { }
virtual ~VectorParamKnotHolderEntity_Vector() {}
virtual void knot_set(Geom::Point const &p, Geom::Point const &/*origin*/, guint state) {
Geom::Point const s = p - param->origin;
/// @todo implement angle snapping when holding CTRL
param->setVector(s);
sp_lpe_item_update_patheffect(SP_LPE_ITEM(item), false, false);
};
virtual Geom::Point knot_get(){
return param->origin + param->vector;
};
virtual void knot_click(guint /*state*/){
g_print ("This is the vector handle associated to parameter '%s'\n", param->param_key.c_str());
};
private:
VectorParam *param;
};
void
VectorParam::addKnotHolderEntities(KnotHolder *knotholder, SPDesktop *desktop, SPItem *item)
{
VectorParamKnotHolderEntity_Origin *origin_e = new VectorParamKnotHolderEntity_Origin(this);
origin_e->create(desktop, item, knotholder, handleTip(), ori_knot_shape, ori_knot_mode, ori_knot_color);
knotholder->add(origin_e);
VectorParamKnotHolderEntity_Vector *vector_e = new VectorParamKnotHolderEntity_Vector(this);
vector_e->create(desktop, item, knotholder, handleTip(), vec_knot_shape, vec_knot_mode, vec_knot_color);
knotholder->add(vector_e);
}
} /* namespace LivePathEffect */
} /* namespace Inkscape */
/*
Local Variables:
mode:c++
c-file-style:"stroustrup"
c-file-offsets:((innamespace . 0)(inline-open . 0)(case-label . +))
indent-tabs-mode:nil
fill-column:99
End:
*/
// vim: filetype=cpp:expandtab:shiftwidth=4:tabstop=8:softtabstop=4 :
|