From 420970c8b83f20a4a2411af687e9d4a38a5fe81a Mon Sep 17 00:00:00 2001 From: 3gg <3gg@shellblade.net> Date: Mon, 16 Sep 2024 19:56:36 -0700 Subject: Add function to query mouse buttons. --- app/src/app.c | 20 +++++++++++++++++++- 1 file changed, 19 insertions(+), 1 deletion(-) (limited to 'app/src/app.c') diff --git a/app/src/app.c b/app/src/app.c index 1e636af..9b816ee 100644 --- a/app/src/app.c +++ b/app/src/app.c @@ -149,12 +149,30 @@ void gfx_app_get_mouse_position(double* x, double* y) { glfwGetCursorPos(g_gfx_app.window, x, y); } +static int to_glfw_mouse_button(MouseButton button); + +bool gfx_app_is_mouse_button_pressed(MouseButton button) { + return glfwGetMouseButton(g_gfx_app.window, to_glfw_mouse_button(button)) == + GLFW_PRESS; +} + static int to_glfw_key(Key key); -bool gfx_is_key_pressed(Key key) { +bool gfx_app_is_key_pressed(Key key) { return glfwGetKey(g_gfx_app.window, to_glfw_key(key)) == GLFW_PRESS; } +static int to_glfw_mouse_button(MouseButton button) { + switch (button) { + case LMB: + return GLFW_MOUSE_BUTTON_LEFT; + case RMB: + return GLFW_MOUSE_BUTTON_RIGHT; + case MMB: + return GLFW_MOUSE_BUTTON_MIDDLE; + } +} + static int to_glfw_key(Key key) { switch (key) { case KeyA: -- cgit v1.2.3