Browse Source

Add OptionEntries for Hardware Cursor

pull/3782/head
obligaron 4 years ago committed by Anders Jenbo
parent
commit
9a14edfcd9
  1. 3
      Source/DiabloUI/settingsmenu.cpp
  2. 2
      Source/engine/demomode.cpp
  3. 8
      Source/hwcursor.cpp
  4. 2
      Source/hwcursor.hpp
  5. 22
      Source/options.cpp
  6. 8
      Source/options.h
  7. 3
      test/main.cpp

3
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;
}

2
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

8
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;

2
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

22
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<OptionEntryBase *> GraphicsOptions::GetEntries()
#endif
&blendedTransparancy,
&colorCycling,
#if SDL_VERSION_ATLEAST(2, 0, 0)
&hardwareCursor,
&hardwareCursorForItems,
&hardwareCursorMaxSize,
#endif
&limitFPS,
&showFPS,
};

8
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<int> 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;
/**

3
test/main.cpp

@ -1,11 +1,14 @@
#include <gtest/gtest.h>
#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();

Loading…
Cancel
Save