Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: Window config & replace the loop with winit loop
- Loading branch information
Showing
5 changed files
with
127 additions
and
9 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -6,6 +6,7 @@ edition = "2018" | |
|
||
[dependencies] | ||
legion = "0.4.0" | ||
winit = "0.24.0" | ||
|
||
serde = "1.0.124" | ||
toml = "0.5.8" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1 +1,2 @@ | ||
pub mod scion_config; | ||
pub mod scion_config; | ||
pub mod window_config; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,82 @@ | ||
use std::path::PathBuf; | ||
use winit::window::{WindowBuilder, WindowAttributes}; | ||
use winit::dpi::Size; | ||
use serde::{Deserialize, Serialize}; | ||
|
||
/// Main configuration for the game window | ||
#[derive(Debug, Serialize, Deserialize, Clone)] | ||
pub(crate) struct WindowConfig { | ||
/// Window title | ||
pub title: String, | ||
/// Enables fullscreen mode | ||
#[serde(default)] | ||
pub fullscreen: bool, | ||
/// Default window width and height in pixels. | ||
#[serde(default)] | ||
pub dimensions: Option<(u32, u32)>, | ||
/// Minimum window width and height in pixels. | ||
#[serde(default)] | ||
pub min_dimensions: Option<(u32, u32)>, | ||
/// Maximum window width and height in pixels. | ||
#[serde(default)] | ||
pub max_dimensions: Option<(u32, u32)>, | ||
/// Whether to display the window, Use full for loading | ||
pub visibility: bool, | ||
/// The path relative to the game executable of the window icon. | ||
#[serde(default)] | ||
pub icon: Option<PathBuf>, | ||
/// Whether the window should always be on top of other windows. | ||
#[serde(default)] | ||
pub always_on_top: bool, | ||
/// Whether the window should have borders and bars. | ||
pub decorations: bool, | ||
/// Whether the window should be maximized upon creation. | ||
#[serde(default)] | ||
pub maximized: bool, | ||
/// If the user can resize the window | ||
pub resizable: bool, | ||
/// If the window should be able to be transparent. | ||
#[serde(default)] | ||
pub transparent: bool, | ||
} | ||
|
||
impl Default for WindowConfig { | ||
fn default() -> Self { | ||
Self { | ||
title: "Default Scion game".to_string(), | ||
fullscreen: false, | ||
dimensions: Some((1024, 768)), | ||
min_dimensions: Some((640, 480)), | ||
max_dimensions: None, | ||
visibility: true, | ||
icon: None, | ||
always_on_top: false, | ||
decorations: true, | ||
maximized: false, | ||
resizable: true, | ||
transparent: false | ||
} | ||
} | ||
} | ||
|
||
impl Into<WindowBuilder> for WindowConfig { | ||
fn into(self) -> WindowBuilder { | ||
let mut builder = WindowBuilder::new(); | ||
|
||
builder.window = WindowAttributes { | ||
title: self.title.clone(), | ||
fullscreen: None, | ||
inner_size: self.dimensions.map(|d| d.into()).map(Size::Logical), | ||
min_inner_size: self.min_dimensions.map(|d| d.into()).map(Size::Logical), | ||
max_inner_size: self.max_dimensions.map(|d| d.into()).map(Size::Logical), | ||
visible: self.visibility, | ||
window_icon: None, | ||
always_on_top: self.always_on_top, | ||
decorations: self.decorations, | ||
maximized: self.maximized, | ||
resizable: self.resizable, | ||
transparent: self.transparent, | ||
}; | ||
builder | ||
} | ||
} |