-
Notifications
You must be signed in to change notification settings - Fork 58
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Handle set_mouse_cursor method on windows (#186)
This adds the ability to change the cursor on Windows platforms. For some reason there are very few default cursors included in Windows so a lot of cursors available on other platforms aren't available yet, which is why many of the `MouseCursor` options just maps to `IDC_ARROW`. I'll look into adding custom cursors next. `LoadCursorW` is supposedly superseded by [LoadImageW](https://learn.microsoft.com/en-us/windows/win32/api/winuser/nf-winuser-loadcursorw) but I couldn't find a way to do it with that one that doesn't crash. Tested with Vizia's cursor icon example [here](https://github.com/Fredemus/vizia/tree/baseview-window-events) and everything seems to work as it should. Also tested by hovering over some buttons on a plugin.
- Loading branch information
Showing
3 changed files
with
93 additions
and
12 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,54 @@ | ||
use crate::MouseCursor; | ||
use winapi::{ | ||
shared::ntdef::LPCWSTR, | ||
um::winuser::{ | ||
IDC_APPSTARTING, IDC_ARROW, IDC_CROSS, IDC_HAND, IDC_HELP, IDC_IBEAM, IDC_NO, IDC_SIZEALL, | ||
IDC_SIZENESW, IDC_SIZENS, IDC_SIZENWSE, IDC_SIZEWE, IDC_WAIT, | ||
}, | ||
}; | ||
|
||
pub fn cursor_to_lpcwstr(cursor: MouseCursor) -> LPCWSTR { | ||
match cursor { | ||
MouseCursor::Default => IDC_ARROW, | ||
MouseCursor::Hand => IDC_HAND, | ||
MouseCursor::HandGrabbing => IDC_SIZEALL, | ||
MouseCursor::Help => IDC_HELP, | ||
// an empty LPCWSTR results in the cursor being hidden | ||
MouseCursor::Hidden => std::ptr::null(), | ||
|
||
MouseCursor::Text => IDC_IBEAM, | ||
MouseCursor::VerticalText => IDC_IBEAM, | ||
|
||
MouseCursor::Working => IDC_WAIT, | ||
MouseCursor::PtrWorking => IDC_APPSTARTING, | ||
|
||
MouseCursor::NotAllowed => IDC_NO, | ||
MouseCursor::PtrNotAllowed => IDC_NO, | ||
|
||
MouseCursor::ZoomIn => IDC_ARROW, | ||
MouseCursor::ZoomOut => IDC_ARROW, | ||
|
||
MouseCursor::Alias => IDC_ARROW, | ||
MouseCursor::Copy => IDC_ARROW, | ||
MouseCursor::Move => IDC_SIZEALL, | ||
MouseCursor::AllScroll => IDC_SIZEALL, | ||
MouseCursor::Cell => IDC_CROSS, | ||
MouseCursor::Crosshair => IDC_CROSS, | ||
|
||
MouseCursor::EResize => IDC_SIZEWE, | ||
MouseCursor::NResize => IDC_SIZENS, | ||
MouseCursor::NeResize => IDC_SIZENESW, | ||
MouseCursor::NwResize => IDC_SIZENWSE, | ||
MouseCursor::SResize => IDC_SIZENS, | ||
MouseCursor::SeResize => IDC_SIZENWSE, | ||
MouseCursor::SwResize => IDC_SIZENESW, | ||
MouseCursor::WResize => IDC_SIZEWE, | ||
MouseCursor::EwResize => IDC_SIZEWE, | ||
MouseCursor::NsResize => IDC_SIZENS, | ||
MouseCursor::NwseResize => IDC_SIZENWSE, | ||
MouseCursor::NeswResize => IDC_SIZENESW, | ||
|
||
MouseCursor::ColResize => IDC_SIZEWE, | ||
MouseCursor::RowResize => IDC_SIZENS, | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,4 @@ | ||
mod cursor; | ||
mod drop_target; | ||
mod keyboard; | ||
mod window; | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters