1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
|
use super::*;
impl ScreenDevice {
pub fn draw_rect(&mut self, colour: u8, layer: ScreenLayer) {
if let Some([x0, y0, x1, y1]) = self.find_vector_bounding_box() {
let screen_width = self.dimensions.width as usize;
let rect_width = x1 - x0 + 1;
let mut i = x0 + (screen_width * y0);
let buffer = match layer {
ScreenLayer::Background => &mut self.background,
ScreenLayer::Foreground => &mut self.foreground,
};
for _ in y0..=y1 {
buffer[i..i+rect_width].fill(colour);
i += screen_width;
}
}
}
pub fn draw_rect_1bit(&mut self, params: u8, layer: ScreenLayer) {
if let Some([x0, y0, x1, y1]) = self.find_vector_bounding_box() {
let screen_width = self.dimensions.width as usize;
let rect_width = x1 - x0 + 1;
let mut i = x0 + (screen_width * y0);
let sprite = self.sprite_buffer.get_1bit_sprite(params);
let buffer = match layer {
ScreenLayer::Background => &mut self.background,
ScreenLayer::Foreground => &mut self.foreground,
};
for y in y0..=y1 {
let row = sprite[y % 8];
for x in x0..=x1 {
let colour = row[x % 8];
if colour != 0xff { buffer[i] = colour }
i += 1;
}
i += screen_width - rect_width;
}
};
}
}
|