Fixed draw_pixel
This commit is contained in:
parent
16d8071a03
commit
0804a16639
1 changed files with 8 additions and 5 deletions
13
src/lib.rs
13
src/lib.rs
|
|
@ -217,17 +217,20 @@ impl DoubleFrame<AutomaticPartialWindow> {
|
||||||
|
|
||||||
impl<PartialWindow: ApplyPartialWindow> DoubleFrame<PartialWindow> {
|
impl<PartialWindow: ApplyPartialWindow> DoubleFrame<PartialWindow> {
|
||||||
pub fn draw_pixel(&mut self, x: u16, y: u16, colour: PixelColour) {
|
pub fn draw_pixel(&mut self, x: u16, y: u16, colour: PixelColour) {
|
||||||
|
if x >= EPD_WIDTH as u16 || y >= EPD_HEIGHT as u16 {
|
||||||
|
return; // pixel is offscreen so can be skipped
|
||||||
|
}
|
||||||
self.partial_window.update_partial_window(x, x, y, y);
|
self.partial_window.update_partial_window(x, x, y, y);
|
||||||
let x_i = x / 8;
|
let x_i = x as usize / 8;
|
||||||
let x_shift = x % 8;
|
let x_shift = 7 - (x % 8);
|
||||||
let i = y * (EPD_WIDTH as u16 / 8) + x_i;
|
let i = y as usize * (EPD_WIDTH / 8) + x_i;
|
||||||
match colour {
|
match colour {
|
||||||
PixelColour::Black => {
|
PixelColour::Black => {
|
||||||
self.new.0[i as usize] &= !(1 << x_shift);
|
self.new.0[i as usize] &= !(1 << x_shift);
|
||||||
},
|
}
|
||||||
PixelColour::White => {
|
PixelColour::White => {
|
||||||
self.new.0[i as usize] |= 1 << x_shift;
|
self.new.0[i as usize] |= 1 << x_shift;
|
||||||
},
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue