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.
This commit is contained in:
parent
318f0d2d06
commit
b532b8c65f
9 changed files with 174 additions and 3 deletions
|
|
@ -1,4 +1,4 @@
|
|||
use {Event, BuilderAttribs};
|
||||
use {Event, BuilderAttribs, MouseCursor};
|
||||
use CreationError;
|
||||
use CreationError::OsError;
|
||||
use libc;
|
||||
|
|
@ -611,4 +611,48 @@ impl Window {
|
|||
|
||||
pub fn set_window_resize_callback(&mut self, _: Option<fn(uint, uint)>) {
|
||||
}
|
||||
|
||||
pub fn set_cursor(&self, cursor: MouseCursor) {
|
||||
unsafe {
|
||||
use std::ffi::CString;
|
||||
let cursor_name = match cursor {
|
||||
MouseCursor::Default => "left_ptr",
|
||||
MouseCursor::Crosshair => "crosshair",
|
||||
MouseCursor::Hand => "hand",
|
||||
MouseCursor::Arrow => "arrow",
|
||||
MouseCursor::Move => "fleur",
|
||||
MouseCursor::Text => "xterm",
|
||||
MouseCursor::Wait => "watch",
|
||||
MouseCursor::Help => "question_arrow",
|
||||
MouseCursor::Progress => "watch", // TODO: Find better matching X11 cursor
|
||||
MouseCursor::EResize => "right_side",
|
||||
MouseCursor::NResize => "top_side",
|
||||
MouseCursor::NeResize => "top_right_corner",
|
||||
MouseCursor::NwResize => "top_left_corner",
|
||||
MouseCursor::SResize => "bottom_side",
|
||||
MouseCursor::SeResize => "bottom_right_corner",
|
||||
MouseCursor::SwResize => "bottom_left_corner",
|
||||
MouseCursor::WResize => "left_side",
|
||||
MouseCursor::EwResize => "h_double_arrow",
|
||||
MouseCursor::NsResize => "v_double_arrow",
|
||||
|
||||
|
||||
MouseCursor::NeswResize | MouseCursor::NwseResize => "sizing", // TODO: Better matching X11 cursor
|
||||
|
||||
MouseCursor::ColResize | MouseCursor::RowResize => "double_arrow", // TODO: Better matching X11 cursor
|
||||
|
||||
/// TODO: Find matching X11 cursors
|
||||
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 => "left_ptr",
|
||||
};
|
||||
let c_string = CString::from_slice(cursor_name.as_bytes());
|
||||
let xcursor = ffi::XcursorLibraryLoadCursor(self.x.display, c_string.as_ptr());
|
||||
ffi::XDefineCursor (self.x.display, self.x.window, xcursor);
|
||||
ffi::XFlush(self.x.display);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue