mirror of
https://github.com/glfw/glfw.git
synced 2024-11-22 13:04:35 +00: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;
|
||||
|
||||
// HACK: Try to use a private message
|
||||
if (shape == GLFW_RESIZE_EW_CURSOR)
|
||||
switch (shape)
|
||||
{
|
||||
case GLFW_RESIZE_EW_CURSOR:
|
||||
cursorSelector = NSSelectorFromString(@"_windowResizeEastWestCursor");
|
||||
else if (shape == GLFW_RESIZE_NS_CURSOR)
|
||||
break;
|
||||
case GLFW_RESIZE_NS_CURSOR:
|
||||
cursorSelector = NSSelectorFromString(@"_windowResizeNorthSouthCursor");
|
||||
else if (shape == GLFW_RESIZE_NWSE_CURSOR)
|
||||
break;
|
||||
case GLFW_RESIZE_NWSE_CURSOR:
|
||||
cursorSelector = NSSelectorFromString(@"_windowResizeNorthWestSouthEastCursor");
|
||||
else if (shape == GLFW_RESIZE_NESW_CURSOR)
|
||||
break;
|
||||
case GLFW_RESIZE_NESW_CURSOR:
|
||||
cursorSelector = NSSelectorFromString(@"_windowResizeNorthEastSouthWestCursor");
|
||||
break;
|
||||
}
|
||||
|
||||
if (cursorSelector && [NSCursor respondsToSelector:cursorSelector])
|
||||
{
|
||||
@ -1653,22 +1660,33 @@ int _glfwPlatformCreateStandardCursor(_GLFWcursor* cursor, int shape)
|
||||
|
||||
if (!cursor->ns.object)
|
||||
{
|
||||
if (shape == GLFW_ARROW_CURSOR)
|
||||
switch (shape)
|
||||
{
|
||||
case GLFW_ARROW_CURSOR:
|
||||
cursor->ns.object = [NSCursor arrowCursor];
|
||||
else if (shape == GLFW_IBEAM_CURSOR)
|
||||
break;
|
||||
case GLFW_IBEAM_CURSOR:
|
||||
cursor->ns.object = [NSCursor IBeamCursor];
|
||||
else if (shape == GLFW_CROSSHAIR_CURSOR)
|
||||
break;
|
||||
case GLFW_CROSSHAIR_CURSOR:
|
||||
cursor->ns.object = [NSCursor crosshairCursor];
|
||||
else if (shape == GLFW_POINTING_HAND_CURSOR)
|
||||
break;
|
||||
case GLFW_POINTING_HAND_CURSOR:
|
||||
cursor->ns.object = [NSCursor pointingHandCursor];
|
||||
else if (shape == GLFW_RESIZE_EW_CURSOR)
|
||||
break;
|
||||
case GLFW_RESIZE_EW_CURSOR:
|
||||
cursor->ns.object = [NSCursor resizeLeftRightCursor];
|
||||
else if (shape == GLFW_RESIZE_NS_CURSOR)
|
||||
break;
|
||||
case GLFW_RESIZE_NS_CURSOR:
|
||||
cursor->ns.object = [NSCursor resizeUpDownCursor];
|
||||
else if (shape == GLFW_RESIZE_ALL_CURSOR)
|
||||
break;
|
||||
case GLFW_RESIZE_ALL_CURSOR:
|
||||
cursor->ns.object = [NSCursor closedHandCursor];
|
||||
else if (shape == GLFW_NOT_ALLOWED_CURSOR)
|
||||
break;
|
||||
case GLFW_NOT_ALLOWED_CURSOR:
|
||||
cursor->ns.object = [NSCursor operationNotAllowedCursor];
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
if (!cursor->ns.object)
|
||||
|
@ -2123,28 +2123,39 @@ int _glfwPlatformCreateStandardCursor(_GLFWcursor* cursor, int shape)
|
||||
{
|
||||
int id = 0;
|
||||
|
||||
if (shape == GLFW_ARROW_CURSOR)
|
||||
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
|
||||
switch (shape)
|
||||
{
|
||||
case GLFW_ARROW_CURSOR:
|
||||
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;
|
||||
}
|
||||
|
@ -1242,26 +1242,39 @@ int _glfwPlatformCreateStandardCursor(_GLFWcursor* cursor, int shape)
|
||||
const char* name = NULL;
|
||||
|
||||
// Try the XDG names first
|
||||
if (shape == GLFW_ARROW_CURSOR)
|
||||
switch (shape)
|
||||
{
|
||||
case GLFW_ARROW_CURSOR:
|
||||
name = "default";
|
||||
else if (shape == GLFW_IBEAM_CURSOR)
|
||||
break;
|
||||
case GLFW_IBEAM_CURSOR:
|
||||
name = "text";
|
||||
else if (shape == GLFW_CROSSHAIR_CURSOR)
|
||||
break;
|
||||
case GLFW_CROSSHAIR_CURSOR:
|
||||
name = "crosshair";
|
||||
else if (shape == GLFW_POINTING_HAND_CURSOR)
|
||||
break;
|
||||
case GLFW_POINTING_HAND_CURSOR:
|
||||
name = "pointer";
|
||||
else if (shape == GLFW_RESIZE_EW_CURSOR)
|
||||
break;
|
||||
case GLFW_RESIZE_EW_CURSOR:
|
||||
name = "ew-resize";
|
||||
else if (shape == GLFW_RESIZE_NS_CURSOR)
|
||||
break;
|
||||
case GLFW_RESIZE_NS_CURSOR:
|
||||
name = "ns-resize";
|
||||
else if (shape == GLFW_RESIZE_NWSE_CURSOR)
|
||||
break;
|
||||
case GLFW_RESIZE_NWSE_CURSOR:
|
||||
name = "nwse-resize";
|
||||
else if (shape == GLFW_RESIZE_NESW_CURSOR)
|
||||
break;
|
||||
case GLFW_RESIZE_NESW_CURSOR:
|
||||
name = "nesw-resize";
|
||||
else if (shape == GLFW_RESIZE_ALL_CURSOR)
|
||||
break;
|
||||
case GLFW_RESIZE_ALL_CURSOR:
|
||||
name = "all-scroll";
|
||||
else if (shape == GLFW_NOT_ALLOWED_CURSOR)
|
||||
break;
|
||||
case GLFW_NOT_ALLOWED_CURSOR:
|
||||
name = "not-allowed";
|
||||
break;
|
||||
}
|
||||
|
||||
cursor->wl.cursor = wl_cursor_theme_get_cursor(_glfw.wl.cursorTheme, name);
|
||||
|
||||
@ -1274,22 +1287,23 @@ int _glfwPlatformCreateStandardCursor(_GLFWcursor* cursor, int shape)
|
||||
if (!cursor->wl.cursor)
|
||||
{
|
||||
// Fall back to the core X11 names
|
||||
if (shape == GLFW_ARROW_CURSOR)
|
||||
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
|
||||
switch (shape)
|
||||
{
|
||||
case GLFW_ARROW_CURSOR:
|
||||
name = "left_ptr";
|
||||
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;
|
||||
|
@ -2935,26 +2935,39 @@ int _glfwPlatformCreateStandardCursor(_GLFWcursor* cursor, int shape)
|
||||
const int size = XcursorGetDefaultSize(_glfw.x11.display);
|
||||
const char* name = NULL;
|
||||
|
||||
if (shape == GLFW_ARROW_CURSOR)
|
||||
switch (shape)
|
||||
{
|
||||
case GLFW_ARROW_CURSOR:
|
||||
name = "default";
|
||||
else if (shape == GLFW_IBEAM_CURSOR)
|
||||
break;
|
||||
case GLFW_IBEAM_CURSOR:
|
||||
name = "text";
|
||||
else if (shape == GLFW_CROSSHAIR_CURSOR)
|
||||
break;
|
||||
case GLFW_CROSSHAIR_CURSOR:
|
||||
name = "crosshair";
|
||||
else if (shape == GLFW_POINTING_HAND_CURSOR)
|
||||
break;
|
||||
case GLFW_POINTING_HAND_CURSOR:
|
||||
name = "pointer";
|
||||
else if (shape == GLFW_RESIZE_EW_CURSOR)
|
||||
break;
|
||||
case GLFW_RESIZE_EW_CURSOR:
|
||||
name = "ew-resize";
|
||||
else if (shape == GLFW_RESIZE_NS_CURSOR)
|
||||
break;
|
||||
case GLFW_RESIZE_NS_CURSOR:
|
||||
name = "ns-resize";
|
||||
else if (shape == GLFW_RESIZE_NWSE_CURSOR)
|
||||
break;
|
||||
case GLFW_RESIZE_NWSE_CURSOR:
|
||||
name = "nwse-resize";
|
||||
else if (shape == GLFW_RESIZE_NESW_CURSOR)
|
||||
break;
|
||||
case GLFW_RESIZE_NESW_CURSOR:
|
||||
name = "nesw-resize";
|
||||
else if (shape == GLFW_RESIZE_ALL_CURSOR)
|
||||
break;
|
||||
case GLFW_RESIZE_ALL_CURSOR:
|
||||
name = "all-scroll";
|
||||
else if (shape == GLFW_NOT_ALLOWED_CURSOR)
|
||||
break;
|
||||
case GLFW_NOT_ALLOWED_CURSOR:
|
||||
name = "not-allowed";
|
||||
break;
|
||||
}
|
||||
|
||||
XcursorImage* image = XcursorLibraryLoadImage(name, theme, size);
|
||||
if (image)
|
||||
@ -2969,22 +2982,30 @@ int _glfwPlatformCreateStandardCursor(_GLFWcursor* cursor, int shape)
|
||||
{
|
||||
unsigned int native = 0;
|
||||
|
||||
if (shape == GLFW_ARROW_CURSOR)
|
||||
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
|
||||
switch (shape)
|
||||
{
|
||||
case GLFW_ARROW_CURSOR:
|
||||
native = XC_left_ptr;
|
||||
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;
|
||||
|
Loading…
Reference in New Issue
Block a user