A windowed action game can hide the OS cursor and lock/confine the mouse to the window. Input.cursor_mode(mode): 0 normal, 1 hidden (draw your own reticle), 2 locked (hidden + dissociated — the mouse feeds relative motion via Input.mouse_dx/dy and Input.mouse_x/y is a clamped virtual cursor, FPS/twin-stick aim), 3 confined (dissociated but visible; the mouse can't leave the window). The platform auto-releases (shows + reconnects) while the window is not key (Cmd-Tab) and on close, so the cursor is never left captured. Headless it is a no-op (DCE'd). Native macOS impl in cocoa.ll: [NSCursor hide]/[unhide] (ref-counted, toggled only on change so the count stays balanced across focus changes), CGAssociateMouseAndMouseCursorPosition, and CGGetLastMouseDelta for the relative virtual cursor, behind a new win_cursor_mode intrinsic. Windowed-only behaviour (not in the headless golden suite); example compiles headless and links windowed. Full suite 115/0, fixpoint holds. Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
24 lines
956 B
Text
24 lines
956 B
Text
# cursor_capture.ludic — cursor capture (#89): a windowed game hides / locks the
|
|
# OS mouse and draws its own reticle from the mouse position. Input.cursor_mode is
|
|
# a no-op headless (it only touches the platform cursor on a windowed build), so
|
|
# this compiles and links both ways; the capture behaviour is windowed-only.
|
|
#
|
|
# Run windowed: bin/ludicc examples/library/cursor_capture.ludic -o /tmp/aim && /tmp/aim
|
|
program CursorCapture {
|
|
property Tag { n: int = 0 }
|
|
model P { Tag }
|
|
|
|
@OnStart handler Boot {
|
|
Input.cursor_mode(2) # 2 = locked: hide the OS cursor, feed relative motion
|
|
}
|
|
|
|
handler Draw phase Render {
|
|
Screen.clear(0x101018)
|
|
# a reticle drawn at the captured mouse position (a virtual cursor while locked)
|
|
let mx = Input.mouse_x()
|
|
let my = Input.mouse_y()
|
|
Screen.fill_rectangle(mx - 3, my - 1, 7, 2, 0xffcc00)
|
|
Screen.fill_rectangle(mx - 1, my - 3, 2, 7, 0xffcc00)
|
|
Screen.show()
|
|
}
|
|
}
|