From 52557c8a1c78ee02bd0eda1c740a37f8d6759b0c Mon Sep 17 00:00:00 2001 From: ubq323 Date: Sun, 24 Mar 2024 22:28:12 +0000 Subject: multiple chunks, and drawing works completely correctly with moving around --- drawing.ha | 32 ++++++++++++++++++++++++-------- 1 file changed, 24 insertions(+), 8 deletions(-) (limited to 'drawing.ha') diff --git a/drawing.ha b/drawing.ha index 804aee4..5812109 100644 --- a/drawing.ha +++ b/drawing.ha @@ -1,4 +1,5 @@ use sdl2; +use fmt; // 2d position, x and y type pos = (i32, i32); @@ -7,13 +8,20 @@ type drawing_state = struct { // is the mouse button held down? drawing: bool, pos: pos, - picture: *picture, + pictures: []picture, }; type picture = struct { + // the surface data as u32s d: *[*]u32, w: size, h: size, + + // backreference to the surface whose data we're using + surf: *sdl2::SDL_Surface, + + pos: pos, + }; // Returns array index of the pixel at position pos. @@ -33,10 +41,12 @@ fn pidx(pic: *picture, pos: pos) size = { 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 { +fn picture_from_surface(surf: *sdl2::SDL_Surface, pos: pos) picture = picture { w = surf.w: size, h = surf.h: size, d = (surf.pixels as *opaque: *[*]u32), + surf = surf, + pos = pos, }; fn clear_picture(pic: *picture, color: u32) void = { @@ -57,14 +67,15 @@ fn outline_picture(pic: *picture) void = { fn min(a: i32, b: i32) i32 = if (a