1 #define INKSCAPE_LIVEPATHEFFECT_PARAMETER_CPP
3 /*
4 * Copyright (C) Johan Engelen 2007 <j.b.c.engelen@utwente.nl>
5 *
6 * Released under GNU GPL, read the file 'COPYING' for more information
7 */
9 #include "live_effects/parameter/parameter.h"
10 #include "live_effects/effect.h"
11 #include "svg/svg.h"
12 #include "libnr/nr-values.h"
14 #include <gtkmm.h>
15 #include "ui/widget/scalar.h"
17 #include "svg/stringstream.h"
19 #include "verbs.h"
21 #define noLPEREALPARAM_DEBUG
23 namespace Inkscape {
25 namespace LivePathEffect {
28 Parameter::Parameter( const Glib::ustring& label, const Glib::ustring& tip,
29 const Glib::ustring& key, Inkscape::UI::Widget::Registry* wr,
30 Effect* effect )
31 {
32 param_label = label;
33 param_tooltip = tip;
34 param_key = key;
35 param_wr = wr;
36 param_effect = effect;
37 }
41 /*###########################################
42 * REAL PARAM
43 */
44 ScalarParam::ScalarParam( const Glib::ustring& label, const Glib::ustring& tip,
45 const Glib::ustring& key, Inkscape::UI::Widget::Registry* wr,
46 Effect* effect, gdouble default_value)
47 : Parameter(label, tip, key, wr, effect)
48 {
49 defvalue = default_value;
50 value = defvalue;
51 min = -NR_HUGE;
52 max = NR_HUGE;
53 integer = false;
54 rsu = NULL;
55 inc_step = 0.1;
56 inc_page = 1;
57 digits = 2;
58 }
60 ScalarParam::~ScalarParam()
61 {
62 if (rsu)
63 delete rsu;
64 }
66 bool
67 ScalarParam::param_readSVGValue(const gchar * strvalue)
68 {
69 double newval;
70 unsigned int success = sp_svg_number_read_d(strvalue, &newval);
71 if (success == 1) {
72 param_set_value(newval);
73 return true;
74 }
75 return false;
76 }
78 gchar *
79 ScalarParam::param_writeSVGValue() const
80 {
81 Inkscape::SVGOStringStream os;
82 os << value;
83 gchar * str = g_strdup(os.str().c_str());
84 return str;
85 }
87 void
88 ScalarParam::param_set_default()
89 {
90 param_set_value(defvalue);
91 }
93 void
94 ScalarParam::param_set_value(gdouble val)
95 {
96 value = val;
97 if (integer)
98 value = round(value);
99 if (value > max)
100 value = max;
101 if (value < min)
102 value = min;
104 if (rsu && !rsu->is_updating())
105 rsu->setValue(value);
106 }
108 void
109 ScalarParam::param_set_range(gdouble min, gdouble max)
110 {
111 this->min = min;
112 this->max = max;
113 if (rsu)
114 rsu->getS()->setRange(min, max);
116 param_set_value(value); // reset value to see whether it is in ranges
117 }
119 void
120 ScalarParam::param_make_integer(bool yes)
121 {
122 integer = yes;
123 digits = 0;
124 inc_step = 1;
125 inc_page = 10;
126 if (rsu) {
127 rsu->getS()->setDigits(digits);
128 rsu->getS()->setIncrements(inc_step, inc_page);
129 }
130 }
132 Gtk::Widget *
133 ScalarParam::param_getWidget()
134 {
135 if (!rsu) {
136 rsu = new Inkscape::UI::Widget::RegisteredScalar();
137 rsu->init(param_label, param_tooltip, param_key, *param_wr, param_effect->getRepr(), param_effect->getSPDoc());
138 rsu->setValue(value);
139 rsu->getS()->setDigits(digits);
140 rsu->getS()->setIncrements(inc_step, inc_page);
142 rsu->set_undo_parameters(SP_VERB_DIALOG_LIVE_PATH_EFFECT, _("Change scalar parameter"));
143 }
144 return dynamic_cast<Gtk::Widget *> (rsu->getS());
145 }
147 void
148 ScalarParam::param_set_digits(unsigned digits)
149 {
150 this->digits = digits;
151 if (rsu) {
152 rsu->getS()->setDigits(digits);
153 }
154 }
156 void
157 ScalarParam::param_set_increments(double step, double page)
158 {
159 inc_step = step;
160 inc_page = page;
161 if (rsu) {
162 rsu->getS()->setIncrements(inc_step, inc_page);
163 }
164 }
169 } /* namespace LivePathEffect */
170 } /* namespace Inkscape */
172 /*
173 Local Variables:
174 mode:c++
175 c-file-style:"stroustrup"
176 c-file-offsets:((innamespace . 0)(inline-open . 0)(case-label . +))
177 indent-tabs-mode:nil
178 fill-column:99
179 End:
180 */
181 // vim: filetype=cpp:expandtab:shiftwidth=4:tabstop=8:softtabstop=4 :