winit-sonoma-fix/examples/grabbing.rs

49 lines
1.3 KiB
Rust
Raw Normal View History

#[cfg(target_os = "android")]
#[macro_use]
extern crate android_glue;
extern crate glutin;
use glutin::{Event, ElementState};
mod support;
#[cfg(target_os = "android")]
android_start!(main);
fn main() {
2015-08-06 06:31:34 +10:00
let window = glutin::WindowBuilder::new().build().unwrap();
window.set_title("glutin - Cursor grabbing test");
2015-09-29 02:19:36 +10:00
let _ = unsafe { window.make_current() };
let context = support::load(&window);
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;
window.set_cursor_state(glutin::CursorState::Normal)
.ok().expect("could not ungrab mouse cursor");
} else {
grabbed = true;
window.set_cursor_state(glutin::CursorState::Grab)
.ok().expect("could not grab mouse cursor");
}
},
2015-12-27 01:47:25 +11:00
Event::Closed => break,
a @ Event::MouseMoved(_, _) => {
2015-06-16 21:48:08 +10:00
println!("{:?}", a);
},
_ => (),
}
context.draw_frame((0.0, 1.0, 0.0, 1.0));
2015-09-29 02:19:36 +10:00
let _ = window.swap_buffers();
}
}