aboutsummaryrefslogtreecommitdiffstats
path: root/examples
diff options
context:
space:
mode:
authorBryan Bell <bryan.w.bell@gmail.com>2015-01-12 16:22:37 -0800
committerBryan Bell <bryan.w.bell@gmail.com>2015-01-12 16:22:37 -0800
commitb532b8c65fd1828fd7d742d0994c6118880d07f0 (patch)
tree21931aaa0baf32a3da5b0a2f37ff213842d5a9c7 /examples
parent318f0d2d0662194d84836899d3077b33f0f8196f (diff)
downloadglutin-b532b8c65fd1828fd7d742d0994c6118880d07f0.tar.gz
glutin-b532b8c65fd1828fd7d742d0994c6118880d07f0.zip
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.
Diffstat (limited to 'examples')
-rw-r--r--examples/cursor.rs49
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;
+ }
+ },
+ _ => (),
+ }
+
+ }
+
+ }
+}