summaryrefslogtreecommitdiff
path: root/Source/Core/InputCommon
diff options
context:
space:
mode:
authorshuffle2 <godisgovernment@gmail.com>2016-10-03 03:26:04 -0700
committerGitHub <noreply@github.com>2016-10-03 03:26:04 -0700
commit2db2e886206c1380bc86cfc5282096adf2e51272 (patch)
treea2e30b3240b3beef5518782d3b26bda7389922ec /Source/Core/InputCommon
parent4b62d417283abd2bc40409b9f73eed900a89995c (diff)
parent149654df5a7db04315badc95354bab3ccd02964f (diff)
Merge pull request #4010 from leoetlino/relative-input
Add relative input for the Wiimote IR
Diffstat (limited to 'Source/Core/InputCommon')
-rw-r--r--Source/Core/InputCommon/ControllerEmu.cpp3
-rw-r--r--Source/Core/InputCommon/ControllerEmu.h36
2 files changed, 37 insertions, 2 deletions
diff --git a/Source/Core/InputCommon/ControllerEmu.cpp b/Source/Core/InputCommon/ControllerEmu.cpp
index 2fd85b3fac..84f511f822 100644
--- a/Source/Core/InputCommon/ControllerEmu.cpp
+++ b/Source/Core/InputCommon/ControllerEmu.cpp
@@ -295,10 +295,13 @@ ControllerEmu::Cursor::Cursor(const std::string& _name)
controls.emplace_back(std::make_unique<Input>("Forward"));
controls.emplace_back(std::make_unique<Input>("Backward"));
controls.emplace_back(std::make_unique<Input>(_trans("Hide")));
+ controls.emplace_back(std::make_unique<Input>("Recenter"));
numeric_settings.emplace_back(std::make_unique<NumericSetting>(_trans("Center"), 0.5));
numeric_settings.emplace_back(std::make_unique<NumericSetting>(_trans("Width"), 0.5));
numeric_settings.emplace_back(std::make_unique<NumericSetting>(_trans("Height"), 0.5));
+ numeric_settings.emplace_back(std::make_unique<NumericSetting>(_trans("Dead Zone"), 0, 0, 20));
+ boolean_settings.emplace_back(std::make_unique<BooleanSetting>(_trans("Relative Input"), false));
}
void ControllerEmu::LoadDefaults(const ControllerInterface& ciface)
diff --git a/Source/Core/InputCommon/ControllerEmu.h b/Source/Core/InputCommon/ControllerEmu.h
index 215b2557b4..90247d699e 100644
--- a/Source/Core/InputCommon/ControllerEmu.h
+++ b/Source/Core/InputCommon/ControllerEmu.h
@@ -12,6 +12,7 @@
#include <vector>
#include "Common/IniFile.h"
+#include "Common/MathUtil.h"
#include "Core/ConfigManager.h"
#include "InputCommon/ControllerInterface/ControllerInterface.h"
#include "InputCommon/GCPadStatus.h"
@@ -424,12 +425,43 @@ public:
yy += (numeric_settings[0]->GetValue() - 0.5);
}
- *x = xx;
- *y = yy;
+ // relative input
+ if (boolean_settings[0]->GetValue())
+ {
+ const ControlState deadzone = numeric_settings[3]->GetValue();
+ // deadzone to avoid the cursor slowly drifting
+ if (std::abs(xx) > deadzone)
+ m_x = MathUtil::Clamp(m_x + xx * SPEED_MULTIPLIER, -1.0, 1.0);
+ if (std::abs(yy) > deadzone)
+ m_y = MathUtil::Clamp(m_y + yy * SPEED_MULTIPLIER, -1.0, 1.0);
+
+ // recenter
+ if (controls[7]->control_ref->State() > 0.5)
+ {
+ m_x = 0.0;
+ m_y = 0.0;
+ }
+ }
+ else
+ {
+ m_x = xx;
+ m_y = yy;
+ }
+
+ *x = m_x;
+ *y = m_y;
}
}
ControlState m_z;
+
+ private:
+ // This is used to reduce the cursor speed for relative input
+ // to something that makes sense with the default range.
+ static constexpr double SPEED_MULTIPLIER = 0.04;
+
+ ControlState m_x = 0.0;
+ ControlState m_y = 0.0;
};
class Extension : public ControlGroup