rectangle.rs - icy_draw - icy_draw is the successor to mystic draw. fork / mirror
(HTM) git clone https://git.drkhsh.at/icy_draw.git
(DIR) Log
(DIR) Files
(DIR) Refs
(DIR) README
(DIR) LICENSE
---
rectangle.rs (2050B)
---
1 use icy_engine::Position;
2 use icy_engine_egui::BufferView;
3
4 use super::{plot_point, BrushMode, ColorMode, PointRole};
5
6 pub fn draw_rectangle(buffer_view: &mut BufferView, from: impl Into<Position>, to: impl Into<Position>, mode: BrushMode, color_mode: ColorMode) {
7 let mut from = from.into();
8 let mut to = to.into();
9 let mut y_mul = 1;
10 if !matches!(mode, BrushMode::HalfBlock) {
11 from.y /= 2;
12 to.y /= 2;
13 y_mul = 2;
14 }
15
16 for x in from.x + 1..to.x {
17 plot_point(buffer_view, (x, from.y * y_mul), mode.clone(), color_mode, PointRole::TopSide);
18 plot_point(buffer_view, (x, to.y * y_mul), mode.clone(), color_mode, PointRole::BottomSide);
19 }
20
21 for y in from.y + 1..to.y {
22 plot_point(buffer_view, (from.x, y * y_mul), mode.clone(), color_mode, PointRole::LeftSide);
23 plot_point(buffer_view, (to.x, y * y_mul), mode.clone(), color_mode, PointRole::RightSide);
24 }
25
26 if from.x != to.x && from.y != to.y {
27 plot_point(buffer_view, (from.x, from.y * y_mul), mode.clone(), color_mode, PointRole::NWCorner);
28 plot_point(buffer_view, (to.x, from.y * y_mul), mode.clone(), color_mode, PointRole::NECorner);
29
30 plot_point(buffer_view, (from.x, to.y * y_mul), mode.clone(), color_mode, PointRole::SWCorner);
31 plot_point(buffer_view, (to.x, to.y * y_mul), mode.clone(), color_mode, PointRole::SECorner);
32 }
33 }
34
35 pub fn fill_rectangle(buffer_view: &mut BufferView, from: impl Into<Position>, to: impl Into<Position>, mode: BrushMode, color_mode: ColorMode) {
36 let mut from = from.into();
37 let mut to = to.into();
38 let mut y_mul = 1;
39 if !matches!(mode, BrushMode::HalfBlock) {
40 from.y /= 2;
41 to.y /= 2;
42 y_mul = 2;
43 }
44
45 for y in from.y + 1..to.y {
46 for x in from.x + 1..to.x {
47 plot_point(buffer_view, (x, y * y_mul), mode.clone(), color_mode, PointRole::Fill);
48 }
49 }
50 if matches!(mode, BrushMode::HalfBlock) {
51 draw_rectangle(buffer_view, from, to, mode, color_mode);
52 }
53 }