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