Skip to content

Commit 279556a

Browse files
committed
Make window size configurable; Move format to YAML
1 parent 45a93ff commit 279556a

File tree

6 files changed

+73
-53
lines changed

6 files changed

+73
-53
lines changed

config/default.toml

-28
This file was deleted.

config/default.yaml

+32
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
general:
2+
display-framerate: false
3+
data-root: ""
4+
log:
5+
level: "WARN"
6+
7+
window:
8+
size:
9+
windowed:
10+
width: 1200
11+
height: 800
12+
13+
renderer:
14+
vertex-shader: "config/shader.vert"
15+
fragment-shader: "config/shader.frag"
16+
css: "config/style.css"
17+
ui-font: "config/Ruda-Bold.ttf"
18+
max-tiles: 200
19+
max-features: 1000
20+
tile-size: 384
21+
msaa-samples: 4
22+
selection-tags: []
23+
temperature:
24+
vertex-shader: "config/temperature/shader.vert"
25+
fragment-shader: "config/temperature/shader.frag"
26+
27+
map:
28+
initial:
29+
zoom: 13.0
30+
center:
31+
latitude: 47.3769
32+
longitude: 8.5417

src/bin/app_state.rs

+4-4
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ use osm::math::{deg2num, tile_to_world_space, Screen, TileId};
77
use osm::object::Object;
88
use std::sync::{Arc, Mutex, RwLock};
99
use std::thread;
10+
use winit::dpi::PhysicalSize;
1011

1112
use crate::config::CONFIG;
1213
use crate::drawing::ui::state::UIState;
@@ -29,8 +30,7 @@ impl AppState {
2930
pub fn new(
3031
style: impl Into<String>,
3132
center: Point,
32-
width: u32,
33-
height: u32,
33+
size: PhysicalSize<u32>,
3434
zoom: f32,
3535
hidpi_factor: f64,
3636
) -> Self {
@@ -40,8 +40,8 @@ impl AppState {
4040
.expect("Unable to load the style file. Please consult the log."),
4141
screen: Screen::new(
4242
center,
43-
width,
44-
height,
43+
size.width,
44+
size.height,
4545
CONFIG.renderer.tile_size,
4646
hidpi_factor,
4747
),

src/bin/config.rs

+14
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,20 @@ pub struct Config {
99
pub general: General,
1010
pub map: MapState,
1111
pub renderer: Renderer,
12+
pub window: Window,
13+
}
14+
15+
#[derive(Debug, Deserialize)]
16+
#[serde(rename_all = "kebab-case")]
17+
pub struct Window {
18+
pub size: WindowSize,
19+
}
20+
21+
#[derive(Debug, Deserialize)]
22+
#[serde(rename_all = "kebab-case")]
23+
pub enum WindowSize {
24+
Windowed { width: f64, height: f64 },
25+
Fullscreen,
1226
}
1327

1428
#[derive(Debug, Deserialize)]

src/bin/drawing/painter.rs

+3-13
Original file line numberDiff line numberDiff line change
@@ -16,8 +16,8 @@ use util::StagingBelt;
1616
use wgpu::naga::ShaderStage;
1717
use wgpu::util::{BufferInitDescriptor, DeviceExt};
1818
use wgpu::*;
19-
use winit::window::WindowAttributes;
20-
use winit::{dpi::LogicalSize, event_loop::EventLoop, window::Window};
19+
use winit::dpi::PhysicalSize;
20+
use winit::window::Window;
2121

2222
use crate::app_state::AppState;
2323
use crate::drawing::helpers::load_glsl;
@@ -53,18 +53,8 @@ pub struct Painter {
5353

5454
impl Painter {
5555
/// Initializes the entire draw machinery.
56-
pub fn init(event_loop: &EventLoop<()>, width: u32, height: u32, app_state: &AppState) -> Self {
57-
#[allow(deprecated)]
58-
let window = Arc::new(
59-
event_loop
60-
.create_window(WindowAttributes::default().with_inner_size(LogicalSize {
61-
width: width as f64,
62-
height: height as f64,
63-
}))
64-
.unwrap(),
65-
);
56+
pub fn init(window: Arc<Window>, size: PhysicalSize<u32>, app_state: &AppState) -> Self {
6657
let factor = window.scale_factor();
67-
let size = window.inner_size();
6858

6959
let instance = wgpu::Instance::new(InstanceDescriptor::default());
7060
let surface = instance.create_surface(window.clone()).unwrap();

src/bin/main.rs

+20-8
Original file line numberDiff line numberDiff line change
@@ -3,16 +3,18 @@ mod config;
33
mod drawing;
44
mod stats;
55

6+
use std::sync::Arc;
7+
68
use crate::config::CONFIG;
79
use lyon::math::vector;
810
use osm::math::{deg2num, tile_to_world_space};
911
use winit::{
1012
application::ApplicationHandler,
11-
dpi::{LogicalPosition, PhysicalPosition},
13+
dpi::{LogicalPosition, LogicalSize, PhysicalPosition},
1214
event::{ElementState, KeyEvent, MouseButton, MouseScrollDelta, WindowEvent},
1315
event_loop::ActiveEventLoop,
1416
keyboard::{Key, ModifiersState, NamedKey},
15-
window::WindowId,
17+
window::{WindowAttributes, WindowId},
1618
};
1719

1820
fn main() {
@@ -26,21 +28,31 @@ fn main() {
2628
);
2729
let initial_center = tile_to_world_space(&tile_coordinate);
2830

29-
let width = 1200;
30-
let height = 800;
31-
3231
let event_loop = winit::event_loop::EventLoop::new().unwrap();
3332

33+
let attributes = WindowAttributes::default();
34+
let window_attributes = match CONFIG.window.size {
35+
config::WindowSize::Windowed { width, height } => attributes
36+
.with_inner_size(LogicalSize { width, height })
37+
.with_decorations(false),
38+
config::WindowSize::Fullscreen => {
39+
attributes.with_fullscreen(Some(winit::window::Fullscreen::Borderless(None)))
40+
}
41+
};
42+
43+
#[allow(deprecated)]
44+
let window = Arc::new(event_loop.create_window(window_attributes).unwrap());
45+
let size = window.inner_size();
46+
3447
let app_state = app_state::AppState::new(
3548
CONFIG.renderer.css.clone(),
3649
initial_center,
37-
width,
38-
height,
50+
size,
3951
CONFIG.map.initial.zoom,
4052
2.0,
4153
);
4254

43-
let mut painter = drawing::Painter::init(&event_loop, width, height, &app_state);
55+
let mut painter = drawing::Painter::init(window, size, &app_state);
4456
let hud = drawing::ui::Hud::new(
4557
&painter.window,
4658
&mut painter.device,

0 commit comments

Comments
 (0)