Gainput  v1.0.0
GainputInputDevice.h
1 
2 #ifndef GAINPUTINPUTDEVICE_H_
3 #define GAINPUTINPUTDEVICE_H_
4 
5 namespace gainput
6 {
7 
8 
11 {
15 };
16 
17 
19 
33 class GAINPUT_LIBEXPORT InputDevice
34 {
35 public:
38  {
47  DT_COUNT
48  };
49 
52  {
55  DV_NULL
56  };
57 
60  {
63  DS_UNAVAILABLE
64  };
65 
66  static const unsigned AutoIndex = unsigned(-1);
67 
69 
72  InputDevice(InputManager& manager, DeviceId device, unsigned index);
73 
75  virtual ~InputDevice();
76 
78 
81  void Update(InputDeltaState* delta);
82 
84  DeviceId GetDeviceId() const { return deviceId_; }
86  unsigned GetIndex() const { return index_; }
87 
89  virtual DeviceType GetType() const = 0;
91  virtual DeviceVariant GetVariant() const { return DV_STANDARD; }
93  virtual const char* GetTypeName() const = 0;
95  virtual bool IsLateUpdate() const { return false; }
97  DeviceState GetState() const;
99  virtual bool IsAvailable() const { return GetState() == DS_OK || GetState() == DS_LOW_BATTERY; }
100 
102  virtual bool IsValidButtonId(DeviceButtonId deviceButton) const = 0;
103 
105  bool GetBool(DeviceButtonId deviceButton) const;
107  bool GetBoolPrevious(DeviceButtonId deviceButton) const;
109  float GetFloat(DeviceButtonId deviceButton) const;
111  float GetFloatPrevious(DeviceButtonId deviceButton) const;
112 
114 
119  virtual size_t GetAnyButtonDown(DeviceButtonSpec* outButtons, size_t maxButtonCount) const { GAINPUT_UNUSED(outButtons); GAINPUT_UNUSED(maxButtonCount); return 0; }
120 
122 
128  virtual size_t GetButtonName(DeviceButtonId deviceButton, char* buffer, size_t bufferLength) const { GAINPUT_UNUSED(deviceButton); GAINPUT_UNUSED(buffer); GAINPUT_UNUSED(bufferLength); return 0; }
130  virtual ButtonType GetButtonType(DeviceButtonId deviceButton) const = 0;
131 
133 
137  virtual DeviceButtonId GetButtonByName(const char* name) const { GAINPUT_UNUSED(name); return InvalidDeviceButtonId; }
138 
140  InputState* GetInputState() { return state_; }
142  const InputState* GetInputState() const { return state_; }
144  InputState* GetPreviousInputState() { return previousState_; }
146  virtual InputState* GetNextInputState() { return 0; }
147 
149  float GetDeadZone(DeviceButtonId buttonId) const;
151  void SetDeadZone(DeviceButtonId buttonId, float value);
152 
154  void SetDebugRenderingEnabled(bool enabled);
156  bool IsDebugRenderingEnabled() const { return debugRenderingEnabled_; }
157 
158 #if defined(GAINPUT_DEV) || defined(GAINPUT_ENABLE_RECORDER)
159  bool IsSynced() const { return synced_; }
163 
166  void SetSynced(bool synced) { synced_ = synced; }
167 #endif
168 
169 protected:
172 
175 
177  unsigned index_;
178 
183 
184  float* deadZones_;
185 
188 
189 #if defined(GAINPUT_DEV) || defined(GAINPUT_ENABLE_RECORDER)
190  bool synced_;
193 #endif
194 
196 
199  virtual void InternalUpdate(InputDeltaState* delta) = 0;
200 
202 
205  virtual DeviceState InternalGetState() const = 0;
206 
208 
216  size_t CheckAllButtonsDown(DeviceButtonSpec* outButtons, size_t maxButtonCount, unsigned start, unsigned end) const;
217 };
218 
219 
220 inline
221 bool
223 {
224  if (!IsAvailable())
225  {
226  return false;
227  }
228  GAINPUT_ASSERT(state_);
229  return state_->GetBool(deviceButton);
230 }
231 
232 inline
233 bool
235 {
236  if (!IsAvailable())
237  {
238  return false;
239  }
240  GAINPUT_ASSERT(previousState_);
241  return previousState_->GetBool(deviceButton);
242 }
243 
244 inline
245 float
247 {
248  if (!IsAvailable())
249  {
250  return 0.0f;
251  }
252  GAINPUT_ASSERT(state_);
253  return state_->GetFloat(deviceButton);
254 }
255 
256 inline
257 float
259 {
260  if (!IsAvailable())
261  {
262  return 0.0f;
263  }
264  GAINPUT_ASSERT(previousState_);
265  return previousState_->GetFloat(deviceButton);
266 }
267 
268 }
269 
270 #endif
271 
virtual size_t GetButtonName(DeviceButtonId deviceButton, char *buffer, size_t bufferLength) const
Gets the name of the given button.
Definition: GainputInputDevice.h:128
float GetFloat(DeviceButtonId deviceButton) const
Returns the current state of the given button.
Definition: GainputInputDevice.h:246
bool GetBoolPrevious(DeviceButtonId deviceButton) const
Returns the previous state of the given button.
Definition: GainputInputDevice.h:234
virtual InputState * GetNextInputState()
Returns the device's state that is currently being determined, may be 0 if not available.
Definition: GainputInputDevice.h:146
virtual bool IsLateUpdate() const
Returns if this device should be updated after other devices.
Definition: GainputInputDevice.h:95
void SetSynced(bool synced)
Sets if this device is being controlled remotely or from a recording.
Definition: GainputInputDevice.h:166
InputState * GetInputState()
Returns the device's state, probably best if only used internally.
Definition: GainputInputDevice.h:140
Manages all input devices and some other helpful stuff.
Definition: GainputInputManager.h:24
A gesture input device, building on top of other input devices.
Definition: GainputInputDevice.h:45
DeviceId GetDeviceId() const
Returns this device's ID.
Definition: GainputInputDevice.h:84
InputState * state_
The current state of this device.
Definition: GainputInputDevice.h:180
The raw input implementation of the given device type.
Definition: GainputInputDevice.h:54
A boolean value button, either down (true) or up (false).
Definition: GainputInputDevice.h:12
InputManager & manager_
The manager this device belongs to.
Definition: GainputInputDevice.h:171
ButtonType
Type of an input device button.
Definition: GainputInputDevice.h:10
A mouse/cursor input device featuring one pointer.
Definition: GainputInputDevice.h:39
A touch-sensitive input device supporting multiple simultaneous pointers.
Definition: GainputInputDevice.h:42
The input device is low on battery.
Definition: GainputInputDevice.h:62
Any controls directly built into the device that also contains the screen.
Definition: GainputInputDevice.h:43
A joypad/gamepad input device.
Definition: GainputInputDevice.h:41
virtual DeviceVariant GetVariant() const
Returns the device variant.
Definition: GainputInputDevice.h:91
const InputState * GetInputState() const
Returns the device's state, probably best if only used internally.
Definition: GainputInputDevice.h:142
Stores a list of input state changes.
Definition: GainputInputDeltaState.h:9
Describes a device button on a specific device.
Definition: gainput.h:112
InputState * previousState_
The previous state of this device.
Definition: GainputInputDevice.h:182
unsigned int DeviceId
ID of an input device.
Definition: gainput.h:107
DeviceState
State of an input device.
Definition: GainputInputDevice.h:59
DeviceVariant
Variant of an input device type.
Definition: GainputInputDevice.h:51
unsigned GetIndex() const
Returns the device's index among devices of the same type.
Definition: GainputInputDevice.h:86
Everything is okay.
Definition: GainputInputDevice.h:61
virtual bool IsAvailable() const
Returns if this device is available.
Definition: GainputInputDevice.h:99
DeviceType
Type of an input device.
Definition: GainputInputDevice.h:37
InputState * GetPreviousInputState()
Returns the device's previous state, probably best if only used internally.
Definition: GainputInputDevice.h:144
A custom, user-created input device.
Definition: GainputInputDevice.h:46
Interface for anything that provides device inputs.
Definition: GainputInputDevice.h:33
A floating-point value button, between -1.0f and 1.0f or 0.0f and 1.0f.
Definition: GainputInputDevice.h:13
virtual size_t GetAnyButtonDown(DeviceButtonSpec *outButtons, size_t maxButtonCount) const
Checks if any button on this device is down.
Definition: GainputInputDevice.h:119
DeviceId deviceId_
The ID of this device.
Definition: GainputInputDevice.h:174
bool IsDebugRenderingEnabled() const
Returns true if debug rendering is enabled, false otherwise.
Definition: GainputInputDevice.h:156
bool GetBool(DeviceButtonId deviceButton) const
Returns the current state of the given button.
Definition: GainputInputDevice.h:222
A keyboard input device.
Definition: GainputInputDevice.h:40
A generic networked input device.
Definition: GainputInputDevice.h:44
The number of different button types.
Definition: GainputInputDevice.h:14
unsigned index_
Index of this device among devices of the same type.
Definition: GainputInputDevice.h:177
bool debugRenderingEnabled_
Specifies if this device is currently rendering debug information.
Definition: GainputInputDevice.h:187
unsigned int DeviceButtonId
ID of a specific button unique to an input device.
Definition: gainput.h:109
State of an input device.
Definition: GainputInputState.h:9
The standard implementation of the given device type.
Definition: GainputInputDevice.h:53
Contains all Gainput related classes, types, and functions.
Definition: gainput.h:103
float GetFloatPrevious(DeviceButtonId deviceButton) const
Returns the previous state of the given button.
Definition: GainputInputDevice.h:258
virtual DeviceButtonId GetButtonByName(const char *name) const
Returns the button's ID if the name is of this device's buttons.
Definition: GainputInputDevice.h:137