From 643f259cbfd01d0daa3fbe21cb2acc24d2ef302e Mon Sep 17 00:00:00 2001
From: Justin Ivany <jrivany@gmail.com>
Date: Tue, 2 Jul 2019 11:19:10 +0000
Subject: [PATCH] Adding option for cursor speed when using gamepad

---
 apps/openmw/mwinput/inputmanagerimp.cpp          |  5 +++--
 apps/openmw/mwinput/inputmanagerimp.hpp          |  1 +
 docs/source/reference/modding/settings/input.rst | 13 +++++++++++++
 files/settings-default.cfg                       |  3 +++
 4 files changed, 20 insertions(+), 2 deletions(-)

diff --git a/apps/openmw/mwinput/inputmanagerimp.cpp b/apps/openmw/mwinput/inputmanagerimp.cpp
index 6a6ac20a8e..581a96e7b9 100644
--- a/apps/openmw/mwinput/inputmanagerimp.cpp
+++ b/apps/openmw/mwinput/inputmanagerimp.cpp
@@ -77,6 +77,7 @@ namespace MWInput
         , mSneaking(false)
         , mAttemptJump(false)
         , mInvUiScalingFactor(1.f)
+        , mGamepadCursorSpeed(Settings::Manager::getFloat("gamepad cursor speed", "Input"))
         , mFakeDeviceID(1)
     {
         mInputManager = new SDLUtil::InputWrapper(window, viewer, grab);
@@ -558,8 +559,8 @@ namespace MWInput
 
             // We keep track of our own mouse position, so that moving the mouse while in
             // game mode does not move the position of the GUI cursor
-            float xmove = xAxis * dt * 1500.0f * mInvUiScalingFactor;
-            float ymove = yAxis * dt * 1500.0f * mInvUiScalingFactor;
+            float xmove = xAxis * dt * 1500.0f * mInvUiScalingFactor * mGamepadCursorSpeed;
+            float ymove = yAxis * dt * 1500.0f * mInvUiScalingFactor * mGamepadCursorSpeed;
             if (xmove != 0|| ymove != 0 || zAxis != 0)
             {
                 mGuiCursorX += xmove;
diff --git a/apps/openmw/mwinput/inputmanagerimp.hpp b/apps/openmw/mwinput/inputmanagerimp.hpp
index 8b3253dcd1..caf57681da 100644
--- a/apps/openmw/mwinput/inputmanagerimp.hpp
+++ b/apps/openmw/mwinput/inputmanagerimp.hpp
@@ -209,6 +209,7 @@ namespace MWInput
         std::map<std::string, bool> mControlSwitch;
 
         float mInvUiScalingFactor;
+        float mGamepadCursorSpeed;
 
     private:
         void convertMousePosForMyGUI(int& x, int& y);
diff --git a/docs/source/reference/modding/settings/input.rst b/docs/source/reference/modding/settings/input.rst
index 51c72e15dd..d481321c2e 100644
--- a/docs/source/reference/modding/settings/input.rst
+++ b/docs/source/reference/modding/settings/input.rst
@@ -133,3 +133,16 @@ which are always sent if a controller is present and detected.
 Disabling this setting can be useful for working around controller-related issues or for setting up split-screen gameplay configurations.
 
 This setting can be toggled in game with the Enable Joystick button in the Controls panel of the Options menu.
+
+gamepad cursor speed
+--------------------
+
+:Type: float
+:Range: >0
+:Default: 1.0
+
+This setting controls the speed of the cursor within GUI mode when using the joystick.
+This setting has no effect on the camera rotation speed, which is controlled by the
+camera sensitivity setting.
+
+This setting can only be configured by editing the settings configuration file.
diff --git a/files/settings-default.cfg b/files/settings-default.cfg
index d3776e92f5..d16e8c92c2 100644
--- a/files/settings-default.cfg
+++ b/files/settings-default.cfg
@@ -364,6 +364,9 @@ invert y axis = false
 # Enable controller support.
 enable controller = true
 
+# Emulated gamepad cursor sensitivity.
+gamepad cursor speed = 1.0
+
 [Saves]
 
 # Name of last character played, and default for loading save files.