summaryrefslogtreecommitdiff
path: root/app/sdl/impl/input-device-keyboard-sdl.hh
diff options
context:
space:
mode:
authorHannes Schulze <haschu0103@outlook.de>2025-02-07 22:15:57 +0100
committerHannes Schulze <haschu0103@outlook.de>2025-02-07 22:15:57 +0100
commit0de4957a22dd408793d0526351bcb7d61786fe86 (patch)
tree3160c72a45022b1e0b7e5ab928c690e85e20cded /app/sdl/impl/input-device-keyboard-sdl.hh
parenta6bfb14562982c8c0139566e5a9b3051543791c4 (diff)
add sdl implementation
Diffstat (limited to 'app/sdl/impl/input-device-keyboard-sdl.hh')
-rw-r--r--app/sdl/impl/input-device-keyboard-sdl.hh28
1 files changed, 28 insertions, 0 deletions
diff --git a/app/sdl/impl/input-device-keyboard-sdl.hh b/app/sdl/impl/input-device-keyboard-sdl.hh
new file mode 100644
index 0000000..1c38065
--- /dev/null
+++ b/app/sdl/impl/input-device-keyboard-sdl.hh
@@ -0,0 +1,28 @@
+#pragma once
+
+#include "nes/app/input/input-device-keyboard.hh"
+#include "nes/app/input/input-buffer.hh"
+#include <optional>
+
+#include <SDL3/SDL.h>
+
+namespace nes::app::sdl
+{
+ /// Keyboard implementation using SDL.
+ class input_device_keyboard_sdl final : public input_device_keyboard
+ {
+ input_buffer buffer_;
+
+ public:
+ explicit input_device_keyboard_sdl() = default;
+
+ auto handle_key_down(SDL_Event*) -> void;
+ auto handle_key_up(SDL_Event*) -> void;
+
+ auto read_key(key const key) -> bool override { return buffer_.read_key(key); }
+ auto poll_event() -> input_event override { return buffer_.poll_event(); }
+
+ private:
+ auto convert_key(SDL_Scancode) const -> std::optional<key>;
+ };
+} // namespace nes::app::sdl