diff options
author | gennyble <gen@nyble.dev> | 2024-11-30 04:20:28 -0600 |
---|---|---|
committer | gennyble <gen@nyble.dev> | 2024-11-30 04:20:28 -0600 |
commit | 7a720b63d1fe4e2f50813d5c1a1d89579258d453 (patch) | |
tree | ca5f9aa7786c4f00e02184d4bc8111be6e5e85bb /src/image.rs | |
parent | 4c9c479ddc80d245d1ae7424cc3dd775f9ee3eef (diff) | |
download | really-etches-7a720b63d1fe4e2f50813d5c1a1d89579258d453.tar.gz really-etches-7a720b63d1fe4e2f50813d5c1a1d89579258d453.zip |
Add 50% deadzone
Also: - fixes my a mispelling - lets you erase with the South button - tunes thumbstick angle movement
Diffstat (limited to 'src/image.rs')
-rw-r--r-- | src/image.rs | 27 |
1 files changed, 17 insertions, 10 deletions
diff --git a/src/image.rs b/src/image.rs index 0ce41d9..6f03db5 100644 --- a/src/image.rs +++ b/src/image.rs @@ -1,3 +1,5 @@ +use crate::Vec2; + #[allow(dead_code)] pub struct Image { width: u32, @@ -36,12 +38,16 @@ impl Image { self.height } - pub fn rect(&mut self, x: u32, y: u32, width: u32, height: u32, clr: Color) { - let x_start = x as usize; - let x_end = (x + width) as usize; + pub fn fill(&mut self, clr: Color) { + self.data.fill(clr.into()); + } + + pub fn rect(&mut self, pos: Vec2<u32>, dim: Vec2<u32>, clr: Color) { + let x_start = pos.x as usize; + let x_end = (pos.x + dim.x) as usize; for idx in x_start..x_end { - for idy in y as usize..y as usize + height as usize { + for idy in pos.y as usize..pos.y as usize + dim.y as usize { let data_idx = idx + idy * self.width as usize; self.data[data_idx] = clr.into(); } @@ -50,11 +56,11 @@ impl Image { /// Primitive, naive line drawing funciton. lerps the points together and /// draws a rect of the specified width at that location. - pub fn line(&mut self, x1: u32, y1: u32, x2: u32, y2: u32, width: u32, clr: Color) { - let start_x = x1.min(x2) as f32; - let start_y = y1.min(y2) as f32; - let end_x = x1.max(x2) as f32; - let end_y = y1.max(y2) as f32; + pub fn line(&mut self, p1: Vec2<u32>, p2: Vec2<u32>, width: u32, clr: Color) { + let start_x = p1.x.min(p2.x) as f32; + let start_y = p1.y.min(p2.y) as f32; + let end_x = p1.x.max(p2.x) as f32; + let end_y = p1.y.max(p2.y) as f32; tracing::trace!("start_x = {start_x} / end_x = {end_x}"); tracing::trace!("start_y = {start_y} / end_y = {end_y}"); @@ -63,11 +69,12 @@ impl Image { let dy = end_y - start_y; let long = dx.max(dy); + let dim = Vec2::new(width, width); for idx in 0..long as usize { let x = start_x + dx * (idx as f32 / long); let y = start_y + dy * (idx as f32 / long); - self.rect(x as u32, y as u32, width, width, clr); + self.rect(Vec2::new(x, y).as_u32(), dim, clr); } } } |