package fw import "core:c" import "core:log" import "vendor:glfw" Keyboard_Input :: union { Key, Mouse_Button, } Controller_Input :: union { } Keybind :: struct { input: Keyboard_Input, was_pressed: bool, just_pressed: bool, } update_keybind :: proc(keybind: ^Keybind) { pressed: bool switch val in keybind.input { case Key: pressed = glfw.GetKey(window, c.int(val)) == glfw.PRESS case Mouse_Button: pressed = glfw.GetMouseButton(window, c.int(val)) == glfw.PRESS } keybind.just_pressed = !keybind.was_pressed && pressed keybind.was_pressed = pressed } @(require_results) is_keybind_down :: proc(keybind: Keybind) -> bool { switch val in keybind.input { case Key: return glfw.GetKey(window, c.int(val)) == glfw.PRESS case Mouse_Button: return glfw.GetMouseButton(window, c.int(val)) == glfw.PRESS case: log.warn("Keybind input is invalid") return false } } @(require_results) is_keybind_just_down :: proc(keybind: Keybind) -> bool { return keybind.just_pressed } @(require_results) get_mouse_pos :: proc() -> (mouse_pos: Vec2) { w_width, w_height := glfw.GetWindowSize(window) mx, my := glfw.GetCursorPos(window) mouse_pos = Vec2{f32(mx), f32(my)} mouse_pos /= Vec2{f32(w_width), f32(w_height)} mouse_pos *= Vec2{f32(framebuf.color.size.x), f32(framebuf.color.size.y)} mouse_pos += renderer.camera_pos return }