summaryrefslogtreecommitdiff
path: root/chapter32/src/main/smp/sys/draw.smp
diff options
context:
space:
mode:
authorCliff Click <cliffc@acm.org>2026-11-15 16:11:39 -0800
committerCliff Click <cliffc@acm.org>2026-11-15 16:11:39 -0800
commit9fe7c6f9697b5bbf3041261fdc60040e75cc674f (patch)
treed92a8ff20ed984938d90ad8917b4d67fba9fb745 /chapter32/src/main/smp/sys/draw.smp
parentf0a6c6757a795b8e186de0076836a87acef59fa7 (diff)
downloadSimple-ch32.tar.gz
Simple-ch32.zip
Split off chapter 31ch32
Ch 32 will be focused on compiler performance issues.
Diffstat (limited to 'chapter32/src/main/smp/sys/draw.smp')
-rw-r--r--chapter32/src/main/smp/sys/draw.smp19
1 files changed, 19 insertions, 0 deletions
diff --git a/chapter32/src/main/smp/sys/draw.smp b/chapter32/src/main/smp/sys/draw.smp
new file mode 100644
index 00000000..92bf04b7
--- /dev/null
+++ b/chapter32/src/main/smp/sys/draw.smp
@@ -0,0 +1,19 @@
+// Software raster drawing. No window or native calls; pixels are packed RGB (0x00RRGGBB).
+// API reference: draw/README.md.
+u32 BLACK = 0x000000;
+u32 WHITE = 0xffffff;
+u32 RED = 0xff0000;
+u32 GREEN = 0x00ff00;
+u32 BLUE = 0x0000ff;
+
+// Components are clamped to bytes rather than wrapping.
+val rgb = { int r, int g, int b ->
+ r = r < 0 ? 0 : r > 255 ? 255 : r;
+ g = g < 0 ? 0 : g > 255 ? 255 : g;
+ b = b < 0 ? 0 : b > 255 ? 255 : b;
+ u32 color = (r<<16) | (g<<8) | b;
+ return color;
+};
+
+val Canvas = Canvas; // Pixel canvas and drawing methods
+val Button = Button; // Pointer state and rendering for a rectangular button