use maraiah::durandal::image::*; use std::collections::HashMap; #[derive(Copy, Clone, Debug)] pub struct Rect {pub x: u32, pub y: u32, pub w: u32, pub h: u32} pub type Point = (u32, u32); pub trait DrawArea { fn w(&self) -> u32; fn h(&self) -> u32; fn clear(&self, cr: impl Color); fn rect(&self, rect: Rect, cr: impl Color); fn text(&self, pos: Point, cr: impl Color, text: &str); } pub trait Resource { fn as_dir(&self) -> Option<&ResDir> {None} fn as_file(&self) -> Option<&ResFile> {None} } impl ResDir { pub fn new() -> ResDir { ResDir{hash: HashMap::new()} } pub fn insert(&mut self, name: &str, res: Box) { self.hash.insert(name.to_string(), res); } pub fn get(&self, name: &str) -> Option<&Box> { self.hash.get(name) } } impl Resource for ResDir { fn as_dir(&self) -> Option<&ResDir> {Some(self)} } impl Resource for ResFile { fn as_file(&self) -> Option<&ResFile> {Some(self)} } pub struct ResDir { hash: HashMap>, } struct ResFile { } pub const CR_RED: Color16 = Color16::new(0xFFFF, 0, 0); pub const CR_DARK_RED: Color16 = Color16::new(0x4700, 0, 0); #[test] fn resources() { let mut top = ResDir::new(); top.insert(":basic_sub:resource", Box::new(ResFile{})); top.get(":basic_sub:resource").unwrap(); } // EOF