From 17eb1428875c2de91a3d00eda79ce4a26bc20a0a Mon Sep 17 00:00:00 2001 From: blaiz Date: Thu, 16 Jan 2025 15:24:49 +0100 Subject: [PATCH] add checkerbox background to tile selector --- game/editor/src/tools/tile_layer/brush.rs | 10 ++---- game/editor/src/tools/utils.rs | 39 +++++++++++++++++++++++ 2 files changed, 41 insertions(+), 8 deletions(-) diff --git a/game/editor/src/tools/tile_layer/brush.rs b/game/editor/src/tools/tile_layer/brush.rs index a317fef..2433c3b 100644 --- a/game/editor/src/tools/tile_layer/brush.rs +++ b/game/editor/src/tools/tile_layer/brush.rs @@ -46,7 +46,7 @@ use crate::{ upload_design_tile_layer_buffer, upload_physics_layer_buffer, }, tools::utils::{ - render_filled_rect, render_filled_rect_from_state, render_rect, render_rect_from_state, + render_checkerboard_background, render_filled_rect, render_filled_rect_from_state, render_rect, render_rect_from_state }, utils::{ui_pos_to_world_pos, UiCanvasSize}, }; @@ -1566,13 +1566,7 @@ impl TileBrush { canvas_handle.canvas_width(), canvas_handle.canvas_height(), ); - render_filled_rect_from_state( - stream_handle, - render_rect, - ubvec4::new(0, 0, 0, 255), - state, - false, - ); + render_checkerboard_background(stream_handle, render_rect, &state); state.map_canvas( tl_x, diff --git a/game/editor/src/tools/utils.rs b/game/editor/src/tools/utils.rs index 4570261..1711151 100644 --- a/game/editor/src/tools/utils.rs +++ b/game/editor/src/tools/utils.rs @@ -76,6 +76,45 @@ pub fn render_rect( render_rect_from_state(stream_handle, state, rect, color) } +pub fn render_checkerboard_background( + stream_handle: &GraphicsStreamHandle, + render_rect: egui::Rect, + state: &State, +) { + const FIELD_SIZE: f32 = 15.0; + + let cols = (render_rect.width() / FIELD_SIZE).ceil() as i32; + let rows = (render_rect.height() / FIELD_SIZE).ceil() as i32; + + let color1 = ubvec4::new(180, 180, 180, 255); + let color2 = ubvec4::new(140, 140, 140, 255); + + for row in 0..rows { + for col in 0..cols { + let x = render_rect.min.x + (col as f32 * FIELD_SIZE); + let y = render_rect.min.y + (row as f32 * FIELD_SIZE); + + let checker_rect = egui::Rect::from_min_size( + egui::pos2(x, y), + egui::vec2( + FIELD_SIZE.min(render_rect.max.x - x), + FIELD_SIZE.min(render_rect.max.y - y) + ) + ); + + let color = if (row + col) % 2 == 0 { color1 } else { color2 }; + + render_filled_rect_from_state( + stream_handle, + checker_rect, + color, + state.clone(), + false, + ); + } + } +} + pub fn render_filled_rect_from_state( stream_handle: &GraphicsStreamHandle, rect: egui::Rect,