rewrite it in rust #1
|
@ -58,6 +58,7 @@ pub struct WindowState {
|
||||||
pub surface_desc: wgpu::SurfaceConfiguration,
|
pub surface_desc: wgpu::SurfaceConfiguration,
|
||||||
pub surface: wgpu::Surface<'static>,
|
pub surface: wgpu::Surface<'static>,
|
||||||
pub hidpi_factor: f64,
|
pub hidpi_factor: f64,
|
||||||
|
pub minimized: bool,
|
||||||
}
|
}
|
||||||
|
|
||||||
impl WindowState {
|
impl WindowState {
|
||||||
|
@ -105,6 +106,7 @@ impl WindowState {
|
||||||
surface_desc,
|
surface_desc,
|
||||||
surface,
|
surface,
|
||||||
hidpi_factor,
|
hidpi_factor,
|
||||||
|
minimized: false,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -114,9 +116,14 @@ impl WindowState {
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn handle_resize(&mut self, size: &PhysicalSize<u32>) {
|
pub fn handle_resize(&mut self, size: &PhysicalSize<u32>) {
|
||||||
|
if size.width > 0 && size.height > 0 {
|
||||||
|
self.minimized = false;
|
||||||
self.surface_desc.width = size.width;
|
self.surface_desc.width = size.width;
|
||||||
self.surface_desc.height = size.height;
|
self.surface_desc.height = size.height;
|
||||||
self.surface.configure(&self.device, &self.surface_desc);
|
self.surface.configure(&self.device, &self.surface_desc);
|
||||||
|
} else {
|
||||||
|
self.minimized = true;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -30,6 +30,7 @@ pub struct GameWindow {
|
||||||
client: EmulatorClient,
|
client: EmulatorClient,
|
||||||
input_mapper: Arc<RwLock<InputMapper>>,
|
input_mapper: Arc<RwLock<InputMapper>>,
|
||||||
proxy: EventLoopProxy<UserEvent>,
|
proxy: EventLoopProxy<UserEvent>,
|
||||||
|
paused_due_to_minimize: bool,
|
||||||
}
|
}
|
||||||
|
|
||||||
impl GameWindow {
|
impl GameWindow {
|
||||||
|
@ -165,6 +166,7 @@ impl GameWindow {
|
||||||
client,
|
client,
|
||||||
input_mapper,
|
input_mapper,
|
||||||
proxy,
|
proxy,
|
||||||
|
paused_due_to_minimize: false,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -181,7 +183,9 @@ impl GameWindow {
|
||||||
let frame = match window.surface.get_current_texture() {
|
let frame = match window.surface.get_current_texture() {
|
||||||
Ok(frame) => frame,
|
Ok(frame) => frame,
|
||||||
Err(e) => {
|
Err(e) => {
|
||||||
|
if !self.window.minimized {
|
||||||
eprintln!("dropped frame: {e:?}");
|
eprintln!("dropped frame: {e:?}");
|
||||||
|
}
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
@ -325,7 +329,18 @@ impl AppWindow for GameWindow {
|
||||||
fn handle_event(&mut self, event_loop: &ActiveEventLoop, event: &Event<UserEvent>) {
|
fn handle_event(&mut self, event_loop: &ActiveEventLoop, event: &Event<UserEvent>) {
|
||||||
match event {
|
match event {
|
||||||
Event::WindowEvent { event, .. } => match event {
|
Event::WindowEvent { event, .. } => match event {
|
||||||
WindowEvent::Resized(size) => self.window.handle_resize(size),
|
WindowEvent::Resized(size) => {
|
||||||
|
self.window.handle_resize(size);
|
||||||
|
if self.window.minimized {
|
||||||
|
if self.client.is_running() {
|
||||||
|
self.client.send_command(EmulatorCommand::Pause);
|
||||||
|
self.paused_due_to_minimize = true;
|
||||||
|
}
|
||||||
|
} else if self.paused_due_to_minimize {
|
||||||
|
self.client.send_command(EmulatorCommand::Resume);
|
||||||
|
self.paused_due_to_minimize = false;
|
||||||
|
}
|
||||||
|
}
|
||||||
WindowEvent::CloseRequested => event_loop.exit(),
|
WindowEvent::CloseRequested => event_loop.exit(),
|
||||||
WindowEvent::RedrawRequested => self.draw(event_loop),
|
WindowEvent::RedrawRequested => self.draw(event_loop),
|
||||||
_ => (),
|
_ => (),
|
||||||
|
|
|
@ -73,7 +73,9 @@ impl InputWindow {
|
||||||
let frame = match window.surface.get_current_texture() {
|
let frame = match window.surface.get_current_texture() {
|
||||||
Ok(frame) => frame,
|
Ok(frame) => frame,
|
||||||
Err(e) => {
|
Err(e) => {
|
||||||
|
if !self.window.minimized {
|
||||||
eprintln!("dropped frame: {e:?}");
|
eprintln!("dropped frame: {e:?}");
|
||||||
|
}
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
Loading…
Reference in New Issue