Gainput  v1.0.0
Public Types | Public Member Functions | Static Public Attributes | Protected Member Functions | Protected Attributes | List of all members
gainput::InputDevice Class Referenceabstract

Interface for anything that provides device inputs. More...

#include <GainputInputDevice.h>

Inheritance diagram for gainput::InputDevice:
gainput::InputDeviceBuiltIn gainput::InputDeviceKeyboard gainput::InputDeviceMouse gainput::InputDevicePad gainput::InputDeviceTouch gainput::InputGesture gainput::DoubleClickGesture gainput::HoldGesture gainput::PinchGesture gainput::RotateGesture gainput::SimultaneouslyDownGesture gainput::TapGesture

Public Types

enum  DeviceType {
  DT_MOUSE, DT_KEYBOARD, DT_PAD, DT_TOUCH,
  DT_BUILTIN, DT_REMOTE, DT_GESTURE, DT_CUSTOM,
  DT_COUNT
}
 Type of an input device. More...
 
enum  DeviceVariant { DV_STANDARD, DV_RAW, DV_NULL }
 Variant of an input device type. More...
 
enum  DeviceState { DS_OK, DS_LOW_BATTERY, DS_UNAVAILABLE }
 State of an input device. More...
 

Public Member Functions

 InputDevice (InputManager &manager, DeviceId device, unsigned index)
 Initializes the input device. More...
 
virtual ~InputDevice ()
 Empty virtual destructor.
 
void Update (InputDeltaState *delta)
 Update this device, internally called by InputManager. More...
 
DeviceId GetDeviceId () const
 Returns this device's ID.
 
unsigned GetIndex () const
 Returns the device's index among devices of the same type.
 
virtual DeviceType GetType () const =0
 Returns the device type.
 
virtual DeviceVariant GetVariant () const
 Returns the device variant.
 
virtual const char * GetTypeName () const =0
 Returns the device type's name.
 
virtual bool IsLateUpdate () const
 Returns if this device should be updated after other devices.
 
DeviceState GetState () const
 Returns the device state.
 
virtual bool IsAvailable () const
 Returns if this device is available.
 
virtual bool IsValidButtonId (DeviceButtonId deviceButton) const =0
 Returns if the given button is valid for this device.
 
bool GetBool (DeviceButtonId deviceButton) const
 Returns the current state of the given button.
 
bool GetBoolPrevious (DeviceButtonId deviceButton) const
 Returns the previous state of the given button.
 
float GetFloat (DeviceButtonId deviceButton) const
 Returns the current state of the given button.
 
float GetFloatPrevious (DeviceButtonId deviceButton) const
 Returns the previous state of the given button.
 
virtual size_t GetAnyButtonDown (DeviceButtonSpec *outButtons, size_t maxButtonCount) const
 Checks if any button on this device is down. More...
 
virtual size_t GetButtonName (DeviceButtonId deviceButton, char *buffer, size_t bufferLength) const
 Gets the name of the given button. More...
 
virtual ButtonType GetButtonType (DeviceButtonId deviceButton) const =0
 Returns the type of the given button.
 
virtual DeviceButtonId GetButtonByName (const char *name) const
 Returns the button's ID if the name is of this device's buttons. More...
 
InputStateGetInputState ()
 Returns the device's state, probably best if only used internally.
 
const InputStateGetInputState () const
 Returns the device's state, probably best if only used internally.
 
InputStateGetPreviousInputState ()
 Returns the device's previous state, probably best if only used internally.
 
virtual InputStateGetNextInputState ()
 Returns the device's state that is currently being determined, may be 0 if not available.
 
float GetDeadZone (DeviceButtonId buttonId) const
 Returns the previously set dead zone for the given button or 0.0f if none was set yet.
 
void SetDeadZone (DeviceButtonId buttonId, float value)
 Sets the dead zone for the given button.
 
void SetDebugRenderingEnabled (bool enabled)
 Enable/disable debug rendering of this device.
 
bool IsDebugRenderingEnabled () const
 Returns true if debug rendering is enabled, false otherwise.
 
bool IsSynced () const
 
void SetSynced (bool synced)
 Sets if this device is being controlled remotely or from a recording. More...
 

Static Public Attributes

static const unsigned AutoIndex = unsigned(-1)
 

Protected Member Functions

virtual void InternalUpdate (InputDeltaState *delta)=0
 Implementation of the device's Update function. More...
 
virtual DeviceState InternalGetState () const =0
 Implementation of the device's GetState function. More...
 
size_t CheckAllButtonsDown (DeviceButtonSpec *outButtons, size_t maxButtonCount, unsigned start, unsigned end) const
 Checks which buttons are down. More...
 

Protected Attributes

InputManagermanager_
 The manager this device belongs to.
 
DeviceId deviceId_
 The ID of this device.
 
unsigned index_
 Index of this device among devices of the same type.
 
InputStatestate_
 The current state of this device.
 
InputStatepreviousState_
 The previous state of this device.
 
float * deadZones_
 
bool debugRenderingEnabled_
 Specifies if this device is currently rendering debug information.
 
bool synced_
 

Detailed Description

Interface for anything that provides device inputs.

An InputDevice can be anything from a physical device, like a mouse or keyboard, to the more abstract concept of gestures that in turn themselves depend on other InputDevices. What they have in common is that they provide a number of device buttons (identified by a DeviceButtonId) which can be queried for their state.

Note that you may not instantiate an InputDevice (or any derived implementation) directly. Instead you have to call InputManager::CreateDevice() or InputManager::CreateAndGetDevice() with the device you want to instantiate as the template parameter. That way the device will be properly registered with the InputManager and continuously updated.

Normally, you won't interact with an InputDevice directly, but instead use its device ID and its device buttons' IDs to map the device buttons to user buttons (see InputMap).

Examples:
/samples/dynamic/dynamicsample.cpp, /samples/gesture/gesturesample.cpp, /samples/listener/listenersample.cpp, /samples/recording/recordingsample.cpp, and /samples/sync/syncsample.cpp.

Member Enumeration Documentation

◆ DeviceState

State of an input device.

Enumerator
DS_OK 

Everything is okay.

DS_LOW_BATTERY 

The input device is low on battery.

DS_UNAVAILABLE 

The input device is currently not available.

◆ DeviceType

Type of an input device.

Enumerator
DT_MOUSE 

A mouse/cursor input device featuring one pointer.

DT_KEYBOARD 

A keyboard input device.

DT_PAD 

A joypad/gamepad input device.

DT_TOUCH 

A touch-sensitive input device supporting multiple simultaneous pointers.

DT_BUILTIN 

Any controls directly built into the device that also contains the screen.

DT_REMOTE 

A generic networked input device.

DT_GESTURE 

A gesture input device, building on top of other input devices.

DT_CUSTOM 

A custom, user-created input device.

DT_COUNT 

The count of input device types.

◆ DeviceVariant

Variant of an input device type.

Enumerator
DV_STANDARD 

The standard implementation of the given device type.

DV_RAW 

The raw input implementation of the given device type.

DV_NULL 

The null/empty implementation of the given device type.

Constructor & Destructor Documentation

◆ InputDevice()

gainput::InputDevice::InputDevice ( InputManager manager,
DeviceId  device,
unsigned  index 
)

Initializes the input device.

Do not instantiate any input device directly. Call InputManager::CreateDevice() instead.

Member Function Documentation

◆ CheckAllButtonsDown()

size_t gainput::InputDevice::CheckAllButtonsDown ( DeviceButtonSpec outButtons,
size_t  maxButtonCount,
unsigned  start,
unsigned  end 
) const
protected

Checks which buttons are down.

This function is normally used by GetAnyButtonDown implementations internally.

Parameters
outButtonsAn array to write buttons that are down to.
maxButtonCountThe size of outButtons.
startThe lowest device button ID to check.
endThe biggest device button ID to check.
Returns
The number of buttons written to outButtons.

◆ GetAnyButtonDown()

virtual size_t gainput::InputDevice::GetAnyButtonDown ( DeviceButtonSpec outButtons,
size_t  maxButtonCount 
) const
inlinevirtual

Checks if any button on this device is down.

Parameters
[out]outButtonsAn array with maxButtonCount fields to receive the device buttons that are down.
maxButtonCountThe number of fields in outButtons.
Returns
The number of device buttons written to outButtons.

Reimplemented in gainput::InputDeviceKeyboard, gainput::InputDevicePad, gainput::InputDeviceTouch, gainput::InputDeviceMouse, and gainput::InputDeviceBuiltIn.

◆ GetButtonByName()

virtual DeviceButtonId gainput::InputDevice::GetButtonByName ( const char *  name) const
inlinevirtual

Returns the button's ID if the name is of this device's buttons.

Parameters
nameName of the device button to look for.
Returns
The device button ID.

Reimplemented in gainput::InputDeviceKeyboard, gainput::InputDevicePad, gainput::InputDeviceTouch, gainput::InputDeviceMouse, and gainput::InputDeviceBuiltIn.

Examples:
/samples/dynamic/dynamicsample.cpp.

◆ GetButtonName()

virtual size_t gainput::InputDevice::GetButtonName ( DeviceButtonId  deviceButton,
char *  buffer,
size_t  bufferLength 
) const
inlinevirtual

Gets the name of the given button.

Parameters
deviceButtonID of the button.
bufferA char-buffer to receive the button name.
bufferLengthLength of the buffer receiving the button name in bytes.
Returns
The number of bytes written to buffer (includes the trailing \0).

Reimplemented in gainput::InputDeviceKeyboard, gainput::InputDevicePad, gainput::InputDeviceTouch, gainput::InputDeviceMouse, and gainput::InputDeviceBuiltIn.

Examples:
/samples/dynamic/dynamicsample.cpp, /samples/listener/listenersample.cpp, /samples/recording/recordingsample.cpp, and /samples/sync/syncsample.cpp.

◆ InternalGetState()

virtual DeviceState gainput::InputDevice::InternalGetState ( ) const
protectedpure virtual

◆ InternalUpdate()

virtual void gainput::InputDevice::InternalUpdate ( InputDeltaState delta)
protectedpure virtual

◆ IsSynced()

bool gainput::InputDevice::IsSynced ( ) const
inline

Returns true if this device is being controlled by a remote device or a recorded input sequence, false otherwise.

◆ SetSynced()

void gainput::InputDevice::SetSynced ( bool  synced)
inline

Sets if this device is being controlled remotely or from a recording.

See also
IsSynced()

◆ Update()

void gainput::InputDevice::Update ( InputDeltaState delta)

Update this device, internally called by InputManager.

Parameters
deltaThe delta state to add changes to. May be 0.

Member Data Documentation

◆ synced_

bool gainput::InputDevice::synced_
protected

Specifies if this device's state is actually set from a device or manually set by some other system.


The documentation for this class was generated from the following file: