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
43
44
45
46
47
48
49
50
51
52
53
54
use crate::model::color::Color;
use crate::model::point::Point;
use crate::model::rgba::Rgba;
use crate::view::screen::DefaultScreen;
use super::Canvas;
pub struct FullblockCanvas {
screen: Option<DefaultScreen>,
}
impl FullblockCanvas {
pub fn new() -> Self {
Self { screen: None }
}
}
impl From<DefaultScreen> for FullblockCanvas {
fn from(screen: DefaultScreen) -> Self {
Self {
screen: Some(screen),
}
}
}
impl Canvas for FullblockCanvas {
fn init(&mut self, screen: DefaultScreen) {
self.screen = Some(screen);
}
fn resize(&mut self) -> Point {
self.screen.as_mut().unwrap().resize()
}
fn clear(&mut self) {
self.screen.as_mut().unwrap().clear();
}
fn draw_pixel(&mut self, p: &Point, rgb: &Rgba) {
self.screen.as_mut().unwrap().draw_pixel(p, rgb);
}
fn draw_char(&mut self, p: &Point, color: &Color, ch: char) {
self.screen.as_mut().unwrap().draw_char(p, color, ch);
}
fn draw_text(&mut self, p: &Point, color: &Color, text: &str) {
self.screen.as_mut().unwrap().draw_text(p, color, text);
}
fn display(&mut self) {
self.screen.as_mut().unwrap().display();
}
}