#![allow(
clippy::cast_possible_truncation,
clippy::cast_possible_wrap,
clippy::cast_precision_loss,
clippy::cast_sign_loss
)]
use ab_glyph::{Font, FontArc, PxScale, ScaleFont, point};
use anyhow::{Context, Result};
use super::{Action, Draft, Field, Machine, PAGE_SIZE, Ui};
use crate::aen_window::{Configure, Frame};
use crate::config::{Acceleration, Firmware, NetworkMode};
use crate::manager::VmStatus;
type Color = [u8; 3];
#[derive(Clone, PartialEq, Eq)]
struct Palette {
background: Color,
surface: Color,
raised: Color,
interactive: Color,
border: Color,
line: Color,
accent: Color,
text: Color,
muted: Color,
success: Color,
danger: Color,
radius: i32,
}
impl Default for Palette {
fn default() -> Self {
Self {
background: [11, 27, 21],
surface: [18, 41, 31],
raised: [25, 52, 39],
interactive: [40, 66, 49],
border: [108, 132, 99],
line: [47, 75, 57],
accent: [226, 236, 172],
text: [239, 245, 229],
muted: [179, 199, 183],
success: [168, 222, 160],
danger: [255, 166, 153],
radius: 20,
}
}
}
fn color(value: &toml::Value, key: &str, fallback: Color) -> Color {
let Some(hex) = value
.get(key)
.and_then(toml::Value::as_str)
.and_then(|value| value.strip_prefix('#'))
else {
return fallback;
};
if !hex.as_bytes().iter().all(u8::is_ascii_hexdigit) {
return fallback;
}
let Some(rgb) = hex
.get(..6)
.and_then(|rgb| u32::from_str_radix(rgb, 16).ok())
else {
return fallback;
};
rgb.to_be_bytes()[1..].try_into().unwrap_or(fallback)
}
impl Palette {
fn read() -> Self {
let paths = std::env::var_os("AEN_CONFIG")
.map(std::path::PathBuf::from)
.into_iter()
.chain(
std::env::var_os("XDG_CONFIG_HOME")
.map(|dir| std::path::PathBuf::from(dir).join("aen/aen.toml")),
)
.chain(
std::env::var_os("HOME")
.map(|dir| std::path::PathBuf::from(dir).join(".config/aen/aen.toml")),
)
.chain(["/etc/xdg/aen/aen.toml".into(), "/etc/aen/aen.toml".into()]);
let mut p = Self::default();
let Some(theme) = paths
.filter_map(|p| std::fs::read_to_string(p).ok())
.filter_map(|source| source.parse::<toml::Value>().ok())
.find_map(|value| value.get("theme").cloned())
else {
return p;
};
p.background = color(&theme, "background", p.background);
p.surface = color(&theme, "surface", p.surface);
p.raised = color(&theme, "surface_elevated", p.raised);
p.interactive = color(&theme, "surface_interactive", p.interactive);
p.border = color(&theme, "border", p.border);
p.line = color(&theme, "border_subtle", p.line);
p.accent = color(&theme, "accent", p.accent);
p.text = color(&theme, "text", p.text);
p.muted = color(&theme, "text_muted", p.muted);
p.success = color(&theme, "success", p.success);
p.danger = color(&theme, "danger", p.danger);
p.radius = match theme.get("corner_style").and_then(toml::Value::as_str) {
Some("square") => 0,
Some("soft") => 12,
_ => p.radius,
};
p
}
}
pub(super) struct Assets {
palette: Palette,
sans: FontArc,
serif: FontArc,
}
impl Assets {
pub(super) fn load() -> Result<Self> {
let sans = load_font(&[
"/usr/share/fonts/Adwaita/AdwaitaSans-Regular.ttf",
"/usr/share/fonts/adwaita-fonts/AdwaitaSans-Regular.ttf",
"/usr/share/fonts/TTF/AdwaitaSans-Regular.ttf",
"/usr/share/fonts/TTF/DejaVuSans.ttf",
"/usr/share/fonts/truetype/dejavu/DejaVuSans.ttf",
"/usr/share/fonts/liberation/LiberationSans-Regular.ttf",
"/usr/share/fonts/liberation-sans/LiberationSans-Regular.ttf",
])
.context("Aev VM needs an installed TrueType sans-serif font such as DejaVu Sans")?;
let serif = load_font(&[
"/usr/share/fonts/noto/NotoSerifDisplay-Regular.ttf",
"/usr/share/fonts/noto/NotoSerif-Regular.ttf",
"/usr/share/fonts/truetype/noto/NotoSerif-Regular.ttf",
"/usr/share/fonts/TTF/DejaVuSerif.ttf",
"/usr/share/fonts/truetype/dejavu/DejaVuSerif.ttf",
])
.unwrap_or_else(|| sans.clone());
Ok(Self {
palette: Palette::read(),
sans,
serif,
})
}
pub(super) fn refresh_theme(&mut self) -> bool {
let next = Palette::read();
if self.palette == next {
return false;
}
self.palette = next;
true
}
}
fn load_font(paths: &[&str]) -> Option<FontArc> {
paths
.iter()
.find_map(|path| FontArc::try_from_vec(std::fs::read(path).ok()?).ok())
}
#[derive(Clone, Copy)]
struct Rect(i32, i32, i32, i32);
impl Rect {
fn contains(self, x: i32, y: i32) -> bool {
x >= self.0 && x < self.0 + self.2 && y >= self.1 && y < self.1 + self.3
}
}
pub(super) struct Hit {
rect: Rect,
pub(super) action: Action,
}
impl Hit {
pub(super) fn at(hits: &[Self], x: i32, y: i32) -> Option<Action> {
hits.iter()
.rev()
.find(|hit| hit.rect.contains(x, y))
.map(|hit| hit.action.clone())
}
}
fn mix(a: Color, b: Color, blend: f32) -> Color {
std::array::from_fn(|i| {
(f32::from(a[i]) * (1. - blend) + f32::from(b[i]) * blend).round() as u8
})
}
struct Canvas<'a> {
pixels: Vec<u8>,
w: i32,
h: i32,
scale: f32,
fonts: &'a Assets,
}
impl Canvas<'_> {
fn pixel(&mut self, x: i32, y: i32, color: Color, opacity: f32) {
if x < 0 || x >= self.w || y < 0 || y >= self.h {
return;
}
let i = ((y * self.w + x) * 4) as usize;
let px = &mut self.pixels[i..i + 4];
let blend = mix([px[2], px[1], px[0]], color, opacity);
px.copy_from_slice(&[blend[2], blend[1], blend[0], 255]);
}
fn rect(
&mut self,
Rect(x, y, width, height): Rect,
radius: i32,
fill: Color,
rim: Option<Color>,
) {
let scale = self.scale;
let (left, top, physical_width, physical_height, radius) = (
x as f32 * scale,
y as f32 * scale,
width as f32 * scale,
height as f32 * scale,
radius as f32 * scale,
);
if physical_width <= 0. || physical_height <= 0. {
return;
}
let radius = radius.min(physical_width / 2.).min(physical_height / 2.);
for py in (top as i32).max(0)..((top + physical_height).ceil() as i32).min(self.h) {
let cy = py as f32 + 0.5 - top;
for px in (left as i32).max(0)..((left + physical_width).ceil() as i32).min(self.w) {
let cx = px as f32 + 0.5 - left;
let edge_x = cx.min(physical_width - cx);
let edge_y = cy.min(physical_height - cy);
let distance = if edge_x < radius && edge_y < radius {
radius - (radius - edge_x).hypot(radius - edge_y)
} else {
edge_x.min(edge_y)
};
let opacity = (distance + 0.5).clamp(0., 1.);
if opacity > 0. {
let shade = rim.map_or(fill, |rim| {
mix(rim, fill, (distance - scale + 0.5).clamp(0., 1.))
});
self.pixel(px, py, shade, opacity);
}
}
}
}
#[allow(clippy::too_many_arguments)]
fn text(&mut self, x: i32, y: i32, width: i32, text: &str, size: i32, ink: Color, serif: bool) {
let mut s = x as f32 * self.scale;
let end = s + width as f32 * self.scale;
let font = if serif {
&self.fonts.serif
} else {
&self.fonts.sans
};
let scaled = font.as_scaled(PxScale::from(size as f32 * self.scale));
let mut prev = None;
let ellipsis = scaled.glyph_id('…');
let baseline = y as f32 * self.scale + scaled.ascent();
for (index, ch) in text.char_indices() {
let id = scaled.glyph_id(if ch.is_control() { ' ' } else { ch });
if let Some(last) = prev {
s += scaled.kern(last, id);
}
let more = index + ch.len_utf8() < text.len();
let needs_ellipsis =
s + scaled.h_advance(id) + if more { scaled.h_advance(ellipsis) } else { 0. } > end;
let glyph = if needs_ellipsis { ellipsis } else { id };
if s + scaled.h_advance(glyph) > end {
break;
}
if let Some(glyph) = font
.outline_glyph(glyph.with_scale_and_position(scaled.scale(), point(s, baseline)))
{
let bounds = glyph.px_bounds();
glyph.draw(|dx, dy, coverage| {
self.pixel(
bounds.min.x as i32 + dx as i32,
bounds.min.y as i32 + dy as i32,
ink,
coverage,
);
});
}
if needs_ellipsis {
break;
}
s += scaled.h_advance(id);
prev = Some(id);
}
}
}
struct Screen<'a> {
canvas: Canvas<'a>,
ui: &'a Ui,
p: &'a Palette,
hits: Vec<Hit>,
logical_scale: f32,
w: i32,
h: i32,
}
impl Screen<'_> {
fn text(&mut self, x: i32, y: i32, w: i32, content: &str, size: i32, ink: Color) {
self.canvas.text(x, y, w, content, size, ink, false);
}
fn heading(&mut self, x: i32, y: i32, w: i32, content: &str, size: i32) {
self.canvas.text(x, y, w, content, size, self.p.text, true);
}
fn hit(&mut self, rect: Rect, action: Action) {
let scale = self.logical_scale;
self.hits.push(Hit {
rect: Rect(
(rect.0 as f32 * scale) as i32,
(rect.1 as f32 * scale) as i32,
(rect.2 as f32 * scale).ceil() as i32,
(rect.3 as f32 * scale).ceil() as i32,
),
action,
});
}
fn button(&mut self, rect: Rect, label: &str, action: Action, primary: bool) {
let hover = self.ui.hover.as_ref() == Some(&action);
let focus = self.ui.focus.as_ref() == Some(&action);
let press = self.ui.pressed.as_ref() == Some(&action) && hover;
let (mut fill, ink) = if primary {
let accent = self.p.accent;
let luma =
u32::from(accent[0]) * 212 + u32::from(accent[1]) * 715 + u32::from(accent[2]) * 73;
(
accent,
if luma > 151_000 {
[15, 25, 20]
} else {
[255; 3]
},
)
} else {
(self.p.raised, self.p.text)
};
if hover {
fill = mix(fill, ink, if press { 0.24 } else { 0.12 });
}
let rim = if focus {
self.p.accent
} else {
mix(fill, ink, if primary { 0.19 } else { 0.23 })
};
self.canvas
.rect(rect, self.p.radius.min(11), fill, Some(rim));
self.text(
rect.0 + 12,
rect.1 + (rect.3 - 15) / 2,
rect.2 - 23,
label,
14,
ink,
);
self.hit(rect, action);
}
fn field(
&mut self,
rect: Rect,
label: &str,
value: &str,
placeholder: &str,
action: Option<Action>,
) {
self.text(rect.0, rect.1 - 21, rect.2, label, 13, self.p.muted);
let focus = action.is_some() && self.ui.focus == action;
let rim = if focus { self.p.accent } else { self.p.border };
self.canvas
.rect(rect, self.p.radius.min(8), self.p.surface, Some(rim));
let content = if focus {
if value.chars().count() as i32 * 8 > rect.2 - 30 {
let keep = ((rect.2 - 32) / 8).max(1) as usize;
let tail: String = value
.chars()
.rev()
.take(keep)
.collect::<Vec<_>>()
.into_iter()
.rev()
.collect();
format!("…{tail}▏")
} else {
format!("{value}▏")
}
} else if value.is_empty() {
placeholder.into()
} else {
value.into()
};
self.text(
rect.0 + 11,
rect.1 + 11,
rect.2 - 20,
&content,
15,
if value.is_empty() && !focus {
self.p.muted
} else {
self.p.text
},
);
if let Some(action) = action {
self.hit(rect, action);
}
}
fn main(&mut self) {
let p = self.p;
let sidebar = (self.w / 4).clamp(210, 260);
self.canvas
.rect(Rect(1, 1, sidebar, self.h - 2), 0, p.surface, None);
self.canvas
.rect(Rect(sidebar, 0, 1, self.h), 0, p.line, None);
self.monitor(22, 19, 34, p.accent);
self.heading(68, 19, sidebar - 76, "Aev VM", 28);
self.canvas
.rect(Rect(20, 63, sidebar - 39, 1), 0, p.line, None);
self.button(
Rect(20, 81, sidebar - 40, 41),
"+ New virtual machine",
Action::New,
false,
);
self.text(23, 145, sidebar - 40, "Virtual machines", 14, p.muted);
for (i, vm) in self
.ui
.machines
.iter()
.skip(self.ui.machine_page * PAGE_SIZE)
.take(PAGE_SIZE)
.enumerate()
{
let action = Action::Select(vm.name.clone());
let y = 173 + i as i32 * 51;
let selected =
self.ui.draft.is_none() && self.ui.selected.as_deref() == Some(vm.name.as_str());
let hovered =
self.ui.hover.as_ref() == Some(&action) || self.ui.focus.as_ref() == Some(&action);
let rect = Rect(13, y, sidebar - 25, 46);
if selected || hovered {
self.canvas.rect(
rect,
p.radius.min(12),
p.interactive,
Some(if selected { p.border } else { p.line }),
);
}
self.monitor(25, y + 12, 20, if selected { p.accent } else { p.muted });
self.text(54, y + 6, sidebar - 74, &vm.name, 15, p.text);
self.text(54, y + 25, sidebar - 74, vm.status_label(), 12, p.muted);
self.hit(rect, action);
}
if self.ui.machines.len() > PAGE_SIZE && self.ui.directory.is_none() {
self.pages(
20,
self.h - 59,
sidebar - 40,
self.ui.machine_page,
self.ui.machines.len(),
);
}
if self.ui.directory.is_some() {
self.hits.clear();
}
let x = sidebar + 28;
let cw = self.w - x - 28;
self.button(Rect(self.w - 51, 16, 31, 30), "×", Action::Close, false);
self.canvas.rect(Rect(x, 63, cw, 1), 0, p.line, None);
let title = if let Some(draft) = &self.ui.draft {
if self.ui.directory.is_some() {
"Installation image"
} else if draft.editing {
"Virtual hardware"
} else {
"New virtual machine"
}
} else {
"Virtual machines"
};
self.heading(x, 17, cw - 57, title, 29);
if let Some(directory) = &self.ui.directory {
self.directory(x, cw, directory);
} else if let Some(draft) = &self.ui.draft {
self.form(x, cw, draft);
} else if let Some(machine) = self.ui.selected() {
self.machine(x, cw, machine);
} else {
let hero = Rect(x, 91, cw, 345);
self.card(hero, p.surface);
self.monitor(x + 34, 124, 68, p.accent);
self.heading(x + 32, 206, cw - 64, "Boot an operating system", 44);
self.text(
x + 33,
270,
cw - 66,
"Choose an ISO and set the guest hardware.",
17,
p.muted,
);
self.button(
Rect(x + 32, 320, 180, 44),
"New virtual machine",
Action::New,
true,
);
}
let footer = self.h - 45;
self.canvas.rect(Rect(x, footer, cw, 1), 0, p.line, None);
if let Some((notice, problem)) = &self.ui.notice {
self.text(
x,
footer + 13,
cw,
notice,
13,
if *problem { p.danger } else { p.muted },
);
} else if self.ui.pending {
self.text(x, footer + 13, cw, "Working…", 13, p.muted);
}
}
fn card(&mut self, rect: Rect, fill: Color) {
self.canvas
.rect(rect, self.p.radius, fill, Some(self.p.border));
}
fn monitor(&mut self, x: i32, y: i32, width: i32, accent: Color) {
let height = width * 67 / 100;
let bezel = (width / 12).max(2);
let palette = self.p;
self.canvas.rect(
Rect(x, y, width, height),
self.p.radius.min((width / 7).max(3)),
mix(palette.background, accent, 0.2),
Some(accent),
);
if width >= 35 {
self.canvas.rect(
Rect(x + bezel, y + bezel, width - 2 * bezel, height - 2 * bezel),
self.p.radius.min(bezel),
palette.background,
None,
);
self.canvas.rect(
Rect(x + 2 * bezel, y + 2 * bezel, width / 3, 1),
0,
accent,
None,
);
self.canvas.rect(
Rect(x + 2 * bezel, y + 3 * bezel, width / 5, 1),
0,
palette.muted,
None,
);
}
self.canvas.rect(
Rect(x + width / 2 - bezel / 2, y + height, bezel, width / 7),
0,
accent,
None,
);
self.canvas.rect(
Rect(
x + width / 4,
y + height + width / 7,
width / 2,
bezel.min(3),
),
1,
accent,
None,
);
}
fn pages(&mut self, x: i32, y: i32, width: i32, page: usize, total: usize) {
if page > 0 {
self.button(Rect(x, y, 33, 29), "‹", Action::Previous, false);
}
if (page + 1) * PAGE_SIZE < total {
self.button(Rect(x + width - 33, y, 33, 29), "›", Action::Next, false);
}
self.text(
x + 45,
y + 7,
width - 88,
&format!("{} / {}", page + 1, total.div_ceil(PAGE_SIZE)),
13,
self.p.muted,
);
}
fn directory(&mut self, x: i32, w: i32, d: &super::Directory) {
self.text(x, 80, w, &d.path.to_string_lossy(), 16, self.p.text);
self.button(Rect(x, 112, 82, 33), "Cancel", Action::Back, false);
if let Some(parent) = d.path.parent() {
self.button(
Rect(x + 94, 112, 126, 33),
"Parent folder",
Action::Directory(parent.into()),
false,
);
}
for (i, (path, directory)) in d
.files
.iter()
.skip(self.ui.file_page * PAGE_SIZE)
.take(PAGE_SIZE)
.enumerate()
{
let action = if *directory {
Action::Directory(path.clone())
} else {
Action::Pick(path.clone())
};
let name = path
.file_name()
.map_or_else(|| path.to_string_lossy(), std::ffi::OsStr::to_string_lossy);
let label = if *directory {
format!("{name}/")
} else {
name.into_owned()
};
self.button(Rect(x, 160 + i as i32 * 46, w, 39), &label, action, false);
}
if d.files.is_empty() {
self.text(
x,
163,
w,
"This folder has no installation images.",
15,
self.p.muted,
);
}
if d.files.len() > PAGE_SIZE {
self.pages(x, 489, w, self.ui.file_page, d.files.len());
}
}
fn form(&mut self, x: i32, w: i32, d: &Draft) {
let p = self.p;
self.text(
x,
82,
w,
if d.editing {
"Changes apply the next time the guest starts."
} else {
"Choose an installation image and set up the guest hardware."
},
15,
p.muted,
);
self.card(Rect(x, 116, w, 350), p.surface);
let x = x + 21;
let w = w - 42;
self.field(
Rect(x, 157, w, 39),
"VM name",
&d.name,
"KnottOS",
(!d.editing).then_some(Action::Field(Field::Name)),
);
self.field(
Rect(x, 229, w - 109, 39),
"Installation image",
&d.media,
"Path to an .iso or .img file",
Some(Action::Field(Field::Media)),
);
self.button(
Rect(x + w - 98, 229, 98, 39),
"Browse…",
Action::Browse,
false,
);
let count = if d.editing { 2 } else { 3 };
let slot = (w - (count - 1) * 10) / count;
self.field(
Rect(x, 308, slot, 39),
"Memory (MiB)",
&d.memory,
"4096",
Some(Action::Field(Field::Memory)),
);
self.field(
Rect(x + slot + 10, 308, slot, 39),
"Virtual CPUs",
&d.cpus,
"4",
Some(Action::Field(Field::Cpus)),
);
if !d.editing {
self.field(
Rect(x + 2 * (slot + 10), 308, slot, 39),
"System disk",
&d.disk,
"32G",
Some(Action::Field(Field::Disk)),
);
}
let slot = (w - 20) / 3;
for (i, (label, value, action)) in [
("Firmware", firmware(d.firmware), Action::Firmware),
(
"Acceleration",
acceleration(d.acceleration),
Action::Acceleration,
),
("Guest network", network(d.network), Action::Network),
]
.into_iter()
.enumerate()
{
let left = x + i as i32 * (slot + 10);
self.text(left, 379, slot, label, 13, p.muted);
self.button(Rect(left, 401, slot, 39), value, action, false);
}
self.button(Rect(x - 21, 487, 89, 44), "Cancel", Action::Back, false);
if d.editing {
self.button(
Rect(x + w - 145, 487, 166, 44),
"Save changes",
Action::Save(false),
true,
);
} else {
self.button(
Rect(x + w - 269, 487, 104, 44),
"Create",
Action::Save(false),
false,
);
self.button(
Rect(x + w - 154, 487, 175, 44),
"Create and start",
Action::Save(true),
true,
);
}
}
fn machine(&mut self, x: i32, w: i32, vm: &Machine) {
let p = self.p;
self.card(Rect(x, 84, w, 195), mix(p.surface, p.accent, 0.06));
self.heading(x + 23, 112, w - 178, &vm.name, 42);
self.canvas.rect(
Rect(x + 24, 170, 8, 8),
4,
if matches!(vm.status, Ok(VmStatus::Running { .. })) {
p.success
} else {
p.muted
},
None,
);
self.text(x + 42, 167, w - 190, vm.status_label(), 15, p.muted);
self.monitor(x + w - 131, 114, 92, p.accent);
match &vm.status {
Ok(VmStatus::Stopped) if vm.config.is_ok() => {
self.button(
Rect(x + 23, 214, 152, 42),
"Start and open",
Action::Start,
true,
);
self.button(
Rect(x + 186, 214, 144, 42),
"Edit hardware",
Action::Edit,
false,
);
}
Ok(VmStatus::Running { qemu_status, .. }) => {
let paused = qemu_status == "paused";
self.button(
Rect(x + 23, 214, 147, 42),
"Open console",
Action::Console,
true,
);
self.button(
Rect(x + 180, 214, 94, 42),
if paused { "Resume" } else { "Pause" },
if paused {
Action::Resume
} else {
Action::Pause
},
false,
);
self.button(
Rect(x + 284, 214, 109, 42),
"Shut down",
Action::Shutdown,
false,
);
}
_ => {}
}
if let Ok(cfg) = &vm.config {
self.heading(x, 298, w, "Virtual hardware", 25);
let count = 3;
let size = (w - (count - 1) * 10) / count;
for (i, (label, value)) in [
("Memory", format!("{} MiB", cfg.memory_mib)),
("Virtual CPUs", cfg.vcpus.to_string()),
("Firmware", firmware(cfg.firmware).into()),
]
.into_iter()
.enumerate()
{
let x = x + i as i32 * (size + 10);
self.card(Rect(x, 337, size, 72), p.surface);
self.text(x + 12, 350, size - 24, label, 13, p.muted);
self.text(x + 12, 376, size - 24, &value, 19, p.text);
}
self.card(Rect(x, 421, w, 105), p.surface);
self.text(x + 13, 437, w - 26, "Installation image", 13, p.muted);
let media = cfg
.install_media
.as_ref()
.and_then(|p| p.file_name())
.map_or_else(
|| "No image attached".into(),
std::ffi::OsStr::to_string_lossy,
);
self.text(x + 13, 459, w - 26, &media, 16, p.text);
self.text(
x + 13,
493,
w - 26,
&format!(
"{} · {}",
acceleration(cfg.acceleration),
network(cfg.network.mode)
),
13,
p.muted,
);
} else if let Err(error) = &vm.config {
self.text(x, 308, w, error, 14, p.danger);
}
}
}
fn acceleration(value: Acceleration) -> &'static str {
match value {
Acceleration::Auto => "Auto · KVM / software",
Acceleration::Kvm => "KVM",
Acceleration::Tcg => "Software",
}
}
fn firmware(value: Firmware) -> &'static str {
match value {
Firmware::Uefi => "UEFI",
Firmware::UefiSecure => "UEFI Secure Boot",
Firmware::Bios => "Legacy BIOS",
}
}
fn network(value: NetworkMode) -> &'static str {
match value {
NetworkMode::User => "Shared network",
NetworkMode::None => "Offline",
}
}
pub(super) fn render(
assets: &Assets,
ui: &Ui,
configure: Configure,
serial: u64,
) -> Result<(Frame, Vec<Hit>)> {
let (width, height) = configure.buffer_size()?;
let logical_scale = (configure.width as f32 / 860.)
.min(configure.height as f32 / 600.)
.min(1.45);
let [red, green, blue] = assets.palette.background;
let mut pixels = vec![0; crate::aen_window::frame_bytes(width, height)?];
for pixel in pixels.chunks_exact_mut(4) {
pixel.copy_from_slice(&[blue, green, red, 255]);
}
let mut screen = Screen {
canvas: Canvas {
pixels,
w: width as i32,
h: height as i32,
scale: logical_scale * configure.scale as f32,
fonts: assets,
},
ui,
p: &assets.palette,
hits: Vec::new(),
logical_scale,
w: (configure.width as f32 / logical_scale).ceil() as i32,
h: (configure.height as f32 / logical_scale).ceil() as i32,
};
screen.main();
Ok((
Frame {
frame_serial: serial,
configure_serial: configure.configure_serial,
width,
height,
pixels: screen.canvas.pixels.into(),
},
screen.hits,
))
}