]> git.tdb.fi Git - libs/gui.git/blob - source/input/binarycontrol.cpp
Normalize device axis ranges to [-1, 1]
[libs/gui.git] / source / input / binarycontrol.cpp
1 /* $Id$
2
3 This file is part of libmspgbase
4 Copyright © 2007 Mikko Rasa, Mikkosoft Productions
5 Distributed under the LGPL
6 */
7
8 #include "binarycontrol.h"
9 #include "device.h"
10
11 namespace Msp {
12 namespace Input {
13
14 BinaryControl::BinaryControl():
15         state(false),
16         threshold(0.5)
17 { }
18
19 BinaryControl::BinaryControl(const ControlSource &s):
20         Control(s),
21         state(false),
22         threshold(0.5)
23 { }
24
25 BinaryControl::BinaryControl(Device &d, ControlSrcType t, unsigned i):
26         Control(d, t, i),
27         state(false),
28         threshold(0.5)
29 { }
30
31 void BinaryControl::set_threshold(float t)
32 {
33         threshold=t;
34 }
35
36 void BinaryControl::on_press()
37 {
38         if(!state)
39         {
40                 state=true;
41                 signal_press.emit();
42         }
43 }
44
45 void BinaryControl::on_release()
46 {
47         if(state)
48         {
49                 state=false;
50                 signal_release.emit();
51         }
52 }
53
54 void BinaryControl::on_motion(float value, float)
55 {
56         if(value>threshold)
57                 on_press();
58         else
59                 on_release();
60 }
61
62 } // namespace Input
63 } // namespace Msp