Next: , Up: Booting   [Contents][Index]


4.1.1 Window Creation

(use-modules (sly window))

Sly uses the windowing features of SDL 1.2 under the hood, which currently restricts Sly applications to using only a single window. SDL2 support will come in a future release.

The window data structure:

Scheme Procedure: make-window [#:title] [#:resolution] [#:fullscreen?]

Create a new window object. title is a string to display in the window’s title bar. resolution is a 2D vector that specifies the dimensions of the window in pixels. fullscreen? is a boolean that toggles fullscreen mode.

Scheme Procedure: window? obj

Return #t if obj is a window.

Scheme Procedure: window-title window

Return the title of window.

Scheme Procedure: window-resolution window

Return the resolution of window.

Scheme Procedure: window-fullscreen? window

Return #t if window is set to fullscreen mode.

The following signals hold the state of the current window:

Scheme Signal: window-width

The width of the current window.

Scheme Signal: window-height

The height of the current window.

Scheme Signal: window-size

The size of the current window as a 2D vector.

In addition to signals, the following hooks are triggered upon certain changes to window state:

Scheme Variable: window-resize-hook

This hook is run when the current window is resized. Procedures added to this hook should accept two arguments: Numbers width and height, the new dimensions of the window in pixels.

Scheme Variable: window-close-hook

This hook is run when the close button is clicked. Note that this event is simply a request from the user to close the window, it does not mean that the window has actually been closed. Procedures added to this hook should accept no arguments.

The following procedures are used to open/close windows:

Scheme Procedure: open-window [window]

Open the game window using the settings in window.

Scheme Procedure: close-window

Close the currently open window.

Scheme Syntax: with-window window body

Evaluate body in the context of window. window is opened before evaluating body, and closed afterwards.


Next: , Up: Booting   [Contents][Index]