gooey/interface/model/component/
pixmap.rs

1use derive_more::{From, TryInto};
2use mat::Mat;
3use super::impl_kind;
4
5#[derive(Clone, Debug, PartialEq, From, TryInto)]
6pub enum Pixmap {
7  // TODO: bitmap variant
8  Pixmap8  (Mat  <u8>),
9  Pixmap16 (Mat <u16>),
10  Pixmap32 (Mat <u32>),
11  Pixmap64 (Mat <u64>),
12  Texture {
13    resource_id : u16,
14    index       : u16,
15    width       : u32,
16    height      : u32
17  }
18}
19
20impl_kind!(Pixmap, Pixmap);
21
22impl Default for Pixmap {
23  fn default() -> Self {
24    Pixmap::Pixmap8 (Mat::default())
25  }
26}
27
28impl Pixmap {
29  pub fn width (&self) -> usize {
30    match self {
31      Pixmap::Pixmap8  (mat) => mat.width(),
32      Pixmap::Pixmap16 (mat) => mat.width(),
33      Pixmap::Pixmap32 (mat) => mat.width(),
34      Pixmap::Pixmap64 (mat) => mat.width(),
35      Pixmap::Texture { width, .. } => *width as usize
36    }
37  }
38  pub fn height (&self) -> usize {
39    match self {
40      Pixmap::Pixmap8  (mat) => mat.height(),
41      Pixmap::Pixmap16 (mat) => mat.height(),
42      Pixmap::Pixmap32 (mat) => mat.height(),
43      Pixmap::Pixmap64 (mat) => mat.height(),
44      Pixmap::Texture { height, .. } => *height as usize
45    }
46  }
47}