add window and user input

This commit is contained in:
2026-04-16 23:49:06 -03:00
parent 47f8b8598d
commit b3d64b40b1
8 changed files with 419 additions and 7 deletions

35
source/ui/user_input.cpp Normal file
View File

@@ -0,0 +1,35 @@
#include "user_input.hpp"
namespace rog::ui {
void user_input::set_key_state(key_code key, key_state state) {
const auto key_index = static_cast<int>(key);
if (key_index < this->state.keys.size()) {
this->state.keys[key_index] = state;
}
}
void user_input::set_mouse_pos(glm::vec2 pos) { state.mouse_pos = pos; }
void user_input::set_mouse_button(mouse_button button, button_state state) {
this->state.mouse_buttons[static_cast<int>(button)] = state;
}
bool user_input::is_key_down(key_code code) const noexcept {
const auto idx = static_cast<int>(code);
return state.keys[idx] == key_state::pressed ||
state.keys[idx] == key_state::repeat ||
state.keys[idx] == key_state::held;
}
bool user_input::is_key_pressed(key_code code) const noexcept {
return state.keys[static_cast<int>(code)] == key_state::pressed;
}
glm::vec2 user_input::get_mouse_position() const noexcept {
return state.mouse_pos;
}
input_state user_input::current_state() const noexcept { return state; }
} // namespace rog::ui