input_device.h
1 /*
2 ** ClanLib SDK
3 ** Copyright (c) 1997-2013 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 "../api_display.h"
34 #include "../../Core/Signals/signal_v1.h"
35 #include "../../Core/Math/point.h"
36 #include <memory>
37 
38 namespace clan
39 {
42 
43 class InputEvent;
44 class InputDeviceProvider;
45 class InputDevice_Impl;
46 
48 class CL_API_DISPLAY InputDevice
49 {
50 public:
52  enum Type
53  {
58  unknown
59  };
60 
63 
64 public:
66  InputDevice();
67 
72 
76  InputDevice(std::weak_ptr<InputDevice_Impl> impl);
77 
78  ~InputDevice();
79 
83 
84 public:
86  bool is_null() const { return !impl; }
87 
89  void throw_if_null() const;
90 
92  InputDeviceProvider *get_provider() const;
93 
95  std::string get_name() const;
96 
98  std::string get_device_name() const;
99 
101  Type get_type() const;
102 
104 
106  std::string get_key_name(int id) const;
107 
109  std::string keyid_to_string(int keycode) const;
110 
112  int string_to_keyid(const std::string &str) const;
113 
115 
116  bool get_keycode(int keycode) const;
117 
119 
120  Point get_position() const;
121 
123 
124  int get_x() const;
125 
127 
128  int get_y() const;
129 
131  float get_axis(int axisid) const;
132 
134  std::vector<int> get_axis_ids() const;
135 
138  int get_hat(int index) const;
139 
141 
142  int get_button_count() const;
143 
145 
146  bool in_proximity() const;
147 
151 
152 public:
153  InputDevice &operator =(const InputDevice &copy);
154 
156 
157  void set_position(int x, int y);
158 
162 
163 public:
165  Signal_v1<const InputEvent &> &sig_key_down();
166 
168  Signal_v1<const InputEvent &> &sig_key_up();
169 
171  Signal_v1<const InputEvent &> &sig_pointer_move();
172 
174  Signal_v1<const InputEvent &> &sig_axis_move();
175 
177  Signal_v1<const InputEvent &> &sig_key_dblclk();
178 
180  Signal_v1<const InputEvent &> &sig_proximity_change();
181 
185 
186 private:
187  std::shared_ptr<InputDevice_Impl> impl;
188 
189  friend class InputContext_Impl;
191 };
192 
193 }
194 
Type
Input device types.
Definition: input_device.h:52
InputDevice.
Definition: input_device.h:48
Signal_v1.
Definition: signal_v1.h:110
Interface for implementing a InputDevice source.
Definition: input_device_provider.h:45
2D (x,y) point structure - Integer
Definition: point.h:63
Definition: input_device.h:54
Definition: input_device.h:57
Definition: input_device.h:56
bool is_null() const
Returns true if this object is invalid.
Definition: input_device.h:86
Definition: input_device.h:55