From 21c64fd0afc1ea59a27e057f490c02eeb0a01eb9 Mon Sep 17 00:00:00 2001 From: Gleb Mazovetskiy Date: Mon, 11 Apr 2022 08:59:51 +0100 Subject: [PATCH] Hardware cursor: Simplify initialization Set the palette at load time. Since we only support hardware cursors in SDL2, we can take advantage of its reference-counted palettes. --- Source/DiabloUI/diabloui.cpp | 8 ++++++++ Source/hwcursor.cpp | 10 +++------- 2 files changed, 11 insertions(+), 7 deletions(-) diff --git a/Source/DiabloUI/diabloui.cpp b/Source/DiabloUI/diabloui.cpp index ad49ad486..509de86cf 100644 --- a/Source/DiabloUI/diabloui.cpp +++ b/Source/DiabloUI/diabloui.cpp @@ -574,8 +574,16 @@ void LoadUiGFX() LoadMaskedArt("ui_art\\focus16.pcx", &ArtFocus[FOCUS_SMALL], 8); LoadMaskedArt("ui_art\\focus.pcx", &ArtFocus[FOCUS_MED], 8); LoadMaskedArt("ui_art\\focus42.pcx", &ArtFocus[FOCUS_BIG], 8); + LoadMaskedArt("ui_art\\cursor.pcx", &ArtCursor, 1, 0); +#if SDL_VERSION_ATLEAST(2, 0, 0) + // Set the palette because `ArtCursor` may be used as the hardware cursor. + if (ArtCursor.surface != nullptr) { + SDL_SetSurfacePalette(ArtCursor.surface.get(), Palette.get()); + } +#endif + LoadHeros(); } diff --git a/Source/hwcursor.cpp b/Source/hwcursor.cpp index 8ef286b07..a8c5091ef 100644 --- a/Source/hwcursor.cpp +++ b/Source/hwcursor.cpp @@ -144,13 +144,9 @@ void SetHardwareCursor(CursorInfo cursorInfo) case CursorType::UserInterface: // ArtCursor is null while loading the game on the progress screen, // called via palette fade from ShowProgress. - if (ArtCursor.surface != nullptr) { - SDL_SetSurfacePalette(ArtCursor.surface.get(), Palette.get()); - SDL_SetColorKey(ArtCursor.surface.get(), 1, 0); - CurrentCursorInfo.SetEnabled( - IsCursorSizeAllowed(Size { ArtCursor.surface->w, ArtCursor.surface->h }) - && SetHardwareCursor(ArtCursor.surface.get(), HotpointPosition::TopLeft)); - } + CurrentCursorInfo.SetEnabled( + ArtCursor.surface != nullptr && IsCursorSizeAllowed(Size { ArtCursor.surface->w, ArtCursor.surface->h }) + && SetHardwareCursor(ArtCursor.surface.get(), HotpointPosition::TopLeft)); break; case CursorType::Unknown: CurrentCursorInfo.SetEnabled(false);