CUGL
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::GestureInput cugl::Keyboard cugl::Mouse cugl::PanInput cugl::PinchInput cugl::RotationInput cugl::TextInput cugl::Touchscreen

Public Member Functions

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 ()
 
virtual bool init ()
 
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

Uint32 _focus
 

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

cugl::InputDevice::InputDevice ( )
inlineprotected

Creates and initializes a new input device.

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

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

Deletes this input device, disposing of all resources

Member Function Documentation

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::GestureInput, cugl::Mouse, cugl::Keyboard, cugl::PanInput, cugl::Touchscreen, cugl::PinchInput, cugl::RotationInput, cugl::Accelerometer, and cugl::TextInput.

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

Returns the index of the object with current focus

Returns
the index of the object with current focus
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::GestureInput, cugl::Touchscreen, cugl::TextInput, cugl::PanInput, cugl::PinchInput, and cugl::RotationInput.

virtual bool cugl::InputDevice::init ( )
inlineprotectedvirtual

Initializes this device, acquiring any necessary resources

Returns
true if initialization was successful
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::GestureInput, cugl::Mouse, cugl::Keyboard, cugl::PanInput, cugl::Touchscreen, cugl::PinchInput, cugl::RotationInput, cugl::Accelerometer, and cugl::TextInput.

void cugl::InputDevice::releaseFocus ( )
inline

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

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::GestureInput, cugl::Mouse, cugl::Keyboard, cugl::PanInput, cugl::Touchscreen, cugl::PinchInput, cugl::RotationInput, cugl::Accelerometer, and cugl::TextInput.

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::GestureInput, cugl::Mouse, cugl::Keyboard, cugl::PanInput, cugl::Touchscreen, cugl::PinchInput, cugl::RotationInput, cugl::Accelerometer, and cugl::TextInput.

Member Data Documentation

Uint32 cugl::InputDevice::_focus
protected

The key identifying the object with focus

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: