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