]> git.tdb.fi Git - libs/gui.git/blob - source/input/device.h
Reorganize files to separate gbase and input
[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, with range depending on the device.
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         float axis_threshold;
35         float axis_dead_zone;
36
37         Device() { }
38 public:
39         virtual ~Device() { }
40         const std::string &get_name() const { return name; }
41         bool  get_button_state(unsigned) const;
42         float get_axis_value(unsigned) const;
43         float get_axis_threshold() const { return axis_threshold; }
44
45         virtual std::string get_button_name(unsigned) const;
46         virtual std::string get_axis_name(unsigned) const;
47 protected:
48         void set_button_state(unsigned, bool, bool);
49         void set_axis_value(unsigned, float, bool);
50 };
51
52 } // namespace Input
53 } // namespace Msp
54
55 #endif