diff options
| author | ubq323 <ubq323@ubq323.website> | 2024-04-14 18:38:10 +0100 | 
|---|---|---|
| committer | ubq323 <ubq323@ubq323.website> | 2024-04-14 18:38:34 +0100 | 
| commit | 1f8e6e98b924ee4661be2e7b75cf09a6a8bb7cd3 (patch) | |
| tree | 057c24efd61e8d417199be70cdd487722c652f6c /client | |
| parent | 047718ad845ee5850fe70316d7c1ac9dec10b6dd (diff) | |
change brush size and colour
Diffstat (limited to 'client')
| -rw-r--r-- | client/main.ha | 29 | ||||
| -rw-r--r-- | client/paintui/paintui.ha | 39 | 
2 files changed, 57 insertions, 11 deletions
diff --git a/client/main.ha b/client/main.ha index 2a341c4..04e6854 100644 --- a/client/main.ha +++ b/client/main.ha @@ -47,8 +47,6 @@ export fn main() void = {  		case let err: net::error =>  			fmt::fatal("couldn't connect to server:",net::strerror(err));  	}; - -  	const pollfd: [1]poll::pollfd = [ poll::pollfd {  		fd = conn, events=poll::event::POLLIN, revents = 0 @@ -56,7 +54,7 @@ export fn main() void = {  	const packet_reader = packet_reader::new();  	// paintui state -	let pstate = paintui::state { ... }; +	let pstate = paintui::state { size_idx = 4, ... };  	let camera_pos: pos = (25, 50);  	let quit = false; @@ -65,10 +63,14 @@ export fn main() void = {  	let requested_chunks: []pos = []; -	// in WORLD coords +	// in SCREEN coords  	let mouse_pos: pos = (0,0);  	let mouse_down = false;  	request_visible_chunks(pictures, conn, camera_pos, &requested_chunks); + + +	const win_pic = picture_from_surface(wsurf, (9,9)); +  	for (!quit) {  		const did_move = do_movement(&camera_pos); @@ -86,20 +88,27 @@ export fn main() void = {  			case sdl2::SDL_EventType::QUIT => quit = true;  			case sdl2::SDL_EventType::KEYDOWN =>  				const keysym = ev.key.keysym.sym; -				if (keysym == sdl2::SDL_Keycode::ESCAPE) quit = true; +				if (keysym == sdl2::SDL_Keycode::ESCAPE) quit = true +				else if (sdl2::SDL_Keycode::ZERO <= keysym +						&& keysym <= sdl2::SDL_Keycode::NINE) +					paintui::key(&pstate, keysym - sdl2::SDL_Keycode::ZERO);  			case sdl2::SDL_EventType::MOUSEBUTTONDOWN,  					sdl2::SDL_EventType::MOUSEBUTTONUP =>  				const edata = ev.button; -				mouse_pos = (edata.x + camera_pos.0, edata.y + camera_pos.1); +				mouse_pos = (edata.x, edata.y);  				if (edata.button == 1)  					mouse_down = (edata.state == 1);  			case sdl2::SDL_EventType::MOUSEMOTION =>  				const edata = ev.motion; -				mouse_pos = (edata.x + camera_pos.0, edata.y + camera_pos.1); +				mouse_pos = (edata.x, edata.y); +			case sdl2::SDL_EventType::MOUSEWHEEL => +				const edata = ev.wheel; +				paintui::mousewheel(&pstate, edata.y);  			case => void;  		}; -		match (paintui::tick(&pstate, mouse_pos, mouse_down)) { +		const mouse_pos_world = (mouse_pos.0 + camera_pos.0, mouse_pos.1 + camera_pos.1); +		match (paintui::tick(&pstate, mouse_pos_world, mouse_down)) {  		case void => yield;  		case let op: drawing::op =>  			drawing::perform(pictures, op); @@ -140,7 +149,8 @@ export fn main() void = {  			};  		}; -		drawing::clear_picture(&picture_from_surface(wsurf,(9,9)), 0xff0000); + +		drawing::clear_picture(&win_pic, 0xff0000);  		for (let i = 0z; i < len(pictures); i += 1) {  			const psurf = picture_surfaces[i]; @@ -148,6 +158,7 @@ export fn main() void = {  			render_picture(pic, psurf, wsurf, camera_pos);  		}; +		drawing::circle_hollow(&win_pic, mouse_pos, paintui::sizes[pstate.size_idx]: i32, pstate.color);  		sdl2::SDL_UpdateWindowSurface(win)!;  		n += 1; 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]; +}; +  | 
