diff options
author | 2020-05-29 02:00:28 +0200 | |
---|---|---|
committer | 2020-05-29 02:00:28 +0200 | |
commit | 0cde20b3550ede81bc7ddef628b91eec225aa8af (patch) | |
tree | 56920437979012cceb49718f2dd4ce27d5ba5d40 /graphics/src/viewport.rs | |
parent | 67b6f044e870df41be92cdc79f571682b97a5d0d (diff) | |
parent | e11b5c614f5bf73c137b8b4f24f56047617527eb (diff) | |
download | iced-0cde20b3550ede81bc7ddef628b91eec225aa8af.tar.gz iced-0cde20b3550ede81bc7ddef628b91eec225aa8af.tar.bz2 iced-0cde20b3550ede81bc7ddef628b91eec225aa8af.zip |
Merge branch 'master' into improvement/update-wgpu_glyph
Diffstat (limited to 'graphics/src/viewport.rs')
-rw-r--r-- | graphics/src/viewport.rs | 70 |
1 files changed, 70 insertions, 0 deletions
diff --git a/graphics/src/viewport.rs b/graphics/src/viewport.rs new file mode 100644 index 00000000..66122e6d --- /dev/null +++ b/graphics/src/viewport.rs @@ -0,0 +1,70 @@ +use crate::{Size, Transformation}; + +/// A viewing region for displaying computer graphics. +#[derive(Debug)] +pub struct Viewport { + physical_size: Size<u32>, + logical_size: Size<f32>, + scale_factor: f64, + projection: Transformation, +} + +impl 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 { + 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), + } + } + + /// Returns the physical size of the [`Viewport`]. + /// + /// [`Viewport`]: struct.Viewport.html + pub fn physical_size(&self) -> Size<u32> { + self.physical_size + } + + /// Returns the physical width of the [`Viewport`]. + /// + /// [`Viewport`]: struct.Viewport.html + pub fn physical_width(&self) -> u32 { + self.physical_size.height + } + + /// Returns the physical height of the [`Viewport`]. + /// + /// [`Viewport`]: struct.Viewport.html + pub fn physical_height(&self) -> u32 { + self.physical_size.height + } + + /// Returns the logical size of the [`Viewport`]. + /// + /// [`Viewport`]: struct.Viewport.html + pub fn logical_size(&self) -> Size<f32> { + self.logical_size + } + + /// Returns the scale factor of the [`Viewport`]. + /// + /// [`Viewport`]: struct.Viewport.html + pub fn scale_factor(&self) -> f64 { + self.scale_factor + } + + /// Returns the projection transformation of the [`Viewport`]. + /// + /// [`Viewport`]: struct.Viewport.html + pub fn projection(&self) -> Transformation { + self.projection + } +} |