FPLBase
An open source project by FPL.
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Groups Pages
fplbase::InputSystem Class Reference

Use to handle time, touch/mouse/keyboard/etc input, and lifecyle events. More...

#include <input.h>

Detailed Description

Use to handle time, touch/mouse/keyboard/etc input, and lifecyle events.

Public Types

typedef std::function< void(Event)> AppEventCallback
 A function pointer to an app event callback function.
 

Public Member Functions

 InputSystem ()
 Construct an uninitialized InputSystem.
 
void Initialize ()
 Initialize the input system. More...
 
void AdvanceFrame (mathfu::vec2i *window_size)
 Call once a frame to update the input state. More...
 
double Time () const
 Get time in seconds since the start of the game. Updated once per frame. More...
 
double RealTime () const
 Get time in seconds since start of the game. Updated every call. More...
 
double DeltaTime () const
 The time in seconds since the last frame. Updated once per frame. More...
 
void Delay (double seconds) const
 Make the application go to sleep a certain duration.
 
ButtonGetButton (int button)
 Get a Button object describing the input state of the specified button ID. More...
 
bool RelativeMouseMode () const
 Checks if relative mouse mode is enabled. More...
 
void SetRelativeMouseMode (bool enabled)
 Enable / disable relative mouse mode (disabled by default). More...
 
JoystickGetJoystick (JoystickId joystick_id)
 Get a Joystick object describing the input state of the specified joystick ID. More...
 
const std::map< JoystickId,
Joystick > & 
JoystickMap () const
 Get a map containing all currently connected joysticks. More...
 
GamepadGetGamepad (AndroidInputDeviceId gamepad_device_id)
 Get a Gamepad object describing the input state of the specified device ID. More...
 
const std::map
< AndroidInputDeviceId,
Gamepad > & 
GamepadMap () const
 Get a map containing all currently connected gamepads. More...
 
void HandleGamepadEvents ()
 Runs through all the received events and processes them.
 
ButtonGetPointerButton (FingerId pointer)
 Get a Button object for a pointer index. More...
 
void OpenConnectedJoysticks ()
 Open all connected joysticks.
 
void CloseOpenJoysticks ()
 Close all opened joysticks.
 
void UpdateConnectedJoystickList ()
 Close any open joysticks, and then refresh the list by opening any joysticks that are still connected.
 
void HandleJoystickEvent (Event event)
 Handle a joystick event. More...
 
std::vector< AppEventCallback > & app_event_callbacks ()
 Get the vector of all app event callbacks. More...
 
void AddAppEventCallback (AppEventCallback callback)
 Add an app event callback function.
 
int minimized_frame () const
 Get the most recent frame at which we were minimized or maximized. More...
 
void set_minimized_frame (int minimized_frame)
 Set the most recent frame at which we were minimized or maximized. More...
 
int frames () const
 The total number of frames elapsed so far.
 
mathfu::vec2i mousewheel_delta ()
 Accumulated mousewheel delta since the previous frame.
 
void RecordTextInput (bool b)
 Start/Stop recording text input events. More...
 
bool IsRecordingTextInput ()
 Checks if text input is being recorded.
 
const std::vector
< TextInputEvent > * 
GetTextInputEvents ()
 Retrieve a vector of text input events. More...
 
void ClearTextInputEvents ()
 Clear the recorded text input events. More...
 
void StartTextInput ()
 Start a text input. More...
 
void StopTextInput ()
 Stop a text input. More...
 
void SetTextInputRect (const mathfu::vec4 &input_rect)
 Indicates a text input region to IME(Input Method Editor). More...
 
const std::vector< InputPointer > & get_pointers () const
 Gets the vector of all the input pointers in the system.
 
std::vector< InputPointer > & get_pointers ()
 
bool minimized ()
 Gets if the application is currently minimized.
 
void set_minimized (bool b)
 Sets if the application is currently minimized.
 
bool exit_requested ()
 Gets if exit has been requested by the system.
 
void set_exit_requested (bool b)
 Sets if exit has been requested.
 

Static Public Member Functions

static void ReceiveGamepadEvent (int controller_id, int event_code, int control_code, float x, float y)
 Receives events from java, and stuffs them into a vector until we're ready.
 

Static Public Attributes

static const int kMaxSimultanuousPointers = 10
 

Member Function Documentation

void fplbase::InputSystem::AdvanceFrame ( mathfu::vec2i *  window_size)

Call once a frame to update the input state.

Call this once a frame to process all new events and update the input state. The window_size argument may get updated whenever the window resizes.

