2015-03-25 23:17:47 +11:00
|
|
|
#[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();
|
2015-03-25 23:17:47 +11:00
|
|
|
window.set_title("glutin - Cursor grabbing test");
|
2015-09-29 02:19:36 +10:00
|
|
|
let _ = unsafe { window.make_current() };
|
2015-03-25 23:17:47 +11:00
|
|
|
|
|
|
|
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,
|
|
|
|
|
2015-06-16 21:48:08 +10:00
|
|
|
a @ Event::MouseMoved(_) => {
|
|
|
|
println!("{:?}", a);
|
|
|
|
},
|
|
|
|
|
|
|
|
_ => (),
|
|
|
|
}
|
|
|
|
|
2015-03-25 23:17:47 +11:00
|
|
|
context.draw_frame((0.0, 1.0, 0.0, 1.0));
|
2015-09-29 02:19:36 +10:00
|
|
|
let _ = window.swap_buffers();
|
2015-03-25 23:17:47 +11:00
|
|
|
}
|
|
|
|
}
|