Typed input code — packs device type + code index into a single value. Compatible with existing INPUT_DEVICE_* | code integers used in KeyList.
| 21 | // Typed input code — packs device type + code index into a single value. |
| 22 | // Compatible with existing INPUT_DEVICE_* | code integers used in KeyList. |
| 23 | struct InputCode |
| 24 | { |
| 25 | uint32_t raw = 0; |
| 26 | |
| 27 | constexpr InputCode() = default; |
| 28 | constexpr explicit InputCode(uint32_t packed) : raw(packed) {} |
| 29 | |
| 30 | static constexpr InputCode Key(SDL_Scancode sc) { return InputCode(static_cast<uint32_t>(InputDevice::Keyboard) | static_cast<uint32_t>(sc)); } |
| 31 | static constexpr InputCode MouseButton(int btn) { return InputCode(static_cast<uint32_t>(InputDevice::Mouse) | static_cast<uint32_t>(btn)); } |
| 32 | static constexpr InputCode GamepadBtn(int btn) { return InputCode(static_cast<uint32_t>(InputDevice::GamepadButton) | static_cast<uint32_t>(btn)); } |
| 33 | static constexpr InputCode GamepadAx(int axis) { return InputCode(static_cast<uint32_t>(InputDevice::GamepadAxis) | static_cast<uint32_t>(axis)); } |
| 34 | static constexpr InputCode GamepadPov(int pov) { return InputCode(static_cast<uint32_t>(InputDevice::GamepadPOV) | static_cast<uint32_t>(pov)); } |
| 35 | |
| 36 | static constexpr InputCode FromLegacy(int packed) { return InputCode(static_cast<uint32_t>(packed)); } |
| 37 | |
| 38 | constexpr InputDevice device() const { return static_cast<InputDevice>(raw & INPUT_CODE_DEVICE_MASK); } |
| 39 | constexpr uint32_t code() const { return raw & INPUT_CODE_VALUE_MASK; } |
| 40 | constexpr int toLegacy() const { return static_cast<int>(raw); } |
| 41 | constexpr bool valid() const { return raw != 0; } |
| 42 | |
| 43 | constexpr bool operator==(InputCode other) const { return raw == other.raw; } |
| 44 | constexpr bool operator!=(InputCode other) const { return raw != other.raw; } |
| 45 | constexpr bool operator<(InputCode other) const { return raw < other.raw; } |
| 46 | }; |
| 47 | } // namespace Poseidon |
| 48 |
no outgoing calls
no test coverage detected