]> git.tdb.fi Git - libs/gltk.git/blob - source/slider.cpp
Support loading Panels from datafiles
[libs/gltk.git] / source / slider.cpp
1 #include "slider.h"
2
3 namespace Msp {
4 namespace GLtk {
5
6 Slider::Slider(const Resources &r):
7         Widget(r),
8         min(0),
9         max(1),
10         value(0),
11         step(0.1)
12 { }
13
14 void Slider::set_range(double a, double b)
15 {
16         min=a;
17         max=b;
18         set_value(value);
19 }
20
21 void Slider::set_step(double s)
22 {
23         step=s;
24         set_value(value);
25 }
26
27 void Slider::set_value(double v)
28 {
29         double old_value=value;
30
31         if(v<min)
32                 value=min;
33         else if(v>max)
34                 value=max;
35         else
36         {
37                 unsigned steps=static_cast<unsigned>((v-min)/step+0.5);
38                 value=min+steps*step;
39         }
40
41         if(value!=old_value)
42                 signal_value_changed.emit(value);
43 }
44
45 } // namespace GLtk
46 } // namespace Msp