mirror of
https://github.com/Noratrieb/game-wip-dontplay.git
synced 2026-01-15 04:05:02 +01:00
55 lines
1.2 KiB
Rust
55 lines
1.2 KiB
Rust
use egui_inspect::derive::Inspect;
|
|
use serde::{Deserialize, Serialize};
|
|
use sfml::{
|
|
graphics::RenderWindow,
|
|
system::Vector2f,
|
|
window::{ContextSettings, Style, VideoMode},
|
|
};
|
|
use sfml_xt::graphics::RenderWindowExt;
|
|
|
|
use crate::math::FPS_TARGET;
|
|
|
|
pub struct ScreenRes {
|
|
pub w: u16,
|
|
pub h: u16,
|
|
}
|
|
|
|
impl ScreenRes {
|
|
fn to_sf(&self) -> VideoMode {
|
|
VideoMode {
|
|
width: self.w as _,
|
|
height: self.h as _,
|
|
bits_per_pixel: 32,
|
|
}
|
|
}
|
|
}
|
|
|
|
#[derive(Default, Clone, Copy, Debug, Inspect, Serialize, Deserialize)]
|
|
pub struct ScreenVec {
|
|
pub x: ScreenSc,
|
|
pub y: ScreenSc,
|
|
}
|
|
|
|
/// Screen position/offset scalar
|
|
/// We assume this game won't be played above 32767*32767 resolution
|
|
pub type ScreenSc = i16;
|
|
|
|
impl ScreenVec {
|
|
pub fn to_sf_vec(self) -> Vector2f {
|
|
Vector2f::new(self.x.into(), self.y.into())
|
|
}
|
|
}
|
|
|
|
const DEFAULT_RES: ScreenRes = ScreenRes { w: 960, h: 540 };
|
|
|
|
pub fn make_window() -> RenderWindow {
|
|
let mut rw = RenderWindow::new(
|
|
DEFAULT_RES.to_sf(),
|
|
"Mantle Diver",
|
|
Style::DEFAULT,
|
|
&ContextSettings::default(),
|
|
);
|
|
rw.set_framerate_limit(FPS_TARGET.into());
|
|
rw.center();
|
|
rw
|
|
}
|