From 9a14edfcd97fd9debd214b105c5f0dde52688047 Mon Sep 17 00:00:00 2001 From: obligaron Date: Fri, 17 Dec 2021 19:04:42 +0100 Subject: [PATCH] Add OptionEntries for Hardware Cursor --- Source/DiabloUI/settingsmenu.cpp | 3 +-- Source/engine/demomode.cpp | 2 +- Source/hwcursor.cpp | 8 ++++---- Source/hwcursor.hpp | 2 +- Source/options.cpp | 22 +++++++++++----------- Source/options.h | 8 ++++---- test/main.cpp | 3 +++ 7 files changed, 25 insertions(+), 23 deletions(-) diff --git a/Source/DiabloUI/settingsmenu.cpp b/Source/DiabloUI/settingsmenu.cpp index 70905079c..ee8622317 100644 --- a/Source/DiabloUI/settingsmenu.cpp +++ b/Source/DiabloUI/settingsmenu.cpp @@ -111,8 +111,7 @@ bool ChangeOptionValue(OptionEntryBase *pOption, size_t listIndex) // Reinitalize UI with changed settings (for example game mode, language or resolution) UiInitialize(); InitItemGFX(); - if (IsHardwareCursor()) - SetHardwareCursor(CursorInfo::UnknownCursor()); + SetHardwareCursor(CursorInfo::UnknownCursor()); return false; } diff --git a/Source/engine/demomode.cpp b/Source/engine/demomode.cpp index 942012260..0ea8e07d6 100644 --- a/Source/engine/demomode.cpp +++ b/Source/engine/demomode.cpp @@ -142,7 +142,7 @@ void OverrideOptions() sgOptions.Graphics.fitToScreen.SetValue(false); #endif #if SDL_VERSION_ATLEAST(2, 0, 0) - sgOptions.Graphics.bHardwareCursor = false; + sgOptions.Graphics.hardwareCursor.SetValue(false); #endif if (Timedemo) { #ifndef USE_SDL1 diff --git a/Source/hwcursor.cpp b/Source/hwcursor.cpp index 556ae7d43..5f7c38072 100644 --- a/Source/hwcursor.cpp +++ b/Source/hwcursor.cpp @@ -44,11 +44,11 @@ Size ScaledSize(Size size) bool IsCursorSizeAllowed(Size size) { - if (sgOptions.Graphics.nHardwareCursorMaxSize <= 0) + if (*sgOptions.Graphics.hardwareCursorMaxSize <= 0) return true; size = ScaledSize(size); - return size.width <= sgOptions.Graphics.nHardwareCursorMaxSize - && size.height <= sgOptions.Graphics.nHardwareCursorMaxSize; + return size.width <= *sgOptions.Graphics.hardwareCursorMaxSize + && size.height <= *sgOptions.Graphics.hardwareCursorMaxSize; } Point GetHotpointPosition(const SDL_Surface &surface, HotpointPosition position) @@ -99,7 +99,7 @@ bool SetHardwareCursor(SDL_Surface *surface, HotpointPosition hotpointPosition) bool SetHardwareCursorFromSprite(int pcurs) { const bool isItem = IsItemSprite(pcurs); - if (isItem && !sgOptions.Graphics.bHardwareCursorForItems) + if (isItem && !*sgOptions.Graphics.hardwareCursorForItems) return false; const int outlineWidth = isItem ? 1 : 0; diff --git a/Source/hwcursor.hpp b/Source/hwcursor.hpp index 86485898e..56e01edb5 100644 --- a/Source/hwcursor.hpp +++ b/Source/hwcursor.hpp @@ -13,7 +13,7 @@ namespace devilution { inline bool IsHardwareCursorEnabled() { #if SDL_VERSION_ATLEAST(2, 0, 0) - return sgOptions.Graphics.bHardwareCursor; + return *sgOptions.Graphics.hardwareCursor; #else return false; #endif diff --git a/Source/options.cpp b/Source/options.cpp index ab7516940..bbbac85e7 100644 --- a/Source/options.cpp +++ b/Source/options.cpp @@ -35,6 +35,7 @@ #include "diablo.h" #include "discord/discord.h" #include "engine/demomode.h" +#include "hwcursor.hpp" #include "options.h" #include "qol/monhealthbar.h" #include "qol/xpbar.h" @@ -343,12 +344,6 @@ void LoadOptions() sgOptions.Audio.nMusicVolume = GetIniInt("Audio", "Music Volume", VOLUME_MAX); sgOptions.Graphics.nGammaCorrection = GetIniInt("Graphics", "Gamma Correction", 100); -#if SDL_VERSION_ATLEAST(2, 0, 0) - sgOptions.Graphics.bHardwareCursor = GetIniBool("Graphics", "Hardware Cursor", HardwareCursorDefault()); - sgOptions.Graphics.bHardwareCursorForItems = GetIniBool("Graphics", "Hardware Cursor For Items", false); - sgOptions.Graphics.nHardwareCursorMaxSize = GetIniInt("Graphics", "Hardware Cursor Maximum Size", 128); -#endif - sgOptions.Gameplay.nTickRate = GetIniInt("Game", "Speed", 20); GetIniValue("Network", "Bind Address", sgOptions.Network.szBindAddress, sizeof(sgOptions.Network.szBindAddress), "0.0.0.0"); @@ -392,11 +387,6 @@ void SaveOptions() SetIniValue("Audio", "Music Volume", sgOptions.Audio.nMusicVolume); SetIniValue("Graphics", "Gamma Correction", sgOptions.Graphics.nGammaCorrection); -#if SDL_VERSION_ATLEAST(2, 0, 0) - SetIniValue("Graphics", "Hardware Cursor", sgOptions.Graphics.bHardwareCursor); - SetIniValue("Graphics", "Hardware Cursor For Items", sgOptions.Graphics.bHardwareCursorForItems); - SetIniValue("Graphics", "Hardware Cursor Maximum Size", sgOptions.Graphics.nHardwareCursorMaxSize); -#endif SetIniValue("Game", "Speed", sgOptions.Gameplay.nTickRate); @@ -771,6 +761,11 @@ GraphicsOptions::GraphicsOptions() #endif , blendedTransparancy("Blended Transparency", OptionEntryFlags::CantChangeInGame, N_("Blended Transparency"), N_("Enables uniform transparency mode. This setting affects the transparency on walls, game text menus, and boxes. If disabled will default to old checkerboard transparency."), true) , colorCycling("Color Cycling", OptionEntryFlags::None, N_("Color Cycling"), N_("Color cycling effect used for water, lava, and acid animation."), true) +#if SDL_VERSION_ATLEAST(2, 0, 0) + , hardwareCursor("Hardware Cursor", OptionEntryFlags::CantChangeInGame | OptionEntryFlags::RecreateUI, N_("Hardware Cursor"), N_("Use a hardware cursor"), HardwareCursorDefault()) + , hardwareCursorForItems("Hardware Cursor For Items", OptionEntryFlags::CantChangeInGame, N_("Hardware Cursor For Items"), N_("Use a hardware cursor for items."), false) + , hardwareCursorMaxSize("Hardware Cursor Maximum Size", OptionEntryFlags::CantChangeInGame | OptionEntryFlags::RecreateUI, N_("Hardware Cursor Maximum Size"), N_("Maximum width / height for the hardware cursor. Larger cursors fall back to software."), 128, { 0, 64, 128, 256, 512 }) +#endif , limitFPS("FPS Limiter", OptionEntryFlags::None, N_("FPS Limiter"), N_("FPS is limited to avoid high CPU load. Limit considers refresh rate."), true) , showFPS("Show FPS", OptionEntryFlags::None, N_("Show FPS"), N_("Displays the FPS in the upper left corner of the screen."), true) { @@ -806,6 +801,11 @@ std::vector GraphicsOptions::GetEntries() #endif &blendedTransparancy, &colorCycling, +#if SDL_VERSION_ATLEAST(2, 0, 0) + &hardwareCursor, + &hardwareCursorForItems, + &hardwareCursorMaxSize, +#endif &limitFPS, &showFPS, }; diff --git a/Source/options.h b/Source/options.h index 39a358c4c..f1396a504 100644 --- a/Source/options.h +++ b/Source/options.h @@ -398,11 +398,11 @@ struct GraphicsOptions : OptionCategoryBase { OptionEntryBoolean colorCycling; #if SDL_VERSION_ATLEAST(2, 0, 0) /** @brief Use a hardware cursor (SDL2 only). */ - bool bHardwareCursor; + OptionEntryBoolean hardwareCursor; /** @brief Use a hardware cursor for items. */ - bool bHardwareCursorForItems; + OptionEntryBoolean hardwareCursorForItems; /** @brief Maximum width / height for the hardware cursor. Larger cursors fall back to software. */ - int nHardwareCursorMaxSize; + OptionEntryInt hardwareCursorMaxSize; #endif /** @brief Enable FPS Limiter. */ OptionEntryBoolean limitFPS; @@ -553,7 +553,7 @@ struct Options { bool GetIniValue(const char *sectionName, const char *keyName, char *string, int stringSize, const char *defaultString = ""); void SetIniValue(const char *sectionName, const char *keyName, const char *value, int len = 0); -extern Options sgOptions; +extern DVL_API_FOR_TEST Options sgOptions; extern bool sbWasOptionsLoaded; /** diff --git a/test/main.cpp b/test/main.cpp index 77998426a..1df8ac4f6 100644 --- a/test/main.cpp +++ b/test/main.cpp @@ -1,11 +1,14 @@ #include #include "diablo.h" +#include "options.h" int main(int argc, char **argv) { // Disable error dialogs. devilution::gbQuietMode = true; + // Disable hardware cursor while testing. + devilution::sgOptions.Graphics.hardwareCursor.SetValue(false); testing::InitGoogleTest(&argc, argv); return RUN_ALL_TESTS();