blob: e18cddb42bf1c88b78c12e6d4e4d898d1759f383 (
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
|
#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
|