light/modules/input/public/input.hpp

81 lines
1.5 KiB
C++
Raw Normal View History

2025-07-05 13:28:41 +03:30
#pragma once
#include <array>
#include <math/vec2.hpp>
2025-07-05 13:28:41 +03:30
2025-07-11 00:05:48 +03:30
namespace lt {
2025-07-05 13:28:41 +03:30
class Event;
2025-07-05 16:07:51 +03:30
class Input
2025-07-05 13:28:41 +03:30
{
public:
2025-07-06 17:23:28 +03:30
static auto instance() -> Input &
{
static auto instance = Input {};
return instance;
}
2025-07-05 13:28:41 +03:30
2025-07-06 14:02:50 +03:30
static void receive_user_interface_events(bool receive, bool toggle = false)
2025-07-05 13:28:41 +03:30
{
2025-07-06 17:23:28 +03:30
instance().receive_user_interface_events_impl(receive, toggle);
2025-07-05 13:28:41 +03:30
}
2025-07-06 17:23:28 +03:30
2025-07-06 14:02:50 +03:30
static void receive_game_events(bool receive, bool toggle = false)
2025-07-05 13:28:41 +03:30
{
2025-07-06 17:23:28 +03:30
instance().receieve_game_events_impl(receive, toggle);
2025-07-05 13:28:41 +03:30
}
2025-07-06 14:02:50 +03:30
static auto get_keyboard_key(int code) -> bool
2025-07-05 13:28:41 +03:30
{
2025-07-06 17:23:28 +03:30
return instance().m_keyboad_keys[code];
2025-07-05 13:28:41 +03:30
}
2025-07-06 17:23:28 +03:30
2025-07-06 14:02:50 +03:30
static auto get_mouse_button(int code) -> bool
2025-07-05 13:28:41 +03:30
{
2025-07-06 17:23:28 +03:30
return instance().m_mouse_buttons[code];
2025-07-05 13:28:41 +03:30
}
static auto get_mouse_position(int /*code*/) -> const math::vec2 &
2025-07-05 13:28:41 +03:30
{
2025-07-06 17:23:28 +03:30
return instance().m_mouse_position;
2025-07-05 13:28:41 +03:30
}
void on_event(const Event &inputEvent);
2025-07-05 13:28:41 +03:30
2025-07-06 16:52:50 +03:30
[[nodiscard]] auto is_receiving_input_events() const -> bool
2025-07-05 13:28:41 +03:30
{
return m_user_interface_events;
2025-07-05 13:28:41 +03:30
}
2025-07-06 14:02:50 +03:30
2025-07-06 16:52:50 +03:30
[[nodiscard]] auto is_receiving_game_events() const -> bool
2025-07-05 13:28:41 +03:30
{
return m_game_events;
2025-07-05 13:28:41 +03:30
}
private:
2025-07-06 17:23:28 +03:30
Input();
2025-07-05 16:07:51 +03:30
2025-07-06 17:23:28 +03:30
void receive_user_interface_events_impl(bool receive, bool toggle = false);
2025-07-05 16:07:51 +03:30
2025-07-06 17:23:28 +03:30
void receieve_game_events_impl(bool receive, bool toggle = false);
2025-07-05 16:07:51 +03:30
2025-07-06 17:23:28 +03:30
void restart_input_state();
2025-07-05 16:07:51 +03:30
2025-07-06 17:23:28 +03:30
std::array<bool, 348> m_keyboad_keys {};
2025-07-05 16:07:51 +03:30
2025-07-06 17:23:28 +03:30
std::array<bool, 8> m_mouse_buttons {};
2025-07-05 16:07:51 +03:30
math::vec2 m_mouse_position;
2025-07-05 16:07:51 +03:30
math::vec2 m_mouse_delta;
2025-07-05 13:28:41 +03:30
2025-07-06 17:23:28 +03:30
float m_mouse_wheel_delta {};
2025-07-05 16:07:51 +03:30
2025-07-06 17:23:28 +03:30
bool m_user_interface_events { true };
2025-07-05 13:28:41 +03:30
2025-07-06 17:23:28 +03:30
bool m_game_events { true };
2025-07-05 13:28:41 +03:30
};
2025-07-11 00:05:48 +03:30
} // namespace lt