Oficina Framework  1.3
Games Framework
OficinaFramework::InputSystem Class Reference

Groups all input-related methods and objects. Has built-in support for keyboard, multiple gamepads and mouse. More...

#include <InputSystem.hpp>

Classes

struct  State
 Represents a state for the input. More...
 

Public Types

enum  Type { Type::KEYBOARD = 0x00u, Type::XBOXPAD = 0x7Fu, Type::JOYPAD = 0xFFu }
 Represents the current input type on the input system. More...
 
enum  ThumbStick { ThumbStick::LEFTSTICK = 0x00u, ThumbStick::NOSTICK = 0x7Fu, ThumbStick::RIGHTSTICK = 0xFFu }
 Represents one thumbstick on a gamepad. More...
 
enum  ThumbStickAxis { ThumbStickAxis::HORIZONTAL = 0x00u, ThumbStickAxis::NOAXIS = 0x7Fu, ThumbStickAxis::VERTICAL = 0xFFu }
 Represents an axis of a thumbstick. More...
 
enum  ThumbStickAxisSignal { ThumbStickAxisSignal::CENTERED = 0x7FFFu, ThumbStickAxisSignal::POSITIVE = 0xFFFEu, ThumbStickAxisSignal::NEGATIVE = 0x0000u }
 Represents the signal of a thumbstick's axis or a Trigger. More...
 
enum  GamePadTrigger { GamePadTrigger::LEFTTRIGGER = 0x00u, GamePadTrigger::RIGHTTRIGGER = 0xFFu }
 Represents a trigger of the gamepad. More...
 
enum  GamePadButton {
  GamePadButton::START = 0x00u, GamePadButton::SELECT = 0x01u, GamePadButton::A = 0x02u, GamePadButton::B = 0x03u,
  GamePadButton::X = 0x04u, GamePadButton::Y = 0x05u, GamePadButton::LSTICK = 0x06u, GamePadButton::RSTICK = 0x07u,
  GamePadButton::HAT_UP = 0x08u, GamePadButton::HAT_DOWN = 0x09u, GamePadButton::HAT_LEFT = 0x0Au, GamePadButton::HAT_RIGHT = 0x0Bu,
  GamePadButton::LSHOULDER1 = 0x0Cu, GamePadButton::LSHOULDER2 = 0x0Du, GamePadButton::RSHOULDER1 = 0x0Eu, GamePadButton::RSHOULDER2 = 0x0Fu,
  GamePadButton::BIGBUTTON = 0x10u
}
 Represents a button of the gamepad. More...
 
enum  MouseButton { MouseButton::LEFTMB = 0x00u, MouseButton::MIDDLEMB = 0x01u, MouseButton::RIGHTMB = 0x02u }
 Represents a button of the mouse. More...
 

Static Public Member Functions

static void init ()
 Initializes the Input System and Joysticks, if connected. More...
 
static void dispose ()
 Disposes all Input System and Joysticks. More...
 
static void Update ()
 Updates the system. More...
 
static void SetType (Type t)
 Sets the type of input for the input system. More...
 
static void Set (GamePadButton btn, bool st)
 Sets the state of a gamepad button. Also works for keyboard, as key bindings have equivalent gamepad buttons. More...
 
static void SetMouse (MouseButton btn, bool st)
 Sets the state of a mouse button. More...
 
static void SetKeyboard (ThumbStick thumb, ThumbStickAxis axis, ThumbStickAxisSignal sig)
 Sets the state of the thumbsticks according to a keyboard key press. More...
 
static void SetJoystick (ThumbStick thumb, ThumbStickAxis axis, word_s sig)
 Sets the state of the thumbsticks according to a joypad thumbstick move. More...
 
static void SetTrigger (GamePadTrigger trig, word_s pos)
 Sets the state of a trigger according to a joypad trigger move, if supported. More...
 
static void SetMouse (vec2dw pos)
 Sets the state of the mouse position. More...
 
static void SetDeadZone (word dz)
 Sets the thumbsticks' dead zone value. More...
 
static bool PressingButton (GamePadButton btn)
 Gets if a specific button is being pressed and held down. More...
 
static bool PressedButton (GamePadButton btn)
 Gets if a specific button was pressed, at the pressing moment. More...
 
