diff options
| author | untodesu <kirill@untode.su> | 2025-12-30 13:20:33 +0500 |
|---|---|---|
| committer | untodesu <kirill@untode.su> | 2025-12-30 13:20:33 +0500 |
| commit | a1c83d56f41e6f2e0ad86dcd76d1446bfc60a37c (patch) | |
| tree | 5754f0cd6ef3678c2e9d9c31174ae435d463c8ed /src/game/client/io/keyboard.hh | |
| parent | 49d3dff9e98e70e599dfd3059f85bb08ae247fe5 (diff) | |
| download | voxelius-a1c83d56f41e6f2e0ad86dcd76d1446bfc60a37c.tar.bz2 voxelius-a1c83d56f41e6f2e0ad86dcd76d1446bfc60a37c.zip | |
begin working on qf ports (#21)
Diffstat (limited to 'src/game/client/io/keyboard.hh')
| -rw-r--r-- | src/game/client/io/keyboard.hh | 83 |
1 files changed, 83 insertions, 0 deletions
diff --git a/src/game/client/io/keyboard.hh b/src/game/client/io/keyboard.hh new file mode 100644 index 0000000..566d38b --- /dev/null +++ b/src/game/client/io/keyboard.hh @@ -0,0 +1,83 @@ +// SPDX-License-Identifier: BSD-2-Clause +// Copyright (c) 2025 Kirill Dmitrievich +// File: keyboard.hh; Created: Tue Dec 30 2025 12:27:04 +// Description: Keyboard handling + +#ifndef CLIENT_IO_KEYBOARD_HH +#define CLIENT_IO_KEYBOARD_HH +#pragma once + +class KeyEvent final { +public: + constexpr explicit KeyEvent(int keycode, int scancode, int action, int modbits); + + constexpr int keycode(void) const noexcept; + constexpr int scancode(void) const noexcept; + constexpr int action(void) const noexcept; + constexpr int modbits(void) const noexcept; + + constexpr bool is_keycode(int keycode) const noexcept; + constexpr bool is_action(int action) const noexcept; + constexpr bool has_modbits(int modbits) const noexcept; + + constexpr bool is_valid(void) const noexcept; + +private: + int m_keycode; + int m_scancode; + int m_action; + int m_modbits; +}; + +namespace keyboard +{ +void init(void); +} // namespace keyboard + +constexpr KeyEvent::KeyEvent(int keycode, int scancode, int action, int modbits) + : m_keycode(keycode), m_scancode(scancode), m_action(action), m_modbits(modbits) +{ + // empty +} + +constexpr int KeyEvent::keycode(void) const noexcept +{ + return m_keycode; +} + +constexpr int KeyEvent::scancode(void) const noexcept +{ + return m_scancode; +} + +constexpr int KeyEvent::action(void) const noexcept +{ + return m_action; +} + +constexpr int KeyEvent::modbits(void) const noexcept +{ + return m_modbits; +} + +constexpr bool KeyEvent::is_keycode(int keycode) const noexcept +{ + return m_keycode == keycode; +} + +constexpr bool KeyEvent::is_action(int action) const noexcept +{ + return m_action == action; +} + +constexpr bool KeyEvent::has_modbits(int modbits) const noexcept +{ + return static_cast<bool>(m_modbits & modbits); +} + +constexpr bool KeyEvent::is_valid(void) const noexcept +{ + return m_keycode >= 0 && m_keycode <= GLFW_KEY_LAST; +} + +#endif |
