diff options
Diffstat (limited to 'lib/nes/app/input/input-event.hh')
| -rw-r--r-- | lib/nes/app/input/input-event.hh | 46 |
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 |
