From 6d766d6dd9177ececb14ebfe2ac68cc581eeeb44 Mon Sep 17 00:00:00 2001 From: ubq323 Date: Fri, 22 Mar 2024 23:52:56 +0000 Subject: movement, multiple surfaces (sort of) --- drawing.ha | 41 ++++++++++++++++++++++++++++++----------- 1 file changed, 30 insertions(+), 11 deletions(-) (limited to 'drawing.ha') diff --git a/drawing.ha b/drawing.ha index ff2aa71..804aee4 100644 --- a/drawing.ha +++ b/drawing.ha @@ -1,14 +1,13 @@ use sdl2; - // 2d position, x and y -type pos = (int, int); +type pos = (i32, i32); type drawing_state = struct { // is the mouse button held down? drawing: bool, pos: pos, - picture: picture, + picture: *picture, }; type picture = struct { @@ -16,6 +15,7 @@ type picture = struct { w: size, h: size, }; + // Returns array index of the pixel at position pos. // Bounds check happens in here instead of using a slice type, so // that it's easier to remove later. @@ -29,22 +29,42 @@ fn pidx(pic: *picture, pos: pos) size = { return xs + pic.w*ys; }; -fn pic_set(pic: *picture, pos: pos, val: u32) void = pic.d[pidx(pic,pos)] = val; + +fn pic_set(pic: *picture, pos: pos, val: u32) void = + pic.d[pidx(pic,pos)] = val; + fn picture_from_surface(surf: *sdl2::SDL_Surface) picture = picture { w = surf.w: size, h = surf.h: size, d = (surf.pixels as *opaque: *[*]u32), }; -fn min(a: int, b: int) int = if (a