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
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
use crate::{Size, Transformation};
#[derive(Debug)]
pub struct Viewport {
physical_size: Size<u32>,
logical_size: Size<f32>,
scale_factor: f64,
projection: Transformation,
}
impl Viewport {
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),
}
}
pub fn physical_size(&self) -> Size<u32> {
self.physical_size
}
pub fn physical_width(&self) -> u32 {
self.physical_size.height
}
pub fn physical_height(&self) -> u32 {
self.physical_size.height
}
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
}
}