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
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
use std::path::PathBuf;
use log::error;
use serde::{Deserialize, Serialize};
use winit::{Icon, WindowAttributes, WindowBuilder};
use crate::monitor::{MonitorIdent, MonitorsAccess};
#[derive(Clone, Debug, Deserialize, Eq, PartialEq, Serialize)]
pub struct DisplayConfig {
#[serde(default = "default_title")]
pub title: String,
#[serde(default)]
pub fullscreen: Option<MonitorIdent>,
#[serde(default)]
pub dimensions: Option<(u32, u32)>,
#[serde(default)]
pub min_dimensions: Option<(u32, u32)>,
#[serde(default)]
pub max_dimensions: Option<(u32, u32)>,
#[serde(default = "default_visibility")]
pub visibility: bool,
#[serde(default)]
pub icon: Option<PathBuf>,
#[serde(default)]
pub always_on_top: bool,
#[serde(default = "default_decorations")]
pub decorations: bool,
#[serde(default)]
pub maximized: bool,
#[serde(default)]
pub multitouch: bool,
#[serde(default = "default_resizable")]
pub resizable: bool,
#[serde(default)]
pub transparent: bool,
#[serde(skip)]
pub loaded_icon: Option<Icon>,
}
impl Default for DisplayConfig {
fn default() -> Self {
DisplayConfig {
title: default_title(),
fullscreen: None,
dimensions: None,
min_dimensions: None,
max_dimensions: None,
visibility: default_visibility(),
icon: None,
always_on_top: false,
decorations: default_decorations(),
maximized: false,
multitouch: false,
resizable: default_resizable(),
transparent: false,
loaded_icon: None,
}
}
}
fn default_title() -> String {
"Amethyst game".to_string()
}
fn default_decorations() -> bool {
true
}
fn default_visibility() -> bool {
true
}
fn default_resizable() -> bool {
true
}
impl DisplayConfig {
pub fn into_window_builder(self, monitors: &impl MonitorsAccess) -> WindowBuilder {
let attrs = WindowAttributes {
dimensions: self.dimensions.map(Into::into),
max_dimensions: self.max_dimensions.map(Into::into),
min_dimensions: self.min_dimensions.map(Into::into),
title: self.title,
maximized: self.maximized,
visible: self.visibility,
transparent: self.transparent,
decorations: self.decorations,
always_on_top: self.always_on_top,
window_icon: None,
fullscreen: self.fullscreen.map(|ident| ident.monitor_id(monitors)),
resizable: self.resizable,
multitouch: self.multitouch,
};
let mut builder = WindowBuilder::new();
builder.window = attrs;
if self.loaded_icon.is_some() {
builder = builder.with_window_icon(self.loaded_icon);
} else if let Some(icon) = self.icon {
let icon = match Icon::from_path(&icon) {
Ok(x) => Some(x),
Err(e) => {
error!(
"Failed to load window icon from `{}`: {}",
icon.display(),
e
);
None
}
};
builder = builder.with_window_icon(icon);
}
builder
}
}