fix(main): Use LogicalSize and PhysicalSize properly

This commit is contained in:
Rekai Nyangadzayi Musuka 2021-09-11 22:56:40 -03:00
parent ee5504111b
commit 10ac579c40
1 changed files with 9 additions and 29 deletions

View File

@ -4,13 +4,13 @@ use gb::{AudioSPSC, Cycle, GB_HEIGHT, GB_WIDTH};
use gilrs::Gilrs; use gilrs::Gilrs;
use pixels::{PixelsBuilder, SurfaceTexture}; use pixels::{PixelsBuilder, SurfaceTexture};
use rodio::{OutputStream, Sink}; use rodio::{OutputStream, Sink};
use winit::dpi::LogicalSize; use winit::dpi::{LogicalSize, PhysicalSize};
use winit::event::{Event, VirtualKeyCode}; use winit::event::{Event, VirtualKeyCode};
use winit::event_loop::{ControlFlow, EventLoop}; use winit::event_loop::{ControlFlow, EventLoop};
use winit::window::{Window, WindowBuilder}; use winit::window::{Window, WindowBuilder};
use winit_input_helper::WinitInputHelper; use winit_input_helper::WinitInputHelper;
const WINDOW_SCALE: f64 = 2.0; const WINDOW_SCALE: usize = 3;
const AUDIO_ENABLED: bool = true; const AUDIO_ENABLED: bool = true;
fn main() -> Result<()> { fn main() -> Result<()> {
@ -114,37 +114,17 @@ fn main() -> Result<()> {
}); });
} }
#[cfg(not(windows))]
fn create_window(event_loop: &EventLoop<()>, title: &str) -> Result<Window> { fn create_window(event_loop: &EventLoop<()>, title: &str) -> Result<Window> {
let size = LogicalSize::new( let logical = LogicalSize::new(GB_WIDTH as f64, GB_HEIGHT as f64);
(GB_WIDTH as f64) * WINDOW_SCALE, let physical = PhysicalSize::new(
(GB_HEIGHT as f64) * WINDOW_SCALE, (GB_WIDTH * WINDOW_SCALE) as f32,
(GB_HEIGHT * WINDOW_SCALE) as f32,
); );
Ok(WindowBuilder::new() Ok(WindowBuilder::new()
.with_title(title) .with_title(title)
.with_inner_size(size) .with_min_inner_size(logical)
.with_min_inner_size(size) .with_inner_size(physical)
.with_resizable(true) .with_resizable(true)
.with_decorations(true)
.with_transparent(false)
.build(event_loop)?)
}
#[cfg(windows)]
fn create_window(event_loop: &EventLoop<()>, title: &str) -> Result<Window> {
use winit::platform::windows::WindowBuilderExtWindows;
let size = LogicalSize::new(
(GB_WIDTH as f64) * WINDOW_SCALE,
(GB_HEIGHT as f64) * WINDOW_SCALE,
);
Ok(WindowBuilder::new()
.with_title(title)
.with_inner_size(size)
.with_min_inner_size(size)
.with_resizable(true)
.with_decorations(true)
.with_transparent(false)
.with_drag_and_drop(false)
.build(event_loop)?) .build(event_loop)?)
} }