snap window cursor to crosshair when looking stops

This commit is contained in:
jacob 2026-02-04 08:29:39 -06:00
parent e457dd392a
commit a6a5e27cb9
4 changed files with 21 additions and 3 deletions

View File

@ -1961,7 +1961,16 @@ void V_TickForever(WaveLaneCtx *lane)
} }
else 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->shade_cursor = MulAffineVec2(frame->af.screen_to_shade, frame->screen_cursor);
frame->world_cursor = MulAffineVec2(frame->af.screen_to_world, frame->screen_cursor); frame->world_cursor = MulAffineVec2(frame->af.screen_to_world, frame->screen_cursor);

View File

@ -639,7 +639,6 @@ PixelShader(V_CompositePS, V_CompositePSOutput, V_CompositePSInput input)
// TODO: Remove this // TODO: Remove this
Vec4 crosshair_color = 0; Vec4 crosshair_color = 0;
if (frame.is_looking)
{ {
f32 dist = length(frame.screen_crosshair - screen_pos); f32 dist = length(frame.screen_crosshair - screen_pos);
if (dist < 4) if (dist < 4)

View File

@ -36,6 +36,7 @@ Enum(WND_CmdKind)
WND_CmdKind_SetFullscreen, WND_CmdKind_SetFullscreen,
WND_CmdKind_SetForcedTop, WND_CmdKind_SetForcedTop,
WND_CmdKind_SetCursor, WND_CmdKind_SetCursor,
WND_CmdKind_SetCursorPos,
WND_CmdKind_SetLockedCursor, WND_CmdKind_SetLockedCursor,
WND_CmdKind_Restore, WND_CmdKind_Restore,
}; };
@ -46,6 +47,7 @@ Struct(WND_Cmd)
WND_CursorKind cursor; WND_CursorKind cursor;
String restore; String restore;
b32 v; b32 v;
Vec2 pos;
}; };
//////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////

View File

@ -681,6 +681,14 @@ void WND_EndFrame(WND_Frame frame, i32 vsync)
} }
} break; } 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 //- Set locked cursor
case WND_CmdKind_SetLockedCursor: case WND_CmdKind_SetLockedCursor:
{ {
@ -747,7 +755,7 @@ void WND_EndFrame(WND_Frame frame, i32 vsync)
BringWindowToTop(hwnd); BringWindowToTop(hwnd);
} }
// Set/Clip/Hide cursor // Set / Clip / Hide cursor
{ {
RECT virtual_screen_rect = Zi; RECT virtual_screen_rect = Zi;
{ {