Browse Source

ArtCursor: Art -> CLX

pull/5221/head
Gleb Mazovetskiy 4 years ago
parent
commit
f3e37781d9
  1. 22
      Source/DiabloUI/diabloui.cpp
  2. 2
      Source/DiabloUI/diabloui.h
  3. 8
      Source/cursor.cpp
  4. 17
      Source/hwcursor.cpp

22
Source/DiabloUI/diabloui.cpp

@ -50,7 +50,7 @@ std::array<OptionalOwnedClxSpriteList, 3> ArtFocus;
OptionalOwnedClxSpriteList ArtBackgroundWidescreen;
OptionalOwnedClxSpriteList ArtBackground;
Art ArtCursor;
OptionalOwnedClxSpriteList ArtCursor;
bool textInputActive = true;
std::size_t SelectedItem = 0;
@ -567,14 +567,7 @@ void LoadUiGFX()
ArtFocus[FOCUS_MED] = LoadPcxSpriteList("ui_art\\focus.pcx", /*numFrames=*/8, /*transparentColor=*/250);
ArtFocus[FOCUS_BIG] = LoadPcxSpriteList("ui_art\\focus42.pcx", /*numFrames=*/8, /*transparentColor=*/250);
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
ArtCursor = LoadPcx("ui_art\\cursor.pcx", /*transparentColor=*/0);
LoadHeros();
}
@ -593,7 +586,7 @@ void UnloadUiGFX()
ArtHero = std::nullopt;
for (OptionalOwnedClxSpriteList &override : ArtHeroOverrides)
override = std::nullopt;
ArtCursor.Unload();
ArtCursor = std::nullopt;
for (auto &art : ArtFocus)
art = std::nullopt;
ArtLogo = std::nullopt;
@ -603,7 +596,7 @@ void UiInitialize()
{
LoadUiGFX();
if (ArtCursor.surface != nullptr) {
if (ArtCursor) {
if (SDL_ShowCursor(SDL_DISABLE) <= -1) {
ErrSdl();
}
@ -694,7 +687,7 @@ void LoadBackgroundArt(const char *pszFile, int frames)
fadeTc = 0;
fadeValue = 0;
if (IsHardwareCursorEnabled() && ArtCursor.surface != nullptr && ControlDevice == ControlTypes::KeyboardAndMouse && GetCurrentCursorInfo().type() != CursorType::UserInterface) {
if (IsHardwareCursorEnabled() && ArtCursor && ControlDevice == ControlTypes::KeyboardAndMouse && GetCurrentCursorInfo().type() != CursorType::UserInterface) {
SetHardwareCursor(CursorInfo::UserInterfaceCursor());
}
@ -1130,9 +1123,8 @@ bool UiItemMouseEvents(SDL_Event *event, const std::vector<std::unique_ptr<UiIte
void DrawMouse()
{
if (ControlDevice != ControlTypes::KeyboardAndMouse || IsHardwareCursor())
if (ControlDevice != ControlTypes::KeyboardAndMouse || IsHardwareCursor() || !ArtCursor)
return;
DrawArt(MousePosition, &ArtCursor);
RenderClxSprite(Surface(DiabloUiSurface()), (*ArtCursor)[0], MousePosition);
}
} // namespace devilution

2
Source/DiabloUI/diabloui.h

@ -65,7 +65,7 @@ extern OptionalOwnedClxSpriteList ArtLogo;
extern std::array<OptionalOwnedClxSpriteList, 3> ArtFocus;
extern OptionalOwnedClxSpriteList ArtBackgroundWidescreen;
extern OptionalOwnedClxSpriteList ArtBackground;
extern Art ArtCursor;
extern OptionalOwnedClxSpriteList ArtCursor;
extern bool (*gfnHeroInfo)(bool (*fninfofunc)(_uiheroinfo *));

8
Source/cursor.cpp

@ -193,12 +193,12 @@ void NewCursor(int cursId)
pcurs = cursId;
if (IsHardwareCursorEnabled() && ControlDevice == ControlTypes::KeyboardAndMouse) {
if (ArtCursor.surface == nullptr && cursId == CURSOR_NONE)
if (!ArtCursor && cursId == CURSOR_NONE)
return;
const CursorInfo newCursor = ArtCursor.surface == nullptr
? CursorInfo::GameCursor(cursId)
: CursorInfo::UserInterfaceCursor();
const CursorInfo newCursor = ArtCursor
? CursorInfo::UserInterfaceCursor()
: CursorInfo::GameCursor(cursId);
if (newCursor != GetCurrentCursorInfo())
SetHardwareCursor(newCursor);
}

17
Source/hwcursor.cpp

@ -13,7 +13,9 @@
#include "appfat.h"
#include "cursor.h"
#include "engine.h"
#include "engine/clx_sprite.hpp"
#include "engine/render/clx_render.hpp"
#include "engine/surface.hpp"
#include "utils/display.h"
#include "utils/sdl_bilinear_scale.hpp"
#include "utils/sdl_wrap.h"
@ -96,6 +98,15 @@ bool SetHardwareCursor(SDL_Surface *surface, HotpointPosition hotpointPosition)
return true;
}
bool SetHardwareCursor(ClxSprite sprite, HotpointPosition hotpointPosition)
{
OwnedSurface surface { sprite.width(), sprite.height() };
SDL_SetSurfacePalette(surface.surface, Palette.get());
SDL_SetColorKey(surface.surface, SDL_TRUE, 0);
RenderClxSprite(surface, sprite, { 0, 0 });
return SetHardwareCursor(surface.surface, hotpointPosition);
}
bool SetHardwareCursorFromSprite(int pcurs)
{
const bool isItem = !MyPlayer->HoldItem.isEmpty();
@ -145,8 +156,8 @@ void SetHardwareCursor(CursorInfo cursorInfo)
// ArtCursor is null while loading the game on the progress screen,
// called via palette fade from ShowProgress.
CurrentCursorInfo.SetEnabled(
ArtCursor.surface != nullptr && IsCursorSizeAllowed(Size { ArtCursor.surface->w, ArtCursor.surface->h })
&& SetHardwareCursor(ArtCursor.surface.get(), HotpointPosition::TopLeft));
ArtCursor && IsCursorSizeAllowed(Size { (*ArtCursor)[0].width(), (*ArtCursor)[0].height() })
&& SetHardwareCursor((*ArtCursor)[0], HotpointPosition::TopLeft));
break;
case CursorType::Unknown:
CurrentCursorInfo.SetEnabled(false);

Loading…
Cancel
Save