add window and user input
This commit is contained in:
35
source/ui/user_input.cpp
Normal file
35
source/ui/user_input.cpp
Normal 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
|
||||
Reference in New Issue
Block a user