diff options
Diffstat (limited to 'graphics/src/viewport.rs')
-rw-r--r-- | graphics/src/viewport.rs | 47 |
1 files changed, 31 insertions, 16 deletions
diff --git a/graphics/src/viewport.rs b/graphics/src/viewport.rs index 48e5a249..745ef339 100644 --- a/graphics/src/viewport.rs +++ b/graphics/src/viewport.rs @@ -1,33 +1,48 @@ -use crate::Transformation; +use crate::{Size, Transformation}; /// A viewing region for displaying computer graphics. #[derive(Debug)] pub struct Viewport { - width: u32, - height: u32, - transformation: Transformation, + physical_size: Size<u32>, + logical_size: Size<f32>, + scale_factor: f64, + projection: Transformation, } impl Viewport { - /// Creates a new [`Viewport`] with the given dimensions. - pub fn new(width: u32, height: u32) -> Viewport { + /// Creates a new [`Viewport`] with the given physical dimensions and scale + /// factor. + /// + /// [`Viewport`]: struct.Viewport.html + pub fn with_physical_size(size: Size<u32>, scale_factor: f64) -> Viewport { Viewport { - width, - height, - transformation: Transformation::orthographic(width, height), + physical_size: size, + logical_size: Size::new( + (size.width as f64 / scale_factor) as f32, + (size.height as f64 / scale_factor) as f32, + ), + scale_factor, + projection: Transformation::orthographic(size.width, size.height), } } - pub fn height(&self) -> u32 { - self.height + pub fn physical_size(&self) -> Size<u32> { + self.physical_size } - /// Returns the dimensions of the [`Viewport`]. - pub fn dimensions(&self) -> (u32, u32) { - (self.width, self.height) + pub fn physical_height(&self) -> u32 { + self.physical_size.height } - pub fn transformation(&self) -> Transformation { - self.transformation + pub fn logical_size(&self) -> Size<f32> { + self.logical_size + } + + pub fn scale_factor(&self) -> f64 { + self.scale_factor + } + + pub fn projection(&self) -> Transformation { + self.projection } } |