From 40231bd839dbe5b8aa65e8f3bde31bd33b9a9190 Mon Sep 17 00:00:00 2001 From: ubq323 Date: Mon, 8 Apr 2024 02:28:59 +0100 Subject: giant refactor, start to use drawing ops for drawing --- client/drawing.ha | 127 ------------------------------------------------------ 1 file changed, 127 deletions(-) delete mode 100644 client/drawing.ha (limited to 'client/drawing.ha') diff --git a/client/drawing.ha b/client/drawing.ha deleted file mode 100644 index 2d093ae..0000000 --- a/client/drawing.ha +++ /dev/null @@ -1,127 +0,0 @@ -use sdl2; -use fmt; -use io; -use endian; -use math::random; - -// 2d position, x and y -export type pos = (i32, i32); - -export type drawing_state = struct { - // is the mouse button held down? - drawing: bool, - pos: pos, - pictures: []picture, - - // hack. change this - conn: io::file, -}; - -export 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. -// Bounds check happens in here instead of using a slice type, so -// that it's easier to remove later. -export fn pidx(pic: *picture, pos: pos) size = { - const (x,y) = pos; - const (xs,ys) = (x:size, y:size); - assert(0 <= x, "x position must not be less than 0"); - assert(0 <= y, "y position must not be less than 0"); - assert(xs < pic.w, "x position must be less than picture width"); - assert(ys < pic.h, "y position must be less than picture height"); - - return xs + pic.w*ys; -}; - -export fn pic_set(pic: *picture, pos: pos, val: u32) void = - pic.d[pidx(pic,pos)] = val; - -export 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, -}; - -export fn clear_picture(pic: *picture, color: u32) void = { - for (let i = 0z; i < pic.w*pic.h; i+=1) pic.d[i] = color; -}; - -export fn outline_picture(pic: *picture) void = { - for (let x = 0; x:size < pic.w; x+=1) { - pic_set(pic, (x, 0), 0); - pic_set(pic, (x, pic.h:int-1), 0); - }; - for (let y = 0; y:size < pic.h; y+=1) { - pic_set(pic, (0, y), 0); - pic_set(pic, (pic.w:int-1, y), 0); - }; -}; - -fn min(a: i32, b: i32) i32 = if (a