MochiEngine
Loading...
Searching...
No Matches
Mochi::Input::InputManager Class Reference

Class that takes one IKeyboardProvider, one IMouseProvider and one IGamepadProvider and updates and collects data from them each frame automatically. It provides functions to poll the state of each provider, used by the ActionManager. This class is not meant to be implemented differently in any way, as it already receives different sets of providers for that purpose. More...

#include <InputManager.h>

Public Member Functions

 InputManager (std::unique_ptr< IKeyboardProvider > keyboardProvider, std::unique_ptr< IMouseProvider > mouseProvider, std::unique_ptr< IGamepadProvider > mGamepadProvider)
bool IsDown (const int &key) const
 Checks if a keyboard key is down in this frame.
bool WasPressed (const int &key) const
 Checks if a keyboard key is pressed this frame and wasn't the last.
bool WasReleased (const int &key) const
 Checks if a keyboard key is not pressed this frame and was the last.
void Update ()
 Updates the previous frame data with the data of the previous frame and updates the previous frame data with the data of this frame.
bool MouseIsDown (const unsigned int &mouseButton) const
 Checks if a mouse button is down in this frame.
bool MouseWasPressed (const unsigned int &mouseButton) const
 Checks if a mouse button is down in this frame and wasn't last frame.
bool MouseWasReleased (const unsigned int &mouseButton) const
 Checks if a mouse button is not pressed in this frame and was last frame.
Vector2f GetMousePosition () const
 Gets the mouse position in this frame in screen coordinates.
Vector2f GetMouseDelta () const
 Gets the difference in position between last frames mouse position and this frame mouse position.
float GetGamepadAxis (const GamepadAxis &axis) const
 Gets the value of the axis of the gamepad, between -1 and 1.
bool GamepadButtonIsDown (const GamepadButton &button) const
 Checks if a gamepad button is down.
bool GamepadButtonWasPressed (const GamepadButton &button) const
 Checks if a gamepad button is down and wasn't last frame.
bool GamepadButtonWasReleased (const GamepadButton &button) const
 Checks if a gamepad button is not down and was down last frame.

Detailed Description

Class that takes one IKeyboardProvider, one IMouseProvider and one IGamepadProvider and updates and collects data from them each frame automatically. It provides functions to poll the state of each provider, used by the ActionManager. This class is not meant to be implemented differently in any way, as it already receives different sets of providers for that purpose.

Remarks
The engine is not prepared for more than one player as for now. The InputManager takes the polling of IGamepadProvider from the first slot gamepad only.

Ownership:

Guarantees:

  • The correct state of each state is polled.
  • Previous frame states are stored to poll the correct data.

Non responsible:

  • InputManager doesn't check the validity of the provider implementations. The user is responsible to use providers that are tested and do what is expected.

Constructor & Destructor Documentation

◆ InputManager()

Mochi::Input::InputManager::InputManager ( std::unique_ptr< IKeyboardProvider > keyboardProvider,
std::unique_ptr< IMouseProvider > mouseProvider,
std::unique_ptr< IGamepadProvider > mGamepadProvider )
Parameters
keyboardProvider
mouseProvider
mGamepadProvider

Member Function Documentation

◆ GamepadButtonIsDown()

bool Mochi::Input::InputManager::GamepadButtonIsDown ( const GamepadButton & button) const

Checks if a gamepad button is down.

Parameters
buttonThe button.
Returns
True if pressed.

◆ GamepadButtonWasPressed()

bool Mochi::Input::InputManager::GamepadButtonWasPressed ( const GamepadButton & button) const

Checks if a gamepad button is down and wasn't last frame.

Parameters
buttonThe button.
Returns
True if pressed and wasn't pressed last frame.

◆ GamepadButtonWasReleased()

bool Mochi::Input::InputManager::GamepadButtonWasReleased ( const GamepadButton & button) const

Checks if a gamepad button is not down and was down last frame.

Parameters
buttonThe button.
Returns
True if not pressed and was pressed last frame.

◆ GetGamepadAxis()

float Mochi::Input::InputManager::GetGamepadAxis ( const GamepadAxis & axis) const

Gets the value of the axis of the gamepad, between -1 and 1.

Parameters
axisThe axis to check.
Returns
The value.

◆ GetMouseDelta()

Vector2f Mochi::Input::InputManager::GetMouseDelta ( ) const

Gets the difference in position between last frames mouse position and this frame mouse position.

Returns
A vector with the difference vector.

◆ GetMousePosition()

Vector2f Mochi::Input::InputManager::GetMousePosition ( ) const

Gets the mouse position in this frame in screen coordinates.

Returns
A vector with the x and y position

◆ IsDown()

bool Mochi::Input::InputManager::IsDown ( const int & key) const

Checks if a keyboard key is down in this frame.

Parameters
keyThe key code, as defined in the SDL keycode definitions
Returns
True if is pressed.

◆ MouseIsDown()

bool Mochi::Input::InputManager::MouseIsDown ( const unsigned int & mouseButton) const

Checks if a mouse button is down in this frame.

Parameters
mouseButtonThe index of the mouse button as defined in MouseButton.
Returns
True if pressed.

◆ MouseWasPressed()

bool Mochi::Input::InputManager::MouseWasPressed ( const unsigned int & mouseButton) const

Checks if a mouse button is down in this frame and wasn't last frame.

Parameters
mouseButtonThe index of the mouse button as defined in MouseButton.
Returns
True if pressed and not pressed last frame.

◆ MouseWasReleased()

bool Mochi::Input::InputManager::MouseWasReleased ( const unsigned int & mouseButton) const

Checks if a mouse button is not pressed in this frame and was last frame.

Parameters
mouseButtonThe index of the mouse button as defined in MouseButton.
Returns
True if not pressed and was pressed last frame.

◆ WasPressed()

bool Mochi::Input::InputManager::WasPressed ( const int & key) const

Checks if a keyboard key is pressed this frame and wasn't the last.

Parameters
keyThe key code, as defined in the SDL keycode definitions
Returns
True if is pressed and wasn't pressed last frame.

◆ WasReleased()

bool Mochi::Input::InputManager::WasReleased ( const int & key) const

Checks if a keyboard key is not pressed this frame and was the last.

Parameters
keyThe key code, as defined in the SDL keycode definitions
Returns
True if not pressed and was pressed last frame.

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