solstice_2d/d2/
canvas.rs

1use solstice::texture::{TextureInfo, TextureType};
2use solstice::{canvas as s, TextureKey};
3
4#[derive(Clone, Debug, PartialEq)]
5pub struct Canvas {
6    pub inner: solstice::canvas::Canvas,
7}
8
9impl Canvas {
10    pub fn new(
11        ctx: &mut solstice::Context,
12        width: f32,
13        height: f32,
14    ) -> Result<Self, solstice::GraphicsError> {
15        Self::with_settings(
16            ctx,
17            s::Settings {
18                width: width as _,
19                height: height as _,
20                ..s::Settings::default()
21            },
22        )
23    }
24
25    pub fn with_settings(
26        ctx: &mut solstice::Context,
27        settings: s::Settings,
28    ) -> Result<Self, solstice::GraphicsError> {
29        let inner = s::Canvas::new(ctx, settings)?;
30        Ok(Self { inner })
31    }
32
33    pub fn dimensions(&self) -> (f32, f32) {
34        let info = solstice::texture::Texture::get_texture_info(&self.inner);
35        (info.width() as _, info.height() as _)
36    }
37}
38
39impl solstice::texture::Texture for Canvas {
40    fn get_texture_key(&self) -> TextureKey {
41        self.inner.get_texture_key()
42    }
43
44    fn get_texture_type(&self) -> TextureType {
45        self.inner.get_texture_type()
46    }
47
48    fn get_texture_info(&self) -> TextureInfo {
49        self.inner.get_texture_info()
50    }
51}
52
53impl solstice::texture::Texture for &Canvas {
54    fn get_texture_key(&self) -> TextureKey {
55        self.inner.get_texture_key()
56    }
57
58    fn get_texture_type(&self) -> TextureType {
59        self.inner.get_texture_type()
60    }
61
62    fn get_texture_info(&self) -> TextureInfo {
63        self.inner.get_texture_info()
64    }
65}