FifeGUI 0.3.0
A C++ GUI library designed for games.
fcn::Shortcut Class Reference

#include <shortcut.hpp>

Public Types

enum  Modifier : uint16_t {
  None = 0 , Shift = 1 << 0 , Control = 1 << 1 , Alt = 1 << 2 ,
  Meta = 1 << 3
}

Public Member Functions

bool conflicts (Shortcut const &other) const
Key getKey () const
uint16_t getModMask () const
bool matches (KeyEvent const &event) const
bool operator!= (Shortcut const &other) const
bool operator== (Shortcut const &other) const
 Shortcut ()=default
 Shortcut (Key key, uint16_t modMask=Modifier::None)
std::string to_string () const

Static Public Member Functions

static Shortcut fromKeycode (uint32_t keycode, uint16_t sdlMods=0)

Protected Attributes

Key mKey
uint16_t mModMask {Modifier::None}

Detailed Description

High-level shortcut binding a semantic key with a modifier mask.

Shortcut is the primary key representation exposed to widgets and game code. It stores an fcn::Key semantic keycode and a uint16_t modifier bitmask, hiding raw scancode details.

Scancode-based construction and matching are handled internally by the input backend. Widget code interacts only with the semantic API.

Usage

// Register a shortcut
fcn::Shortcut saveSc(fcn::Key('S'), fcn::Shortcut::Modifier::Control);
// Match against a key event
if (saveSc.matches(keyEvent)) { }
// Build from raw SDL keycode (backend use)
auto sc = fcn::Shortcut::fromKeycode(SDLK_s, SDL_KMOD_CTRL);
High-level shortcut binding a semantic key with a modifier mask.
Definition shortcut.hpp:58
static Shortcut fromKeycode(uint32_t keycode, uint16_t sdlMods=0)
Creates a Shortcut from a raw SDL keycode + SDL modifier mask.
Definition shortcut.cpp:22

Layout Independence

Shortcuts are layout-independent by design. A shortcut created with fromKeycode(SDLK_a) matches the logical "A" key across keyboard layouts because SDL keycodes are semantic and derived from the active OS keyboard layout.

Physical-position bindings such as WASD are resolved internally with SDL_GetKeyFromScancode(), which maps a physical key position to the correct semantic keycode for the current layout.

Definition at line 57 of file shortcut.hpp.

Member Enumeration Documentation

◆ Modifier

enum fcn::Shortcut::Modifier : uint16_t

Modifier flags.

Definition at line 63 of file shortcut.hpp.

Constructor & Destructor Documentation

◆ Shortcut()

fcn::Shortcut::Shortcut ( Key key,
uint16_t modMask = Modifier::None )
explicit

Constructor.

Parameters
keyThe semantic key.
modMaskBitmask of Modifier flags.

Definition at line 18 of file shortcut.cpp.

References mKey, and mModMask.

Member Function Documentation

◆ conflicts()

bool fcn::Shortcut::conflicts ( Shortcut const & other) const

Checks for collision with another shortcut.

Two shortcuts conflict if they have the same key and share at least one modifier flag (i.e. the modifier masks overlap).

Parameters
otherThe other shortcut to check against.
Returns
True if the shortcuts conflict.

Definition at line 67 of file shortcut.cpp.

References mKey, mModMask, and Shortcut().

Referenced by Shortcut().

◆ fromKeycode()

Shortcut fcn::Shortcut::fromKeycode ( uint32_t keycode,
uint16_t sdlMods = 0 )
static

Creates a Shortcut from a raw SDL keycode + SDL modifier mask.

Since fcn::KeyType mirrors SDL_Keycode 1:1, this is an inline passthrough requiring no SDL headers.

Parameters
keycodeSDL_Keycode value (uint32_t).
sdlModsSDL key modifier bitmask.
Returns
A Shortcut with the matching semantic key.

Definition at line 22 of file shortcut.cpp.

References Shortcut().

Referenced by Shortcut().

◆ getKey()

Key fcn::Shortcut::getKey ( ) const

Gets the semantic key.

Returns
The key.

Definition at line 105 of file shortcut.cpp.

References mKey.

Referenced by Shortcut().

◆ getModMask()

uint16_t fcn::Shortcut::getModMask ( ) const

Gets the modifier bitmask.

Returns
The modifier mask.

Definition at line 110 of file shortcut.cpp.

References mModMask.

Referenced by Shortcut().

◆ matches()

bool fcn::Shortcut::matches ( KeyEvent const & event) const

Compares the shortcut to a KeyEvent.

Both the semantic key value and modifier mask must match.

Parameters
eventThe key event to test against.
Returns
True if the event matches this shortcut.

Definition at line 43 of file shortcut.cpp.

References fcn::KeyEvent::getKey(), fcn::InputEvent::isAltPressed(), fcn::InputEvent::isControlPressed(), fcn::InputEvent::isMetaPressed(), fcn::InputEvent::isShiftPressed(), mKey, and mModMask.

Referenced by Shortcut().

◆ operator!=()

bool fcn::Shortcut::operator!= ( Shortcut const & other) const

Compares two shortcuts for inequality.

Definition at line 120 of file shortcut.cpp.

References Shortcut().

Referenced by Shortcut().

◆ operator==()

bool fcn::Shortcut::operator== ( Shortcut const & other) const

Compares two shortcuts for equality (same key + same mods).

Definition at line 115 of file shortcut.cpp.

References mKey, mModMask, and Shortcut().

Referenced by Shortcut().

◆ to_string()

std::string fcn::Shortcut::to_string ( ) const

Returns a human-readable string, e.g.

"Ctrl+Shift+W".

Modifier names and key names are determined via SDL_GetKeyName() at the backend level. This base implementation uses generic names.

Returns
A human-readable representation.

Definition at line 77 of file shortcut.cpp.

References mKey, and mModMask.

Referenced by Shortcut().

Member Data Documentation

◆ mKey

Key fcn::Shortcut::mKey
protected

The semantic key.

Definition at line 154 of file shortcut.hpp.

Referenced by conflicts(), getKey(), matches(), operator==(), Shortcut(), and to_string().

◆ mModMask

uint16_t fcn::Shortcut::mModMask {Modifier::None}
protected

Bitmask of Modifier flags.

Definition at line 157 of file shortcut.hpp.

Referenced by conflicts(), getModMask(), matches(), operator==(), Shortcut(), and to_string().


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