1 #define INKSCAPE_LIVEPATHEFFECT_PARAMETER_TEXT_CPP
3 /*
4 * Copyright (C) Maximilian Albert 2008 <maximilian.albert@gmail.com>
5 *
6 * Authors:
7 * Maximilian Albert
8 * Johan Engelen
9 *
10 * Released under GNU GPL, read the file 'COPYING' for more information
11 */
13 #include "live_effects/parameter/text.h"
14 #include "live_effects/effect.h"
15 #include "svg/svg.h"
16 #include "svg/stringstream.h"
17 #include <gtkmm.h>
18 #include "widgets/icon.h"
19 #include "ui/widget/registered-widget.h"
20 #include "inkscape.h"
21 #include "verbs.h"
22 #include "display/canvas-text.h"
23 #include <2geom/sbasis-geometric.h>
25 namespace Inkscape {
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),
33 value(default_value),
34 defvalue(default_value)
35 {
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);
40 }
42 void
43 TextParam::param_set_default()
44 {
45 param_setValue(defvalue);
46 }
48 void
49 TextParam::setPos(Geom::Point pos)
50 {
51 sp_canvastext_set_coords (canvas_text, pos);
52 }
54 void
55 TextParam::setPosAndAnchor(const Geom::Piecewise<Geom::D2<Geom::SBasis> > &pwd2,
56 const double t, const double length, bool /*use_curvature*/)
57 {
58 using namespace Geom;
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));
69 }
71 void
72 TextParam::setAnchor(double x_value, double y_value)
73 {
74 anchor_x = x_value;
75 anchor_y = y_value;
76 sp_canvastext_set_anchor (canvas_text, anchor_x, anchor_y);
77 }
79 bool
80 TextParam::param_readSVGValue(const gchar * strvalue)
81 {
82 param_setValue(strvalue);
83 return true;
84 }
86 gchar *
87 TextParam::param_getSVGValue() const
88 {
89 return (gchar *) value.c_str();
90 }
92 Gtk::Widget *
93 TextParam::param_newWidget(Gtk::Tooltips * /*tooltips*/)
94 {
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);
104 }
106 void
107 TextParam::param_setValue(const Glib::ustring newvalue)
108 {
109 value = newvalue;
111 sp_canvastext_set_text (canvas_text, newvalue.c_str());
112 }
114 } /* namespace LivePathEffect */
116 } /* namespace Inkscape */
118 /*
119 Local Variables:
120 mode:c++
121 c-file-style:"stroustrup"
122 c-file-offsets:((innamespace . 0)(inline-open . 0)(case-label . +))
123 indent-tabs-mode:nil
124 fill-column:99
125 End:
126 */
127 // vim: filetype=cpp:expandtab:shiftwidth=4:tabstop=8:softtabstop=4 :