2016-03-27 04:07:52 +11:00
|
|
|
extern crate winit;
|
2015-03-25 23:17:47 +11:00
|
|
|
|
2017-06-08 00:12:41 +10:00
|
|
|
use winit::{ControlFlow, WindowEvent, ElementState, KeyboardInput};
|
2015-03-25 23:17:47 +11:00
|
|
|
|
|
|
|
fn main() {
|
2017-06-08 00:12:41 +10:00
|
|
|
let mut events_loop = winit::EventsLoop::new();
|
2017-01-29 01:45:01 +11:00
|
|
|
|
|
|
|
let window = winit::WindowBuilder::new().build(&events_loop).unwrap();
|
2016-03-27 04:07:52 +11:00
|
|
|
window.set_title("winit - Cursor grabbing test");
|
2015-03-25 23:17:47 +11:00
|
|
|
|
|
|
|
let mut grabbed = false;
|
2015-12-27 01:47:25 +11:00
|
|
|
|
2017-01-29 01:45:01 +11:00
|
|
|
events_loop.run_forever(|event| {
|
|
|
|
println!("{:?}", event);
|
|
|
|
|
2015-06-16 21:48:08 +10:00
|
|
|
match event {
|
2017-01-29 01:45:01 +11:00
|
|
|
winit::Event::WindowEvent { event, .. } => {
|
|
|
|
match event {
|
2017-04-23 06:52:35 +10:00
|
|
|
WindowEvent::KeyboardInput { input: KeyboardInput { state: ElementState::Pressed, .. }, .. } => {
|
2017-01-29 01:45:01 +11:00
|
|
|
if grabbed {
|
|
|
|
grabbed = false;
|
|
|
|
window.set_cursor_state(winit::CursorState::Normal)
|
|
|
|
.ok().expect("could not ungrab mouse cursor");
|
|
|
|
} else {
|
|
|
|
grabbed = true;
|
|
|
|
window.set_cursor_state(winit::CursorState::Grab)
|
|
|
|
.ok().expect("could not grab mouse cursor");
|
|
|
|
}
|
|
|
|
},
|
2015-06-16 21:48:08 +10:00
|
|
|
|
2018-04-25 06:20:40 +10:00
|
|
|
WindowEvent::CloseRequested => return ControlFlow::Break,
|
2015-12-27 01:47:25 +11:00
|
|
|
|
2017-11-13 07:56:57 +11:00
|
|
|
a @ WindowEvent::CursorMoved { .. } => {
|
2017-01-29 01:45:01 +11:00
|
|
|
println!("{:?}", a);
|
|
|
|
},
|
2015-06-16 21:48:08 +10:00
|
|
|
|
2017-01-29 01:45:01 +11:00
|
|
|
_ => (),
|
|
|
|
}
|
2017-04-23 06:52:35 +10:00
|
|
|
}
|
|
|
|
_ => {}
|
2015-06-16 21:48:08 +10:00
|
|
|
}
|
2017-06-08 00:12:41 +10:00
|
|
|
|
|
|
|
ControlFlow::Continue
|
2017-01-29 01:45:01 +11:00
|
|
|
});
|
2015-03-25 23:17:47 +11:00
|
|
|
}
|