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