From cdfb8223301faba2c478c805b35ca457e6547629 Mon Sep 17 00:00:00 2001 From: falkTX Date: Fri, 27 May 2022 00:30:12 +0100 Subject: Add diagonal cursors --- examples/pugl_cursor_demo.c | 4 ++-- include/pugl/pugl.h | 16 +++++++++------- src/mac.m | 17 +++++++++++++++++ src/win.c | 16 +++++++++------- src/x11.c | 6 ++++-- 5 files changed, 41 insertions(+), 18 deletions(-) diff --git a/examples/pugl_cursor_demo.c b/examples/pugl_cursor_demo.c index c9839da..ccece41 100644 --- a/examples/pugl_cursor_demo.c +++ b/examples/pugl_cursor_demo.c @@ -8,9 +8,9 @@ #include -static const int N_CURSORS = 7; +static const int N_CURSORS = 9; static const int N_ROWS = 2; -static const int N_COLS = 4; +static const int N_COLS = 5; typedef struct { PuglWorld* world; diff --git a/include/pugl/pugl.h b/include/pugl/pugl.h index b928c9e..67b1e60 100644 --- a/include/pugl/pugl.h +++ b/include/pugl/pugl.h @@ -1261,13 +1261,15 @@ puglPostRedisplayRect(PuglView* view, PuglRect rect); Windows. */ typedef enum { - PUGL_CURSOR_ARROW, ///< Default pointing arrow - PUGL_CURSOR_CARET, ///< Caret (I-Beam) for text entry - PUGL_CURSOR_CROSSHAIR, ///< Cross-hair - PUGL_CURSOR_HAND, ///< Hand with a pointing finger - PUGL_CURSOR_NO, ///< Operation not allowed - PUGL_CURSOR_LEFT_RIGHT, ///< Left/right arrow for horizontal resize - PUGL_CURSOR_UP_DOWN, ///< Up/down arrow for vertical resize + PUGL_CURSOR_ARROW, ///< Default pointing arrow + PUGL_CURSOR_CARET, ///< Caret (I-Beam) for text entry + PUGL_CURSOR_CROSSHAIR, ///< Cross-hair + PUGL_CURSOR_HAND, ///< Hand with a pointing finger + PUGL_CURSOR_NO, ///< Operation not allowed + PUGL_CURSOR_LEFT_RIGHT, ///< Left/right arrow for horizontal resize + PUGL_CURSOR_UP_DOWN, ///< Up/down arrow for vertical resize + PUGL_CURSOR_UP_LEFT_DOWN_RIGHT, ///< Diagonal arrow for down/right resize + PUGL_CURSOR_UP_RIGHT_DOWN_LEFT, ///< Diagonal arrow for down/left resize } PuglCursor; /// The number of #PuglCursor values diff --git a/src/mac.m b/src/mac.m index f93f80c..ab8ea68 100644 --- a/src/mac.m +++ b/src/mac.m @@ -1671,6 +1671,19 @@ puglGetClipboard(PuglView* const view, return [data bytes]; } +static NSCursor* +extendedCursor(const SEL cursorSelector) +{ + if (cursorSelector && [NSCursor respondsToSelector:cursorSelector]) { + const id object = [NSCursor performSelector:cursorSelector]; + if ([object isKindOfClass:[NSCursor class]]) { + return (NSCursor*)object; + } + } + + return NULL; +} + static NSCursor* puglGetNsCursor(const PuglCursor cursor) { @@ -1689,6 +1702,10 @@ puglGetNsCursor(const PuglCursor cursor) return [NSCursor resizeLeftRightCursor]; case PUGL_CURSOR_UP_DOWN: return [NSCursor resizeUpDownCursor]; + case PUGL_CURSOR_UP_LEFT_DOWN_RIGHT: + return extendedCursor(@selector(_windowResizeNorthWestSouthEastCursor)); + case PUGL_CURSOR_UP_RIGHT_DOWN_LEFT: + return extendedCursor(@selector(_windowResizeNorthEastSouthWestCursor)); } return NULL; diff --git a/src/win.c b/src/win.c index 75915d7..639f200 100644 --- a/src/win.c +++ b/src/win.c @@ -1295,13 +1295,15 @@ puglPaste(PuglView* const view) } static const char* const cursor_ids[] = { - IDC_ARROW, // ARROW - IDC_IBEAM, // CARET - IDC_CROSS, // CROSSHAIR - IDC_HAND, // HAND - IDC_NO, // NO - IDC_SIZEWE, // LEFT_RIGHT - IDC_SIZENS, // UP_DOWN + IDC_ARROW, // ARROW + IDC_IBEAM, // CARET + IDC_CROSS, // CROSSHAIR + IDC_HAND, // HAND + IDC_NO, // NO + IDC_SIZEWE, // LEFT_RIGHT + IDC_SIZENS, // UP_DOWN + IDC_SIZENWSE, // UP_LEFT_DOWN_RIGHT + IDC_SIZENESW, // UP_RIGHT_DOWN_LEFT }; PuglStatus diff --git a/src/x11.c b/src/x11.c index b6b6695..ac4950d 100644 --- a/src/x11.c +++ b/src/x11.c @@ -66,7 +66,7 @@ enum WmClientStateMessageAction { WM_STATE_TOGGLE }; -#define NUM_CURSORS ((unsigned)PUGL_CURSOR_UP_DOWN + 1U) +#define NUM_CURSORS ((unsigned)PUGL_CURSOR_UP_RIGHT_DOWN_LEFT + 1U) #ifdef HAVE_XCURSOR static const char* const cursor_names[NUM_CURSORS] = { @@ -76,7 +76,9 @@ static const char* const cursor_names[NUM_CURSORS] = { "pointer", // HAND "not-allowed", // NO "sb_h_double_arrow", // LEFT_RIGHT - "sb_v_double_arrow" // UP_DOWN + "sb_v_double_arrow", // UP_DOWN + "size_fdiag", // UP_LEFT_DOWN_RIGHT + "size_bdiag", // UP_RIGHT_DOWN_LEFT }; #endif -- cgit v1.2.1