FPLBase
An open source project by
FPL.
|
Use to handle time, touch/mouse/keyboard/etc input, and lifecyle events. More...
#include <input.h>
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. | |
Button & | GetButton (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... | |
Joystick & | GetJoystick (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... | |
Gamepad & | GetGamepad (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. | |
Button & | GetPointerButton (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 |
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.
window_size | The current window size of the application. |
|
inline |
Get the vector of all app event callbacks.
std::vector<AppEventCallback>
with all app event callbacks.
|
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.
|
inline |
Get a map containing all currently connected gamepads.
Button& fplbase::InputSystem::GetButton | ( | int | button | ) |
Get a Button object describing the input state of the specified button ID.
button | The ID of the 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.
gamepad_device_id | The ID of the gamepad device. |
Joystick& fplbase::InputSystem::GetJoystick | ( | JoystickId | joystick_id | ) |
Get a Joystick object describing the input state of the specified joystick ID.
joystick_id | The ID of the joystick, contained in every joystick event. |
|
inline |
Get a Button object for a pointer index.
pointer | The FingerId of the 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.
void fplbase::InputSystem::HandleJoystickEvent | ( | Event | event | ) |
Handle a joystick event.
[in] | event | The joystick event that should be handled. |
void fplbase::InputSystem::Initialize | ( | ) |
Initialize the input system.
Call this after the Renderer is initialized.
|
inline |
Get a map containing all currently connected joysticks.
|
inline |
Get 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.
|
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.
|
inline |
Set the most recent frame at which we were minimized or maximized.
[in] | minimized_frame | The most recent frame at which we were minimized or maximized. |
void fplbase::InputSystem::SetRelativeMouseMode | ( | bool | enabled | ) |
Enable / disable relative mouse mode (disabled by default).
enabled | The state to set relative mouse mode to. |
void fplbase::InputSystem::SetTextInputRect | ( | const mathfu::vec4 & | input_rect | ) |
Indicates a text input region to IME(Input Method Editor).
input_rect | The 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.