]> git.tdb.fi Git - libs/gui.git/blob - source/inputdevice.h
Add a control layer suitable for games
[libs/gui.git] / source / inputdevice.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_INPUTDEVICE_H_
9 #define MSP_GBASE_INPUTDEVICE_H_
10
11 #include <vector>
12 #include <sigc++/signal.h>
13
14 namespace Msp {
15 namespace Input {
16
17 /**
18 Base class for input devices.  Input devices have two types of controls:
19 buttons and axes.  Buttons are either on or off.  Axes have a floating-point
20 value, with range depending on the device.
21 */
22 class Device
23 {
24 public:
25         sigc::signal<void, unsigned> signal_button_press;
26         sigc::signal<void, unsigned> signal_button_release;
27         sigc::signal<void, unsigned, float, float> signal_axis_motion;
28
29 protected:
30         std::vector<char>  buttons;
31         std::vector<float> axes;
32         float axis_threshold;
33         float axis_dead_zone;
34
35         Device() { }
36 public:
37         virtual ~Device() { }
38         bool  get_button_state(unsigned) const;
39         float get_axis_value(unsigned) const;
40         float get_axis_threshold() const { return axis_threshold; }
41 protected:
42         void set_button_state(unsigned, bool, bool);
43         void set_axis_value(unsigned, float, bool);
44 };
45
46 } // namespace Input
47 } // namespace Msp
48
49 #endif