input_device.h
1/*
2** ClanLib SDK
3** Copyright (c) 1997-2020 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#pragma once
31
32#include "../../Core/Signals/signal.h"
33#include "../../Core/Math/point.h"
34#include <memory>
35
36namespace clan
37{
40
41 class InputEvent;
43 class InputDevice_Impl;
44
47 {
48 public:
57
60
65
69 InputDevice(std::weak_ptr<InputDevice_Impl> impl);
70
72
74 bool is_null() const { return !impl; }
75 explicit operator bool() const { return bool(impl); }
76
78 void throw_if_null() const;
79
82
84 std::string get_name() const;
85
87 std::string get_device_name() const;
88
90 Type get_type() const;
91
94 // should only be used to display the name of the key to the user
95 // and not as a key identifier inside key binding configuration
96 // files and such.
97 std::string get_key_name(int id) const;
98
100 std::string keyid_to_string(int keycode) const;
101
103 int string_to_keyid(const std::string &str) const;
104
107 bool get_keycode(int keycode) const;
108
112
116
118 float get_axis(int axisid) const;
119
121 std::vector<int> get_axis_ids() const;
122
125 int get_hat(int index) const;
126
129 int get_button_count() const;
130
132
134 void set_position(float x, float y);
135
137 void set_device_position(int x, int y);
138
140 Signal<void(const InputEvent &)> &sig_key_down();
141
143 Signal<void(const InputEvent &)> &sig_key_up();
144
147
149 Signal<void(const InputEvent &)> &sig_axis_move();
150
153
156
157 private:
158 std::shared_ptr<InputDevice_Impl> impl;
159 };
160
162}
Interface for implementing a InputDevice source.
Definition input_device_provider.h:44
InputDeviceProvider * get_provider() const
Returns the provider for this input device.
std::string get_name() const
Returns the human readable name of the device (i.e. 'Microsoft Sidewinder 3D').
Signal< void(const InputEvent &)> & sig_proximity_change()
Signal emitted when proximity is entered or exited.
InputDevice()
Constructs a null instance.
int get_hat(int index) const
Returns the current position of a joystick hat. (Joysticks only)
bool is_null() const
Returns true if this object is invalid.
Definition input_device.h:74
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.
void throw_if_null() const
Throw an exception if this object is invalid.
Signal< void(const InputEvent &)> & sig_key_down()
Signal emitted when key is pressed.
Signal< void(const InputEvent &)> & sig_key_dblclk()
Signal emitted when the mouse is double-clicked.
void set_position(float x, float y)
Sets the display-independent position of the device. (Pointing devices only)
std::string keyid_to_string(int keycode) const
Returns a generic string name for the specified key code.
int string_to_keyid(const std::string &str) const
Returns the key code for the specified generic string key name.
std::string get_key_name(int id) const
Retrieves the localized friendly key name for specified identifier (i.e. A, B, Leertaste,...
Pointf get_position() const
Returns the current device-independent x and y position (DIP) of the device. (Pointing devices only) ...
InputDevice(std::weak_ptr< InputDevice_Impl > impl)
Constructs a InputDevice.
Signal< void(const InputEvent &)> & sig_pointer_move()
Signal emitted when pointer is moved (absolute movement).
Signal< void(const InputEvent &)> & sig_axis_move()
Signal emitted when axis is moved.
void set_device_position(int x, int y)
Sets the actual position of the device. (Pointing devices only)
Type
Input device types.
Definition input_device.h:51
@ unknown
Definition input_device.h:55
@ joystick
Definition input_device.h:54
@ pointer
Definition input_device.h:53
@ keyboard
Definition input_device.h:52
InputDevice & operator=(const InputDevice &copy)
std::string get_device_name() const
Return the hardware id/device for this device (i.e. /dev/input/js0)
std::vector< int > get_axis_ids() const
Returns the number of axes available on this device. (Joysticks only)
float get_axis(int axisid) const
Returns the the current position of a joystick axis. (Joysticks only)
Point get_device_position() const
Returns the current devicesice-supplied x and y position of the device. (Pointing devices only) The r...
InputDevice(InputDeviceProvider *provider)
Constructs a InputDevice.
Type get_type() const
Returns the input device type.
int get_button_count() const
Returns the number of buttons available on this device. \warn If used on a keyboard or mouse,...
Signal< void(const InputEvent &)> & sig_key_up()
Signal emitted when key is released.
Input event class.
Definition input_event.h:43
2D (x,y) point structure - Integer
Definition point.h:62
2D (x,y) point structure - Float
Definition point.h:72
Definition signal.h:105
Definition clanapp.h:36
@ y
Definition keys.h:105
@ x
Definition keys.h:104