FifeGUI 0.3.0
A C++ GUI library designed for games.
shortcut.hpp
1// SPDX-License-Identifier: LGPL-2.1-or-later OR BSD-3-Clause
2// SPDX-FileCopyrightText: 2026 Fifengine contributors
3
4#ifndef INCLUDE_FIFECHAN_SHORTCUT_HPP_
5#define INCLUDE_FIFECHAN_SHORTCUT_HPP_
6
7// Standard library includes
8#include <cstdint>
9#include <string>
10
11// Platform config include
12#include "fifechan/platform.hpp"
13
14// Project headers (subdirs before local)
15#include "fifechan/key.hpp"
16
17namespace fcn
18{
19 class KeyEvent;
20
57 class FIFEGUI_API Shortcut
58 {
59 public:
63 enum Modifier : uint16_t
64 {
65 None = 0,
66 Shift = 1 << 0,
67 Control = 1 << 1,
68 Alt = 1 << 2,
69 Meta = 1 << 3
70 };
71
75 Shortcut() = default;
76
83 explicit Shortcut(Key key, uint16_t modMask = Modifier::None);
84
95 static Shortcut fromKeycode(uint32_t keycode, uint16_t sdlMods = 0);
96
105 bool matches(KeyEvent const & event) const;
106
116 bool conflicts(Shortcut const & other) const;
117
126 std::string to_string() const;
127
133 Key getKey() const;
134
140 uint16_t getModMask() const;
141
145 bool operator==(Shortcut const & other) const;
146
150 bool operator!=(Shortcut const & other) const;
151
152 protected:
154 Key mKey;
155
157 uint16_t mModMask{Modifier::None};
158 };
159} // namespace fcn
160
161#endif // INCLUDE_FIFECHAN_SHORTCUT_HPP_
Represents a key event.
Definition keyevent.hpp:26
uint16_t mModMask
Bitmask of Modifier flags.
Definition shortcut.hpp:157
bool conflicts(Shortcut const &other) const
Checks for collision with another shortcut.
Definition shortcut.cpp:67
std::string to_string() const
Returns a human-readable string, e.g.
Definition shortcut.cpp:77
bool operator==(Shortcut const &other) const
Compares two shortcuts for equality (same key + same mods).
Definition shortcut.cpp:115
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
Key mKey
The semantic key.
Definition shortcut.hpp:154
Modifier
Modifier flags.
Definition shortcut.hpp:64
bool operator!=(Shortcut const &other) const
Compares two shortcuts for inequality.
Definition shortcut.cpp:120
bool matches(KeyEvent const &event) const
Compares the shortcut to a KeyEvent.
Definition shortcut.cpp:43
Shortcut()=default
Default constructor creates an unbound shortcut (key 0, no mods).
Key getKey() const
Gets the semantic key.
Definition shortcut.cpp:105
uint16_t getModMask() const
Gets the modifier bitmask.
Definition shortcut.cpp:110
Used replacement tokens by configure_file():