static bool PressingMouse (MouseButton btn)
 Gets if a specific mouse button is being pressed and held down. More...
 
static bool PressedMouse (MouseButton btn)
 Gets if a specific mouse button was pressed, at the pressing moment. More...
 
static Type GetType ()
 Gets the current type of input being received. More...
 
static vec2 GetLeftStick ()
 Gets the current position of the left thumbstick. More...
 
static vec2 GetRightStick ()
 Gets the current position of the right thumbstick. More...
 
static word GetDeadZone ()
 Gets the current Dead Zone of the thumbsticks. More...
 
static float GetTrigger (GamePadTrigger tr)
 Gets the current position of a gamepad trigger. More...
 
static vec2dw GetMousePos ()
 Gets the current position of the mouse. More...
 
static State GetState ()
 Gets the current state of input. More...
 
static State GetOldState ()
 Gets the old state of input. More...
 
static void InitJoystick ()
 Tries to initialize a joystick, if there's any connected. More...
 
static bool IsJoystickAvailable ()
 Shows if a joystick is available. More...
 
static void StartJoystickRumbleSupport ()
 Starts the rumble support for the joystick, if available. More...
 
static void StopJoystickRumbleSupport ()
 Stops the rumble support for the joystick, if active. More...
 
static bool IsJoystickRumbleSupported ()
 Gets the rumble support for the joystick. More...
 
static void Rumble (float strength, dword duration)
 Rumbles the joystick, if the rumble support is active. More...
 
static bool IsXboxController ()
 Checks if the currently attached joystick is an Xbox Controller. More...
 
static void CallExitCommand ()
 Calls the exit command input, setting the Exit flag to true. More...
 
static bool IsExitFlagActive ()
 Checks if the exit flag has been activated. More...
 
static void ShowMouse ()
 Shows mouse pointer, if hidden. More...
 
static void HideMouse ()
 Hides mouse pointer, if visible. More...
 
static void BindKey (SDL_Keycode key, GamePadButton btn)
 Binds a keyboard key to a gamepad button. More...
 
static void UnbindKey (SDL_Keycode key)
 Unbinds a keyboard key to a gamepad button. More...
 
static void BindStick (SDL_Keycode key, ThumbStick stick, ThumbStickAxis axis, ThumbStickAxisSignal signal)
 Binds a keyboard key to a gamepad thumbstick movement. More...
 
static void UnbindStick (ThumbStick stick, ThumbStickAxis axis, ThumbStickAxisSignal signal)
 Unbinds a keyboard key to a gamepad thumbstick movement. If the key is not binded, nothing happens. More...
 
static void BindDefaultKeys ()
 Binds default keyboard keys to the application.
Here's the equivalency table for the default bindings. More...
 
static bool PressingKey (SDL_Scancode code)
 Gets if a keyboard key is being pressed. More...
 
static bool PressedKey (SDL_Scancode code)
 Gets if a keyboard key was pressed. More...
 
static bool MovedStick (ThumbStick thumbstick, ThumbStickAxis axis, ThumbStickAxisSignal signal)
 Gets if a thumbstick was moved to a given direction (current frame only). More...
 
static std::string GetInputDeviceName ()
 Gets the current input device name. More...
 

Detailed Description

Groups all input-related methods and objects. Has built-in support for keyboard, multiple gamepads and mouse.

Member Enumeration Documentation

◆ GamePadButton

Represents a button of the gamepad.

Enumerator
START 

START button of gamepad.

SELECT 

SELECT/BACK button of gamepad.

A button of gamepad.

B button of gamepad.

X button of gamepad.

Y button of gamepad.

LSTICK 

Left Stick (press) button of gamepad.

RSTICK 

Right Stick (press) button of gamepad.

HAT_UP 

UP directional of digital pad from gamepad.

HAT_DOWN 

DOWN directional of digital pad from gamepad.

HAT_LEFT 

LEFT directional of digital pad from gamepad.

HAT_RIGHT 

RIGHT directional of digital pad from gamepad.

LSHOULDER1 

Left Shoulder 1/Left Bumper button from gamepad.

LSHOULDER2 

Left Shoulder 2/Left Trigger button from gamepad.

RSHOULDER1 

Right Shoulder 1/Right Bumper button from gamepad.

