AtlatestRepositorysigil-raylib

sigil-raylib / tree / src / raylibwindow.sgl

1;;; (raylib window) — Window management and cursor control
2;;;
3;;; Provides window lifecycle, state queries, monitor info, clipboard,
4;;; and cursor visibility/state functions.
5
6(define-library (raylib window)
7 (import (sigil core)
8 (sigil ffi)
9 (raylib core))
11 (export
12 ;; Window management
13 init-window close-window window-should-close?
14 window-ready? window-fullscreen? window-hidden?
15 window-minimized? window-maximized? window-focused?
16 window-resized? window-state?
17 set-window-state clear-window-state
18 toggle-fullscreen toggle-borderless-windowed
19 maximize-window minimize-window restore-window
20 set-window-title set-window-position
21 set-window-monitor set-window-min-size set-window-max-size
22 set-window-size set-window-opacity set-window-focused
23 get-window-handle
24 get-screen-width get-screen-height
25 get-render-width get-render-height
26 get-monitor-count get-current-monitor
27 get-monitor-width get-monitor-height
28 get-monitor-physical-width get-monitor-physical-height
29 get-monitor-refresh-rate get-monitor-name
30 set-clipboard-text get-clipboard-text
31 enable-event-waiting disable-event-waiting
33 ;; Cursor
34 show-cursor hide-cursor cursor-hidden?
35 enable-cursor disable-cursor cursor-on-screen?)
37 (begin
39 ;; ============================================================
40 ;; Raw FFI Bindings (private)
41 ;; ============================================================
43 ;; --- Window management ---
44 (define %init-window (c-function rl-lib "InitWindow" (list ffi/int ffi/int ffi/string) ffi/void))
45 (define %close-window (c-function rl-lib "CloseWindow" '() ffi/void))
46 (define %window-should-close (c-function rl-lib "WindowShouldClose" '() ffi/int))
47 (define %window-ready (c-function rl-lib "IsWindowReady" '() ffi/int))
48 (define %window-fullscreen (c-function rl-lib "IsWindowFullscreen" '() ffi/int))
49 (define %window-hidden (c-function rl-lib "IsWindowHidden" '() ffi/int))
50 (define %window-minimized (c-function rl-lib "IsWindowMinimized" '() ffi/int))
51 (define %window-maximized (c-function rl-lib "IsWindowMaximized" '() ffi/int))
52 (define %window-focused (c-function rl-lib "IsWindowFocused" '() ffi/int))
53 (define %window-resized (c-function rl-lib "IsWindowResized" '() ffi/int))
54 (define %window-state (c-function rl-lib "IsWindowState" (list ffi/uint) ffi/int))
55 (define %set-window-state (c-function rl-lib "SetWindowState" (list ffi/uint) ffi/void))
56 (define %clear-window-state (c-function rl-lib "ClearWindowState" (list ffi/uint) ffi/void))
57 (define %toggle-fullscreen (c-function rl-lib "ToggleFullscreen" '() ffi/void))
58 (define %toggle-borderless-windowed (c-function rl-lib "ToggleBorderlessWindowed" '() ffi/void))
59 (define %maximize-window (c-function rl-lib "MaximizeWindow" '() ffi/void))
60 (define %minimize-window (c-function rl-lib "MinimizeWindow" '() ffi/void))
61 (define %restore-window (c-function rl-lib "RestoreWindow" '() ffi/void))
62 (define %set-window-title (c-function rl-lib "SetWindowTitle" (list ffi/string) ffi/void))
63 (define %set-window-position (c-function rl-lib "SetWindowPosition" (list ffi/int ffi/int) ffi/void))
64 (define %set-window-monitor (c-function rl-lib "SetWindowMonitor" (list ffi/int) ffi/void))
65 (define %set-window-min-size (c-function rl-lib "SetWindowMinSize" (list ffi/int ffi/int) ffi/void))
66 (define %set-window-max-size (c-function rl-lib "SetWindowMaxSize" (list ffi/int ffi/int) ffi/void))
67 (define %set-window-size (c-function rl-lib "SetWindowSize" (list ffi/int ffi/int) ffi/void))
68 (define %set-window-opacity (c-function rl-lib "SetWindowOpacity" (list ffi/float) ffi/void))
69 (define %set-window-focused (c-function rl-lib "SetWindowFocused" '() ffi/void))
70 (define %get-window-handle (c-function rl-lib "GetWindowHandle" '() ffi/pointer))
71 (define %get-screen-width (c-function rl-lib "GetScreenWidth" '() ffi/int))
72 (define %get-screen-height (c-function rl-lib "GetScreenHeight" '() ffi/int))
73 (define %get-render-width (c-function rl-lib "GetRenderWidth" '() ffi/int))
74 (define %get-render-height (c-function rl-lib "GetRenderHeight" '() ffi/int))
75 (define %get-monitor-count (c-function rl-lib "GetMonitorCount" '() ffi/int))
76 (define %get-current-monitor (c-function rl-lib "GetCurrentMonitor" '() ffi/int))
77 (define %get-monitor-width (c-function rl-lib "GetMonitorWidth" (list ffi/int) ffi/int))
78 (define %get-monitor-height (c-function rl-lib "GetMonitorHeight" (list ffi/int) ffi/int))
79 (define %get-monitor-physical-width (c-function rl-lib "GetMonitorPhysicalWidth" (list ffi/int) ffi/int))
80 (define %get-monitor-physical-height (c-function rl-lib "GetMonitorPhysicalHeight" (list ffi/int) ffi/int))
81 (define %get-monitor-refresh-rate (c-function rl-lib "GetMonitorRefreshRate" (list ffi/int) ffi/int))
82 (define %get-monitor-name (c-function rl-lib "GetMonitorName" (list ffi/int) ffi/string))
83 (define %set-clipboard-text (c-function rl-lib "SetClipboardText" (list ffi/string) ffi/void))
84 (define %get-clipboard-text (c-function rl-lib "GetClipboardText" '() ffi/string))
85 (define %enable-event-waiting (c-function rl-lib "EnableEventWaiting" '() ffi/void))
86 (define %disable-event-waiting (c-function rl-lib "DisableEventWaiting" '() ffi/void))
88 ;; --- Cursor ---
89 (define %show-cursor (c-function rl-lib "ShowCursor" '() ffi/void))
90 (define %hide-cursor (c-function rl-lib "HideCursor" '() ffi/void))
91 (define %cursor-hidden (c-function rl-lib "IsCursorHidden" '() ffi/int))
92 (define %enable-cursor (c-function rl-lib "EnableCursor" '() ffi/void))
93 (define %disable-cursor (c-function rl-lib "DisableCursor" '() ffi/void))
94 (define %cursor-on-screen (c-function rl-lib "IsCursorOnScreen" '() ffi/int))
96 ;; ============================================================
97 ;; Public API
98 ;; ============================================================
100 ;; --- Window management ---
102 ;;; Initialize window and OpenGL context.
103 (define (init-window width height title)
104 (: integer? integer? string? -> void?)
105 (%init-window width height title))
107 ;;; Close window and unload OpenGL context.
108 (define (close-window) (: -> void?) (%close-window))
110 ;;; Check if application should close (KEY_ESCAPE pressed or window close).
111 (define (window-should-close?) (: -> boolean?) (not (= 0 (%window-should-close))))
113 (define (window-ready?) (: -> boolean?) (not (= 0 (%window-ready))))
114 (define (window-fullscreen?) (: -> boolean?) (not (= 0 (%window-fullscreen))))
115 (define (window-hidden?) (: -> boolean?) (not (= 0 (%window-hidden))))
116 (define (window-minimized?) (: -> boolean?) (not (= 0 (%window-minimized))))
117 (define (window-maximized?) (: -> boolean?) (not (= 0 (%window-maximized))))
118 (define (window-focused?) (: -> boolean?) (not (= 0 (%window-focused))))
119 (define (window-resized?) (: -> boolean?) (not (= 0 (%window-resized))))
120 (define (window-state? flag) (: integer? -> boolean?) (not (= 0 (%window-state flag))))
122 (define (set-window-state flags) (: integer? -> void?) (%set-window-state flags))
123 (define (clear-window-state flags) (: integer? -> void?) (%clear-window-state flags))
124 (define (toggle-fullscreen) (: -> void?) (%toggle-fullscreen))
125 (define (toggle-borderless-windowed) (: -> void?) (%toggle-borderless-windowed))
126 (define (maximize-window) (: -> void?) (%maximize-window))
127 (define (minimize-window) (: -> void?) (%minimize-window))
128 (define (restore-window) (: -> void?) (%restore-window))
129 (define (set-window-title title) (: string? -> void?) (%set-window-title title))
130 (define (set-window-position x y) (: integer? integer? -> void?) (%set-window-position x y))
131 (define (set-window-monitor monitor) (: integer? -> void?) (%set-window-monitor monitor))
132 (define (set-window-min-size w h) (: integer? integer? -> void?) (%set-window-min-size w h))
133 (define (set-window-max-size w h) (: integer? integer? -> void?) (%set-window-max-size w h))
134 (define (set-window-size w h) (: integer? integer? -> void?) (%set-window-size w h))
135 (define (set-window-opacity opacity) (: number? -> void?) (%set-window-opacity opacity))
136 (define (set-window-focused) (: -> void?) (%set-window-focused))
137 (define (get-window-handle) (: -> pointer?) (%get-window-handle))
138 (define (get-screen-width) (: -> integer?) (%get-screen-width))
139 (define (get-screen-height) (: -> integer?) (%get-screen-height))
140 (define (get-render-width) (: -> integer?) (%get-render-width))
141 (define (get-render-height) (: -> integer?) (%get-render-height))
142 (define (get-monitor-count) (: -> integer?) (%get-monitor-count))
143 (define (get-current-monitor) (: -> integer?) (%get-current-monitor))
144 (define (get-monitor-width m) (: integer? -> integer?) (%get-monitor-width m))
145 (define (get-monitor-height m) (: integer? -> integer?) (%get-monitor-height m))
146 (define (get-monitor-physical-width m) (: integer? -> integer?) (%get-monitor-physical-width m))
147 (define (get-monitor-physical-height m) (: integer? -> integer?) (%get-monitor-physical-height m))
148 (define (get-monitor-refresh-rate m) (: integer? -> integer?) (%get-monitor-refresh-rate m))
149 (define (get-monitor-name m) (: integer? -> string?) (%get-monitor-name m))
150 (define (set-clipboard-text text) (: string? -> void?) (%set-clipboard-text text))
151 (define (get-clipboard-text) (: -> string?) (%get-clipboard-text))
152 (define (enable-event-waiting) (: -> void?) (%enable-event-waiting))
153 (define (disable-event-waiting) (: -> void?) (%disable-event-waiting))
155 ;; --- Cursor ---
157 (define (show-cursor) (: -> void?) (%show-cursor))
158 (define (hide-cursor) (: -> void?) (%hide-cursor))
159 (define (cursor-hidden?) (: -> boolean?) (not (= 0 (%cursor-hidden))))
160 (define (enable-cursor) (: -> void?) (%enable-cursor))
161 (define (disable-cursor) (: -> void?) (%disable-cursor))
162 (define (cursor-on-screen?) (: -> boolean?) (not (= 0 (%cursor-on-screen))))))