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 
48 {
49 public:
51  enum Type
52  {
57  unknown
58  };
59 
62 
63 public:
66 
71 
75  InputDevice(std::weak_ptr<InputDevice_Impl> impl);
76 
78 
82 
83 public:
85  bool is_null() const { return !impl; }
86 
88  void throw_if_null() const;
89 
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 
122 
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:
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 
179 
183 
184 private:
185  std::shared_ptr<InputDevice_Impl> impl;
186 
187  friend class InputContext_Impl;
189 };
190 
191 }
192 
2D (x,y) point structure - Integer
Definition: point.h:63
void throw_if_null() const
Throw an exception if this object is invalid.
@ unknown
Definition: input_device.h:57
std::string keyid_to_string(int keycode) const
Returns a generic string name for the specified key code.
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.
Point get_device_position() const
Returns the current devicesice-supplied x and y position of the device. (Pointing devices only) The r...
Input event class.
Definition: input_event.h:44
int string_to_keyid(const std::string &str) const
Returns the key code for the specified generic string key name.
int get_button_count() const
Returns the number of buttons available on this device. \warn If used on a keyboard or mouse,...
@ tablet
Definition: input_device.h:56
InputDevice()
Constructs a null instance.
int get_hat(int index) const
Returns the current position of a joystick hat. (Joysticks only)
InputDevice.
Definition: input_device.h:48
Signal< void(const InputEvent &)> & sig_key_dblclk()
Signal emitted when the mouse is double-clicked.
InputDevice(std::weak_ptr< InputDevice_Impl > impl)
Constructs a InputDevice.
Signal< void(const InputEvent &)> & sig_proximity_change()
Signal emitted when proximity is entered or exited.
2D (x,y) point structure - Float
Definition: point.h:73
Signal< void(const InputEvent &)> & sig_key_up()
Signal emitted when key is released.
InputDeviceProvider * get_provider() const
Returns the provider for this input device.
Definition: signal.h:105
std::string get_key_name(int id) const
Retrieves the localized friendly key name for specified identifier (i.e. A, B, Leertaste,...
@ joystick
Definition: input_device.h:55
@ keyboard
Definition: input_device.h:53
Signal< void(const InputEvent &)> & sig_axis_move()
Signal emitted when axis is moved.
Interface for implementing a InputDevice source.
Definition: input_device_provider.h:45
float get_axis(int axisid) const
Returns the the current position of a joystick axis. (Joysticks only)
Signal< void(const InputEvent &)> & sig_key_down()
Signal emitted when key is pressed.
Signal< void(const InputEvent &)> & sig_pointer_move()
Signal emitted when pointer is moved (absolute movement).
Pointf get_position() const
Returns the current device-independent x and y position (DIP) of the device. (Pointing devices only) ...
InputDevice(InputDeviceProvider *provider)
Constructs a InputDevice.
Type get_type() const
Returns the input device type.
void set_position(float x, float y)
Sets the display-independent position of the device. (Pointing devices only)
Type
Input device types.
Definition: input_device.h:52
Definition: clanapp.h:36
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)
std::string get_name() const
Returns the human readable name of the device (i.e. 'Microsoft Sidewinder 3D').
bool is_null() const
Returns true if this object is invalid.
Definition: input_device.h:85
@ pointer
Definition: input_device.h:54
friend class InputContext_Impl
Definition: input_device.h:187
void set_device_position(int x, int y)
Sets the actual position of the device. (Pointing devices only)
InputDevice & operator=(const InputDevice &copy)
bool in_proximity() const
Returns true if the input device is in proximity mode. (Tablets only)