CUGL 2.0
Cornell University Game Library
|
#include <CUInput.h>
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 |
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.
|
inlineprotected |
Creates and initializes a new input device.
WARNING: Never allocate an input device directly. Always use the Input#activate() method instead.
|
inlineprotectedvirtual |
Deletes this input device, disposing of all resources
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.
|
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.
|
inline |
Returns the index of the object with current focus
|
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.
|
inlineprotected |
Initializes this device, acquiring any necessary resources
name | The device name |
|
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.
eventset | The 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.
|
inline |
Releases the current focus so that no object key is assigned.
|
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.
Reimplemented in cugl::Mouse, cugl::Keyboard, cugl::PanInput, cugl::Touchscreen, cugl::PinchInput, cugl::RotationInput, cugl::Accelerometer, and cugl::TextInput.
|
protectedpure virtual |
Processes an SDL_Event
The dispatcher guarantees that an input device only receives events that it subscribes to.
event | The input event to process |
stamp | The event timestamp in CUGL time |
Implemented in cugl::Mouse, cugl::Keyboard, cugl::PanInput, cugl::PinchInput, cugl::Touchscreen, cugl::RotationInput, cugl::Accelerometer, and cugl::TextInput.
|
protected |
The key identifying the object with focus
|
protected |
The name of this device
|
protected |
The next listener key available for this device
|
static |
No object is allowed to use this key, which is the same as UINT32_MAX