summaryrefslogtreecommitdiff
path: root/chapter31/src/main/smp/sys/draw.smp
blob: 92bf04b7dd6fc8dfdaa826ef6c94655f8e1e43ba (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
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