|
FifeGUI 0.3.0
A C++ GUI library designed for games.
|
#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} |
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.
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.
| enum fcn::Shortcut::Modifier : uint16_t |
Modifier flags.
Definition at line 63 of file shortcut.hpp.
|
explicit |
Constructor.
| key | The semantic key. |
| modMask | Bitmask of Modifier flags. |
Definition at line 18 of file shortcut.cpp.
| 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).
| other | The other shortcut to check against. |
Definition at line 67 of file shortcut.cpp.
References mKey, mModMask, and Shortcut().
Referenced by Shortcut().
|
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.
| keycode | SDL_Keycode value (uint32_t). |
| sdlMods | SDL key modifier bitmask. |
Definition at line 22 of file shortcut.cpp.
References Shortcut().
Referenced by Shortcut().
| Key fcn::Shortcut::getKey | ( | ) | const |
Gets the semantic key.
Definition at line 105 of file shortcut.cpp.
References mKey.
Referenced by Shortcut().
| uint16_t fcn::Shortcut::getModMask | ( | ) | const |
Gets the modifier bitmask.
Definition at line 110 of file shortcut.cpp.
References mModMask.
Referenced by Shortcut().
| bool fcn::Shortcut::matches | ( | KeyEvent const & | event | ) | const |
Compares the shortcut to a KeyEvent.
Both the semantic key value and modifier mask must match.
| event | The key event to test against. |
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().
| 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().
| 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().
| 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.
Definition at line 77 of file shortcut.cpp.
References mKey, and mModMask.
Referenced by Shortcut().
|
protected |
The semantic key.
Definition at line 154 of file shortcut.hpp.
Referenced by conflicts(), getKey(), matches(), operator==(), Shortcut(), and to_string().
|
protected |
Bitmask of Modifier flags.
Definition at line 157 of file shortcut.hpp.
Referenced by conflicts(), getModMask(), matches(), operator==(), Shortcut(), and to_string().