From 2b8488a1e24d0edc9bdd72a6e2a6201d8818e3d8 Mon Sep 17 00:00:00 2001 From: Riyyi Date: Sun, 13 Sep 2026 00:43:18 +0200 Subject: [PATCH] Add mouse position input function --- src/input/input.odin | 4 ++++ src/platform/glfw.odin | 12 +++++++----- 2 files changed, 11 insertions(+), 5 deletions(-) diff --git a/src/input/input.odin b/src/input/input.odin index 1277589..fa4fb7c 100644 --- a/src/input/input.odin +++ b/src/input/input.odin @@ -11,5 +11,9 @@ key_state: proc(key: Key) -> Action // implementation in platform package, to prevent cyclic dependency mouse_button_state: proc(button: Mouse_Button) -> Action +// Returns the position of the mouse cursor +// implementation in platform package, to prevent cyclic dependency +mouse_position: proc() -> (x_pos: f32, y_pos: f32) + // ----------------------------------------- // Private functions diff --git a/src/platform/glfw.odin b/src/platform/glfw.odin index 383f078..15dcf5f 100644 --- a/src/platform/glfw.odin +++ b/src/platform/glfw.odin @@ -52,11 +52,7 @@ os_init :: proc(settings: core.Settings) { // Register input functions input.key_state = key_state input.mouse_button_state = mouse_button_state - - // TODO: Figure out proper vsync, found 3 spots so far - // - glfw.SwapInterval(0) this is only for OpenGL it seems? - // - glfw.SetWindowMonitor(refresh) - // - wgpu presentMode = .Fifo + input.mouse_position = mouse_position } os_destroy :: proc() { @@ -157,6 +153,12 @@ mouse_button_state :: proc(button: input.Mouse_Button) -> input.Action { return input_action(glfw.GetMouseButton(state.os.window, i32(button))) } +@(private = "file") +mouse_position :: proc() -> (x_pos: f32, y_pos: f32) { + x_pos_f64, y_pos_64 := glfw.GetCursorPos(state.os.window) + return f32(x_pos_f64), f32(y_pos_64) +} + @(private = "file") input_action :: proc(action: i32) -> input.Action { if action == glfw.RELEASE do return input.Action.Release