From b532b8c65fd1828fd7d742d0994c6118880d07f0 Mon Sep 17 00:00:00 2001 From: Bryan Bell Date: Mon, 12 Jan 2015 16:22:37 -0800 Subject: Add mouse cursor support Add a new api, window.set_cursor, for setting the cursor. The enum MouseCursor lists the possible cursors. Only X11 is implemented. On OSX, Android, & Win32 the window.set_cursor function either does nothing or calls the "unimplemented!" macro. --- examples/cursor.rs | 49 +++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 49 insertions(+) create mode 100644 examples/cursor.rs (limited to 'examples') 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; + } + }, + _ => (), + } + + } + + } +} -- cgit v1.2.3