]> git.tdb.fi Git - libs/gui.git/blob - source/input/binarycontrol.h
0d71bdc3349e0dc4afedf3a5a9423528ca82977a
[libs/gui.git] / source / input / binarycontrol.h
1 #ifndef MSP_INPUT_BINARYCONTROL_H_
2 #define MSP_INPUT_BINARYCONTROL_H_
3
4 #include "control.h"
5
6 namespace Msp {
7 namespace Input {
8
9 /**
10 A control with two possible states.  Button state is mapped directly.  An axis
11 is considered to be active when its value is above a threshold (0.5 by
12 default).
13 */
14 class BinaryControl: public Control
15 {
16 public:
17         sigc::signal<void> signal_press;
18         sigc::signal<void> signal_release;
19
20 private:
21         bool state = false;
22         float threshold = 0.5f;
23
24 public:
25         BinaryControl() = default;
26         BinaryControl(const ControlSource &);
27         BinaryControl(Device &, ControlSrcType, unsigned);
28         ~BinaryControl();
29
30         /** Sets the threshold between states for axis sources.  No effect on button
31         sources */
32         void set_threshold(float);
33
34         bool get_state() const { return state; }
35         bool was_pressed() const { return rising_edge; }
36         bool was_released() const { return falling_edge; }
37
38 private:
39         void on_press() override;
40         void on_release() override;
41         void on_motion(float, float) override;
42 };
43
44 } // namespace Input
45 } // namespace Msp
46
47 #endif