Code

3b69c9ef5f964fd76527eb404fce5dee6ef00d8a
[inkscape.git] / 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"
23 namespace Inkscape {
25 namespace LivePathEffect {
27 TextParam::TextParam( const Glib::ustring& label, const Glib::ustring& tip,
28                       const Glib::ustring& key, Inkscape::UI::Widget::Registry* wr,
29                       Effect* effect, const Glib::ustring default_value )
30     : Parameter(label, tip, key, wr, effect),
31       defvalue(default_value)
32 {
33     canvas_text = (SPCanvasText *) sp_canvastext_new(sp_desktop_tempgroup(inkscape_active_desktop()), Geom::Point(0,0), "");
34     sp_canvastext_set_text (canvas_text, default_value.c_str());
35     sp_canvastext_set_coords (canvas_text, 0, 0);
36 }
38 TextParam::~TextParam()
39 {
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::setAnchor(double x_value, double y_value)
56 {
57     anchor_x = x_value;
58     anchor_y = y_value;
59     sp_canvastext_set_anchor (canvas_text, anchor_x, anchor_y);
60 }
62 bool
63 TextParam::param_readSVGValue(const gchar * strvalue)
64 {
65     param_setValue(strvalue);
66     return true;
67 }
69 gchar *
70 TextParam::param_getSVGValue() const
71 {
72     return (gchar *) defvalue.c_str();
73 }
75 Gtk::Widget *
76 TextParam::param_newWidget(Gtk::Tooltips * /*tooltips*/)
77 {
78     Inkscape::UI::Widget::RegisteredText *rsu = Gtk::manage(new Inkscape::UI::Widget::RegisteredText(
79         param_label, param_tooltip, param_key, *param_wr, param_effect->getRepr(), param_effect->getSPDoc()));
81     rsu->setText("");
82     rsu->setProgrammatically = false;
84     rsu->set_undo_parameters(SP_VERB_DIALOG_LIVE_PATH_EFFECT, _("Change text parameter"));
86     return dynamic_cast<Gtk::Widget *> (rsu);
87 }
89 void
90 TextParam::param_setValue(const Glib::ustring newvalue)
91 {
92     defvalue = newvalue;
94     sp_canvastext_set_text (canvas_text, newvalue.c_str());
95 }
97 } /* namespace LivePathEffect */
99 } /* namespace Inkscape */
101 /*
102   Local Variables:
103   mode:c++
104   c-file-style:"stroustrup"
105   c-file-offsets:((innamespace . 0)(inline-open . 0)(case-label . +))
106   indent-tabs-mode:nil
107   fill-column:99
108   End:
109 */
110 // vim: filetype=cpp:expandtab:shiftwidth=4:tabstop=8:softtabstop=4 :