feat(input): #89 cursor capture — Input.cursor_mode (hide/lock/confine)
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>
This commit is contained in:
parent
f3f1336882
commit
3eb5447f74
11 changed files with 26543 additions and 26240 deletions
24
examples/library/cursor_capture.ludic
Normal file
24
examples/library/cursor_capture.ludic
Normal file
|
|
@ -0,0 +1,24 @@
|
|||
# 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()
|
||||
}
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue