]> git.tdb.fi Git - libs/gui.git/blob - source/control.h
Set override_redirect attribute when fullscreen is requested
[libs/gui.git] / source / 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 };
40
41 /**
42 Provides further abstraction on top of input devices.  There are two types of
43 controls currently defined: BinaryControl and SmoothControl.
44
45 A control uses either a button or half of an axis (positive or negative) as its
46 source.  How the source values are interpreted depends on the exact type of the
47 control.  Controls also support interactive binding by capturing a button press
48 or axis motion.
49 */
50 class Control: public sigc::trackable
51 {
52 public:
53         sigc::signal<void> signal_capture_complete;
54
55 protected:
56         ControlSource src;
57         Device *capture_dev;
58
59         Control();
60         Control(const ControlSource &);
61         Control(Device &, ControlSrcType, unsigned);
62         Control(const Control &);
63 public:
64         Control &operator=(const Control &);
65         virtual ~Control() { }
66
67         void capture(Device &);
68         void cancel_capture();
69         const ControlSource &get_source() const { return src; }
70 protected:
71         virtual void on_press() =0;
72         virtual void on_release() =0;
73         virtual void on_motion(float, float) =0;
74
75 private:
76         void connect_signals();
77         void button_press(unsigned);
78         void button_release(unsigned);
79         void axis_motion(unsigned, float, float);
80 };
81
82 } // namespace Input
83 } // namespace Msp
84
85 #endif