summaryrefslogtreecommitdiff
path: root/lib/nes/app/input/modifier-mask.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/modifier-mask.hh
parentbf88e17d552d85cd18bc31757ef9d73049b327c4 (diff)
revamp input system
Diffstat (limited to 'lib/nes/app/input/modifier-mask.hh')
-rw-r--r--lib/nes/app/input/modifier-mask.hh39
1 files changed, 39 insertions, 0 deletions
diff --git a/lib/nes/app/input/modifier-mask.hh b/lib/nes/app/input/modifier-mask.hh
new file mode 100644
index 0000000..e18cddb
--- /dev/null
+++ b/lib/nes/app/input/modifier-mask.hh
@@ -0,0 +1,39 @@
+#pragma once
+
+#include "nes/common/types.hh"
+
+namespace nes::app
+{
+ /// Keyboard modifiers.
+ class modifier_mask
+ {
+ u8 raw_value_{ 0 };
+
+ public:
+ constexpr explicit modifier_mask() = default;
+
+ static constexpr auto from_raw_value(u8 const raw_value) -> modifier_mask
+ {
+ return modifier_mask{ raw_value };
+ }
+
+ constexpr auto add(modifier_mask const other) -> void { raw_value_ |= other.raw_value_; }
+ constexpr auto remove(modifier_mask const other) -> void { raw_value_ ^= other.raw_value_; }
+ constexpr auto contains(modifier_mask const other) const -> bool { return (raw_value_ & other.raw_value_) == other.raw_value_; }
+ constexpr auto is_empty() const -> bool { return raw_value_ == 0; }
+ constexpr auto get_raw_value() const -> u8 { return raw_value_; }
+
+ private:
+ constexpr explicit modifier_mask(u8 const raw_value)
+ : raw_value_{ raw_value }
+ {
+ }
+ };
+
+ namespace modifiers
+ {
+ inline constexpr auto control = modifier_mask::from_raw_value(1 << 0);
+ inline constexpr auto shift = modifier_mask::from_raw_value(1 << 1);
+ inline constexpr auto alt = modifier_mask::from_raw_value(1 << 2);
+ } // namespace modifiers
+} // namespace nes::app \ No newline at end of file