Modules

Window_Creation

moduleSource

Available on macOS, Linux, Windows

#import "Window_Creation";

Opens native windows (Cocoa, Win32 or X11) with an OpenGL surface.

create_window makes one; get_dimensions, get_mouse_pointer_position and toggle_fullscreen query and change it. Read input with the Input module.

Example↗
#import "Window_Creation";
#import "Input";

window := create_window(800, 600, "hello");
assert(window != WT.INVALID_WINDOW);
while true {
    update_window_events();
    for events_this_frame if it.type == .QUIT return;
}

This one is only checked to compile, not run.

Module parameters#

DEFAULT_MSAA: s32 = 4
The sample count of new windows.

Procedures#

X11 queries#

get_pixel_scale3 overloadssince 0.31.0Source
(win: Window) -> float
(hwnd: Windows.HWND) -> float
(window: *ObjC.NSWindow) -> float

Device pixels per window coordinate unit; window sizes here are already in pixels.

window := create_window(800, 600, "scale");
pixels := cast(int) (800 * get_pixel_scale(window));
↗

This one is only checked to compile, not run.

(win: Window, right_handed: bool) -> (x: s32, y: s32, width: s32, height: s32, success := true)
(hwnd: Windows.HWND, right_handed: bool) -> (x: s32, y: s32, width: s32, height: s32, success := true)
(window: *ObjC.NSWindow, right_handed: bool) -> (x: s32, y: s32, width: s32, height: s32, success := true)

Where the window's drawing area is on the screen and how big it is: x, y, width, height, success.

window := create_window(800, 600, "size");
x, y, width, height, ok := get_dimensions(window, false);
assert(ok && width > 0);
↗

This one is only checked to compile, not run.

(dpy: *Display, win: Window, right_handed: bool) -> (x: int, y: int, success: bool)
(win: Window, right_handed: bool) -> (x: int, y: int, success: bool)
(right_handed := false) -> (x: int, y: int, success: bool)
(hwnd: Windows.HWND, right_handed: bool) -> (x: int, y: int, success: bool)
(right_handed := false) -> (x: int, y: int, success: bool)
(window: *ObjC.NSWindow, right_handed: bool) -> (x: int, y: int, success: bool)
(right_handed := false) -> (x: int, y: int, success: bool)

Where the mouse is, in window coordinates: x, y, success.

(win: Window, desire_fullscreen: bool, saved: *Saved_Window_Info) -> (success: bool, width: s32, height: s32)
(hwnd: Windows.HWND, desire_fullscreen: bool, saved: *Saved_Window_Info) -> (succcess: bool, width: s32, height: s32)
(win: *ObjC.NSWindow, desire_fullscreen: bool, saved: *Saved_Window_Info) -> (success: bool, width: s32, height: s32)

Switches the window between full screen and its normal size. Returns whether it worked and the new size.

window := create_window(800, 600, "full screen");
saved: Saved_Window_Info;
ok, width, height := toggle_fullscreen(window, true, *saved);
toggle_fullscreen(window, false, *saved);
↗

This one is only checked to compile, not run.

X11 create#

(width: int, height: int, window_name: string, window_x := 0, window_y := 0, parent: Window_Type = None, background_color_rgb := DEFAULT_WINDOW_CREATION_COLOR, wanted_msaa: s32 = DEFAULT_MSAA) -> Window
(width: int, height: int, window_name: string, window_x := -1, window_y := -1, parent: Window_Type = null, background_color_rgb := DEFAULT_WINDOW_CREATION_COLOR, wanted_msaa := DEFAULT_MSAA) -> Windows.HWND
(width: int, height: int, window_name: string, window_x := -1, window_y := -1, parent: Window_Type = null, background_color_rgb := DEFAULT_WINDOW_CREATION_COLOR, wanted_msaa := DEFAULT_MSAA) -> *ObjC.NSWindow

Opens a window and returns it, or a null window when it could not be made.

window := create_window(800, 600, "My game");
assert(window != WT.INVALID_WINDOW);
↗

This one is only checked to compile, not run.

Cocoa queries#

Types#

:: struct

The position and size to restore after leaving full screen; toggle_fullscreen fills it in.

Constants#

:: Windows.WS_OVERLAPPEDWINDOW

The Win32 window style of a normal window.

:: u64

The native window handle. Its type depends on the target: an X11.Window (an integer) on Linux, an HWND on Windows, and a pointer on macOS (*NSWindow) and Android. So "no window" is 0 in one place and null in another, and window == null does not compile on Linux.

no_window: Window_Type;
assert(no_window == WT.INVALID_WINDOW);

window := no_window;
if window == WT.INVALID_WINDOW window = no_window;
↗