summaryrefslogtreecommitdiff
path: root/src/Input.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'src/Input.cpp')
-rw-r--r--src/Input.cpp20
1 files changed, 13 insertions, 7 deletions
diff --git a/src/Input.cpp b/src/Input.cpp
index 2362794..b0b58bc 100644
--- a/src/Input.cpp
+++ b/src/Input.cpp
@@ -189,7 +189,7 @@ Key Input::from_glfw_key(I32 const key) {
case GLFW_KEY_F10: return Key::F10;
case GLFW_KEY_F11: return Key::F11;
case GLFW_KEY_F12: return Key::F12;
- default: UNREACHABLE("Unknown key."); return TO(Key, 0);
+ default: return Key::Unknown;
}
}
@@ -198,13 +198,16 @@ Mouse Input::from_glfw_mouse(I32 const button) {
case GLFW_MOUSE_BUTTON_LEFT: return Mouse::Left;
case GLFW_MOUSE_BUTTON_RIGHT: return Mouse::Right;
case GLFW_MOUSE_BUTTON_MIDDLE: return Mouse::Middle;
- default: UNREACHABLE("Unknown mouse button."); return TO(Mouse, 0);
+ default: return Mouse::Unknown;
}
}
-void Input::key_callback(GLFWwindow* _window, I32 const key, I32 _scancode, I32 const action, I32 _mods) {
- if (action == GLFW_PRESS) s_key_buffer[key_value(from_glfw_key(key))] = true;
- else if (action == GLFW_RELEASE) s_key_buffer[key_value(from_glfw_key(key))] = false;
+void Input::key_callback(GLFWwindow* _window, I32 const key, I32 const scancode, I32 const action, I32 _mods) {
+ auto mapped = from_glfw_key(key);
+ if (mapped == Key::Unknown) return;
+
+ if (action == GLFW_PRESS) s_key_buffer[key_value(mapped)] = true;
+ else if (action == GLFW_RELEASE) s_key_buffer[key_value(mapped)] = false;
}
void Input::cursor_position_callback(GLFWwindow* _window, F64 x, F64 y) {
@@ -214,8 +217,11 @@ void Input::cursor_position_callback(GLFWwindow* _window, F64 x, F64 y) {
}
void Input::mouse_button_callback(GLFWwindow* _window, I32 const button, I32 const action, I32 _mods) {
- if (action == GLFW_PRESS) s_mouse_buffer[mouse_button_value(from_glfw_mouse(button))] = true;
- else if (action == GLFW_RELEASE) s_mouse_buffer[mouse_button_value(from_glfw_mouse(button))] = false;
+ auto mapped = from_glfw_mouse(button);
+ if (mapped == Mouse::Unknown) return;
+
+ if (action == GLFW_PRESS) s_mouse_buffer[mouse_button_value(mapped)] = true;
+ else if (action == GLFW_RELEASE) s_mouse_buffer[mouse_button_value(mapped)] = false;
}
}