diff options
Diffstat (limited to 'graphics/src')
-rw-r--r-- | graphics/src/lib.rs | 2 | ||||
-rw-r--r-- | graphics/src/viewport.rs | 33 |
2 files changed, 35 insertions, 0 deletions
diff --git a/graphics/src/lib.rs b/graphics/src/lib.rs index 6e5105d2..bdaefb41 100644 --- a/graphics/src/lib.rs +++ b/graphics/src/lib.rs @@ -2,6 +2,7 @@ mod defaults; mod primitive; mod renderer; mod transformation; +mod viewport; mod widget; pub mod backend; @@ -15,3 +16,4 @@ pub use defaults::Defaults; pub use primitive::Primitive; pub use renderer::Renderer; pub use transformation::Transformation; +pub use viewport::Viewport; diff --git a/graphics/src/viewport.rs b/graphics/src/viewport.rs new file mode 100644 index 00000000..48e5a249 --- /dev/null +++ b/graphics/src/viewport.rs @@ -0,0 +1,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 + } +} |