]> git.tdb.fi Git - libs/gui.git/blob - source/input/smoothcontrol.h
78edbb3acd64a73b26a4ee9391c9b855b3ae5003
[libs/gui.git] / source / input / smoothcontrol.h
1 #ifndef MSP_INPUT_SMOOTHCONTROL_H_
2 #define MSP_INPUT_SMOOTHCONTROL_H_
3
4 #include "control.h"
5
6 namespace Msp {
7 namespace Input {
8
9 /**
10 A control with a continuous range of values.  A button is treated as either 1
11 or 0.  Axis values are mapped to absolute value.
12
13 Two smooth controls can also be paired to each other.  Motion on one control of
14 the pair will cause negative motion on the other.  This works best when the
15 controls are bound to the opposite sides of the same axis.
16 */
17 class SmoothControl: public Control
18 {
19 public:
20         sigc::signal<void, float> signal_motion;
21
22 private:
23         float value;
24         SmoothControl *paired_ctrl;
25         float dead_zone;
26         float threshold;
27
28 public:
29         SmoothControl();
30         SmoothControl(const ControlSource &);
31         SmoothControl(Device &, ControlSrcType, unsigned);
32         virtual ~SmoothControl();
33
34         /// Sets the dead zone value.  Any value below this will be treated as 0.
35         void set_dead_zone(float);
36
37         /// Sets the max-out threshold.  Any value above this will be treated as 1.
38         void set_threshold(float);
39
40         void pair(SmoothControl *ctrl);
41         float get_value() const { return value; }
42
43 private:
44         virtual void on_press();
45         virtual void on_release();
46         virtual void on_motion(float, float);
47 };
48
49 } // namespace Input
50 } // namespace Msp
51
52 #endif