Browse Source

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.
pull/4424/head
Gleb Mazovetskiy 4 years ago committed by Anders Jenbo
parent
commit
21c64fd0af
  1. 8
      Source/DiabloUI/diabloui.cpp
  2. 10
      Source/hwcursor.cpp

8
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();
}

10
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);

Loading…
Cancel
Save