summaryrefslogtreecommitdiff
path: root/lib/nes/app/input/input-event.hh
diff options
context:
space:
mode:
authorHannes Schulze <haschu0103@outlook.de>2025-02-01 23:32:55 +0100
committerHannes Schulze <haschu0103@outlook.de>2025-02-01 23:32:55 +0100
commit8062afc25e895cb49e76f6e26e51a7d4a1ad2df2 (patch)
treef64e6522a84a8f58912b9e58a66c187fbcaadd78 /lib/nes/app/input/input-event.hh
parentbf88e17d552d85cd18bc31757ef9d73049b327c4 (diff)
revamp input system
Diffstat (limited to 'lib/nes/app/input/input-event.hh')
-rw-r--r--lib/nes/app/input/input-event.hh46
1 files changed, 46 insertions, 0 deletions
diff --git a/lib/nes/app/input/input-event.hh b/lib/nes/app/input/input-event.hh
new file mode 100644
index 0000000..90e67b0
--- /dev/null
+++ b/lib/nes/app/input/input-event.hh
@@ -0,0 +1,46 @@
+#pragma once
+
+#include "nes/app/input/key.hh"
+
+namespace nes::app
+{
+ class input_event
+ {
+ public:
+ enum class type
+ {
+ none,
+ key_down,
+ key_up,
+ };
+
+ private:
+ type type_{ type::none };
+ key key_{};
+
+ public:
+ constexpr explicit input_event() = default;
+
+ static constexpr auto key_down(key const key) -> input_event { return input_event{ type::key_down, key }; }
+ static constexpr auto key_up(key const key) -> input_event { return input_event{ type::key_up, key }; }
+
+ constexpr operator bool() const { return type_ != type::none; }
+
+ constexpr auto get_type() const -> type { return type_; }
+ constexpr auto get_key() const -> key { return key_; }
+
+ private:
+ constexpr explicit input_event(type const type, key const key)
+ : type_{ type }
+ , key_{ key }
+ {
+ }
+ };
+
+ constexpr auto operator==(input_event const lhs, input_event const rhs)
+ {
+ return lhs.get_type() == rhs.get_type() && lhs.get_key() == rhs.get_key();
+ }
+
+ constexpr auto operator!=(input_event const lhs, input_event const rhs) { return !(lhs == rhs); }
+} // namespace nes::app \ No newline at end of file