pub mod framebuf;
#[cfg(feature = "sdl")]
pub mod sdl;
#[cfg(feature = "sdl-gpu")]
pub mod sdl_gpu;
use crate::draw::texture::Texture;
use crate::types::{CoordTransform, Fixed, Rect};
pub struct DisplayInfo {
pub width: u16,
pub height: u16,
pub scale: Fixed,
pub format: crate::draw::texture::ColorFormat,
}
impl DisplayInfo {
#[inline]
pub fn transform(&self) -> CoordTransform {
CoordTransform::new(self.width, self.height, self.scale)
}
}
#[derive(Clone, Debug)]
pub enum InputEvent {
Touch { x: Fixed, y: Fixed },
TouchMove { x: Fixed, y: Fixed },
Release { x: Fixed, y: Fixed },
Key { code: u32, pressed: bool },
Quit,
}
#[derive(Clone, Copy, Debug, PartialEq, Eq)]
pub enum BackbufferPersistence {
Persistent,
Transient,
}
pub trait Backend {
fn display_info(&self) -> DisplayInfo;
fn flush(&mut self, area: &Rect);
fn poll_event(&mut self) -> Option<InputEvent>;
fn screen_rect(&self) -> Rect {
let info = self.display_info();
Rect::new(0, 0, info.width, info.height)
}
fn persistence(&self) -> BackbufferPersistence {
BackbufferPersistence::Persistent
}
}
pub trait FramebufferAccess: Backend {
fn framebuffer(&mut self) -> Texture<'_>;
}
#[cfg(test)]
mod tests {
use super::*;
struct NoOpBackend;
impl Backend for NoOpBackend {
fn display_info(&self) -> DisplayInfo {
DisplayInfo {
width: 1,
height: 1,
scale: Fixed::ONE,
format: crate::draw::texture::ColorFormat::ARGB8888,
}
}
fn flush(&mut self, _area: &Rect) {}
fn poll_event(&mut self) -> Option<InputEvent> {
None
}
}
#[test]
fn default_persistence_is_persistent() {
let b = NoOpBackend;
assert_eq!(b.persistence(), BackbufferPersistence::Persistent);
}
}