Refactor Viewport and Compositor
This commit is contained in:
parent
720e7756f2
commit
a1a5fcfd46
24 changed files with 202 additions and 278 deletions
|
|
@ -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
|
||||
}
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue