use rgb::RGBA8;
#[derive(Debug, Clone)]
#[allow(clippy::exhaustive_structs)]
pub struct Config {
pub buffer_width: f32,
pub buffer_height: f32,
pub scaling: f32,
pub vsync: bool,
pub title: String,
pub viewport_color: RGBA8,
pub background_color: RGBA8,
pub rotation_algorithm: RotationAlgorithm,
pub max_frame_time_secs: f32,
pub update_delta_time: f32,
}
impl Config {
#[inline]
#[must_use]
pub fn with_buffer_size(mut self, buffer_size: impl Into<(f32, f32)>) -> Self {
let (buffer_width, buffer_height) = buffer_size.into();
self.buffer_width = buffer_width;
self.buffer_height = buffer_height;
self
}
#[inline]
#[must_use]
pub const fn with_buffer_width(mut self, buffer_width: f32) -> Self {
self.buffer_width = buffer_width;
self
}
#[inline]
#[must_use]
pub const fn with_buffer_height(mut self, buffer_height: f32) -> Self {
self.buffer_height = buffer_height;
self
}
#[inline]
#[must_use]
pub const fn with_scaling(mut self, scaling: f32) -> Self {
self.scaling = scaling;
self
}
#[inline]
#[must_use]
pub const fn with_vsync(mut self, vsync: bool) -> Self {
self.vsync = vsync;
self
}
#[inline]
#[must_use]
pub fn with_title(mut self, title: impl Into<String>) -> Self {
self.title = title.into();
self
}
#[inline]
#[must_use]
pub const fn with_viewport_color(mut self, viewport_color: RGBA8) -> Self {
self.viewport_color = viewport_color;
self
}
#[inline]
#[must_use]
pub const fn with_background_color(mut self, background_color: RGBA8) -> Self {
self.background_color = background_color;
self
}
#[inline]
#[must_use]
pub const fn with_rotation_algorithm(mut self, rotation_algorithm: RotationAlgorithm) -> Self {
self.rotation_algorithm = rotation_algorithm;
self
}
#[inline]
#[must_use]
pub const fn with_max_frame_time_secs(mut self, max_frame_time_secs: f32) -> Self {
self.max_frame_time_secs = max_frame_time_secs;
self
}
#[inline]
#[must_use]
pub const fn with_update_delta_time(mut self, update_delta_time: f32) -> Self {
self.update_delta_time = update_delta_time;
self
}
}
impl Default for Config {
#[inline]
fn default() -> Self {
Self {
buffer_width: 320.0,
buffer_height: 280.0,
scaling: 2.0,
vsync: true,
title: "Pixel Game".to_owned(),
viewport_color: RGBA8::new(0x76, 0x42, 0x8A, 0xFF),
background_color: RGBA8::new(0x9B, 0xAD, 0xB7, 0xFF),
rotation_algorithm: RotationAlgorithm::default(),
max_frame_time_secs: 1.0 / 4.0,
update_delta_time: 1.0 / 30.0,
}
}
}
#[derive(Debug, Default, Clone, Copy, PartialEq, Eq)]
#[non_exhaustive]
pub enum RotationAlgorithm {
CleanEdge,
#[default]
Scale3x,
Diag2x,
NearestNeighbor,
Scale2x,
}