]> git.tdb.fi Git - libs/gui.git/blob - source/input/device.h
Normalize device axis ranges to [-1, 1]
[libs/gui.git] / source / input / device.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 <string>
12 #include <vector>
13 #include <sigc++/signal.h>
14
15 namespace Msp {
16 namespace Input {
17
18 /**
19 Base class for input devices.  Input devices have two types of controls:
20 buttons and axes.  Buttons are either on or off.  Axes have a floating point
21 value in the range [-1, 1].
22 */
23 class Device
24 {
25 public:
26         sigc::signal<void, unsigned> signal_button_press;
27         sigc::signal<void, unsigned> signal_button_release;
28         sigc::signal<void, unsigned, float, float> signal_axis_motion;
29
30 protected:
31         std::string name;
32         std::vector<char>  buttons;
33         std::vector<float> axes;
34
35         Device() { }
36 public:
37         virtual ~Device() { }
38         const std::string &get_name() const { return name; }
39         bool  get_button_state(unsigned) const;
40         float get_axis_value(unsigned) const;
41
42         virtual std::string get_button_name(unsigned) const;
43         virtual std::string get_axis_name(unsigned) const;
44 protected:
45         void set_button_state(unsigned, bool, bool);
46         void set_axis_value(unsigned, float, bool);
47 };
48
49 } // namespace Input
50 } // namespace Msp
51
52 #endif