2016-03-27 04:07:52 +11:00
|
|
|
extern crate winit;
|
2015-03-25 23:17:47 +11:00
|
|
|
|
2016-03-27 04:07:52 +11:00
|
|
|
use winit::{Event, ElementState};
|
2015-03-25 23:17:47 +11:00
|
|
|
|
|
|
|
fn main() {
|
2016-03-27 04:07:52 +11:00
|
|
|
let window = winit::WindowBuilder::new().build().unwrap();
|
|
|
|
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
|
|
|
|
|
|
|
for event in window.wait_events() {
|
2015-06-16 21:48:08 +10:00
|
|
|
match event {
|
|
|
|
Event::KeyboardInput(ElementState::Pressed, _, _) => {
|
|
|
|
if grabbed {
|
|
|
|
grabbed = false;
|
2016-03-27 04:07:52 +11:00
|
|
|
window.set_cursor_state(winit::CursorState::Normal)
|
2015-06-16 21:48:08 +10:00
|
|
|
.ok().expect("could not ungrab mouse cursor");
|
|
|
|
} else {
|
|
|
|
grabbed = true;
|
2016-03-27 04:07:52 +11:00
|
|
|
window.set_cursor_state(winit::CursorState::Grab)
|
2015-06-16 21:48:08 +10:00
|
|
|
.ok().expect("could not grab mouse cursor");
|
|
|
|
}
|
|
|
|
},
|
|
|
|
|
2015-12-27 01:47:25 +11:00
|
|
|
Event::Closed => break,
|
|
|
|
|
2016-03-28 05:39:20 +11:00
|
|
|
a @ Event::MouseMoved(_, _) => {
|
2015-06-16 21:48:08 +10:00
|
|
|
println!("{:?}", a);
|
|
|
|
},
|
|
|
|
|
|
|
|
_ => (),
|
|
|
|
}
|
2015-03-25 23:17:47 +11:00
|
|
|
}
|
|
|
|
}
|