893f0d7f1c88478e4833ad85f311f52c7a9d5200
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 : oncanvas_editable(false)
32 {
33 param_label = label;
34 param_tooltip = tip;
35 param_key = key;
36 param_wr = wr;
37 param_effect = effect;
38 }
41 void
42 Parameter::param_write_to_repr(const char * svgd)
43 {
44 param_effect->getRepr()->setAttribute(param_key.c_str(), svgd);
45 }
47 /*###########################################
48 * REAL PARAM
49 */
50 ScalarParam::ScalarParam( const Glib::ustring& label, const Glib::ustring& tip,
51 const Glib::ustring& key, Inkscape::UI::Widget::Registry* wr,
52 Effect* effect, gdouble default_value)
53 : Parameter(label, tip, key, wr, effect)
54 {
55 defvalue = default_value;
56 value = defvalue;
57 min = -NR_HUGE;
58 max = NR_HUGE;
59 integer = false;
60 rsu = NULL;
61 inc_step = 0.1;
62 inc_page = 1;
63 digits = 2;
64 }
66 ScalarParam::~ScalarParam()
67 {
68 if (rsu)
69 delete rsu;
70 }
72 bool
73 ScalarParam::param_readSVGValue(const gchar * strvalue)
74 {
75 double newval;
76 unsigned int success = sp_svg_number_read_d(strvalue, &newval);
77 if (success == 1) {
78 param_set_value(newval);
79 return true;
80 }
81 return false;
82 }
84 gchar *
85 ScalarParam::param_writeSVGValue() const
86 {
87 Inkscape::SVGOStringStream os;
88 os << value;
89 gchar * str = g_strdup(os.str().c_str());
90 return str;
91 }
93 void
94 ScalarParam::param_set_default()
95 {
96 param_set_value(defvalue);
97 }
99 void
100 ScalarParam::param_set_value(gdouble val)
101 {
102 value = val;
103 if (integer)
104 value = round(value);
105 if (value > max)
106 value = max;
107 if (value < min)
108 value = min;
110 if (rsu && !rsu->is_updating())
111 rsu->setValue(value);
112 }
114 void
115 ScalarParam::param_set_range(gdouble min, gdouble max)
116 {
117 this->min = min;
118 this->max = max;
119 if (rsu)
120 rsu->getS()->setRange(this->min, this->max);
122 param_set_value(value); // reset value to see whether it is in ranges
123 }
125 void
126 ScalarParam::param_make_integer(bool yes)
127 {
128 integer = yes;
129 digits = 0;
130 inc_step = 1;
131 inc_page = 10;
132 if (rsu) {
133 rsu->getS()->setDigits(digits);
134 rsu->getS()->setIncrements(inc_step, inc_page);
135 }
136 }
138 Gtk::Widget *
139 ScalarParam::param_getWidget()
140 {
141 if (!rsu) {
142 rsu = new Inkscape::UI::Widget::RegisteredScalar();
143 rsu->init(param_label, param_tooltip, param_key, *param_wr, param_effect->getRepr(), param_effect->getSPDoc());
144 rsu->setValue(value);
145 rsu->getS()->setDigits(digits);
146 rsu->getS()->setIncrements(inc_step, inc_page);
147 rsu->getS()->setRange(min, max);
149 rsu->set_undo_parameters(SP_VERB_DIALOG_LIVE_PATH_EFFECT, _("Change scalar parameter"));
150 }
151 return dynamic_cast<Gtk::Widget *> (rsu->getS());
152 }
154 void
155 ScalarParam::param_set_digits(unsigned digits)
156 {
157 this->digits = digits;
158 if (rsu) {
159 rsu->getS()->setDigits(digits);
160 }
161 }
163 void
164 ScalarParam::param_set_increments(double step, double page)
165 {
166 inc_step = step;
167 inc_page = page;
168 if (rsu) {
169 rsu->getS()->setIncrements(inc_step, inc_page);
170 }
171 }
176 } /* namespace LivePathEffect */
177 } /* namespace Inkscape */
179 /*
180 Local Variables:
181 mode:c++
182 c-file-style:"stroustrup"
183 c-file-offsets:((innamespace . 0)(inline-open . 0)(case-label . +))
184 indent-tabs-mode:nil
185 fill-column:99
186 End:
187 */
188 // vim: filetype=cpp:expandtab:shiftwidth=4:tabstop=8:softtabstop=4 :