1
#define INKSCAPE_LIVEPATHEFFECT_PARAMETER_TEXT_CPP
4
* Copyright (C) Maximilian Albert 2008 <maximilian.albert@gmail.com>
10
* Released under GNU GPL, read the file 'COPYING' for more information
13
#include "live_effects/parameter/text.h"
14
#include "live_effects/effect.h"
16
#include "svg/stringstream.h"
18
#include "widgets/icon.h"
19
#include "ui/widget/registered-widget.h"
22
#include "display/canvas-text.h"
23
#include <2geom/sbasis-geometric.h>
27
namespace LivePathEffect {
29
TextParam::TextParam( const Glib::ustring& label, const Glib::ustring& tip,
30
const Glib::ustring& key, Inkscape::UI::Widget::Registry* wr,
31
Effect* effect, const Glib::ustring default_value )
32
: Parameter(label, tip, key, wr, effect),
34
defvalue(default_value)
36
SPDesktop *desktop = inkscape_active_desktop(); // FIXME: we shouldn't use this!
37
canvas_text = (SPCanvasText *) sp_canvastext_new(sp_desktop_tempgroup(desktop), desktop, Geom::Point(0,0), "");
38
sp_canvastext_set_text (canvas_text, default_value.c_str());
39
sp_canvastext_set_coords (canvas_text, 0, 0);
43
TextParam::param_set_default()
45
param_setValue(defvalue);
49
TextParam::setPos(Geom::Point pos)
51
sp_canvastext_set_coords (canvas_text, pos);
55
TextParam::setPosAndAnchor(const Geom::Piecewise<Geom::D2<Geom::SBasis> > &pwd2,
56
const double t, const double length, bool /*use_curvature*/)
60
Piecewise<D2<SBasis> > pwd2_reparam = arc_length_parametrization(pwd2, 2 , 0.1);
61
double t_reparam = pwd2_reparam.cuts.back() * t;
62
Point pos = pwd2_reparam.valueAt(t_reparam);
63
Point dir = unit_vector(derivative(pwd2_reparam).valueAt(t_reparam));
64
Point n = -rot90(dir);
65
double angle = Geom::angle_between(dir, Point(1,0));
67
sp_canvastext_set_coords(canvas_text, pos + n * length);
68
sp_canvastext_set_anchor(canvas_text, std::sin(angle), -std::cos(angle));
72
TextParam::setAnchor(double x_value, double y_value)
76
sp_canvastext_set_anchor (canvas_text, anchor_x, anchor_y);
80
TextParam::param_readSVGValue(const gchar * strvalue)
82
param_setValue(strvalue);
87
TextParam::param_getSVGValue() const
89
return (gchar *) value.c_str();
93
TextParam::param_newWidget(Gtk::Tooltips * /*tooltips*/)
95
Inkscape::UI::Widget::RegisteredText *rsu = Gtk::manage(new Inkscape::UI::Widget::RegisteredText(
96
param_label, param_tooltip, param_key, *param_wr, param_effect->getRepr(), param_effect->getSPDoc()));
98
rsu->setText(value.c_str());
99
rsu->setProgrammatically = false;
101
rsu->set_undo_parameters(SP_VERB_DIALOG_LIVE_PATH_EFFECT, _("Change text parameter"));
103
return dynamic_cast<Gtk::Widget *> (rsu);
107
TextParam::param_setValue(const Glib::ustring newvalue)
111
sp_canvastext_set_text (canvas_text, newvalue.c_str());
114
} /* namespace LivePathEffect */
116
} /* namespace Inkscape */
121
c-file-style:"stroustrup"
122
c-file-offsets:((innamespace . 0)(inline-open . 0)(case-label . +))
127
// vim: filetype=cpp:expandtab:shiftwidth=4:tabstop=8:softtabstop=4 :