Code

RegisteredWidget has been renamed to RegisteredWdg. This is a deprecated class, all...
[inkscape.git] / src / live_effects / parameter / parameter.cpp
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)
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);
114 void
115 ScalarParam::param_set_range(gdouble min, gdouble max)
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
125 void
126 ScalarParam::param_make_integer(bool yes)
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     }
138 Gtk::Widget *
139 ScalarParam::param_newWidget(Gtk::Tooltips * tooltips)
141     // WIDGET TODO: This implementation is incorrect, it should create a *new* widget for the caller, not just return an already created widget
142     g_warning("ScalarParam::param_newWidget still needs recoding to work with multiple document views");
143     if (!rsu) {
144         rsu = new Inkscape::UI::Widget::RegisteredScalar();
145         rsu->init(param_label, param_tooltip, param_key, *param_wr, param_effect->getRepr(), param_effect->getSPDoc());
146         rsu->setValue(value);
147         rsu->getS()->setDigits(digits);
148         rsu->getS()->setIncrements(inc_step, inc_page);
149         rsu->getS()->setRange(min, max);
151         rsu->set_undo_parameters(SP_VERB_DIALOG_LIVE_PATH_EFFECT, _("Change scalar parameter"));
152     }
153     return dynamic_cast<Gtk::Widget *> (rsu->getS());
156 void
157 ScalarParam::param_set_digits(unsigned digits)
159     this->digits = digits;
160     if (rsu) {
161         rsu->getS()->setDigits(digits);
162     }
165 void
166 ScalarParam::param_set_increments(double step, double page)
168     inc_step = step;
169     inc_page = page;
170     if (rsu) {
171         rsu->getS()->setIncrements(inc_step, inc_page);
172     }
178 } /* namespace LivePathEffect */
179 } /* namespace Inkscape */
181 /*
182   Local Variables:
183   mode:c++
184   c-file-style:"stroustrup"
185   c-file-offsets:((innamespace . 0)(inline-open . 0)(case-label . +))
186   indent-tabs-mode:nil
187   fill-column:99
188   End:
189 */
190 // vim: filetype=cpp:expandtab:shiftwidth=4:tabstop=8:softtabstop=4 :