Parameters
window_sizeThe current window size of the application.
std::vector<AppEventCallback>& fplbase::InputSystem::app_event_callbacks ( )
inline

Get the vector of all app event callbacks.

Returns
Returns a std::vector<AppEventCallback> with all app event callbacks.
void fplbase::InputSystem::ClearTextInputEvents ( )
inline

Clear the recorded text input events.

The user needs to call the API once they have handled input events.

double fplbase::InputSystem::DeltaTime ( ) const

The time in seconds since the last frame. Updated once per frame.

Returns
Return the incremental time, in seconds.
const std::map<AndroidInputDeviceId, Gamepad>& fplbase::InputSystem::GamepadMap ( ) const
inline

Get a map containing all currently connected gamepads.

Returns
Returns the map of all gamepads.
Button& fplbase::InputSystem::GetButton ( int  button)

Get a Button object describing the input state of the specified button ID.

Parameters
buttonThe ID of the button.
Returns
Returns the corresponding button.
Gamepad& fplbase::InputSystem::GetGamepad ( AndroidInputDeviceId  gamepad_device_id)

Get a Gamepad object describing the input state of the specified device ID.

Get the ID either from an android event, or by checking a known gamepad.

Parameters
gamepad_device_idThe ID of the gamepad device.
Returns
Returns the corresponding gamepad.
Joystick& fplbase::InputSystem::GetJoystick ( JoystickId  joystick_id)

Get a Joystick object describing the input state of the specified joystick ID.

Parameters
joystick_idThe ID of the joystick, contained in every joystick event.
Returns
Returns the corresponding button.
Button& fplbase::InputSystem::GetPointerButton ( FingerId  pointer)
inline

Get a Button object for a pointer index.

Parameters
pointerThe FingerId of the button.
Returns
Returns the corresponding button.
const std::vector<TextInputEvent>* fplbase::InputSystem::GetTextInputEvents ( )

Retrieve a vector of text input events.

The caller uses this API to retrieve text input related events (all key down/up events, keyboard input and IME's intermediate states) and use them to edit and display texts. To start/stop a recording, call RecordTextInput() API.

Returns
Returns a vector containing text input events.
void fplbase::InputSystem::HandleJoystickEvent ( Event  event)

Handle a joystick event.

Parameters
[in]eventThe joystick event that should be handled.
void fplbase::InputSystem::Initialize ( )

Initialize the input system.

Call this after the Renderer is initialized.

const std::map<JoystickId, Joystick>& fplbase::InputSystem::JoystickMap ( ) const
inline

Get a map containing all currently connected joysticks.

Returns
Returns the map of all joysticks.
int fplbase::InputSystem::minimized_frame ( ) const
inline

Get the most recent frame at which we were minimized or maximized.

Returns
Returns the most recent frame at which we were minimized or maximized.
double fplbase::InputSystem::RealTime ( ) const

Get time in seconds since start of the game. Updated every call.

Unlike Time(), it is recomputed every time it is called (slower). Mostly useful for profiling/benchmarking.

Returns
Return the time in seconds since the start of the game.
void fplbase::InputSystem::RecordTextInput ( bool  b)
inline

Start/Stop recording text input events.

Recorded event can be retrieved by GetTextInputEvents().

bool fplbase::InputSystem::RelativeMouseMode ( ) const

Checks if relative mouse mode is enabled.

Returns
Returns the current state of relative mouse mode.
void fplbase::InputSystem::set_minimized_frame ( int  minimized_frame)
inline

Set the most recent frame at which we were minimized or maximized.

Parameters
[in]minimized_frameThe most recent frame at which we were minimized or maximized.
void fplbase::InputSystem::SetRelativeMouseMode ( bool  enabled)

Enable / disable relative mouse mode (disabled by default).

Parameters
enabledThe state to set relative mouse mode to.
Note
Relative mouse mode is currently ignored on Android devices.
void fplbase::InputSystem::SetTextInputRect ( const mathfu::vec4 &  input_rect)

Indicates a text input region to IME(Input Method Editor).

Parameters
input_rectThe input region rectangle.
void fplbase::InputSystem::StartTextInput ( )

Start a text input.

In mobile devices, it may show a software keyboard on the screen.

void fplbase::InputSystem::StopTextInput ( )

Stop a text input.

In mobile devices, it may dismiss a software keyboard.

double fplbase::InputSystem::Time ( ) const

Get time in seconds since the start of the game. Updated once per frame.

This is the time you'd want to use for any gameplay simulation or animation the game does, such that you are in sync with what's rendered each frame.

Returns
Return the time in seconds since the start of the game.

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