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
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
use crate::{display::SimulatorDisplay, theme::BinaryColorTheme};
use embedded_graphics::prelude::*;
#[derive(Debug, PartialEq, Eq, Clone)]
pub struct OutputSettings {
pub scale: u32,
pub pixel_spacing: u32,
pub theme: BinaryColorTheme,
pub max_fps: u32,
}
impl OutputSettings {
pub(crate) fn framebuffer_size<C>(&self, display: &SimulatorDisplay<C>) -> Size
where
C: PixelColor,
{
let width = display.size().width;
let height = display.size().height;
let output_width = width * self.scale + width.saturating_sub(1) * self.pixel_spacing;
let output_height = height * self.scale + height.saturating_sub(1) * self.pixel_spacing;
Size::new(output_width, output_height)
}
}
#[cfg(feature = "with-sdl")]
impl OutputSettings {
pub(crate) const fn output_to_display(&self, output_point: Point) -> Point {
let pitch = self.pixel_pitch() as i32;
Point::new(output_point.x / pitch, output_point.y / pitch)
}
pub(crate) const fn pixel_pitch(&self) -> u32 {
self.scale + self.pixel_spacing
}
}
impl Default for OutputSettings {
fn default() -> Self {
OutputSettingsBuilder::new().build()
}
}
pub struct OutputSettingsBuilder {
scale: Option<u32>,
pixel_spacing: Option<u32>,
theme: BinaryColorTheme,
max_fps: Option<u32>,
}
impl OutputSettingsBuilder {
pub fn new() -> Self {
Self {
scale: None,
pixel_spacing: None,
theme: BinaryColorTheme::Default,
max_fps: None,
}
}
pub fn scale(mut self, scale: u32) -> Self {
assert!(scale > 0, "scale must be > 0");
self.scale = Some(scale);
self
}
pub fn theme(mut self, theme: BinaryColorTheme) -> Self {
self.theme = theme;
self.scale.get_or_insert(3);
self.pixel_spacing.get_or_insert(1);
self
}
pub fn pixel_spacing(mut self, pixel_spacing: u32) -> Self {
self.pixel_spacing = Some(pixel_spacing);
self
}
pub fn max_fps(mut self, max_fps: u32) -> Self {
self.max_fps = Some(max_fps);
self
}
pub fn build(self) -> OutputSettings {
OutputSettings {
scale: self.scale.unwrap_or(1),
pixel_spacing: self.pixel_spacing.unwrap_or(0),
theme: self.theme,
max_fps: self.max_fps.unwrap_or(60),
}
}
}