input_device.h
1 /*
2 ** ClanLib SDK
3 ** Copyright (c) 1997-2015 The ClanLib Team
4 **
5 ** This software is provided 'as-is', without any express or implied
6 ** warranty. In no event will the authors be held liable for any damages
7 ** arising from the use of this software.
8 **
9 ** Permission is granted to anyone to use this software for any purpose,
10 ** including commercial applications, and to alter it and redistribute it
11 ** freely, subject to the following restrictions:
12 **
13 ** 1. The origin of this software must not be misrepresented; you must not
14 ** claim that you wrote the original software. If you use this software
15 ** in a product, an acknowledgment in the product documentation would be
16 ** appreciated but is not required.
17 ** 2. Altered source versions must be plainly marked as such, and must not be
18 ** misrepresented as being the original software.
19 ** 3. This notice may not be removed or altered from any source distribution.
20 **
21 ** Note: Some of the libraries ClanLib may link to may have additional
22 ** requirements or restrictions.
23 **
24 ** File Author(s):
25 **
26 ** Magnus Norddahl
27 ** Harry Storbacka
28 */
29
30
31 #pragma once
32
33 #include "../../Core/Signals/signal.h"
34 #include "../../Core/Math/point.h"
35 #include <memory>
36
37 namespace clan
38 {
41
42 class InputEvent;
43 class InputDeviceProvider;
44 class InputDevice_Impl;
45
47 class InputDevice
48 {
49 public:
51 enum Type
52 {
53 keyboard,
54 pointer,
55 joystick,
56 tablet,
57 unknown
58 };
59
62
63 public:
65 InputDevice();
66
70 InputDevice(InputDeviceProvider *provider);
71
75 InputDevice(std::weak_ptr<InputDevice_Impl> impl);
76
77 ~InputDevice();
78
82
83 public:
85 bool is_null() const { return !impl; }
86
88 void throw_if_null() const;
89
91 InputDeviceProvider *get_provider() const;
92
94 std::string get_name() const;
95
97 std::string get_device_name() const;
98
100 Type get_type() const;
101
104 // should only be used to display the name of the key to the user
105 // and not as a key identifier inside key binding configuration
106 // files and such.
107 std::string get_key_name(int id) const;
108
110 std::string keyid_to_string(int keycode) const;
111
113 int string_to_keyid(const std::string &str) const;
114
117 bool get_keycode(int keycode) const;
118
121 Pointf get_position() const;
122
125 Point get_device_position() const;
126
128 float get_axis(int axisid) const;
129
131 std::vector<int> get_axis_ids() const;
132
135 int get_hat(int index) const;
136
139 int get_button_count() const;
140
142 bool in_proximity() const;
143
147
148 public:
149 InputDevice &operator =(const InputDevice &copy);
150
152 void set_position(float x, float y);
153
155 void set_device_position(int x, int y);
156
160
161 public:
163 Signal<void(const InputEvent &)> &sig_key_down();
164
166 Signal<void(const InputEvent &)> &sig_key_up();
167
169 Signal<void(const InputEvent &)> &sig_pointer_move();
170
172 Signal<void(const InputEvent &)> &sig_axis_move();
173
175 Signal<void(const InputEvent &)> &sig_key_dblclk();
176
178 Signal<void(const InputEvent &)> &sig_proximity_change();
179
183
184 private:
185 std::shared_ptr<InputDevice_Impl> impl;
186
187 friend class InputContext_Impl;
189 };
190
191 }
192
clan
Definition: clanapp.h:35
clan::InputDevice::~InputDevice
~InputDevice()
clan::InputDevice::Type
Type
Input device types.
Definition: input_device.h:51
clan::InputDevice::get_type
Type get_type() const
Returns the input device type.
clan::InputDevice::sig_axis_move
Signal< void(const InputEvent &)> & sig_axis_move()
Signal emitted when axis is moved.
clan::InputDevice::set_position
void set_position(float x, float y)
Sets the display-independent position of the device. (Pointing devices only)
clan::Key::x
clan::InputDevice::sig_key_down
Signal< void(const InputEvent &)> & sig_key_down()
Signal emitted when key is pressed.
clan::InputDevice::keyid_to_string
std::string keyid_to_string(int keycode) const
Returns a generic string name for the specified key code.
clan::InputDevice::get_device_name
std::string get_device_name() const
Return the hardware id/device for this device (i.e. /dev/input/js0)
clan::InputDevice::InputDevice
InputDevice()
Constructs a null instance.
clan::InputDevice::in_proximity
bool in_proximity() const
Returns true if the input device is in proximity mode. (Tablets only)
clan::InputDevice::throw_if_null
void throw_if_null() const
Throw an exception if this object is invalid.
clan::InputDevice::get_axis
float get_axis(int axisid) const
Returns the the current position of a joystick axis. (Joysticks only)
clan::InputDevice
InputDevice.
Definition: input_device.h:47
clan::StyleTokenType::string
@ keyword
clan::InputDevice::get_provider
InputDeviceProvider * get_provider() const
Returns the provider for this input device.
clan::InputDevice::sig_key_dblclk
Signal< void(const InputEvent &)> & sig_key_dblclk()
Signal emitted when the mouse is double-clicked.
clan::Key::y
clan::InputDevice::get_hat
int get_hat(int index) const
Returns the current position of a joystick hat. (Joysticks only)
clan::InputDeviceProvider
Interface for implementing a InputDevice source.
Definition: input_device_provider.h:44
clan::InputDevice::unknown
Definition: input_device.h:57
clan::InputDevice::string_to_keyid
int string_to_keyid(const std::string &str) const
Returns the key code for the specified generic string key name.
clan::Signal
Definition: signal.h:104
clan::InputDevice::InputContext_Impl
friend class InputContext_Impl
Definition: input_device.h:187
clan::InputDevice::set_device_position
void set_device_position(int x, int y)
Sets the actual position of the device. (Pointing devices only)
clan::InputDevice::get_device_position
Point get_device_position() const
Returns the current devicesice-supplied x and y position of the device. (Pointing devices only) The r...
clan::InputDevice::operator=
InputDevice & operator=(const InputDevice &copy)
clan::InputDevice::get_keycode
bool get_keycode(int keycode) const
Returns true if the passed key code is down for this device. See keys.h for list of key codes...
clan::Point
2D (x,y) point structure - Integer
Definition: point.h:62
clan::InputDevice::sig_proximity_change
Signal< void(const InputEvent &)> & sig_proximity_change()
Signal emitted when proximity is entered or exited.
clan::InputDevice::keyboard
Definition: input_device.h:53
clan::InputDevice::get_key_name
std::string get_key_name(int id) const
Retrieves the localized friendly key name for specified identifier (i.e. A, B, Leertaste, Backspace, Mouse Left, ...).
clan::InputDevice::sig_key_up
Signal< void(const InputEvent &)> & sig_key_up()
Signal emitted when key is released.
clan::InputDevice::get_axis_ids
std::vector< int > get_axis_ids() const
Returns the number of axes available on this device. (Joysticks only)
clan::InputDevice::sig_pointer_move
Signal< void(const InputEvent &)> & sig_pointer_move()
Signal emitted when pointer is moved (absolute movement).
clan::InputDevice::get_button_count
int get_button_count() const
Returns the number of buttons available on this device. If used on a keyboard or mouse...
clan::Pointf
2D (x,y) point structure - Float
Definition: point.h:72
clan::InputDevice::tablet
Definition: input_device.h:56
clan::InputDevice::joystick
Definition: input_device.h:55
clan::InputDevice::get_position
Pointf get_position() const
Returns the current device-independent x and y position (DIP) of the device. (Pointing devices only) ...
clan::InputDevice::is_null
bool is_null() const
Returns true if this object is invalid.
Definition: input_device.h:85
clan::InputDevice::get_name
std::string get_name() const
Returns the human readable name of the device (i.e. 'Microsoft Sidewinder 3D').
clan::InputDevice::pointer
Definition: input_device.h:54