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 value(default_value),
32 defvalue(default_value)
33 {
34 SPDesktop *desktop = inkscape_active_desktop(); // FIXME: we shouldn't use this!
35 canvas_text = (SPCanvasText *) sp_canvastext_new(sp_desktop_tempgroup(desktop), desktop, Geom::Point(0,0), "");
36 sp_canvastext_set_text (canvas_text, default_value.c_str());
37 sp_canvastext_set_coords (canvas_text, 0, 0);
38 }
40 void
41 TextParam::param_set_default()
42 {
43 param_setValue(defvalue);
44 }
46 void
47 TextParam::setPos(Geom::Point pos)
48 {
49 sp_canvastext_set_coords (canvas_text, pos);
50 }
52 void
53 TextParam::setAnchor(double x_value, double y_value)
54 {
55 anchor_x = x_value;
56 anchor_y = y_value;
57 sp_canvastext_set_anchor (canvas_text, anchor_x, anchor_y);
58 }
60 bool
61 TextParam::param_readSVGValue(const gchar * strvalue)
62 {
63 param_setValue(strvalue);
64 return true;
65 }
67 gchar *
68 TextParam::param_getSVGValue() const
69 {
70 return (gchar *) value.c_str();
71 }
73 Gtk::Widget *
74 TextParam::param_newWidget(Gtk::Tooltips * /*tooltips*/)
75 {
76 Inkscape::UI::Widget::RegisteredText *rsu = Gtk::manage(new Inkscape::UI::Widget::RegisteredText(
77 param_label, param_tooltip, param_key, *param_wr, param_effect->getRepr(), param_effect->getSPDoc()));
79 rsu->setText(value.c_str());
80 rsu->setProgrammatically = false;
82 rsu->set_undo_parameters(SP_VERB_DIALOG_LIVE_PATH_EFFECT, _("Change text parameter"));
84 return dynamic_cast<Gtk::Widget *> (rsu);
85 }
87 void
88 TextParam::param_setValue(const Glib::ustring newvalue)
89 {
90 value = newvalue;
92 sp_canvastext_set_text (canvas_text, newvalue.c_str());
93 }
95 } /* namespace LivePathEffect */
97 } /* namespace Inkscape */
99 /*
100 Local Variables:
101 mode:c++
102 c-file-style:"stroustrup"
103 c-file-offsets:((innamespace . 0)(inline-open . 0)(case-label . +))
104 indent-tabs-mode:nil
105 fill-column:99
106 End:
107 */
108 // vim: filetype=cpp:expandtab:shiftwidth=4:tabstop=8:softtabstop=4 :