open_sesame/render/
context.rs

1//! Render context for passing state between render passes
2
3use crate::config::Config;
4use tiny_skia::Pixmap;
5
6/// Context passed to each render pass
7pub struct RenderContext<'a> {
8    /// The pixmap being rendered to
9    pub pixmap: &'a mut Pixmap,
10    /// Display scale factor
11    pub scale: f32,
12    /// Configuration reference
13    pub config: &'a Config,
14}
15
16impl<'a> RenderContext<'a> {
17    /// Create a new render context
18    pub fn new(pixmap: &'a mut Pixmap, scale: f32, config: &'a Config) -> Self {
19        Self {
20            pixmap,
21            scale,
22            config,
23        }
24    }
25
26    /// Get the width in pixels
27    pub fn width(&self) -> u32 {
28        self.pixmap.width()
29    }
30
31    /// Get the height in pixels
32    pub fn height(&self) -> u32 {
33        self.pixmap.height()
34    }
35
36    /// Get scaled dimension
37    pub fn scaled(&self, value: f32) -> f32 {
38        value * self.scale
39    }
40}