mirror of
https://gitlab.com/veloren/veloren.git
synced 2024-08-30 18:12:32 +00:00
Merge branch 'imbris/screenshot-tweak' into 'master'
Only screenshot and toggle fullscreen once per frame See merge request veloren/veloren!1217
This commit is contained in:
commit
d46bf03e27
@ -59,6 +59,10 @@ fn handle_main_events_cleared(
|
||||
control_flow: &mut winit::event_loop::ControlFlow,
|
||||
global_state: &mut GlobalState,
|
||||
) {
|
||||
// Screenshot / Fullscreen toggle
|
||||
global_state
|
||||
.window
|
||||
.resolve_deduplicated_events(&mut global_state.settings);
|
||||
// Run tick here
|
||||
|
||||
// What's going on here?
|
||||
|
@ -488,6 +488,9 @@ pub struct Window {
|
||||
// Currently used to send and receive screenshot result messages
|
||||
message_sender: channel::Sender<String>,
|
||||
message_receiver: channel::Receiver<String>,
|
||||
// Used for screenshots & fullscreen toggle to deduplicate/postpone to after event handler
|
||||
take_screenshot: bool,
|
||||
toggle_fullscreen: bool,
|
||||
}
|
||||
|
||||
impl Window {
|
||||
@ -591,6 +594,8 @@ impl Window {
|
||||
// Currently used to send and receive screenshot result messages
|
||||
message_sender,
|
||||
message_receiver,
|
||||
take_screenshot: false,
|
||||
toggle_fullscreen: false,
|
||||
};
|
||||
|
||||
this.fullscreen(settings.graphics.fullscreen);
|
||||
@ -608,6 +613,18 @@ impl Window {
|
||||
|
||||
pub fn renderer_mut(&mut self) -> &mut Renderer { &mut self.renderer }
|
||||
|
||||
pub fn resolve_deduplicated_events(&mut self, settings: &mut Settings) {
|
||||
// Handle screenshots and toggling fullscreen
|
||||
if self.take_screenshot {
|
||||
self.take_screenshot = false;
|
||||
self.take_screenshot(&settings);
|
||||
}
|
||||
if self.toggle_fullscreen {
|
||||
self.toggle_fullscreen = false;
|
||||
self.toggle_fullscreen(settings);
|
||||
}
|
||||
}
|
||||
|
||||
pub fn fetch_events(&mut self) -> Vec<Event> {
|
||||
// Refresh ui size (used when changing playstates)
|
||||
if self.needs_refresh_resize {
|
||||
@ -876,10 +893,6 @@ impl Window {
|
||||
use winit::event::WindowEvent;
|
||||
|
||||
let controls = &mut settings.controls;
|
||||
// TODO: these used to be used to deduplicate events which they no longer do
|
||||
// this needs to be handled elsewhere
|
||||
let mut toggle_fullscreen = false;
|
||||
let mut take_screenshot = false;
|
||||
|
||||
match event {
|
||||
WindowEvent::CloseRequested => self.events.push(Event::Close),
|
||||
@ -954,7 +967,7 @@ impl Window {
|
||||
GameInput::Fullscreen,
|
||||
)
|
||||
{
|
||||
toggle_fullscreen = !toggle_fullscreen;
|
||||
self.toggle_fullscreen = !self.toggle_fullscreen;
|
||||
}
|
||||
Self::set_pressed(
|
||||
&mut self.keypress_map,
|
||||
@ -963,7 +976,7 @@ impl Window {
|
||||
);
|
||||
},
|
||||
GameInput::Screenshot => {
|
||||
take_screenshot = input.state
|
||||
self.take_screenshot = input.state
|
||||
== winit::event::ElementState::Pressed
|
||||
&& !Self::is_pressed(
|
||||
&mut self.keypress_map,
|
||||
@ -993,14 +1006,6 @@ impl Window {
|
||||
},
|
||||
_ => {},
|
||||
}
|
||||
|
||||
if take_screenshot {
|
||||
self.take_screenshot(&settings);
|
||||
}
|
||||
|
||||
if toggle_fullscreen {
|
||||
self.toggle_fullscreen(settings);
|
||||
}
|
||||
}
|
||||
|
||||
/// Moves cursor by an offset
|
||||
|
Loading…
Reference in New Issue
Block a user