Minor fixups
parent
e225464b62
commit
e49e144a34
10
src/color.rs
10
src/color.rs
|
|
@ -185,4 +185,14 @@ mod tests {
|
|||
assert_eq!(Color::from(Color::White.get_bit_value()), Color::White);
|
||||
assert_eq!(Color::from(1u8).get_bit_value(), 1u8);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_oct() {
|
||||
let left = OctColor::Red;
|
||||
let right = OctColor::Green;
|
||||
assert_eq!(
|
||||
OctColor::split_byte(OctColor::colors_byte(left, right)),
|
||||
Ok((left, right))
|
||||
);
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -204,4 +204,48 @@ mod tests {
|
|||
);
|
||||
}
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn graphics_colors() {
|
||||
let mut display = Display5in65f::default();
|
||||
|
||||
const COLORS: [OctColor; 8] = [
|
||||
OctColor::HiZ,
|
||||
OctColor::White,
|
||||
OctColor::Black,
|
||||
OctColor::Red,
|
||||
OctColor::Green,
|
||||
OctColor::Orange,
|
||||
OctColor::Blue,
|
||||
OctColor::Yellow,
|
||||
];
|
||||
for c in &COLORS {
|
||||
display.clear_buffer(*c);
|
||||
for b in display.buffer() {
|
||||
assert_eq!(OctColor::split_byte(*b), Ok((*c, *c)));
|
||||
}
|
||||
}
|
||||
|
||||
for (w, c) in (0..WIDTH).zip(COLORS.iter().cycle()) {
|
||||
let _ = Line::new(
|
||||
Point::new(w as i32, 0),
|
||||
Point::new(w as i32, HEIGHT as i32 - 1),
|
||||
)
|
||||
.into_styled(PrimitiveStyle::with_stroke(*c, 1))
|
||||
.draw(&mut display);
|
||||
}
|
||||
|
||||
COLORS
|
||||
.chunks(2)
|
||||
.cycle()
|
||||
.take(WIDTH as usize * 2)
|
||||
.cycle()
|
||||
.zip(display.buffer())
|
||||
.for_each(|(window, b)| match (window, b) {
|
||||
(&[c1, c2], b) => {
|
||||
assert_eq!(OctColor::split_byte(*b), Ok((c1, c2)));
|
||||
}
|
||||
_ => panic!("unexpected pattern"),
|
||||
})
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -93,9 +93,9 @@ pub trait Display: DrawTarget<BinaryColor> {
|
|||
/// - Clearing
|
||||
pub trait OctDisplay: DrawTarget<OctColor> {
|
||||
/// Clears the buffer of the display with the chosen background color
|
||||
fn clear_buffer(&mut self, background_color: Color) {
|
||||
fn clear_buffer(&mut self, background_color: OctColor) {
|
||||
for elem in self.get_mut_buffer().iter_mut() {
|
||||
*elem = background_color.get_byte_value();
|
||||
*elem = OctColor::colors_byte(background_color, background_color);
|
||||
}
|
||||
}
|
||||
|
||||
|
|
@ -274,7 +274,9 @@ fn find_rotation(x: u32, y: u32, width: u32, height: u32, rotation: DisplayRotat
|
|||
fn find_oct_position(x: u32, y: u32, width: u32, height: u32, rotation: DisplayRotation) -> (u32, bool) {
|
||||
let (nx, ny) = find_rotation(x, y, width, height, rotation);
|
||||
(
|
||||
/* what byte address is this? */
|
||||
nx / 2 + (width / 2) * ny,
|
||||
/* is this the lower nibble (within byte)? */
|
||||
(nx & 0x1) == 0,
|
||||
)
|
||||
}
|
||||
|
|
|
|||
Loading…
Reference in New Issue