Fixes unresponsiveness to input
This commit is contained in:
parent
a06928e6da
commit
50befb5a0f
25
src/main.rs
25
src/main.rs
|
@ -304,6 +304,12 @@ fn main2() {
|
|||
|
||||
let mut last_resource_version = 0;
|
||||
events_loop.run(move |event, _event_loop, control_flow| {
|
||||
*control_flow = glutin::event_loop::ControlFlow::Poll;
|
||||
|
||||
if !handle_window_event(&mut window, &mut game, &mut ui_container, event) {
|
||||
return;
|
||||
}
|
||||
|
||||
let now = Instant::now();
|
||||
let diff = now.duration_since(last_frame);
|
||||
last_frame = now;
|
||||
|
@ -359,8 +365,6 @@ fn main2() {
|
|||
}
|
||||
window.swap_buffers().expect("Failed to swap GL buffers");
|
||||
|
||||
handle_window_event(&mut window, &mut game, &mut ui_container, event);
|
||||
|
||||
if game.should_close {
|
||||
*control_flow = glutin::event_loop::ControlFlow::Exit;
|
||||
}
|
||||
|
@ -370,9 +374,10 @@ fn main2() {
|
|||
fn handle_window_event<T>(window: &mut glutin::WindowedContext<glutin::PossiblyCurrent>,
|
||||
game: &mut Game,
|
||||
ui_container: &mut ui::Container,
|
||||
event: glutin::event::Event<T>) {
|
||||
event: glutin::event::Event<T>) -> bool {
|
||||
use glutin::event::*;
|
||||
match event {
|
||||
Event::MainEventsCleared => return true,
|
||||
Event::DeviceEvent{event, ..} => match event {
|
||||
DeviceEvent::ModifiersChanged(modifiers_state) => {
|
||||
game.is_ctrl_pressed = modifiers_state.ctrl();
|
||||
|
@ -443,12 +448,12 @@ fn handle_window_event<T>(window: &mut glutin::WindowedContext<glutin::PossiblyC
|
|||
game.focused = true;
|
||||
window.window().set_cursor_grab(true).unwrap();
|
||||
window.window().set_cursor_visible(false);
|
||||
return;
|
||||
}
|
||||
if !game.focused {
|
||||
window.window().set_cursor_grab(false).unwrap();
|
||||
window.window().set_cursor_visible(true);
|
||||
ui_container.click_at(game, game.last_mouse_x, game.last_mouse_y, width, height);
|
||||
} else {
|
||||
if !game.focused {
|
||||
window.window().set_cursor_grab(false).unwrap();
|
||||
window.window().set_cursor_visible(true);
|
||||
ui_container.click_at(game, game.last_mouse_x, game.last_mouse_y, width, height);
|
||||
}
|
||||
}
|
||||
},
|
||||
(ElementState::Pressed, MouseButton::Right) => {
|
||||
|
@ -538,4 +543,6 @@ fn handle_window_event<T>(window: &mut glutin::WindowedContext<glutin::PossiblyC
|
|||
|
||||
_ => (),
|
||||
}
|
||||
|
||||
false
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue