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