From 1f8e6e98b924ee4661be2e7b75cf09a6a8bb7cd3 Mon Sep 17 00:00:00 2001 From: ubq323 Date: Sun, 14 Apr 2024 18:38:10 +0100 Subject: change brush size and colour --- client/paintui/paintui.ha | 39 +++++++++++++++++++++++++++++++++++++-- 1 file changed, 37 insertions(+), 2 deletions(-) (limited to 'client/paintui/paintui.ha') diff --git a/client/paintui/paintui.ha b/client/paintui/paintui.ha index ce55bb7..212e16b 100644 --- a/client/paintui/paintui.ha +++ b/client/paintui/paintui.ha @@ -10,12 +10,31 @@ use drawing; use drawing::{pos}; +export const sizes: [_]u8 = [ + 1, 2, 4, 8, 16, 32, 48, 64, 80, 96, 112, 128 +]; + +const colors: [_]u32 = [ + 0xffffff, // white + 0xff4040, // red + 0xff8000, // orange + 0xc0c040, // yellow + 0x00c000, // green + 0x00c0c0, // teal + 0x4040ff, // blue + 0xc000c0, // purple + 0x808080, // grey + 0x000000, // black +]; + export type state = struct { // last known mouse position, in world coordinates last_mouse_pos: pos, // last known mouse pressed-ness - last_mouse_pressed: bool + last_mouse_pressed: bool, + size_idx: size, + color: u32 }; export fn tick( @@ -32,7 +51,23 @@ export fn tick( && (mouse_pos.0 != pstate.last_mouse_pos.0 || mouse_pos.1 != pstate.last_mouse_pos.1 || (!pstate.last_mouse_pressed))) - mouse_pos: drawing::op_circle + drawing::op_circle { + pos = mouse_pos, + radius = sizes[pstate.size_idx], + color = pstate.color, + } else void; }; +export fn mousewheel(pstate: *state, amt: i32) void = { + if (amt < 0 && pstate.size_idx > 0) + pstate.size_idx -= 1 + else if (amt > 0 && pstate.size_idx < len(sizes) - 1) + pstate.size_idx += 1; +}; + +export fn key(pstate: *state, key: uint) void = { + assert(key <= 9, "what what what what what"); + pstate.color = colors[key]; +}; + -- cgit v1.2.3