Code

Warning cleanup
[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"
13 #include "xml/repr.h"
14 #include <gtkmm.h>
15 #include "ui/widget/registered-widget.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     : param_key(key),
32       param_wr(wr),
33       param_label(label),
34       oncanvas_editable(false),
35       widget_is_visible(true),
36       param_tooltip(tip),
37       param_effect(effect)
38 {
39 }
42 void
43 Parameter::param_write_to_repr(const char * svgd)
44 {
45     param_effect->getRepr()->setAttribute(param_key.c_str(), svgd);
46 }
48 /*###########################################
49  *   REAL PARAM
50  */
51 ScalarParam::ScalarParam( const Glib::ustring& label, const Glib::ustring& tip,
52                       const Glib::ustring& key, Inkscape::UI::Widget::Registry* wr,
53                       Effect* effect, gdouble default_value)
54     : Parameter(label, tip, key, wr, effect),
55       value(default_value),
56       min(-NR_HUGE),
57       max(NR_HUGE),
58       integer(false),
59       defvalue(default_value),
60       digits(2),
61       inc_step(0.1),
62       inc_page(1)
63 {
64 }
66 ScalarParam::~ScalarParam()
67 {
68 }
70 bool
71 ScalarParam::param_readSVGValue(const gchar * strvalue)
72 {
73     double newval;
74     unsigned int success = sp_svg_number_read_d(strvalue, &newval);
75     if (success == 1) {
76         param_set_value(newval);
77         return true;
78     }
79     return false;
80 }
82 gchar *
83 ScalarParam::param_getSVGValue() const
84 {
85     Inkscape::SVGOStringStream os;
86     os << value;
87     gchar * str = g_strdup(os.str().c_str());
88     return str;
89 }
91 void
92 ScalarParam::param_set_default()
93 {
94     param_set_value(defvalue);
95 }
97 void
98 ScalarParam::param_set_value(gdouble val)
99 {
100     value = val;
101     if (integer)
102         value = round(value);
103     if (value > max)
104         value = max;
105     if (value < min)
106         value = min;
109 void
110 ScalarParam::param_set_range(gdouble min, gdouble max)
112     this->min = min;
113     this->max = max;
115     param_set_value(value); // reset value to see whether it is in ranges
118 void
119 ScalarParam::param_make_integer(bool yes)
121     integer = yes;
122     digits = 0;
123     inc_step = 1;
124     inc_page = 10;
127 Gtk::Widget *
128 ScalarParam::param_newWidget(Gtk::Tooltips * /*tooltips*/)
130     Inkscape::UI::Widget::RegisteredScalar *rsu = Gtk::manage( new Inkscape::UI::Widget::RegisteredScalar(
131         param_label, param_tooltip, param_key, *param_wr, param_effect->getRepr(), param_effect->getSPDoc() ) );
133     rsu->setValue(value);
134     rsu->setDigits(digits);
135     rsu->setIncrements(inc_step, inc_page);
136     rsu->setRange(min, max);
137     rsu->setProgrammatically = false;
139     rsu->set_undo_parameters(SP_VERB_DIALOG_LIVE_PATH_EFFECT, _("Change scalar parameter"));
141     return dynamic_cast<Gtk::Widget *> (rsu);
144 void
145 ScalarParam::param_set_digits(unsigned digits)
147     this->digits = digits;
150 void
151 ScalarParam::param_set_increments(double step, double page)
153     inc_step = step;
154     inc_page = page;
160 } /* namespace LivePathEffect */
161 } /* namespace Inkscape */
163 /*
164   Local Variables:
165   mode:c++
166   c-file-style:"stroustrup"
167   c-file-offsets:((innamespace . 0)(inline-open . 0)(case-label . +))
168   indent-tabs-mode:nil
169   fill-column:99
170   End:
171 */
172 // vim: filetype=cpp:expandtab:shiftwidth=4:tabstop=8:softtabstop=4 :