]> git.tdb.fi Git - libs/gui.git/blob - source/input/binarycontrol.cpp
Update .gitignore to include build products on Windows
[libs/gui.git] / source / input / binarycontrol.cpp
1 #include "binarycontrol.h"
2 #include "device.h"
3
4 namespace Msp {
5 namespace Input {
6
7 BinaryControl::BinaryControl():
8         state(false),
9         threshold(0.5)
10 { }
11
12 BinaryControl::BinaryControl(const ControlSource &s):
13         Control(s),
14         state(false),
15         threshold(0.5)
16 { }
17
18 BinaryControl::BinaryControl(Device &d, ControlSrcType t, unsigned i):
19         Control(d, t, i),
20         state(false),
21         threshold(0.5)
22 { }
23
24 BinaryControl::~BinaryControl()
25 { }
26
27 void BinaryControl::set_threshold(float t)
28 {
29         threshold = t;
30 }
31
32 void BinaryControl::on_press()
33 {
34         if(!state)
35         {
36                 state = true;
37                 signal_press.emit();
38         }
39 }
40
41 void BinaryControl::on_release()
42 {
43         if(state)
44         {
45                 state = false;
46                 signal_release.emit();
47         }
48 }
49
50 void BinaryControl::on_motion(float value, float)
51 {
52         if(value>threshold)
53                 on_press();
54         else
55                 on_release();
56 }
57
58 } // namespace Input
59 } // namespace Msp