a0ce04487494c14d449824b64a27cd2a1f5fdffc
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 inc_step = 0.1;
61 inc_page = 1;
62 digits = 2;
63 }
65 ScalarParam::~ScalarParam()
66 {
67 }
69 bool
70 ScalarParam::param_readSVGValue(const gchar * strvalue)
71 {
72 double newval;
73 unsigned int success = sp_svg_number_read_d(strvalue, &newval);
74 if (success == 1) {
75 param_set_value(newval);
76 return true;
77 }
78 return false;
79 }
81 gchar *
82 ScalarParam::param_writeSVGValue() const
83 {
84 Inkscape::SVGOStringStream os;
85 os << value;
86 gchar * str = g_strdup(os.str().c_str());
87 return str;
88 }
90 void
91 ScalarParam::param_set_default()
92 {
93 param_set_value(defvalue);
94 }
96 void
97 ScalarParam::param_set_value(gdouble val)
98 {
99 value = val;
100 if (integer)
101 value = round(value);
102 if (value > max)
103 value = max;
104 if (value < min)
105 value = min;
106 }
108 void
109 ScalarParam::param_set_range(gdouble min, gdouble max)
110 {
111 this->min = min;
112 this->max = max;
114 param_set_value(value); // reset value to see whether it is in ranges
115 }
117 void
118 ScalarParam::param_make_integer(bool yes)
119 {
120 integer = yes;
121 digits = 0;
122 inc_step = 1;
123 inc_page = 10;
124 }
126 Gtk::Widget *
127 ScalarParam::param_newWidget(Gtk::Tooltips * tooltips)
128 {
129 Inkscape::UI::Widget::RegisteredScalar *rsu = Gtk::manage( new Inkscape::UI::Widget::RegisteredScalar(
130 param_label, param_tooltip, param_key, *param_wr, param_effect->getRepr(), param_effect->getSPDoc() ) );
132 rsu->setValue(value);
133 rsu->setDigits(digits);
134 rsu->setIncrements(inc_step, inc_page);
135 rsu->setRange(min, max);
136 rsu->setProgrammatically = false;
138 rsu->set_undo_parameters(SP_VERB_DIALOG_LIVE_PATH_EFFECT, _("Change scalar parameter"));
140 return dynamic_cast<Gtk::Widget *> (rsu);
141 }
143 void
144 ScalarParam::param_set_digits(unsigned digits)
145 {
146 this->digits = digits;
147 }
149 void
150 ScalarParam::param_set_increments(double step, double page)
151 {
152 inc_step = step;
153 inc_page = page;
154 }
159 } /* namespace LivePathEffect */
160 } /* namespace Inkscape */
162 /*
163 Local Variables:
164 mode:c++
165 c-file-style:"stroustrup"
166 c-file-offsets:((innamespace . 0)(inline-open . 0)(case-label . +))
167 indent-tabs-mode:nil
168 fill-column:99
169 End:
170 */
171 // vim: filetype=cpp:expandtab:shiftwidth=4:tabstop=8:softtabstop=4 :