From a6a5e27cb922f2324ed9ae7b9b358b20c234a145 Mon Sep 17 00:00:00 2001 From: jacob Date: Wed, 4 Feb 2026 08:29:39 -0600 Subject: [PATCH] snap window cursor to crosshair when looking stops --- src/pp/pp_vis/pp_vis_core.c | 11 ++++++++++- src/pp/pp_vis/pp_vis_gpu.g | 1 - src/window/window.h | 2 ++ src/window/window_win32/window_win32.c | 10 +++++++++- 4 files changed, 21 insertions(+), 3 deletions(-) diff --git a/src/pp/pp_vis/pp_vis_core.c b/src/pp/pp_vis/pp_vis_core.c index 5460bed2..7cd477bf 100644 --- a/src/pp/pp_vis/pp_vis_core.c +++ b/src/pp/pp_vis/pp_vis_core.c @@ -1961,7 +1961,16 @@ void V_TickForever(WaveLaneCtx *lane) } else { - frame->screen_cursor = ui_frame->cursor_pos; + if (prev_frame->is_looking) + { + // Snap cursor to crosshair + frame->screen_cursor = prev_frame->screen_cursor; + WND_PushCmd(window_frame, .kind = WND_CmdKind_SetCursorPos, .pos = prev_frame->screen_cursor); + } + else + { + frame->screen_cursor = ui_frame->cursor_pos; + } } frame->shade_cursor = MulAffineVec2(frame->af.screen_to_shade, frame->screen_cursor); frame->world_cursor = MulAffineVec2(frame->af.screen_to_world, frame->screen_cursor); diff --git a/src/pp/pp_vis/pp_vis_gpu.g b/src/pp/pp_vis/pp_vis_gpu.g index 8306e5a3..76c06904 100644 --- a/src/pp/pp_vis/pp_vis_gpu.g +++ b/src/pp/pp_vis/pp_vis_gpu.g @@ -639,7 +639,6 @@ PixelShader(V_CompositePS, V_CompositePSOutput, V_CompositePSInput input) // TODO: Remove this Vec4 crosshair_color = 0; - if (frame.is_looking) { f32 dist = length(frame.screen_crosshair - screen_pos); if (dist < 4) diff --git a/src/window/window.h b/src/window/window.h index ee29829e..3dfeae9d 100644 --- a/src/window/window.h +++ b/src/window/window.h @@ -36,6 +36,7 @@ Enum(WND_CmdKind) WND_CmdKind_SetFullscreen, WND_CmdKind_SetForcedTop, WND_CmdKind_SetCursor, + WND_CmdKind_SetCursorPos, WND_CmdKind_SetLockedCursor, WND_CmdKind_Restore, }; @@ -46,6 +47,7 @@ Struct(WND_Cmd) WND_CursorKind cursor; String restore; b32 v; + Vec2 pos; }; //////////////////////////////////////////////////////////// diff --git a/src/window/window_win32/window_win32.c b/src/window/window_win32/window_win32.c index e14823b6..77e4ecac 100644 --- a/src/window/window_win32/window_win32.c +++ b/src/window/window_win32/window_win32.c @@ -681,6 +681,14 @@ void WND_EndFrame(WND_Frame frame, i32 vsync) } } break; + //- Set cursor pos + case WND_CmdKind_SetCursorPos: + { + POINT screen_pt = { cmd.pos.x, cmd.pos.y }; + ClientToScreen(hwnd, (LPPOINT)&screen_pt); + SetCursorPos(screen_pt.x, screen_pt.y); + } break; + //- Set locked cursor case WND_CmdKind_SetLockedCursor: { @@ -747,7 +755,7 @@ void WND_EndFrame(WND_Frame frame, i32 vsync) BringWindowToTop(hwnd); } - // Set/Clip/Hide cursor + // Set / Clip / Hide cursor { RECT virtual_screen_rect = Zi; {