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