summaryrefslogtreecommitdiffstats
path: root/graphics/src/viewport.rs
diff options
context:
space:
mode:
authorLibravatar Héctor Ramón Jiménez <hector0193@gmail.com>2020-05-20 20:28:35 +0200
committerLibravatar Héctor Ramón Jiménez <hector0193@gmail.com>2020-05-20 20:28:35 +0200
commita1a5fcfd46622d5b18d1716aa2adb4659835ccf3 (patch)
tree8c9c2468151ebcc517688edc6d0d4867c11c441c /graphics/src/viewport.rs
parent720e7756f2afe30706b6b1a7fbde86b9f15e1d8c (diff)
downloadiced-a1a5fcfd46622d5b18d1716aa2adb4659835ccf3.tar.gz
iced-a1a5fcfd46622d5b18d1716aa2adb4659835ccf3.tar.bz2
iced-a1a5fcfd46622d5b18d1716aa2adb4659835ccf3.zip
Refactor `Viewport` and `Compositor`
Diffstat (limited to 'graphics/src/viewport.rs')
-rw-r--r--graphics/src/viewport.rs47
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
}
}