]> git.tdb.fi Git - libs/gui.git/blob - source/input/control.h
e5679639cf49eabefc9429c1fc83ab32618c60d8
[libs/gui.git] / source / input / control.h
1 #ifndef MSP_INPUT_CONTROL_H_
2 #define MSP_INPUT_CONTROL_H_
3
4 #include <string>
5 #include <sigc++/signal.h>
6 #include <sigc++/trackable.h>
7
8 namespace Msp {
9 namespace Input {
10
11 class Device;
12
13 enum ControlSrcType
14 {
15         NONE,
16         BUTTON,
17         AXIS_POS,
18         AXIS_NEG
19 };
20
21 /**
22 Specifies the source of a control.  This provides a way for setting sources for
23 different types of controls in a uniform way.
24 */
25 struct ControlSource
26 {
27         Device *dev;
28         ControlSrcType type;
29         unsigned index;
30
31         ControlSource();
32         ControlSource(Device &, ControlSrcType, unsigned);
33         std::string str() const;
34 };
35
36 /**
37 Provides further abstraction on top of input devices.  There are two types of
38 controls currently defined: BinaryControl and SmoothControl.
39
40 A control uses either a button or half of an axis (positive or negative) as its
41 source.  How the source values are interpreted depends on the exact type of the
42 control.  Controls also support interactive binding by capturing a button press
43 or axis motion.
44 */
45 class Control: public sigc::trackable
46 {
47 public:
48         sigc::signal<void> signal_capture_complete;
49
50 protected:
51         ControlSource src;
52         Device *capture_dev;
53
54         Control();
55         Control(const ControlSource &);
56         Control(Device &, ControlSrcType, unsigned);
57 public:
58         virtual ~Control();
59
60         void capture(Device &);
61         void cancel_capture();
62         void set_source(Device &, ControlSrcType, unsigned);
63         void set_source(const ControlSource &);
64         const ControlSource &get_source() const { return src; }
65 protected:
66         virtual void on_press() = 0;
67         virtual void on_release() = 0;
68         virtual void on_motion(float, float) = 0;
69
70 private:
71         void connect_signals();
72         void button_press(unsigned);
73         void button_release(unsigned);
74         void axis_motion(unsigned, float, float);
75
76         Control(const Control &);
77         Control &operator=(const Control &);
78 };
79
80 } // namespace Input
81 } // namespace Msp
82
83 #endif