summaryrefslogtreecommitdiff
path: root/lib/nes/app/input/input-event.hh
blob: 26d644872b41db7f870a19e8310771b9fbd308da (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
#pragma once

#include "nes/app/input/key.hh"

namespace nes::app
{
	/// A keyboard input event which can be polled.
	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