Code

updated spanish.nsh and inkscape.nsi to reflect latest file-changes
[inkscape.git] / trunk / src / live_effects / parameter / text.cpp
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 <2geom/sbasis-geometric.h>
24 namespace Inkscape {
26 namespace LivePathEffect {
28 TextParam::TextParam( const Glib::ustring& label, const Glib::ustring& tip,
29                       const Glib::ustring& key, Inkscape::UI::Widget::Registry* wr,
30                       Effect* effect, const Glib::ustring default_value )
31     : Parameter(label, tip, key, wr, effect),
32       value(default_value),
33       defvalue(default_value)
34 {
35     SPDesktop *desktop = inkscape_active_desktop(); // FIXME: we shouldn't use this!
36     canvas_text = (SPCanvasText *) sp_canvastext_new(sp_desktop_tempgroup(desktop), desktop, Geom::Point(0,0), "");
37     sp_canvastext_set_text (canvas_text, default_value.c_str());
38     sp_canvastext_set_coords (canvas_text, 0, 0);
39 }
41 void
42 TextParam::param_set_default()
43 {
44     param_setValue(defvalue);
45 }
47 void
48 TextParam::setPos(Geom::Point pos)
49 {
50     sp_canvastext_set_coords (canvas_text, pos);
51 }
53 void
54 TextParam::setPosAndAnchor(const Geom::Piecewise<Geom::D2<Geom::SBasis> > &pwd2,
55                            const double t, const double length, bool /*use_curvature*/)
56 {
57     using namespace Geom;
59     Piecewise<D2<SBasis> > pwd2_reparam = arc_length_parametrization(pwd2, 2 , 0.1);
60     double t_reparam = pwd2_reparam.cuts.back() * t;
61     Point pos = pwd2_reparam.valueAt(t_reparam);
62     Point dir = unit_vector(derivative(pwd2_reparam).valueAt(t_reparam));
63     Point n = -rot90(dir);
64     double angle = Geom::angle_between(dir, Point(1,0));
66     sp_canvastext_set_coords(canvas_text, pos + n * length);
67     sp_canvastext_set_anchor(canvas_text, std::sin(angle), -std::cos(angle));
68 }
70 void
71 TextParam::setAnchor(double x_value, double y_value)
72 {
73     anchor_x = x_value;
74     anchor_y = y_value;
75     sp_canvastext_set_anchor (canvas_text, anchor_x, anchor_y);
76 }
78 bool
79 TextParam::param_readSVGValue(const gchar * strvalue)
80 {
81     param_setValue(strvalue);
82     return true;
83 }
85 gchar *
86 TextParam::param_getSVGValue() const
87 {
88     return (gchar *) value.c_str();
89 }
91 Gtk::Widget *
92 TextParam::param_newWidget(Gtk::Tooltips * /*tooltips*/)
93 {
94     Inkscape::UI::Widget::RegisteredText *rsu = Gtk::manage(new Inkscape::UI::Widget::RegisteredText(
95         param_label, param_tooltip, param_key, *param_wr, param_effect->getRepr(), param_effect->getSPDoc()));
97     rsu->setText(value.c_str());
98     rsu->setProgrammatically = false;
100     rsu->set_undo_parameters(SP_VERB_DIALOG_LIVE_PATH_EFFECT, _("Change text parameter"));
102     return dynamic_cast<Gtk::Widget *> (rsu);
105 void
106 TextParam::param_setValue(const Glib::ustring newvalue)
108     value = newvalue;
110     sp_canvastext_set_text (canvas_text, newvalue.c_str());
113 } /* namespace LivePathEffect */
115 } /* namespace Inkscape */
117 /*
118   Local Variables:
119   mode:c++
120   c-file-style:"stroustrup"
121   c-file-offsets:((innamespace . 0)(inline-open . 0)(case-label . +))
122   indent-tabs-mode:nil
123   fill-column:99
124   End:
125 */
126 // vim: filetype=cpp:expandtab:shiftwidth=4:tabstop=8:softtabstop=4 :