// Minimal pixel-window interface; drawing belongs in Simple. // API and launch reference: gfx.md beside this file. // One resizable 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"; { i64 u32 u32 u32 -> i32 } simple_gfx_present_size = "C"; { u32 } simple_gfx_width = "C"; { u32 } simple_gfx_height = "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#); }; // Drawable size after the last event dispatch; zero when closed. val width = { -> simple_gfx_width(); }; val height = { -> simple_gfx_height(); }; // Explicit dimensions keep a resize arriving during presentation harmless. val presentSize = { u32[~] pixels, u32 width, u32 height -> if( width == 0 || height == 0 || width > pixels# || height > pixels# ) return ERROR; i64 count = width; count *= height; if( count > pixels# ) return ERROR; i64 ptr = pixels; u32 size = count; simple_gfx_present_size(ptr,size,width,height); }; // 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); };