summaryrefslogtreecommitdiff
path: root/chapter31/src/main/smp/sys/gfx.smp
diff options
context:
space:
mode:
Diffstat (limited to 'chapter31/src/main/smp/sys/gfx.smp')
-rw-r--r--chapter31/src/main/smp/sys/gfx.smp19
1 files changed, 18 insertions, 1 deletions
diff --git a/chapter31/src/main/smp/sys/gfx.smp b/chapter31/src/main/smp/sys/gfx.smp
index ae203bd1..60505ac9 100644
--- a/chapter31/src/main/smp/sys/gfx.smp
+++ b/chapter31/src/main/smp/sys/gfx.smp
@@ -1,5 +1,6 @@
// Minimal pixel-window interface; drawing belongs in Simple.
-// One fixed-size window, main thread only. Pixel format is 0x00RRGGBB.
+// 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;
@@ -9,6 +10,9 @@ 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";
@@ -31,6 +35,19 @@ val present = { u32[~] 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(); };