use crate::color::Color;
use crate::event::Event;
use crate::font;
pub trait Backend {
fn width(&self) -> u32;
fn height(&self) -> u32;
fn fill_rect(&mut self, x: u32, y: u32, w: u32, h: u32, color: Color);
fn present(&mut self);
fn poll_event(&mut self) -> Option<Event>;
fn draw_char(&mut self, x: u32, y: u32, ch: char, color: Color) {
font::render_char(self, x, y, ch, color);
}
fn draw_text(&mut self, x: u32, y: u32, text: &str, color: Color) {
let mut cx = x;
for ch in text.chars() {
if cx + font::CHAR_W > self.width() { break; }
self.draw_char(cx, y, ch, color);
cx += font::CHAR_W;
}
}
fn hline(&mut self, x: u32, y: u32, w: u32, color: Color) {
self.fill_rect(x, y, w, 1, color);
}
fn vline(&mut self, x: u32, y: u32, h: u32, color: Color) {
self.fill_rect(x, y, 1, h, color);
}
fn draw_rect(&mut self, x: u32, y: u32, w: u32, h: u32, color: Color) {
self.hline(x, y, w, color);
self.hline(x, y + h - 1, w, color);
self.vline(x, y, h, color);
self.vline(x + w - 1, y, h, color);
}
fn clear(&mut self, color: Color) {
let (w, h) = (self.width(), self.height());
self.fill_rect(0, 0, w, h, color);
}
fn size(&self) -> (u32, u32) { (self.width(), self.height()) }
}