RSHOULDER2 

Right Shoulder 2/Right Trigger button from gamepad.

BIGBUTTON 

Big Button/Xbox Button of gamepad.

◆ GamePadTrigger

Represents a trigger of the gamepad.

Enumerator
LEFTTRIGGER 

Left Gamepad Trigger.

RIGHTTRIGGER 

Right Gamepad Trigger.

◆ MouseButton

Represents a button of the mouse.

Enumerator
LEFTMB 

Left Mouse Button.

MIDDLEMB 

Middle Mouse Button.

RIGHTMB 

Right Mouse Button.

◆ ThumbStick

Represents one thumbstick on a gamepad.

Enumerator
LEFTSTICK 

Left Thumbstick.

NOSTICK 

No Thumbstick - used to represent an alternative axis or a Trigger.

RIGHTSTICK 

Right Thumbstick.

◆ ThumbStickAxis

Represents an axis of a thumbstick.

Enumerator
HORIZONTAL 

Horizontal axis.

NOAXIS 

No axis - used to represent an alternative axis or a Trigger.

VERTICAL 

Vertical axis.

◆ ThumbStickAxisSignal

Represents the signal of a thumbstick's axis or a Trigger.

Enumerator
CENTERED 

Represents a centered axis.

POSITIVE 

Represents an axis with positive value (beyond center).

NEGATIVE 

Represents an axis with negative value (short of center).

◆ Type

Represents the current input type on the input system.

Enumerator
KEYBOARD 

Keyboard input type.

XBOXPAD 

Xbox Gamepad input type.

JOYPAD 

Generic Joypad input type.

Member Function Documentation

◆ BindDefaultKeys()

static void OficinaFramework::InputSystem::BindDefaultKeys ( )
static

Binds default keyboard keys to the application.
Here's the equivalency table for the default bindings.

Controller equivalent Keyboard equivalent
Digital Hat Up 1
Digital Hat Right 2
Digital Hat Down 3
Digital Hat Left 4
Button A K
Button B L
Button X J
Button Y I
Start ENTER/RETURN
Select BACKSPACE
Right Shoulder 1 E
Right Shoulder 2 SPACE
Left Shoulder 1 Q
Left Shoulder 2 LEFT CTRL
Press Left Stick U
Press Right Stick O
Left Stick Up W
Left Stick Down S
Left Stick Left A
Left Stick Right D
Right Stick Up UP ARROW KEY
Right Stick Down DOWN ARROW KEY
Right Stick Left LEFT ARROW KEY
Right Stick Right RIGHT ARROW KEY

◆ BindKey()

static void OficinaFramework::InputSystem::BindKey ( SDL_Keycode  key,
GamePadButton  btn 
)
static

Binds a keyboard key to a gamepad button.

Warning
If the button is already binded to a key, the key will be replaced; additionally, if the key is already binded to a button or thumbstick movement, the binding process will be ignored.
Parameters
keyThe key to bind to a button.
btnThe button to be binded to.

◆ BindStick()

static void OficinaFramework::InputSystem::BindStick ( SDL_Keycode  key,
ThumbStick  stick,
ThumbStickAxis  axis,
ThumbStickAxisSignal  signal 
)
static

Binds a keyboard key to a gamepad thumbstick movement.

Warning
If the thumbstick movement is already binded to a key, the key will be replaced; additionally, if the key is already binded to a button or a thumbstick movement, the binding process will be ignored.
Parameters
keyThe key to bind to the stick movement.
stickDesired thumbstick.
axisDesired axis of thumbstick.
signalDesired signal of the axis.

◆ CallExitCommand()

static void OficinaFramework::InputSystem::CallExitCommand ( )
static

Calls the exit command input, setting the Exit flag to true.

◆ dispose()

static void OficinaFramework::InputSystem::dispose ( )
static

Disposes all Input System and Joysticks.

◆ GetDeadZone()

static word OficinaFramework::InputSystem::GetDeadZone ( )
static

Gets the current Dead Zone of the thumbsticks.

Returns
The word-precision dead zone value.

◆ GetInputDeviceName()

static std::string OficinaFramework::InputSystem::GetInputDeviceName ( )
static

Gets the current input device name.

Returns
The name of the current main input device which the input is gotten.

