diff options
author | tomaka <pierre.krieger1708@gmail.com> | 2015-01-13 10:43:46 +0100 |
---|---|---|
committer | tomaka <pierre.krieger1708@gmail.com> | 2015-01-13 10:43:46 +0100 |
commit | 05a03fb6a1232621e570fe46a82c6088c74696a9 (patch) | |
tree | f066387449265cb233fbc6040a0902a6a4df9360 /examples/cursor.rs | |
parent | 88fd84f5952ba9fc758957bdc55b911ec694d46b (diff) | |
parent | 0fba0a9a734dcc7c30f9c369d6481a9b1d33828c (diff) | |
download | glutin-05a03fb6a1232621e570fe46a82c6088c74696a9.tar.gz glutin-05a03fb6a1232621e570fe46a82c6088c74696a9.zip |
Merge pull request #192 from bjwbell/mouse-cursors
Add mouse cursor support
Diffstat (limited to 'examples/cursor.rs')
-rw-r--r-- | examples/cursor.rs | 49 |
1 files changed, 49 insertions, 0 deletions
diff --git a/examples/cursor.rs b/examples/cursor.rs new file mode 100644 index 0000000..0dced66 --- /dev/null +++ b/examples/cursor.rs @@ -0,0 +1,49 @@ +#[cfg(target_os = "android")] +#[macro_use] +extern crate android_glue; + +extern crate glutin; + +use glutin::{Event, ElementState, MouseCursor}; + +mod support; + +#[cfg(target_os = "android")] +android_start!(main); + +#[cfg(not(feature = "window"))] +fn main() { println!("This example requires glutin to be compiled with the `window` feature"); } + +#[cfg(feature = "window")] +fn main() { + + let mut window = glutin::Window::new().unwrap(); + window.set_title("A fantastic window!"); + unsafe { window.make_current() }; + + let context = support::load(&window); + let cursors = [MouseCursor::Default, MouseCursor::Crosshair, MouseCursor::Hand, MouseCursor::Arrow, MouseCursor::Move, MouseCursor::Text, MouseCursor::Wait, MouseCursor::Help, MouseCursor::Progress, MouseCursor::NotAllowed, MouseCursor::ContextMenu, MouseCursor::NoneCursor, MouseCursor::Cell, MouseCursor::VerticalText, MouseCursor::Alias, MouseCursor::Copy, MouseCursor::NoDrop, MouseCursor::Grab, MouseCursor::Grabbing, MouseCursor::AllScroll, MouseCursor::ZoomIn, MouseCursor::ZoomOut, MouseCursor::EResize, MouseCursor::NResize, MouseCursor::NeResize, MouseCursor::NwResize, MouseCursor::SResize, MouseCursor::SeResize, MouseCursor::SwResize, MouseCursor::WResize, MouseCursor::EwResize, MouseCursor::NsResize, MouseCursor::NeswResize, MouseCursor::NwseResize, MouseCursor::ColResize, MouseCursor::RowResize]; + let mut cursor_idx = 0; + + while !window.is_closed() { + context.draw_frame((0.0, 1.0, 0.0, 1.0)); + window.swap_buffers(); + + for event in window.wait_events() { + match event { + Event::KeyboardInput(ElementState::Pressed, _, _) => { + println!("Setting cursor to \"{:?}\"", cursors[cursor_idx]); + window.set_cursor(cursors[cursor_idx]); + if cursor_idx < cursors.len() - 1 { + cursor_idx += 1; + } else { + cursor_idx = 0; + } + }, + _ => (), + } + + } + + } +} |