Classes | Functions
Input

Features related to user input, such as object-oriented event callbacks. More...

Classes

class  thor::Action
 Class for dynamic actions that are connected with SFML events. More...
 
struct  thor::ActionContext< ActionId >
 Structure containing information about the context in which an action has occurred. More...
 
class  thor::ActionMap< ActionId >
 Class template that associates identifiers with dynamic actions. More...
 
class  thor::Connection
 Class that maintains control over a registered object. More...
 
class  thor::ScopedConnection
 RAII style connection with automatic disconnect. More...
 
class  thor::EventSystem< Event, EventId >
 Class for object-oriented handling of user-defined events. More...
 
struct  thor::JoystickButton
 Contains information about a joystick number and button number. More...
 
struct  thor::JoystickAxis
 Contains information about a joystick number, an axis and its threshold. More...
 

Functions

std::string thor::toString (sf::Keyboard::Key key)
 Returns a string representation of key. More...
 
std::string thor::toString (sf::Mouse::Button button)
 Returns a string representation of button. More...
 
std::string thor::toString (sf::Joystick::Axis axis)
 Returns a string representation of axis. More...
 
sf::Keyboard::Key thor::toKeyboardKey (const std::string &string)
 Returns the key interpretation of string. More...
 
sf::Mouse::Button thor::toMouseButton (const std::string &string)
 Returns the mouse button interpretation of string. More...
 
sf::Joystick::Axis thor::toJoystickAxis (const std::string &string)
 Returns the joystick axis interpretation of string. More...
 
Action operator|| (const Action &lhs, const Action &rhs)
 OR operator of two actions: The resulting action is in effect if at least one of lhs and rhs is active. More...
 
Action operator&& (const Action &lhs, const Action &rhs)
 AND operator of two actions: The resulting action is in effect if both lhs and rhs are active. More...
 
Action operator! (const Action &action)
 NOT operator of an action: The resulting action is in effect if action is not active. More...
 
Action eventAction (std::function< bool(const sf::Event &)> filter)
 Creates a custom action that operates on events. More...
 
Action realtimeAction (std::function< bool()> filter)
 Creates a custom action that operates on realtime input. More...
 

Detailed Description

Features related to user input, such as object-oriented event callbacks.

Function Documentation

Action eventAction ( std::function< bool(const sf::Event &)>  filter)
related

Creates a custom action that operates on events.

Parameters
filterFunctor that is called for every event (which is passed as a parameter). It shall return true when the passed event makes the action active.

Code example: An action that is active when the X key is pressed. This is just an example, in this specific case you should prefer the equivalent expression thor::Action(sf::Keyboard::X, thor::Action::PressOnce).

bool isXPressed(const sf::Event& event)
{
return event.type == sf::Event::KeyPressed && event.key.code == sf::Keyboard::X;
}
thor::Action xPressed = thor::eventAction(&isXPressed);
Action operator! ( const Action action)
related

NOT operator of an action: The resulting action is in effect if action is not active.

This operator is rarely needed. It can be used to discriminate two actions, for example if X and Shift+X have different assignments and you don't want Shift+X to trigger also the action assigned to X.

thor::Action shift = thor::Action(sf::Keyboard::LShift) || thor::Action(sf::Keyboard::RShift);
thor::Action shiftX = shift && x;
thor::Action onlyX = !shift && x;
Action operator&& ( const Action lhs,
const Action rhs 
)
related

AND operator of two actions: The resulting action is in effect if both lhs and rhs are active.

This operator is typically used to implement key combinations such as Shift+X. It does not make sense if both operands are event actions, because each of them is only active at one time point, hardly together. Instead, implement modifiers as realtime actions and the actual keys as event actions:

thor::Action shift = thor::Action(sf::Keyboard::LShift) || thor::Action(sf::Keyboard::RShift);
thor::Action shiftX = shift && x;
Action operator|| ( const Action lhs,
const Action rhs 
)
related

OR operator of two actions: The resulting action is in effect if at least one of lhs and rhs is active.

This operator can be used when multiple input types are assigned to an action. For example, an action that can be triggered using either the keyboard or joystick. Another typical example is to combine both modifier keys, such as left and right shift:

thor::Action shift = thor::Action(sf::Keyboard::LShift) || thor::Action(sf::Keyboard::RShift);
thor::Action shiftX = shift && x;
Action realtimeAction ( std::function< bool()>  filter)
related

Creates a custom action that operates on realtime input.

Parameters
filterFunctor that is called exactly once per frame, independent of any events. It shall return true when a certain realtime input state should make the action active.

Code example: An action that is active as long as the X key is held down. This is just an example, in this specific case you should prefer the equivalent expression thor::Action(sf::Keyboard::X, thor::Action::Hold).

bool isXHeldDown()
{
return sf::Keyboard::isKeyPressed(sf::Keyboard::X);
}
thor::Action xHeldDown = thor::realtimeAction(&isXHeldDown);
sf::Joystick::Axis thor::toJoystickAxis ( const std::string &  string)

Returns the joystick axis interpretation of string.

The passed string shall be identical to the enum identifier. For example:

thor::toJoystickAxis("U") == sf::Joystick::U
Exceptions
StringConversionExceptionif the string doesn't match a joystick axis.
sf::Keyboard::Key thor::toKeyboardKey ( const std::string &  string)

Returns the key interpretation of string.

The passed string shall be identical to the enum identifier. For example:

thor::toKeyboardKey("BackSlash") == sf::Keyboard::BackSlash
Exceptions
StringConversionExceptionif the string doesn't match a key.
sf::Mouse::Button thor::toMouseButton ( const std::string &  string)

Returns the mouse button interpretation of string.

The passed string shall be identical to the enum identifier. For example:

thor::toMouseButton("Right") == sf::Mouse::Right
Exceptions
StringConversionExceptionif the string doesn't match a mouse button.
std::string thor::toString ( sf::Keyboard::Key  key)

Returns a string representation of key.

The returned string is identical to the enum identifier. For example:

thor::toString(sf::Keyboard::BackSlash) == "BackSlash"
Exceptions
StringConversionExceptionin case of invalid key.
std::string thor::toString ( sf::Mouse::Button  button)

Returns a string representation of button.

The returned string is identical to the enum identifier. For example:

thor::toString(sf::Mouse::Right) == "Right"
Exceptions
StringConversionExceptionin case of invalid mouse button.
std::string thor::toString ( sf::Joystick::Axis  axis)

Returns a string representation of axis.

The returned string is identical to the enum identifier. For example:

thor::toString(sf::Joystick::U) == "U"
Exceptions
StringConversionExceptionin case of invalid joystick axis.