refactor Events

This commit is contained in:
A-Lex-Ra
2023-12-03 23:24:52 +06:00
parent ba83b27179
commit 911e828602
5 changed files with 120 additions and 109 deletions
+8 -4
View File
@@ -34,23 +34,27 @@ void cursor_position_callback(GLFWwindow*, double xpos, double ypos) {
void mouse_button_callback(GLFWwindow*, int button, int action, int) {
if (action == GLFW_PRESS) {
Events::_keys[_MOUSE_BUTTONS + button] = true;
Events::_frames[_MOUSE_BUTTONS + button] = Events::_current;
// Unsafe assignments! (no checks)
Events::_keys[_MOUSE_KEYS_OFFSET + button] = true;
Events::_frames[_MOUSE_KEYS_OFFSET + button] = Events::_current;
}
else if (action == GLFW_RELEASE) {
Events::_keys[_MOUSE_BUTTONS + button] = false;
Events::_frames[_MOUSE_BUTTONS + button] = Events::_current;
// Unsafe assignments! (no checks)
Events::_keys[_MOUSE_KEYS_OFFSET + button] = false;
Events::_frames[_MOUSE_KEYS_OFFSET + button] = Events::_current;
}
}
void key_callback(GLFWwindow*, int key, int scancode, int action, int /*mode*/) {
if (key == GLFW_KEY_UNKNOWN) return;
if (action == GLFW_PRESS) {
// Unsafe assignments! (no checks)
Events::_keys[key] = true;
Events::_frames[key] = Events::_current;
Events::pressedKeys.push_back(key);
}
else if (action == GLFW_RELEASE) {
// Unsafe assignments! (no checks)
Events::_keys[key] = false;
Events::_frames[key] = Events::_current;
}