nomlib
Loading...
Searching...
No Matches
nom::InputStateMapper Class Reference

High-level API for collections of input action maps. More...

#include <InputStateMapper.hpp>

Public Types

typedef InputStateMapper SelfType
typedef std::pair< std::string, InputActionState > Pair
typedef std::map< std::string, InputActionState > InputStateMap

Public Member Functions

 InputStateMapper (void)
 Default constructor.
 ~InputStateMapper (void)
 Destructor.
bool active (const std::string &key) const
 Obtain active state status.
bool insert (const std::string &key, const InputActionMapper &map, bool active)
 Add action mappings to an input state.
bool erase (const std::string &key)
 Remove a state.
bool activate (const std::string &key)
 Activate a state.
bool disable (const std::string &key)
 Disable a state.
void disable (void)
 Disable all input states.
bool activate_only (const std::string &key)
 Enable only a particular state.
void clear (void)
 Empty the container of input states.
void dump ()
 Diagnostic output.
void set_event_handler (EventHandler &evt_handler)
 Install the event handler used by the interface.
void remove_event_handler ()
 Detach the event handler watch previously installed via set_event_handler.

Private Member Functions

void on_event (const Event &ev)
 Internal event handler for triggering mapped action states.
bool on_key_press (const InputAction &mapping, const Event &ev)
 Internal event handler for matching a keyboard action to a keyboard event.
bool on_mouse_button (const InputAction &mapping, const Event &ev)
 Internal event handler for matching a mouse button action to a mouse button event.
bool on_mouse_wheel (const InputAction &mapping, const Event &ev)
 Internal event handler for matching a mouse wheel action to a mouse wheel event.
bool on_joystick_button (const InputAction &mapping, const Event &ev)
 Internal event handler for matching a joystick button action to a joystick button event.
bool on_joystick_axis (const InputAction &mapping, const Event &ev)
 Internal event handler for matching a joystick axis action to a joystick axis event.
bool on_joystick_hat (const InputAction &mapping, const Event &ev)
bool on_game_controller_button (const InputAction &mapping, const Event &ev)
 Internal event handler for matching a game controller button action to an equivalent event.
bool on_game_controller_axis (const InputAction &mapping, const Event &ev)
 Internal event handler for matching a game controller axis action to an equivalent event.

Private Attributes

EventHandler * event_handler_ = nullptr
event_filter event_watch_ = nullptr
InputStateMap states_

Detailed Description

High-level API for collections of input action maps.

Remarks
See also, nom::InputActionMapper, nom::InputAction.

Definition at line 54 of file InputStateMapper.hpp.

Member Typedef Documentation

◆ InputStateMap

typedef std::map<std::string, InputActionState> nom::InputStateMapper::InputStateMap

Definition at line 59 of file InputStateMapper.hpp.

◆ Pair

typedef std::pair<std::string, InputActionState> nom::InputStateMapper::Pair

Definition at line 58 of file InputStateMapper.hpp.

◆ SelfType

typedef InputStateMapper nom::InputStateMapper::SelfType

Definition at line 57 of file InputStateMapper.hpp.

Member Function Documentation

◆ activate()

bool nom::InputStateMapper::activate ( const std::string & key)

Activate a state.

Parameters
keyThe state string index to activate.

◆ activate_only()

bool nom::InputStateMapper::activate_only ( const std::string & key)

Enable only a particular state.

Remarks
All other states, less and except specified state, will be marked inactive.

◆ active()

bool nom::InputStateMapper::active ( const std::string & key) const

Obtain active state status.

Parameters
keyThe state string index to query.

◆ disable()

bool nom::InputStateMapper::disable ( const std::string & key)

Disable a state.

Parameters
keyThe state string index to disable.

◆ dump()

void nom::InputStateMapper::dump ( )

Diagnostic output.

remarks Dumps only the active states.

◆ erase()

bool nom::InputStateMapper::erase ( const std::string & key)

Remove a state.

Parameters
keyThe state string index to remove.

◆ insert()

bool nom::InputStateMapper::insert ( const std::string & key,
const InputActionMapper & map,
bool active )

Add action mappings to an input state.

Parameters
keyThe state string index associated with the input action container.
mapA nom::InputActionMapper object with your input action maps to be assigned to a state.
activeToggle the active state of the input mappings.

◆ remove_event_handler()

void nom::InputStateMapper::remove_event_handler ( )

Detach the event handler watch previously installed via set_event_handler.

Remarks
Safe to call when no handler is installed (no-op). Call this before the installed nom::EventHandler is destroyed; the destructor intentionally does not touch the (non-owned) handler.

◆ set_event_handler()

void nom::InputStateMapper::set_event_handler ( EventHandler & evt_handler)

Install the event handler used by the interface.

Remarks
Installing on the same handler twice is a no-op. Installing on a different handler detaches the previously installed watch first.

The application's events will not be processed until a call is made to the event handler's ::poll_event method.

Note
The installed event handler must outlive the destruction of this interface! The destructor intentionally does not touch the non-owned handler; call remove_event_handler() before the handler is destroyed.

Member Data Documentation

◆ event_handler_

EventHandler* nom::InputStateMapper::event_handler_ = nullptr
private

Definition at line 173 of file InputStateMapper.hpp.

◆ event_watch_

event_filter nom::InputStateMapper::event_watch_ = nullptr
private

Definition at line 177 of file InputStateMapper.hpp.

◆ states_

InputStateMap nom::InputStateMapper::states_
private

Definition at line 179 of file InputStateMapper.hpp.


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