Some updates for allowing crate consumers to use useful utility funcs

This commit is contained in:
JP Stringham
2026-03-25 09:11:20 -04:00
parent 5e01dd810a
commit c9cc177bfd
2 changed files with 60 additions and 49 deletions

View File

@@ -45,10 +45,10 @@ impl GraphicsBuf {
}
});
draw_bresenham_line(0, 0, 127, 0, &mut gfx_buf);
draw_bresenham_line(0, 63, 128, 63, &mut gfx_buf);
draw_bresenham_line(0, 0, 0, 63, &mut gfx_buf);
draw_bresenham_line(127, 0, 127, 63, &mut gfx_buf);
self.draw_bresenham_line(0, 0, 127, 0);
self.draw_bresenham_line(0, 63, 128, 63);
self.draw_bresenham_line(0, 0, 0, 63);
self.draw_bresenham_line(127, 0, 127, 63);
}
pub fn draw_string(&mut self, x: u8, y: u8, string: &str) {
@@ -64,9 +64,19 @@ impl GraphicsBuf {
pub fn get_px_buffer(&self) -> &[u8; 8192] {
&self.buffer
}
pub fn clr_rect(&mut self, x: u8, y: u8, w: u8, h: u8) {
let gfx_buf = &mut self.buffer;
for x in x as u32..(x + w) as u32 {
for y in y as u32..(y + h) as u32 {
gfx_buf[(y * 128 + x) as usize] = 0;
}
}
}
fn draw_bresenham_line(x0: u8, y0: u8, x1: u8, y1: u8, gfx_buf: &mut [u8; 8192]) {
pub fn draw_bresenham_line(&mut self, x0: u8, y0: u8, x1: u8, y1: u8) {
let gfx_buf = &mut self.buffer;
let x0 = (x0 as i32).clamp(0, 127);
let x1 = (x1 as i32).clamp(0, 127);
let y0 = (y0 as i32).clamp(0, 63);
@@ -119,3 +129,4 @@ fn draw_bresenham_line(x0: u8, y0: u8, x1: u8, y1: u8, gfx_buf: &mut [u8; 8192])
}
}
}
}

View File

@@ -116,7 +116,7 @@ impl SpriteAtlas {
}
}
fn get_str_pixel_width(&self, str: &str) -> usize {
pub fn get_str_pixel_width(&self, str: &str) -> usize {
let mut width = 0;
for c in str.chars() {