blob: ae203bd137db02c1420fc8a4c612b964c5d56c9a (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
|
// Minimal pixel-window interface; drawing belongs in Simple.
// One fixed-size window, main thread only. Pixel format is 0x00RRGGBB.
// open/present/poll return OK, CLOSED (normal user close/Esc), or ERROR.
int OK = 0;
int CLOSED = 1;
int ERROR = -1;
int LEFT = 1;
int ESCAPE = 256;
{ i64 u32 u32 -> i32 } simple_gfx_open = "C";
{ i64 u32 -> i32 } simple_gfx_present = "C";
{ i32 -> i32 } simple_gfx_poll = "C";
{ i32 } simple_gfx_mouse_x = "C";
{ i32 } simple_gfx_mouse_y = "C";
{ i32 -> i32 } simple_gfx_button = "C";
{ i32 -> i32 } simple_gfx_key = "C";
{ i32 } simple_gfx_close = "C";
{ i64 -> i32 } simple_gfx_wait = "C";
// Failure prints a diagnostic to stderr and returns ERROR; callers decide
// whether to exit or fall back to text. No native library is loaded until here.
val open = { u8[~] title, u32 width, u32 height ->
i64 ptr = aryu8.str0(title);
simple_gfx_open(ptr,width,height);
};
// Array length must be width*height. The native layer copies for OS repaints;
// it never keeps a pointer into the Simple heap after this call returns.
val present = { u32[~] pixels ->
i64 ptr = pixels;
simple_gfx_present(ptr,pixels#);
};
// wait=true waits up to 17ms, waking early for input to avoid a busy loop.
val poll = { bool wait -> simple_gfx_poll(wait); };
val mouseX = { -> simple_gfx_mouse_x(); };
val mouseY = { -> simple_gfx_mouse_y(); };
val button = { int button -> simple_gfx_button(button); };
// Printable keys use uppercase ASCII; special keys use MiniFB's key codes.
val key = { int key -> simple_gfx_key(key); };
val close = { -> simple_gfx_close(); };
// Wait for input or at most timeout milliseconds; 0 polls, -1 waits indefinitely.
// This blocks the game thread, dispatches window events, and may wake early.
val wait = { i64 timeout_ms -> simple_gfx_wait(timeout_ms); };
|