CUGL 2.0
Cornell University Game Library
Public Member Functions | Static Public Attributes | Protected Member Functions | Protected Attributes | Friends | List of all members
cugl::InputDevice Class Referenceabstract

#include <CUInput.h>

Inheritance diagram for cugl::InputDevice:
cugl::Accelerometer cugl::Keyboard cugl::Mouse cugl::PanInput cugl::PinchInput cugl::RotationInput cugl::TextInput cugl::Touchscreen

Public Member Functions

Uint32 acquireKey ()
 
Uint32 currentFocus () const
 
virtual bool requestFocus (Uint32 key)
 
void releaseFocus ()
 

Static Public Attributes

static const Uint32 RESERVED_KEY = UINT32_MAX
 

Protected Member Functions

 InputDevice ()
 
virtual ~InputDevice ()
 
bool initWithName (const std::string name)
 
virtual void dispose ()
 
virtual void clearState ()=0
 
virtual bool updateState (const SDL_Event &event, const Timestamp &stamp)=0
 
virtual void queryEvents (std::vector< Uint32 > &eventset)=0
 

Protected Attributes

std::string _name
 
Uint32 _focus
 
Uint32 _nextKey
 

Friends

class Input
 

Detailed Description

This class is the abstract base class of every input device.

Most of the methods of this class are pure virtual and are to be implemented in the specific input device. Hence this class works like a Java interface.

The only exception to this rule is focus. Many input devices are designed to send input to a focused object (e.g. a text field or other UI widget). We ask each such object to identify itself by a unique key and use that key to resolve focus.

Constructor & Destructor Documentation

◆ InputDevice()

cugl::InputDevice::InputDevice ( )
inlineprotected

Creates and initializes a new input device.

WARNING: Never allocate an input device directly. Always use the Input#activate() method instead.

◆ ~InputDevice()

virtual cugl::InputDevice::~InputDevice ( )
inlineprotectedvirtual

Deletes this input device, disposing of all resources

Member Function Documentation

◆ acquireKey()

Uint32 cugl::InputDevice::acquireKey ( )

Returns an available listener key for this device

Listeners are globally attached to an input device. However, the standard programming pattern is to attach a listener to a UI widget. Furthermore, a listener is often reused across multiple widgets. To enable this, we assign each widget-listener pair a unique identifier.

In previous versions of the CUGL engine, we required the programmer to assign this key. This method removes that requirement from the programmer.

Returns
an available listener key for this device

◆ clearState()

virtual void cugl::InputDevice::clearState ( )
protectedpure virtual

Clears the state of this input device, readying it for the next frame.

Many devices keep track of what happened "this" frame. This method is necessary to advance the frame.

Implemented in cugl::Mouse, cugl::Keyboard, cugl::PanInput, cugl::PinchInput, cugl::Touchscreen, cugl::RotationInput, cugl::Accelerometer, and cugl::TextInput.

◆ currentFocus()

Uint32 cugl::InputDevice::currentFocus ( ) const
inline

Returns the index of the object with current focus

Returns
the index of the object with current focus

◆ dispose()

virtual void cugl::InputDevice::dispose ( )
inlineprotectedvirtual

Unintializes this device, returning it to its default state

An uninitialized device may not work without reinitialization.

Reimplemented in cugl::Mouse, cugl::Keyboard, cugl::Touchscreen, cugl::TextInput, cugl::PanInput, cugl::PinchInput, and cugl::RotationInput.

◆ initWithName()

bool cugl::InputDevice::initWithName ( const std::string  name)
inlineprotected

Initializes this device, acquiring any necessary resources

Parameters
nameThe device name
Returns
true if initialization was successful

◆ queryEvents()

virtual void cugl::InputDevice::queryEvents ( std::vector< Uint32 > &  eventset)
protectedpure virtual

Determine the SDL events of relevance and store there types in eventset.

An SDL_EventType is really Uint32. This method stores the SDL event types for this input device into the vector eventset, appending them to the end. The Input dispatcher then uses this information to set up subscriptions.

Parameters
eventsetThe set to store the event types.

Implemented in cugl::Mouse, cugl::Keyboard, cugl::PanInput, cugl::PinchInput, cugl::Touchscreen, cugl::RotationInput, cugl::Accelerometer, and cugl::TextInput.

◆ releaseFocus()

void cugl::InputDevice::releaseFocus ( )
inline

Releases the current focus so that no object key is assigned.

◆ requestFocus()

virtual bool cugl::InputDevice::requestFocus ( Uint32  key)
inlinevirtual

Sets the current focus to that of the given object key.

In some input devices, this method may fail if the key is not recognized as valid. See the notes for each input device.

Returns
true if the object for key successfully acquired focus.

Reimplemented in cugl::Mouse, cugl::Keyboard, cugl::PanInput, cugl::Touchscreen, cugl::PinchInput, cugl::RotationInput, cugl::Accelerometer, and cugl::TextInput.

◆ updateState()

virtual bool cugl::InputDevice::updateState ( const SDL_Event &  event,
const Timestamp stamp 
)
protectedpure virtual

Processes an SDL_Event

The dispatcher guarantees that an input device only receives events that it subscribes to.

Parameters
eventThe input event to process
stampThe event timestamp in CUGL time
Returns
false if the input indicates that the application should quit.

Implemented in cugl::Mouse, cugl::Keyboard, cugl::PanInput, cugl::PinchInput, cugl::Touchscreen, cugl::RotationInput, cugl::Accelerometer, and cugl::TextInput.

Member Data Documentation

◆ _focus

Uint32 cugl::InputDevice::_focus
protected

The key identifying the object with focus

◆ _name

std::string cugl::InputDevice::_name
protected

The name of this device

◆ _nextKey

Uint32 cugl::InputDevice::_nextKey
protected

The next listener key available for this device

◆ RESERVED_KEY

const Uint32 cugl::InputDevice::RESERVED_KEY = UINT32_MAX
static

No object is allowed to use this key, which is the same as UINT32_MAX


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