diff --git a/Source/DiabloUI/diabloui.cpp b/Source/DiabloUI/diabloui.cpp index b907c9fe4..7809e274e 100644 --- a/Source/DiabloUI/diabloui.cpp +++ b/Source/DiabloUI/diabloui.cpp @@ -331,12 +331,12 @@ void UiOnBackgroundChange() fadeTc = 0; fadeValue = 0; + BlackPalette(); + if (IsHardwareCursorEnabled() && ArtCursor && ControlDevice == ControlTypes::KeyboardAndMouse && GetCurrentCursorInfo().type() != CursorType::UserInterface) { SetHardwareCursor(CursorInfo::UserInterfaceCursor()); } - BlackPalette(); - SDL_FillRect(DiabloUiSurface(), nullptr, 0x000000); if (DiabloUiSurface() == PalSurface) BltFast(nullptr, nullptr); @@ -749,8 +749,10 @@ void UiFadeIn() fadeValue = 256; fadeTc = 0; } - if (fadeValue != prevFadeValue) - SetFadeLevel(fadeValue); + if (fadeValue != prevFadeValue) { + // We can skip hardware cursor update for fade level 0 (everything is black). + SetFadeLevel(fadeValue, /*updateHardwareCursor=*/fadeValue != 0); + } } if (DiabloUiSurface() == PalSurface) @@ -796,8 +798,9 @@ void UiPollAndRender(std::optional> eventHan DrawMouse(); UiFadeIn(); - // Must happen after the very first UiFadeIn, which sets the cursor. - if (IsHardwareCursor()) + // Must happen after at least one call to `UiFadeIn` with non-zero fadeValue. + // `UiFadeIn` calls `SetFadeLevel` which reinitializes the hardware cursor. + if (IsHardwareCursor() && fadeValue != 0) SetHardwareCursorVisible(ControlDevice == ControlTypes::KeyboardAndMouse); #ifdef __3DS__ diff --git a/Source/engine/palette.cpp b/Source/engine/palette.cpp index 4ff6d5dd1..5a77e49ad 100644 --- a/Source/engine/palette.cpp +++ b/Source/engine/palette.cpp @@ -274,7 +274,7 @@ int UpdateGamma(int gamma) return 130 - *sgOptions.Graphics.gammaCorrection; } -void SetFadeLevel(int fadeval) +void SetFadeLevel(int fadeval, bool updateHardwareCursor) { if (HeadlessMode) return; @@ -285,14 +285,17 @@ void SetFadeLevel(int fadeval) system_palette[i].b = (fadeval * logical_palette[i].b) / 256; } palette_update(); - if (IsHardwareCursor()) { + if (updateHardwareCursor && IsHardwareCursor()) { ReinitializeHardwareCursor(); } } void BlackPalette() { - SetFadeLevel(0); + // With fade level 0 updating the hardware cursor may be redundant + // since everything is black. The caller should update the cursor + // when needed instead. + SetFadeLevel(0, /*updateHardwareCursor=*/false); } void PaletteFadeIn(int fr) @@ -310,7 +313,8 @@ void PaletteFadeIn(int fr) uint32_t prevFadeValue = 255; for (uint32_t i = 0; i < 256; i = fr * (SDL_GetTicks() - tc) / 50) { if (i != prevFadeValue) { - SetFadeLevel(i); + // We can skip hardware cursor update for fade level 0 (everything is black). + SetFadeLevel(i, /*updateHardwareCursor=*/i != 0u); prevFadeValue = i; } BltFast(nullptr, nullptr); diff --git a/Source/engine/palette.h b/Source/engine/palette.h index a70451d12..b1c33dc8b 100644 --- a/Source/engine/palette.h +++ b/Source/engine/palette.h @@ -60,7 +60,7 @@ void ApplyGamma(std::array &dst, const std::array