ImagoEngine
A C++ 2D game engine built on a sparse-set ECS, with scenes, scheduled systems, events, and action-based input
Loading...
Searching...
No Matches
Imago::Engine::InputHandler Class Reference

Owned by Game. Handles registering actions and adding raw inputs to them. It updates InputState based off of window events. Systems never see this class, instead they see the InputState it owns. An action has inputs that the user decides but all logic within states should be based off of whether or not the action has been executed, not the input. Mutiple inputs can drive a single action. More...

#include <Imago/Engine/InputHandler.hpp>

Public Member Functions

 InputHandler ()=default
 Constructs an InputHandler object.
 InputHandler (const InputHandler &)=delete
InputHandler & operator= (const InputHandler &)=delete
 InputHandler (InputHandler &&)=delete
InputHandler & operator= (InputHandler &&)=delete
ActionId register_action (const std::string &name)
 Registers an action name and returns its id.
void add_input (ActionId action, const InputSource &source, float deadZone=0.0f, float threshold=0.5f)
 Adds a raw input to an action. Overloaded so callers can call with action name or action id and InputSource wrapper or SFML object.
void add_input (const std::string &name, const InputSource &source, float deadZone=0.0f, float threshold=0.5f)
void add_input (const std::string &name, sf::Keyboard::Scancode scancode)
void add_input (const std::string &name, sf::Mouse::Button button)
void add_input (const std::string &name, GamepadButton button)
void add_input (const std::string &name, GamepadAxis axis, float deadZone=0.2f, float threshold=0.5f)
void handle_event (const sf::Event &event)
 Updates input and action state from one window event. Handles key and mouse button presses and releases, and focus loss.
void handle_gamepad_button (GamepadButton button, bool down)
 Handles a Gamepad button event. Called by Game which determines what button the event is associated with, and what state it is in.
void handle_gamepad_axis (GamepadAxis axis, float magnitude)
 Handles a Gamepad axis event. Called by Game which determines which axis had motion and what the magnitude of that motion was.
void release_gamepad_inputs ()
 Releases all Gamepad inputs, called by Game when a controller is disconnected.
void clear_edges ()
 Clears latched edges, keeps held state. Game calls this after a scene switch.
InputState & state ()
 Returns the state that SceneContext::input points to.

Detailed Description

Owned by Game. Handles registering actions and adding raw inputs to them. It updates InputState based off of window events. Systems never see this class, instead they see the InputState it owns. An action has inputs that the user decides but all logic within states should be based off of whether or not the action has been executed, not the input. Mutiple inputs can drive a single action.

Member Function Documentation

◆ handle_event()

void Imago::Engine::InputHandler::handle_event ( const sf::Event & event)

Updates input and action state from one window event. Handles key and mouse button presses and releases, and focus loss.

Repeataed KeyPressed events for a key that is already down are ignored.

Parameters
eventThe SFML event

◆ handle_gamepad_axis()

void Imago::Engine::InputHandler::handle_gamepad_axis ( GamepadAxis axis,
float magnitude )

Handles a Gamepad axis event. Called by Game which determines which axis had motion and what the magnitude of that motion was.

Parameters
axisThe Gamepad axis that had motion - turned from an SDL2 enum to an Imago enum by Game.
magnitudethe magnitude of that motion for that axis.

◆ handle_gamepad_button()

void Imago::Engine::InputHandler::handle_gamepad_button ( GamepadButton button,
bool down )

Handles a Gamepad button event. Called by Game which determines what button the event is associated with, and what state it is in.

Parameters
buttonThe Gamepad button - turned from an SDL2 enum to an Imago enum by Game.
downwhether or not the button is down

◆ register_action()

ActionId Imago::Engine::InputHandler::register_action ( const std::string & name)

Registers an action name and returns its id.

Registering an existing action warns and returns its existing id.

Parameters
nameName of the action to register.

The documentation for this class was generated from the following files:
  • engine/include/Imago/Engine/InputHandler.hpp
  • engine/src/Engine/InputHandler.cpp