input_device.h
1 /*
2 ** ClanLib SDK
3 ** Copyright (c) 1997-2016 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 
36 namespace clan
37 {
40 
41  class InputEvent;
42  class InputDeviceProvider;
43  class InputDevice_Impl;
44 
47  {
48  public:
50  enum Type
51  {
56  };
57 
59  InputDevice();
60 
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 
82 
84  std::string get_name() const;
85 
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 
141 
144 
147 
150 
153 
156 
157  private:
158  std::shared_ptr<InputDevice_Impl> impl;
159  };
160 
162 }
float get_axis(int axisid) const
Returns the the current position of a joystick axis. (Joysticks only)
std::string get_name() const
Returns the human readable name of the device (i.e. 'Microsoft Sidewinder 3D').
Definition: clanapp.h:35
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, ...).
Type
Input device types.
Definition: input_device.h:50
void throw_if_null() const
Throw an exception if this object is invalid.
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)
InputDevice & operator=(const InputDevice &copy)
Type get_type() const
Returns the input device type.
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...
InputDeviceProvider * get_provider() const
Returns the provider for this input device.
Signal< void(const InputEvent &)> & sig_key_up()
Signal emitted when key is released.
Signal< void(const InputEvent &)> & sig_key_down()
Signal emitted when key is pressed.
int get_hat(int index) const
Returns the current position of a joystick hat. (Joysticks only)
int get_button_count() const
Returns the number of buttons available on this device. If used on a keyboard or mouse...
int string_to_keyid(const std::string &str) const
Returns the key code for the specified generic string key name.
Signal< void(const InputEvent &)> & sig_proximity_change()
Signal emitted when proximity is entered or exited.
InputDevice.
Definition: input_device.h:46
Signal< void(const InputEvent &)> & sig_axis_move()
Signal emitted when axis is moved.
InputDevice()
Constructs a null instance.
Signal< void(const InputEvent &)> & sig_key_dblclk()
Signal emitted when the mouse is double-clicked.
Interface for implementing a InputDevice source.
Definition: input_device_provider.h:43
Definition: input_device.h:55
Definition: signal.h:104
bool is_null() const
Returns true if this object is invalid.
Definition: input_device.h:74
void set_position(float x, float y)
Sets the display-independent position of the device. (Pointing devices only)
2D (x,y) point structure - Integer
Definition: point.h:61
Definition: input_device.h:52
Point get_device_position() const
Returns the current devicesice-supplied x and y position of the device. (Pointing devices only) The r...
std::string keyid_to_string(int keycode) const
Returns a generic string name for the specified key code.
2D (x,y) point structure - Float
Definition: point.h:71
Signal< void(const InputEvent &)> & sig_pointer_move()
Signal emitted when pointer is moved (absolute movement).
void set_device_position(int x, int y)
Sets the actual position of the device. (Pointing devices only)
Definition: input_device.h:54
Definition: input_device.h:53
Pointf get_position() const
Returns the current device-independent x and y position (DIP) of the device. (Pointing devices only) ...