Aegis2D
Modular C++26 2D game engine for networked games
Loading...
Searching...
No Matches
key_capture.hpp
Go to the documentation of this file.
1
3#pragma once
4
6#include <aegis2d/platform/export.hpp>
8
9#include <cstdint>
10#include <optional>
11
12namespace aegis2d::platform {
13
19 std::optional<Key> key;
21 std::optional<ActionId> taken_from;
22};
23
40class AEGIS2D_PLATFORM_EXPORT KeyCapture {
41public:
44 explicit KeyCapture(Key cancel_key = Key::Escape) noexcept;
45
49 void start(ActionId action, const Keyboard& keyboard) noexcept;
50
52 void cancel() noexcept;
53
56 [[nodiscard]] std::optional<ActionId> waiting() const noexcept;
57
63 std::optional<CapturedKey> update(ActionMap& actions, const Keyboard& keyboard);
64
65private:
66 Key cancel_key_;
67 std::optional<ActionId> action_;
68 std::uint64_t start_frame_ = 0;
69};
70
71} // namespace aegis2d::platform
Named actions (move, fire...) bound to keys and gamepad buttons, so gameplay never reads raw input.
Actions of the game and the keys and gamepad buttons that trigger them.
Definition actions.hpp:38
Key binding step of a settings menu: "press a key for Fire".
Definition key_capture.hpp:40
void cancel() noexcept
Stops waiting, without changing any binding.
KeyCapture(Key cancel_key=Key::Escape) noexcept
Creates a capture that waits for nothing yet.
void start(ActionId action, const Keyboard &keyboard) noexcept
Waits for a key for an action, replacing a capture in progress.
Keys held down, and those pressed or released since the start of the frame.
Definition keyboard.hpp:150
Keyboard keys, their names, and the state of the keyboard during a frame.
Window and input on top of SDL3, independent of the graphics API (client only).
Definition actions.hpp:19
Key
Keyboard key, independent of SDL.
Definition keyboard.hpp:24
std::size_t ActionId
Identifier of an action in its ActionMap, given by ActionMap::add().
Definition actions.hpp:22
Definition endpoint.hpp:85
End of a key capture.
Definition key_capture.hpp:15
std::optional< Key > key
Its new key, or nothing if the player cancelled.
Definition key_capture.hpp:19
ActionId action
Action that was waiting for a key.
Definition key_capture.hpp:17
std::optional< ActionId > taken_from
Action that lost the key, so the menu can say it is now unbound.
Definition key_capture.hpp:21