◆ GetLeftStick()

static vec2 OficinaFramework::InputSystem::GetLeftStick ( )
static

Gets the current position of the left thumbstick.

Returns
float-precision vec2 with the left thumbstick position.

◆ GetMousePos()

static vec2dw OficinaFramework::InputSystem::GetMousePos ( )
static

Gets the current position of the mouse.

Returns
Mouse position related to the left upper corner of the screen, in pixels.

◆ GetOldState()

static State OficinaFramework::InputSystem::GetOldState ( )
static

Gets the old state of input.

Returns
InputSystem::State of the input on the previous frame.

◆ GetRightStick()

static vec2 OficinaFramework::InputSystem::GetRightStick ( )
static

Gets the current position of the right thumbstick.

Returns
A float-precision vec2 with the right thumbstick position.

◆ GetState()

static State OficinaFramework::InputSystem::GetState ( )
static

Gets the current state of input.

Returns
InputSystem::State of the input on the current frame.

◆ GetTrigger()

static float OficinaFramework::InputSystem::GetTrigger ( GamePadTrigger  tr)
static

Gets the current position of a gamepad trigger.

Parameters
trDesired trigger to get its value.
Returns
A float-precision value with the trigger position.

◆ GetType()

static Type OficinaFramework::InputSystem::GetType ( )
static

Gets the current type of input being received.

Returns
The InputSystem::Type of input currently being processed.

◆ HideMouse()

static void OficinaFramework::InputSystem::HideMouse ( )
static

Hides mouse pointer, if visible.

◆ init()

static void OficinaFramework::InputSystem::init ( )
static

Initializes the Input System and Joysticks, if connected.

◆ InitJoystick()

static void OficinaFramework::InputSystem::InitJoystick ( )
static

Tries to initialize a joystick, if there's any connected.

◆ IsExitFlagActive()

static bool OficinaFramework::InputSystem::IsExitFlagActive ( )
static

Checks if the exit flag has been activated.

Returns
Whether the user has sent the Quit signal to the window, via controller or by closing it.

◆ IsJoystickAvailable()

static bool OficinaFramework::InputSystem::IsJoystickAvailable ( )
static

Shows if a joystick is available.

Returns
Whether at least one joystick is attached.

◆ IsJoystickRumbleSupported()

static bool OficinaFramework::InputSystem::IsJoystickRumbleSupported ( )
static

Gets the rumble support for the joystick.

Returns
Whether rumble is supported or not.

◆ IsXboxController()

static bool OficinaFramework::InputSystem::IsXboxController ( )
static

Checks if the currently attached joystick is an Xbox Controller.

Returns
Whether the attached controller has Xbox in its name or not.

◆ MovedStick()

static bool OficinaFramework::InputSystem::MovedStick ( ThumbStick  thumbstick,
ThumbStickAxis  axis,
ThumbStickAxisSignal  signal 
)
static

Gets if a thumbstick was moved to a given direction (current frame only).

Returns
Whether the thumbstick was moved on the given direction or not.
Parameters
thumbstickRelated thumbstick.
axisAxis to be compared.
signalSignal of the axis.

◆ PressedButton()

static bool OficinaFramework::InputSystem::PressedButton ( GamePadButton  btn)
static

Gets if a specific button was pressed, at the pressing moment.

Parameters
btnButton to make the comparision.
Returns
If the button was being pressed at the specific frame of this call.

◆ PressedKey()

static bool OficinaFramework::InputSystem::PressedKey ( SDL_Scancode  code)
static

Gets if a keyboard key was pressed.

Returns
Whether the key is being pressed at the current instant or not.

◆ PressedMouse()

static bool OficinaFramework::InputSystem::PressedMouse ( MouseButton  btn)
static

Gets if a specific mouse button was pressed, at the pressing moment.

Parameters
btnMouse button to make the comparision.
Returns
If the mouse button was being pressed at the specific frame of this call.

◆ PressingButton()

static bool OficinaFramework::InputSystem::PressingButton ( GamePadButton  btn)
static

Gets if a specific button is being pressed and held down.

Parameters
btnButton to make the comparision.
Returns
If the button is being pressed and held.

◆ PressingKey()

static bool OficinaFramework::InputSystem::PressingKey ( SDL_Scancode  code)
static

