summaryrefslogtreecommitdiffstats
path: root/graphics/src/viewport.rs
blob: 48e5a249b4703846c580df4010ef7fb9dd0641f7 (plain) (blame)
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
use crate::Transformation;

/// A viewing region for displaying computer graphics.
#[derive(Debug)]
pub struct Viewport {
    width: u32,
    height: u32,
    transformation: Transformation,
}

impl Viewport {
    /// Creates a new [`Viewport`] with the given dimensions.
    pub fn new(width: u32, height: u32) -> Viewport {
        Viewport {
            width,
            height,
            transformation: Transformation::orthographic(width, height),
        }
    }

    pub fn height(&self) -> u32 {
        self.height
    }

    /// Returns the dimensions of the [`Viewport`].
    pub fn dimensions(&self) -> (u32, u32) {
        (self.width, self.height)
    }

    pub fn transformation(&self) -> Transformation {
        self.transformation
    }
}