ref: fbb518d82487118bc5403a798895642bf7ad4304
parent: 8abfdf1aeef6a20ad1051220cd59e63faf18edeb
author: Iliyas Jorio <[email protected]>
date: Mon Feb 6 13:57:32 EST 2023
Show hand cursor when hovering over clickable area
--- a/src/SDLU.cpp
+++ b/src/SDLU.cpp
@@ -27,6 +27,10 @@
static int s_mouseButton;
static MPoint s_mousePosition;
+// system mouse cursors
+static SDL_Cursor* s_standardCursor = NULL;
+static SDL_Cursor* s_handCursor = NULL;
+
// for event loop
static MBoolean s_isForeground = true;
@@ -206,6 +210,9 @@
s_grayscalePalette = SDL_AllocPalette(256);
SDL_SetPaletteColors(s_grayscalePalette, grayscaleColors, 0, arrsize(grayscaleColors));
+
+ s_standardCursor = SDL_CreateSystemCursor(SDL_SYSTEM_CURSOR_ARROW);
+ s_handCursor = SDL_CreateSystemCursor(SDL_SYSTEM_CURSOR_HAND);
}
@@ -503,6 +510,32 @@
#endif
s_fpsAccumulator = 0;
s_fpsSampleStart = now;
+ }
+#endif
+}
+
+
+void SDLU_SetSystemCursor(int which)
+{
+#if USE_CURSOR_SPRITE
+ SDL_ShowCursor(SDL_DISABLE);
+#else
+ switch (which)
+ {
+ case SYSTEM_CURSOR_OFF:
+ SDL_ShowCursor(SDL_DISABLE);
+ SDL_SetCursor(s_standardCursor);
+ break;
+
+ case SYSTEM_CURSOR_ARROW:
+ SDL_SetCursor(s_standardCursor);
+ SDL_ShowCursor(SDL_ENABLE);
+ break;
+
+ case SYSTEM_CURSOR_HAND:
+ SDL_SetCursor(s_handCursor);
+ SDL_ShowCursor(SDL_ENABLE);
+ break;
}
#endif
}
--- a/src/SDLU.h
+++ b/src/SDLU.h
@@ -23,6 +23,10 @@
#define BYTES_PER_MASK_PIXEL 1
#define MASK_DEPTH 8
+#define SYSTEM_CURSOR_OFF 0
+#define SYSTEM_CURSOR_ARROW 1
+#define SYSTEM_CURSOR_HAND 2
+
void SDLU_Init();
void SDLU_CreateRendererTexture();
SDL_Rect* SDLU_MRectToSDLRect( const MRect* in, SDL_Rect* out );
@@ -46,3 +50,4 @@
MBoolean SDLU_CheckSDLTyping(SDL_Keycode* sdlKey);
MBoolean SDLU_IsForeground();
void SDLU_Present();
+void SDLU_SetSystemCursor(int which);
--- a/src/level.cpp
+++ b/src/level.cpp
@@ -188,8 +188,6 @@
#if USE_CURSOR_SPRITE
cursorBackSurface = SDLU_InitSurface( &cursorBackSDLRect, 32 );
SDL_FillRect( cursorBackSurface, &cursorBackSDLRect, black );
-#else
- SDL_ShowCursor( 1 );
#endif
// make drawing surface
@@ -503,6 +501,7 @@
drawRect[kCursor].bottom = max<short>( drawRect[kCursor].bottom, mouse.v + kCursorHeight );
drawRect[kCursor].right = max<short>( drawRect[kCursor].right, mouse.h + kCursorWidth );
#endif
+ SDLU_SetSystemCursor( selected < 0 ? SYSTEM_CURSOR_ARROW : SYSTEM_CURSOR_HAND );
// Copy down everything
if( shouldFullRepaint )
@@ -548,9 +547,7 @@
}
else
{
-#if !USE_CURSOR_SPRITE
- SDL_ShowCursor( 0 );
-#endif
+ SDLU_SetSystemCursor( SYSTEM_CURSOR_OFF );
}
switch( selected )
binary files a/src/main.cpp b/src/main.cpp differ
--- a/src/pause.cpp
+++ b/src/pause.cpp
@@ -1063,10 +1063,6 @@
SDLU_StartWatchingTyping();
-#if !USE_CURSOR_SPRITE
- SDL_ShowCursor( 1 );
-#endif
-
DoFullRepaint = ItsTimeToRedraw;
while( ((dialogStage != kClosing) || !dialogStageComplete) && !finished )
@@ -1091,9 +1087,7 @@
if( DialogSelected[dialogType]( &dialogItem, inASCII, inSDLKey ) )
{
-#if !USE_CURSOR_SPRITE
- SDL_ShowCursor( 0 );
-#endif
+ SDLU_SetSystemCursor( SYSTEM_CURSOR_OFF );
dialogStage = kClosing;
dialogTarget = 0;
@@ -1145,6 +1139,7 @@
// ... and cursor
DrawDialogCursor( &pauseRect, &dialogShade );
#endif
+ SDLU_SetSystemCursor( dialogItem == kNothing ? SYSTEM_CURSOR_ARROW : SYSTEM_CURSOR_HAND );
}
SurfaceCurveEdges( drawSurface, &pauseRect );