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 canvas_text = (SPCanvasText *) sp_canvastext_new(sp_desktop_tempgroup(inkscape_active_desktop()), Geom::Point(0,0), "");
35 sp_canvastext_set_text (canvas_text, default_value.c_str());
36 sp_canvastext_set_coords (canvas_text, 0, 0);
37 }
39 void
40 TextParam::param_set_default()
41 {
42 param_setValue(defvalue);
43 }
45 void
46 TextParam::setPos(Geom::Point pos)
47 {
48 sp_canvastext_set_coords (canvas_text, pos);
49 }
51 void
52 TextParam::setAnchor(double x_value, double y_value)
53 {
54 anchor_x = x_value;
55 anchor_y = y_value;
56 sp_canvastext_set_anchor (canvas_text, anchor_x, anchor_y);
57 }
59 bool
60 TextParam::param_readSVGValue(const gchar * strvalue)
61 {
62 param_setValue(strvalue);
63 return true;
64 }
66 gchar *
67 TextParam::param_getSVGValue() const
68 {
69 return (gchar *) value.c_str();
70 }
72 Gtk::Widget *
73 TextParam::param_newWidget(Gtk::Tooltips * /*tooltips*/)
74 {
75 Inkscape::UI::Widget::RegisteredText *rsu = Gtk::manage(new Inkscape::UI::Widget::RegisteredText(
76 param_label, param_tooltip, param_key, *param_wr, param_effect->getRepr(), param_effect->getSPDoc()));
78 rsu->setText(value.c_str());
79 rsu->setProgrammatically = false;
81 rsu->set_undo_parameters(SP_VERB_DIALOG_LIVE_PATH_EFFECT, _("Change text parameter"));
83 return dynamic_cast<Gtk::Widget *> (rsu);
84 }
86 void
87 TextParam::param_setValue(const Glib::ustring newvalue)
88 {
89 value = newvalue;
91 sp_canvastext_set_text (canvas_text, newvalue.c_str());
92 }
94 } /* namespace LivePathEffect */
96 } /* namespace Inkscape */
98 /*
99 Local Variables:
100 mode:c++
101 c-file-style:"stroustrup"
102 c-file-offsets:((innamespace . 0)(inline-open . 0)(case-label . +))
103 indent-tabs-mode:nil
104 fill-column:99
105 End:
106 */
107 // vim: filetype=cpp:expandtab:shiftwidth=4:tabstop=8:softtabstop=4 :