input_device.h Source File - ClanLib SDK
Description: input_device.h Source File

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;
42 class InputDeviceProvider;
43 class InputDevice_Impl;
44
46 class InputDevice
47 {
48 public:
50 enum Type
51 {
52 keyboard,
53 pointer,
54 joystick,
55 unknown
56 };
57
59 InputDevice();
60
64 InputDevice(InputDeviceProvider *provider);
65
69 InputDevice(std::weak_ptr<InputDevice_Impl> impl);
70
71 ~InputDevice();
72
74 bool is_null() const { return !impl; }
75 explicit operator bool() const { return bool(impl); }
76
78 void throw_if_null() const;
79
81 InputDeviceProvider *get_provider() const;
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
111 Pointf get_position() const;
112
115 Point get_device_position() const;
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
131 InputDevice &operator =(const InputDevice &copy);
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
146 Signal<void(const InputEvent &)> &sig_pointer_move();
147
149 Signal<void(const InputEvent &)> &sig_axis_move();
150
152 Signal<void(const InputEvent &)> &sig_key_dblclk();
153
155 Signal<void(const InputEvent &)> &sig_proximity_change();
156
157 private:
158 std::shared_ptr<InputDevice_Impl> impl;
159 };
160
162}
clan::InputDeviceProvider
Interface for implementing a InputDevice source.
Definition input_device_provider.h:44
clan::InputDevice::get_provider
InputDeviceProvider * get_provider() const
Returns the provider for this input device.
clan::InputDevice::get_name
std::string get_name() const
Returns the human readable name of the device (i.e. 'Microsoft Sidewinder 3D').
clan::InputDevice::sig_proximity_change
Signal< void(const InputEvent &)> & sig_proximity_change()
Signal emitted when proximity is entered or exited.
clan::InputDevice::InputDevice
InputDevice()
Constructs a null instance.
clan::InputDevice::get_hat
int get_hat(int index) const
Returns the current position of a joystick hat. (Joysticks only)
clan::InputDevice::is_null
bool is_null() const
Returns true if this object is invalid.
Definition input_device.h:74
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::InputDevice::throw_if_null
void throw_if_null() const
Throw an exception if this object is invalid.
clan::InputDevice::sig_key_down
Signal< void(const InputEvent &)> & sig_key_down()
Signal emitted when key is pressed.
clan::InputDevice::sig_key_dblclk
Signal< void(const InputEvent &)> & sig_key_dblclk()
Signal emitted when the mouse is double-clicked.
clan::InputDevice::set_position
void set_position(float x, float y)
Sets the display-independent position of the device. (Pointing devices only)
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::string_to_keyid
int string_to_keyid(const std::string &str) const
Returns the key code for the specified generic string key name.
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,...
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::InputDevice
InputDevice(std::weak_ptr< InputDevice_Impl > impl)
Constructs a InputDevice.
clan::InputDevice::sig_pointer_move
Signal< void(const InputEvent &)> & sig_pointer_move()
Signal emitted when pointer is moved (absolute movement).
clan::InputDevice::sig_axis_move
Signal< void(const InputEvent &)> & sig_axis_move()
Signal emitted when axis is moved.
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::Type
Type
Input device types.
Definition input_device.h:51
clan::InputDevice::unknown
@ unknown
Definition input_device.h:55
clan::InputDevice::joystick
@ joystick
Definition input_device.h:54
clan::InputDevice::pointer
@ pointer
Definition input_device.h:53
clan::InputDevice::keyboard
@ keyboard
Definition input_device.h:52
clan::InputDevice::~InputDevice
~InputDevice()
clan::InputDevice::operator=
InputDevice & operator=(const InputDevice &copy)
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::get_axis_ids
std::vector< int > get_axis_ids() const
Returns the number of axes available on this device. (Joysticks only)
clan::InputDevice::get_axis
float get_axis(int axisid) const
Returns the the current position of a joystick axis. (Joysticks 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::InputDevice
InputDevice(InputDeviceProvider *provider)
Constructs a InputDevice.
clan::InputDevice::get_type
Type get_type() const
Returns the input device type.
clan::InputDevice::get_button_count
int get_button_count() const
Returns the number of buttons available on this device. \warn If used on a keyboard or mouse,...
clan::InputDevice::sig_key_up
Signal< void(const InputEvent &)> & sig_key_up()
Signal emitted when key is released.
clan::InputEvent
Input event class.
Definition input_event.h:43
clan::Point
2D (x,y) point structure - Integer
Definition point.h:62
clan::Pointf
2D (x,y) point structure - Float
Definition point.h:72
clan::Signal
Definition signal.h:105
clan
Definition clanapp.h:36
clan::Key::y
@ y
Definition keys.h:105
clan::Key::x
@ x
Definition keys.h:104