Gets if a keyboard key is being pressed.

Returns
Whether the key is being pressed or not.

◆ PressingMouse()

static bool OficinaFramework::InputSystem::PressingMouse ( MouseButton  btn)
static

Gets if a specific mouse button is being pressed and held down.

Parameters
btnMouse button to make the comparision.
Returns
If the mouse button is being pressed and held.

◆ Rumble()

static void OficinaFramework::InputSystem::Rumble ( float  strength,
dword  duration 
)
static

Rumbles the joystick, if the rumble support is active.

Parameters
strengthThe strength of the rumble (a value between 0 and 1).
durationThe duration of the rumble, in miliseconds.

◆ Set()

static void OficinaFramework::InputSystem::Set ( GamePadButton  btn,
bool  st 
)
static

Sets the state of a gamepad button. Also works for keyboard, as key bindings have equivalent gamepad buttons.

Parameters
btnThe desired button to have the state set.
stThe state of the gamepad button.

◆ SetDeadZone()

static void OficinaFramework::InputSystem::SetDeadZone ( word  dz)
static

Sets the thumbsticks' dead zone value.

Parameters
dzDesired dead zone value.

◆ SetJoystick()

static void OficinaFramework::InputSystem::SetJoystick ( ThumbStick  thumb,
ThumbStickAxis  axis,
word_s  sig 
)
static

Sets the state of the thumbsticks according to a joypad thumbstick move.

Parameters
thumbThe desired thumbstick.
axisThe axis of the desired thumbstick.
sigPosition of the thumbstick on the related axis.

◆ SetKeyboard()

static void OficinaFramework::InputSystem::SetKeyboard ( ThumbStick  thumb,
ThumbStickAxis  axis,
ThumbStickAxisSignal  sig 
)
static

Sets the state of the thumbsticks according to a keyboard key press.

Parameters
thumbThe desired thumbstick.
axisThe axis of the desired thumbstick.
sigAxis' signal of the desired thumbstick.

◆ SetMouse() [1/2]

static void OficinaFramework::InputSystem::SetMouse ( MouseButton  btn,
bool  st 
)
static

Sets the state of a mouse button.

Parameters
btnThe desired mouse button to have the state set.
stThe state of the mouse button.

◆ SetMouse() [2/2]

static void OficinaFramework::InputSystem::SetMouse ( vec2dw  pos)
static

Sets the state of the mouse position.

Parameters
posDesired mouse position to be set.

◆ SetTrigger()

static void OficinaFramework::InputSystem::SetTrigger ( GamePadTrigger  trig,
word_s  pos 
)
static

Sets the state of a trigger according to a joypad trigger move, if supported.

Parameters
trigThe desired trigger.
posThe position of the trigger on its related axis.

◆ SetType()

static void OficinaFramework::InputSystem::SetType ( Type  t)
static

Sets the type of input for the input system.

Parameters
tType of input to be set.

◆ ShowMouse()

static void OficinaFramework::InputSystem::ShowMouse ( )
static

Shows mouse pointer, if hidden.

◆ StartJoystickRumbleSupport()

static void OficinaFramework::InputSystem::StartJoystickRumbleSupport ( )
static

Starts the rumble support for the joystick, if available.

◆ StopJoystickRumbleSupport()

static void OficinaFramework::InputSystem::StopJoystickRumbleSupport ( )
static

Stops the rumble support for the joystick, if active.

◆ UnbindKey()

static void OficinaFramework::InputSystem::UnbindKey ( SDL_Keycode  key)
static

Unbinds a keyboard key to a gamepad button.

Warning
If the key is not binded, nothing happens.
Parameters
keyThe key to unbind to a button.

◆ UnbindStick()

static void OficinaFramework::InputSystem::UnbindStick ( ThumbStick  stick,
ThumbStickAxis  axis,
ThumbStickAxisSignal  signal 
)
static

Unbinds a keyboard key to a gamepad thumbstick movement. If the key is not binded, nothing happens.

Parameters
stickDesired thumbstick to have a movement unbinded.
axisDesired axis of thumbstick to have a movement unbinded.
signalDesired signal of the axis to have a movement unbinded.

◆ Update()

static void OficinaFramework::InputSystem::Update ( )
static

Updates the system.


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