Browse Source

Add OptionEntry Grab Input

pull/3594/head
obligaron 4 years ago committed by Anders Jenbo
parent
commit
21e04d3352
  1. 15
      Source/options.cpp
  2. 2
      Source/options.h
  3. 4
      Source/utils/display.cpp

15
Source/options.cpp

@ -188,6 +188,16 @@ bool HardwareCursorDefault()
}
#endif
void OptionGrabInputChanged()
{
#ifdef USE_SDL1
SDL_WM_GrabInput(*sgOptions.Gameplay.grabInput ? SDL_GRAB_ON : SDL_GRAB_OFF);
#else
if (ghMainWnd != nullptr)
SDL_SetWindowGrab(ghMainWnd, *sgOptions.Gameplay.grabInput ? SDL_TRUE : SDL_FALSE);
#endif
}
} // namespace
void SetIniValue(const char *sectionName, const char *keyName, const char *value, int len)
@ -265,7 +275,6 @@ void LoadOptions()
sgOptions.Graphics.bShowFPS = (GetIniInt("Graphics", "Show FPS", 0) != 0);
sgOptions.Gameplay.nTickRate = GetIniInt("Game", "Speed", 20);
sgOptions.Gameplay.bGrabInput = GetIniBool("Game", "Grab Input", false);
sgOptions.Gameplay.bTheoQuest = GetIniBool("Game", "Theo Quest", false);
sgOptions.Gameplay.bCowQuest = GetIniBool("Game", "Cow Quest", false);
sgOptions.Gameplay.bFriendlyFire = GetIniBool("Game", "Friendly Fire", true);
@ -419,7 +428,6 @@ void SaveOptions()
SetIniValue("Graphics", "Show FPS", sgOptions.Graphics.bShowFPS);
SetIniValue("Game", "Speed", sgOptions.Gameplay.nTickRate);
SetIniValue("Game", "Grab Input", sgOptions.Gameplay.bGrabInput);
SetIniValue("Game", "Theo Quest", sgOptions.Gameplay.bTheoQuest);
SetIniValue("Game", "Cow Quest", sgOptions.Gameplay.bCowQuest);
SetIniValue("Game", "Friendly Fire", sgOptions.Gameplay.bFriendlyFire);
@ -629,12 +637,15 @@ std::vector<OptionEntryBase *> GraphicsOptions::GetEntries()
GameplayOptions::GameplayOptions()
: OptionCategoryBase("Game", N_("Gameplay"), N_("Gameplay Settings"))
, runInTown("Run in Town", OptionEntryFlags::CantChangeInMultiPlayer, N_("Run in Town"), N_("Enable jogging/fast walking in town for Diablo and Hellfire. This option was introduced in the expansion."), AUTO_PICKUP_DEFAULT(false))
, grabInput("Grab Input", OptionEntryFlags::None, N_("Grab Input"), N_("When enabled mouse is locked to the game window."), false)
{
grabInput.SetValueChangedCallback(OptionGrabInputChanged);
}
std::vector<OptionEntryBase *> GameplayOptions::GetEntries()
{
return {
&runInTown,
&grabInput,
};
}

2
Source/options.h

@ -274,7 +274,7 @@ struct GameplayOptions : OptionCategoryBase {
/** @brief Enable double walk speed when in town. */
OptionEntryBoolean runInTown;
/** @brief Do not let the mouse leave the application window. */
bool bGrabInput;
OptionEntryBoolean grabInput;
/** @brief Enable the Theo quest. */
bool bTheoQuest;
/** @brief Enable the cow quest. */

4
Source/utils/display.cpp

@ -196,7 +196,7 @@ bool SpawnWindow(const char *lpWindowName)
#ifdef USE_SDL1
SDL_WM_SetCaption(lpWindowName, WINDOW_ICON_NAME);
SetVideoModeToPrimary(!gbForceWindowed && sgOptions.Graphics.bFullscreen, width, height);
if (sgOptions.Gameplay.bGrabInput)
if (*sgOptions.Gameplay.grabInput)
SDL_WM_GrabInput(SDL_GRAB_ON);
atexit(SDL_VideoQuit); // Without this video mode is not restored after fullscreen.
#else
@ -213,7 +213,7 @@ bool SpawnWindow(const char *lpWindowName)
flags |= SDL_WINDOW_FULLSCREEN;
}
if (sgOptions.Gameplay.bGrabInput) {
if (*sgOptions.Gameplay.grabInput) {
flags |= SDL_WINDOW_INPUT_GRABBED;
}

Loading…
Cancel
Save