Skip to content

Commit

Permalink
Prefer system mouse cursor (for beyond pillarbox)
Browse files Browse the repository at this point in the history
  • Loading branch information
jorio committed Jan 8, 2023
1 parent 54ea6be commit cf21a2e
Show file tree
Hide file tree
Showing 3 changed files with 34 additions and 2 deletions.
20 changes: 20 additions & 0 deletions src/level.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -84,6 +84,7 @@ const int kCursorHeight = 32;

extern MBoolean useNewTitle;

#if USE_CURSOR_SPRITE
static void InsertCursor( MPoint mouseHere, SDL_Surface* scratch, SDL_Surface* surface )
{
SkittlesFontPtr cursorFont = GetFont( picFont );
Expand Down Expand Up @@ -114,6 +115,7 @@ static void RemoveCursor( MPoint mouseHere, SDL_Surface* scratch, SDL_Surface* s
SDLU_BlitSurface( scratch, &cursorBackSDLRect,
surface, &cursorFrontSDLRect );
}
#endif

static void GameStartMenuRepaint()
{
Expand All @@ -126,7 +128,9 @@ void GameStartMenu( void )
// multiple times in a row, thanks to "redo". Put initializations after redo.
SDL_Surface* gameStartSurface;
SDL_Surface* gameStartDrawSurface;
#if USE_CURSOR_SPRITE
SDL_Surface* cursorBackSurface;
#endif
SDL_Rect backdropSDLRect = { 0, 0, 640, 480 };
SDL_Rect cursorBackSDLRect = { 0, 0, kCursorWidth, kCursorHeight };
SDL_Rect destSDLRect;
Expand Down Expand Up @@ -181,8 +185,12 @@ void GameStartMenu( void )
black = SDL_MapRGB( gameStartSurface->format, 0, 0, 0 );

// make cursor backing store
#if USE_CURSOR_SPRITE
cursorBackSurface = SDLU_InitSurface( &cursorBackSDLRect, 32 );
SDL_FillRect( cursorBackSurface, &cursorBackSDLRect, black );
#else
SDL_ShowCursor( 1 );
#endif

// make drawing surface
gameStartDrawSurface = SDLU_InitSurface( &backdropSDLRect, 32 );
Expand Down Expand Up @@ -279,11 +287,13 @@ void GameStartMenu( void )
SDLU_AcquireSurface( gameStartDrawSurface );

// Take the cursor out of the scene
#if USE_CURSOR_SPRITE
RemoveCursor( mouse, cursorBackSurface, gameStartDrawSurface );
drawRect[kCursor].top = mouse.v;
drawRect[kCursor].left = mouse.h;
drawRect[kCursor].bottom = mouse.v + kCursorHeight;
drawRect[kCursor].right = mouse.h + kCursorWidth;
#endif

// Inverted rectangles mean "nothing to do."
drawRect[kLeftSide].top = drawRect[kRightSide].top = drawRect[kGlow].top =
Expand Down Expand Up @@ -486,11 +496,13 @@ void GameStartMenu( void )
}

// Reinsert the cursor into the scene
#if USE_CURSOR_SPRITE
InsertCursor( mouse, cursorBackSurface, gameStartDrawSurface );
drawRect[kCursor].top = min<short>( drawRect[kCursor].top, mouse.v );
drawRect[kCursor].left = min<short>( drawRect[kCursor].left, mouse.h );
drawRect[kCursor].bottom = max<short>( drawRect[kCursor].bottom, mouse.v + kCursorHeight );
drawRect[kCursor].right = max<short>( drawRect[kCursor].right, mouse.h + kCursorWidth );
#endif

// Copy down everything
if( shouldFullRepaint )
Expand Down Expand Up @@ -534,6 +546,12 @@ void GameStartMenu( void )
{
selected = kTitleItemQuit;
}
else
{
#if !USE_CURSOR_SPRITE
SDL_ShowCursor( 0 );
#endif
}

switch( selected )
{
Expand All @@ -547,7 +565,9 @@ void GameStartMenu( void )

SDL_FreeSurface( gameStartSurface );
SDL_FreeSurface( gameStartDrawSurface );
#if USE_CURSOR_SPRITE
SDL_FreeSurface( cursorBackSurface );
#endif

QuickFadeOut( NULL );

Expand Down
2 changes: 1 addition & 1 deletion src/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -560,7 +560,7 @@ void CenterRectOnScreen( MRect *rect, double locationX, double locationY )

void ReserveMonitor( void )
{
SDL_ShowCursor( SDL_DISABLE );
// SDL_ShowCursor( SDL_DISABLE );

SDL_SetHint(SDL_HINT_RENDER_VSYNC, "1");
SDL_SetHint(SDL_HINT_RENDER_SCALE_QUALITY, crispUpscaling? "0": "best");
Expand Down
14 changes: 13 additions & 1 deletion src/pause.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -462,6 +462,7 @@ static MBoolean DrawDialogBox( MBoolean larger, int animationType, int *target,
return animationStageComplete;
}

#if USE_CURSOR_SPRITE
static void DrawDialogCursor( MRect *pauseRect, int *shade )
{
MPoint p, q;
Expand All @@ -482,6 +483,7 @@ static void DrawDialogCursor( MRect *pauseRect, int *shade )

SDLU_ReleaseSurface( drawSurface );
}
#endif

static void DrawDialogLogo( MRect *pauseRect, int shade )
{
Expand Down Expand Up @@ -1051,6 +1053,10 @@ void HandleDialog( int type )
lastPauseRect.bottom = lastPauseRect.right = -9999;

SDLU_StartWatchingTyping();

#if !USE_CURSOR_SPRITE
SDL_ShowCursor( 1 );
#endif

DoFullRepaint = ItsTimeToRedraw;

Expand All @@ -1076,6 +1082,10 @@ void HandleDialog( int type )

if( DialogSelected[dialogType]( &dialogItem, inASCII, inSDLKey ) )
{
#if !USE_CURSOR_SPRITE
SDL_ShowCursor( 0 );
#endif

dialogStage = kClosing;
dialogTarget = 0;
}
Expand Down Expand Up @@ -1121,9 +1131,11 @@ void HandleDialog( int type )

// ... and animation is complete so add content
DialogDraw[dialogType]( &dialogItem, dialogShade );


#if USE_CURSOR_SPRITE
// ... and cursor
DrawDialogCursor( &pauseRect, &dialogShade );
#endif
}

SurfaceCurveEdges( drawSurface, &pauseRect );
Expand Down

0 comments on commit cf21a2e

Please sign in to comment.