mirror of
https://github.com/gwm17/glfw.git
synced 2025-01-30 19:08:51 -05:00
Use switch statement instead of if-else-chain for cursor shapes
Closes #1739.
This commit is contained in:
parent
7e8da57094
commit
08e5a17063
|
@ -1635,14 +1635,21 @@ int _glfwPlatformCreateStandardCursor(_GLFWcursor* cursor, int shape)
|
||||||
SEL cursorSelector = NULL;
|
SEL cursorSelector = NULL;
|
||||||
|
|
||||||
// HACK: Try to use a private message
|
// HACK: Try to use a private message
|
||||||
if (shape == GLFW_RESIZE_EW_CURSOR)
|
switch (shape)
|
||||||
cursorSelector = NSSelectorFromString(@"_windowResizeEastWestCursor");
|
{
|
||||||
else if (shape == GLFW_RESIZE_NS_CURSOR)
|
case GLFW_RESIZE_EW_CURSOR:
|
||||||
cursorSelector = NSSelectorFromString(@"_windowResizeNorthSouthCursor");
|
cursorSelector = NSSelectorFromString(@"_windowResizeEastWestCursor");
|
||||||
else if (shape == GLFW_RESIZE_NWSE_CURSOR)
|
break;
|
||||||
cursorSelector = NSSelectorFromString(@"_windowResizeNorthWestSouthEastCursor");
|
case GLFW_RESIZE_NS_CURSOR:
|
||||||
else if (shape == GLFW_RESIZE_NESW_CURSOR)
|
cursorSelector = NSSelectorFromString(@"_windowResizeNorthSouthCursor");
|
||||||
cursorSelector = NSSelectorFromString(@"_windowResizeNorthEastSouthWestCursor");
|
break;
|
||||||
|
case GLFW_RESIZE_NWSE_CURSOR:
|
||||||
|
cursorSelector = NSSelectorFromString(@"_windowResizeNorthWestSouthEastCursor");
|
||||||
|
break;
|
||||||
|
case GLFW_RESIZE_NESW_CURSOR:
|
||||||
|
cursorSelector = NSSelectorFromString(@"_windowResizeNorthEastSouthWestCursor");
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
|
||||||
if (cursorSelector && [NSCursor respondsToSelector:cursorSelector])
|
if (cursorSelector && [NSCursor respondsToSelector:cursorSelector])
|
||||||
{
|
{
|
||||||
|
@ -1653,22 +1660,33 @@ int _glfwPlatformCreateStandardCursor(_GLFWcursor* cursor, int shape)
|
||||||
|
|
||||||
if (!cursor->ns.object)
|
if (!cursor->ns.object)
|
||||||
{
|
{
|
||||||
if (shape == GLFW_ARROW_CURSOR)
|
switch (shape)
|
||||||
cursor->ns.object = [NSCursor arrowCursor];
|
{
|
||||||
else if (shape == GLFW_IBEAM_CURSOR)
|
case GLFW_ARROW_CURSOR:
|
||||||
cursor->ns.object = [NSCursor IBeamCursor];
|
cursor->ns.object = [NSCursor arrowCursor];
|
||||||
else if (shape == GLFW_CROSSHAIR_CURSOR)
|
break;
|
||||||
cursor->ns.object = [NSCursor crosshairCursor];
|
case GLFW_IBEAM_CURSOR:
|
||||||
else if (shape == GLFW_POINTING_HAND_CURSOR)
|
cursor->ns.object = [NSCursor IBeamCursor];
|
||||||
cursor->ns.object = [NSCursor pointingHandCursor];
|
break;
|
||||||
else if (shape == GLFW_RESIZE_EW_CURSOR)
|
case GLFW_CROSSHAIR_CURSOR:
|
||||||
cursor->ns.object = [NSCursor resizeLeftRightCursor];
|
cursor->ns.object = [NSCursor crosshairCursor];
|
||||||
else if (shape == GLFW_RESIZE_NS_CURSOR)
|
break;
|
||||||
cursor->ns.object = [NSCursor resizeUpDownCursor];
|
case GLFW_POINTING_HAND_CURSOR:
|
||||||
else if (shape == GLFW_RESIZE_ALL_CURSOR)
|
cursor->ns.object = [NSCursor pointingHandCursor];
|
||||||
cursor->ns.object = [NSCursor closedHandCursor];
|
break;
|
||||||
else if (shape == GLFW_NOT_ALLOWED_CURSOR)
|
case GLFW_RESIZE_EW_CURSOR:
|
||||||
cursor->ns.object = [NSCursor operationNotAllowedCursor];
|
cursor->ns.object = [NSCursor resizeLeftRightCursor];
|
||||||
|
break;
|
||||||
|
case GLFW_RESIZE_NS_CURSOR:
|
||||||
|
cursor->ns.object = [NSCursor resizeUpDownCursor];
|
||||||
|
break;
|
||||||
|
case GLFW_RESIZE_ALL_CURSOR:
|
||||||
|
cursor->ns.object = [NSCursor closedHandCursor];
|
||||||
|
break;
|
||||||
|
case GLFW_NOT_ALLOWED_CURSOR:
|
||||||
|
cursor->ns.object = [NSCursor operationNotAllowedCursor];
|
||||||
|
break;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!cursor->ns.object)
|
if (!cursor->ns.object)
|
||||||
|
|
|
@ -2123,30 +2123,41 @@ int _glfwPlatformCreateStandardCursor(_GLFWcursor* cursor, int shape)
|
||||||
{
|
{
|
||||||
int id = 0;
|
int id = 0;
|
||||||
|
|
||||||
if (shape == GLFW_ARROW_CURSOR)
|
switch (shape)
|
||||||
id = OCR_NORMAL;
|
|
||||||
else if (shape == GLFW_IBEAM_CURSOR)
|
|
||||||
id = OCR_IBEAM;
|
|
||||||
else if (shape == GLFW_CROSSHAIR_CURSOR)
|
|
||||||
id = OCR_CROSS;
|
|
||||||
else if (shape == GLFW_POINTING_HAND_CURSOR)
|
|
||||||
id = OCR_HAND;
|
|
||||||
else if (shape == GLFW_RESIZE_EW_CURSOR)
|
|
||||||
id = OCR_SIZEWE;
|
|
||||||
else if (shape == GLFW_RESIZE_NS_CURSOR)
|
|
||||||
id = OCR_SIZENS;
|
|
||||||
else if (shape == GLFW_RESIZE_NWSE_CURSOR)
|
|
||||||
id = OCR_SIZENWSE;
|
|
||||||
else if (shape == GLFW_RESIZE_NESW_CURSOR)
|
|
||||||
id = OCR_SIZENESW;
|
|
||||||
else if (shape == GLFW_RESIZE_ALL_CURSOR)
|
|
||||||
id = OCR_SIZEALL;
|
|
||||||
else if (shape == GLFW_NOT_ALLOWED_CURSOR)
|
|
||||||
id = OCR_NO;
|
|
||||||
else
|
|
||||||
{
|
{
|
||||||
_glfwInputError(GLFW_PLATFORM_ERROR, "Win32: Unknown standard cursor");
|
case GLFW_ARROW_CURSOR:
|
||||||
return GLFW_FALSE;
|
id = OCR_NORMAL;
|
||||||
|
break;
|
||||||
|
case GLFW_IBEAM_CURSOR:
|
||||||
|
id = OCR_IBEAM;
|
||||||
|
break;
|
||||||
|
case GLFW_CROSSHAIR_CURSOR:
|
||||||
|
id = OCR_CROSS;
|
||||||
|
break;
|
||||||
|
case GLFW_POINTING_HAND_CURSOR:
|
||||||
|
id = OCR_HAND;
|
||||||
|
break;
|
||||||
|
case GLFW_RESIZE_EW_CURSOR:
|
||||||
|
id = OCR_SIZEWE;
|
||||||
|
break;
|
||||||
|
case GLFW_RESIZE_NS_CURSOR:
|
||||||
|
id = OCR_SIZENS;
|
||||||
|
break;
|
||||||
|
case GLFW_RESIZE_NWSE_CURSOR:
|
||||||
|
id = OCR_SIZENWSE;
|
||||||
|
break;
|
||||||
|
case GLFW_RESIZE_NESW_CURSOR:
|
||||||
|
id = OCR_SIZENESW;
|
||||||
|
break;
|
||||||
|
case GLFW_RESIZE_ALL_CURSOR:
|
||||||
|
id = OCR_SIZEALL;
|
||||||
|
break;
|
||||||
|
case GLFW_NOT_ALLOWED_CURSOR:
|
||||||
|
id = OCR_NO;
|
||||||
|
break;
|
||||||
|
default:
|
||||||
|
_glfwInputError(GLFW_PLATFORM_ERROR, "Win32: Unknown standard cursor");
|
||||||
|
return GLFW_FALSE;
|
||||||
}
|
}
|
||||||
|
|
||||||
cursor->win32.handle = LoadImageW(NULL,
|
cursor->win32.handle = LoadImageW(NULL,
|
||||||
|
|
|
@ -1242,26 +1242,39 @@ int _glfwPlatformCreateStandardCursor(_GLFWcursor* cursor, int shape)
|
||||||
const char* name = NULL;
|
const char* name = NULL;
|
||||||
|
|
||||||
// Try the XDG names first
|
// Try the XDG names first
|
||||||
if (shape == GLFW_ARROW_CURSOR)
|
switch (shape)
|
||||||
name = "default";
|
{
|
||||||
else if (shape == GLFW_IBEAM_CURSOR)
|
case GLFW_ARROW_CURSOR:
|
||||||
name = "text";
|
name = "default";
|
||||||
else if (shape == GLFW_CROSSHAIR_CURSOR)
|
break;
|
||||||
name = "crosshair";
|
case GLFW_IBEAM_CURSOR:
|
||||||
else if (shape == GLFW_POINTING_HAND_CURSOR)
|
name = "text";
|
||||||
name = "pointer";
|
break;
|
||||||
else if (shape == GLFW_RESIZE_EW_CURSOR)
|
case GLFW_CROSSHAIR_CURSOR:
|
||||||
name = "ew-resize";
|
name = "crosshair";
|
||||||
else if (shape == GLFW_RESIZE_NS_CURSOR)
|
break;
|
||||||
name = "ns-resize";
|
case GLFW_POINTING_HAND_CURSOR:
|
||||||
else if (shape == GLFW_RESIZE_NWSE_CURSOR)
|
name = "pointer";
|
||||||
name = "nwse-resize";
|
break;
|
||||||
else if (shape == GLFW_RESIZE_NESW_CURSOR)
|
case GLFW_RESIZE_EW_CURSOR:
|
||||||
name = "nesw-resize";
|
name = "ew-resize";
|
||||||
else if (shape == GLFW_RESIZE_ALL_CURSOR)
|
break;
|
||||||
name = "all-scroll";
|
case GLFW_RESIZE_NS_CURSOR:
|
||||||
else if (shape == GLFW_NOT_ALLOWED_CURSOR)
|
name = "ns-resize";
|
||||||
name = "not-allowed";
|
break;
|
||||||
|
case GLFW_RESIZE_NWSE_CURSOR:
|
||||||
|
name = "nwse-resize";
|
||||||
|
break;
|
||||||
|
case GLFW_RESIZE_NESW_CURSOR:
|
||||||
|
name = "nesw-resize";
|
||||||
|
break;
|
||||||
|
case GLFW_RESIZE_ALL_CURSOR:
|
||||||
|
name = "all-scroll";
|
||||||
|
break;
|
||||||
|
case GLFW_NOT_ALLOWED_CURSOR:
|
||||||
|
name = "not-allowed";
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
|
||||||
cursor->wl.cursor = wl_cursor_theme_get_cursor(_glfw.wl.cursorTheme, name);
|
cursor->wl.cursor = wl_cursor_theme_get_cursor(_glfw.wl.cursorTheme, name);
|
||||||
|
|
||||||
|
@ -1274,25 +1287,26 @@ int _glfwPlatformCreateStandardCursor(_GLFWcursor* cursor, int shape)
|
||||||
if (!cursor->wl.cursor)
|
if (!cursor->wl.cursor)
|
||||||
{
|
{
|
||||||
// Fall back to the core X11 names
|
// Fall back to the core X11 names
|
||||||
if (shape == GLFW_ARROW_CURSOR)
|
switch (shape)
|
||||||
name = "left_ptr";
|
|
||||||
else if (shape == GLFW_IBEAM_CURSOR)
|
|
||||||
name = "xterm";
|
|
||||||
else if (shape == GLFW_CROSSHAIR_CURSOR)
|
|
||||||
name = "crosshair";
|
|
||||||
else if (shape == GLFW_POINTING_HAND_CURSOR)
|
|
||||||
name = "hand2";
|
|
||||||
else if (shape == GLFW_RESIZE_EW_CURSOR)
|
|
||||||
name = "sb_h_double_arrow";
|
|
||||||
else if (shape == GLFW_RESIZE_NS_CURSOR)
|
|
||||||
name = "sb_v_double_arrow";
|
|
||||||
else if (shape == GLFW_RESIZE_ALL_CURSOR)
|
|
||||||
name = "fleur";
|
|
||||||
else
|
|
||||||
{
|
{
|
||||||
_glfwInputError(GLFW_CURSOR_UNAVAILABLE,
|
case GLFW_ARROW_CURSOR:
|
||||||
"Wayland: Standard cursor shape unavailable");
|
name = "left_ptr";
|
||||||
return GLFW_FALSE;
|
case GLFW_IBEAM_CURSOR:
|
||||||
|
name = "xterm";
|
||||||
|
case GLFW_CROSSHAIR_CURSOR:
|
||||||
|
name = "crosshair";
|
||||||
|
case GLFW_POINTING_HAND_CURSOR:
|
||||||
|
name = "hand2";
|
||||||
|
case GLFW_RESIZE_EW_CURSOR:
|
||||||
|
name = "sb_h_double_arrow";
|
||||||
|
case GLFW_RESIZE_NS_CURSOR:
|
||||||
|
name = "sb_v_double_arrow";
|
||||||
|
case GLFW_RESIZE_ALL_CURSOR:
|
||||||
|
name = "fleur";
|
||||||
|
default:
|
||||||
|
_glfwInputError(GLFW_CURSOR_UNAVAILABLE,
|
||||||
|
"Wayland: Standard cursor shape unavailable");
|
||||||
|
return GLFW_FALSE;
|
||||||
}
|
}
|
||||||
|
|
||||||
cursor->wl.cursor = wl_cursor_theme_get_cursor(_glfw.wl.cursorTheme, name);
|
cursor->wl.cursor = wl_cursor_theme_get_cursor(_glfw.wl.cursorTheme, name);
|
||||||
|
|
|
@ -2935,26 +2935,39 @@ int _glfwPlatformCreateStandardCursor(_GLFWcursor* cursor, int shape)
|
||||||
const int size = XcursorGetDefaultSize(_glfw.x11.display);
|
const int size = XcursorGetDefaultSize(_glfw.x11.display);
|
||||||
const char* name = NULL;
|
const char* name = NULL;
|
||||||
|
|
||||||
if (shape == GLFW_ARROW_CURSOR)
|
switch (shape)
|
||||||
name = "default";
|
{
|
||||||
else if (shape == GLFW_IBEAM_CURSOR)
|
case GLFW_ARROW_CURSOR:
|
||||||
name = "text";
|
name = "default";
|
||||||
else if (shape == GLFW_CROSSHAIR_CURSOR)
|
break;
|
||||||
name = "crosshair";
|
case GLFW_IBEAM_CURSOR:
|
||||||
else if (shape == GLFW_POINTING_HAND_CURSOR)
|
name = "text";
|
||||||
name = "pointer";
|
break;
|
||||||
else if (shape == GLFW_RESIZE_EW_CURSOR)
|
case GLFW_CROSSHAIR_CURSOR:
|
||||||
name = "ew-resize";
|
name = "crosshair";
|
||||||
else if (shape == GLFW_RESIZE_NS_CURSOR)
|
break;
|
||||||
name = "ns-resize";
|
case GLFW_POINTING_HAND_CURSOR:
|
||||||
else if (shape == GLFW_RESIZE_NWSE_CURSOR)
|
name = "pointer";
|
||||||
name = "nwse-resize";
|
break;
|
||||||
else if (shape == GLFW_RESIZE_NESW_CURSOR)
|
case GLFW_RESIZE_EW_CURSOR:
|
||||||
name = "nesw-resize";
|
name = "ew-resize";
|
||||||
else if (shape == GLFW_RESIZE_ALL_CURSOR)
|
break;
|
||||||
name = "all-scroll";
|
case GLFW_RESIZE_NS_CURSOR:
|
||||||
else if (shape == GLFW_NOT_ALLOWED_CURSOR)
|
name = "ns-resize";
|
||||||
name = "not-allowed";
|
break;
|
||||||
|
case GLFW_RESIZE_NWSE_CURSOR:
|
||||||
|
name = "nwse-resize";
|
||||||
|
break;
|
||||||
|
case GLFW_RESIZE_NESW_CURSOR:
|
||||||
|
name = "nesw-resize";
|
||||||
|
break;
|
||||||
|
case GLFW_RESIZE_ALL_CURSOR:
|
||||||
|
name = "all-scroll";
|
||||||
|
break;
|
||||||
|
case GLFW_NOT_ALLOWED_CURSOR:
|
||||||
|
name = "not-allowed";
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
|
||||||
XcursorImage* image = XcursorLibraryLoadImage(name, theme, size);
|
XcursorImage* image = XcursorLibraryLoadImage(name, theme, size);
|
||||||
if (image)
|
if (image)
|
||||||
|
@ -2969,25 +2982,33 @@ int _glfwPlatformCreateStandardCursor(_GLFWcursor* cursor, int shape)
|
||||||
{
|
{
|
||||||
unsigned int native = 0;
|
unsigned int native = 0;
|
||||||
|
|
||||||
if (shape == GLFW_ARROW_CURSOR)
|
switch (shape)
|
||||||
native = XC_left_ptr;
|
|
||||||
else if (shape == GLFW_IBEAM_CURSOR)
|
|
||||||
native = XC_xterm;
|
|
||||||
else if (shape == GLFW_CROSSHAIR_CURSOR)
|
|
||||||
native = XC_crosshair;
|
|
||||||
else if (shape == GLFW_POINTING_HAND_CURSOR)
|
|
||||||
native = XC_hand2;
|
|
||||||
else if (shape == GLFW_RESIZE_EW_CURSOR)
|
|
||||||
native = XC_sb_h_double_arrow;
|
|
||||||
else if (shape == GLFW_RESIZE_NS_CURSOR)
|
|
||||||
native = XC_sb_v_double_arrow;
|
|
||||||
else if (shape == GLFW_RESIZE_ALL_CURSOR)
|
|
||||||
native = XC_fleur;
|
|
||||||
else
|
|
||||||
{
|
{
|
||||||
_glfwInputError(GLFW_CURSOR_UNAVAILABLE,
|
case GLFW_ARROW_CURSOR:
|
||||||
"X11: Standard cursor shape unavailable");
|
native = XC_left_ptr;
|
||||||
return GLFW_FALSE;
|
break;
|
||||||
|
case GLFW_IBEAM_CURSOR:
|
||||||
|
native = XC_xterm;
|
||||||
|
break;
|
||||||
|
case GLFW_CROSSHAIR_CURSOR:
|
||||||
|
native = XC_crosshair;
|
||||||
|
break;
|
||||||
|
case GLFW_POINTING_HAND_CURSOR:
|
||||||
|
native = XC_hand2;
|
||||||
|
break;
|
||||||
|
case GLFW_RESIZE_EW_CURSOR:
|
||||||
|
native = XC_sb_h_double_arrow;
|
||||||
|
break;
|
||||||
|
case GLFW_RESIZE_NS_CURSOR:
|
||||||
|
native = XC_sb_v_double_arrow;
|
||||||
|
break;
|
||||||
|
case GLFW_RESIZE_ALL_CURSOR:
|
||||||
|
native = XC_fleur;
|
||||||
|
break;
|
||||||
|
default:
|
||||||
|
_glfwInputError(GLFW_CURSOR_UNAVAILABLE,
|
||||||
|
"X11: Standard cursor shape unavailable");
|
||||||
|
return GLFW_FALSE;
|
||||||
}
|
}
|
||||||
|
|
||||||
cursor->x11.handle = XCreateFontCursor(_glfw.x11.display, native);
|
cursor->x11.handle = XCreateFontCursor(_glfw.x11.display, native);
|
||||||
|
|
Loading…
Reference in New Issue
Block a user