2020-07-16 13:30:42 -07:00
|
|
|
use alloc::sync::Arc;
|
2020-07-16 17:04:19 -07:00
|
|
|
use crate::graphics::color::RGB;
|
2020-07-16 13:30:42 -07:00
|
|
|
use crate::graphics::display::Display;
|
|
|
|
use crate::graphics::font::psf::PSF;
|
|
|
|
use crate::graphics::terminal::Terminal;
|
2020-07-16 17:04:19 -07:00
|
|
|
use crate::graphics::terminal::frame::TerminalFrame;
|
2020-07-16 13:30:42 -07:00
|
|
|
|
2020-07-16 17:04:19 -07:00
|
|
|
pub struct DisplayTerminal<'display> {
|
|
|
|
display: &'display mut dyn Display,
|
|
|
|
frame: TerminalFrame,
|
2020-07-16 13:30:42 -07:00
|
|
|
font: Arc<PSF>,
|
|
|
|
bg: RGB,
|
|
|
|
fg: RGB,
|
|
|
|
}
|
|
|
|
|
|
|
|
impl DisplayTerminal<'_> {
|
2020-07-16 17:04:19 -07:00
|
|
|
pub fn new<'display>(display: &'display mut dyn Display, font: Arc<PSF>, bg: RGB, fg: RGB) -> DisplayTerminal<'display> {
|
|
|
|
let (dp_width, dp_height) = display.resolution();
|
|
|
|
let (ft_width, ft_height) = font.resolution();
|
|
|
|
let ch_width = dp_width / ft_width as usize;
|
|
|
|
let ch_height = dp_height / ft_height as usize;
|
|
|
|
|
2020-07-16 13:30:42 -07:00
|
|
|
DisplayTerminal {
|
2020-07-16 17:04:19 -07:00
|
|
|
display: display,
|
|
|
|
frame: TerminalFrame::new((ch_width, ch_height)),
|
2020-07-16 13:30:42 -07:00
|
|
|
font: font,
|
2020-07-16 17:04:19 -07:00
|
|
|
bg: bg,
|
|
|
|
fg: fg,
|
2020-07-16 13:30:42 -07:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
impl Terminal for DisplayTerminal<'_> {
|
2020-07-16 17:04:19 -07:00
|
|
|
fn get_frame<'a>(&'a self) -> &'a TerminalFrame {
|
|
|
|
&self.frame
|
2020-07-16 13:30:42 -07:00
|
|
|
}
|
|
|
|
|
2020-07-16 17:04:19 -07:00
|
|
|
fn borrow_frame<'a>(&'a mut self) -> &'a mut TerminalFrame {
|
|
|
|
&mut self.frame
|
2020-07-16 13:30:42 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
fn refresh(&mut self) {
|
2020-07-16 17:04:19 -07:00
|
|
|
self.display.clear(self.bg);
|
|
|
|
for x in 0..self.frame.width() {
|
|
|
|
for y in 0..self.frame.height() {
|
|
|
|
let c = self.frame.get(x, y);
|
|
|
|
if c == '\u{0}' { continue; }
|
|
|
|
|
|
|
|
let glyph = self.font.lookup(c).expect("Character missing from font.");
|
2020-07-16 13:30:42 -07:00
|
|
|
unsafe {
|
2020-07-16 17:04:19 -07:00
|
|
|
self.display.draw_glyph(self.fg, self.font.width() as usize * x, self.font.height() as usize * y, glyph);
|
2020-07-16 13:30:42 -07:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|