Skip to content

Commit

Permalink
add checkerbox background to tile selector
Browse files Browse the repository at this point in the history
  • Loading branch information
BlaiZephyr committed Jan 16, 2025
1 parent 52a4948 commit 17eb142
Show file tree
Hide file tree
Showing 2 changed files with 41 additions and 8 deletions.
10 changes: 2 additions & 8 deletions game/editor/src/tools/tile_layer/brush.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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},
};
Expand Down Expand Up @@ -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,
Expand Down
39 changes: 39 additions & 0 deletions game/editor/src/tools/utils.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down

0 comments on commit 17eb142

Please sign in to comment.