summaryrefslogtreecommitdiff
path: root/Source/Core/InputCommon/ControllerInterface/MappingCommon.h
diff options
context:
space:
mode:
authorJordan Woyak <jordan.woyak@gmail.com>2025-06-15 15:45:04 -0500
committerGitHub <noreply@github.com>2025-06-15 15:45:04 -0500
commit28a6eb26cc2c98726c59f254e8962eb1209f5578 (patch)
treea60a3e16e01077cfdaf80c55a41c530b1884d663 /Source/Core/InputCommon/ControllerInterface/MappingCommon.h
parent3a94289ad6e27011fe0ca3ab0fb0fee771fb9fa8 (diff)
parent83beebaf8b074f1c7161134065f19baea08f78a6 (diff)
Merge pull request #13703 from jordan-woyak/map-and-calibrate
DolphinQt/InputCommon: Make the "Calibrate" button also map inputs.
Diffstat (limited to 'Source/Core/InputCommon/ControllerInterface/MappingCommon.h')
-rw-r--r--Source/Core/InputCommon/ControllerInterface/MappingCommon.h76
1 files changed, 76 insertions, 0 deletions
diff --git a/Source/Core/InputCommon/ControllerInterface/MappingCommon.h b/Source/Core/InputCommon/ControllerInterface/MappingCommon.h
index 62c1a8f281..a72549c458 100644
--- a/Source/Core/InputCommon/ControllerInterface/MappingCommon.h
+++ b/Source/Core/InputCommon/ControllerInterface/MappingCommon.h
@@ -5,8 +5,15 @@
#include <string>
+#include "Common/Matrix.h"
+#include "InputCommon/ControllerEmu/StickGate.h"
#include "InputCommon/ControllerInterface/CoreDevice.h"
+namespace ControllerEmu
+{
+class EmulatedController;
+} // namespace ControllerEmu
+
namespace ciface::MappingCommon
{
enum class Quote
@@ -27,4 +34,73 @@ void RemoveSpuriousTriggerCombinations(Core::InputDetector::Results*);
void RemoveDetectionsAfterTimePoint(Core::InputDetector::Results*, Clock::time_point after);
bool ContainsCompleteDetection(const Core::InputDetector::Results&);
+// class for detecting four directional input mappings in sequence.
+class ReshapableInputMapper
+{
+public:
+ // Four cardinal directions.
+ static constexpr std::size_t REQUIRED_INPUT_COUNT = 4;
+
+ // Caller should hold the "StateLock".
+ ReshapableInputMapper(const Core::DeviceContainer& container,
+ std::span<const std::string> device_strings);
+
+ // Reads inputs and updates internal state.
+ // Returns true if an input was detected in this call.
+ // (useful for UI animation)
+ // Caller should hold the "StateLock".
+ bool Update();
+
+ // A counter-clockwise angle in radians for the currently desired input direction.
+ // Used for a graphical indicator in the UI.
+ // 0 == East
+ float GetCurrentAngle() const;
+
+ // True if all four directions have been detected or the timer expired.
+ bool IsComplete() const;
+
+ // Returns true if "analog" inputs were detected and calibration should be performed.
+ // Must use *before* ApplyResults.
+ bool IsCalibrationNeeded() const;
+
+ // Use when IsComplete returns true.
+ // Updates the mappings on the provided ReshapableInput.
+ // Caller should hold the "StateLock".
+ bool ApplyResults(ControllerEmu::EmulatedController*, ControllerEmu::ReshapableInput* stick);
+
+private:
+ Core::InputDetector m_input_detector;
+};
+
+class CalibrationBuilder
+{
+public:
+ // Provide nullopt if you want to calibrate the center on first Update.
+ explicit CalibrationBuilder(std::optional<Common::DVec2> center = Common::DVec2{});
+
+ // Updates the calibration data using the provided point and the previous point.
+ void Update(Common::DVec2 point);
+
+ // Returns true when the calibration data seems to be reasonably filled in.
+ // Used to update the UI to encourage the user to click the "Finish" button.
+ bool IsCalibrationDataSensible() const;
+
+ // Grabs the calibration value at the provided angle.
+ // Used to render the calibration in the UI while it's in progress.
+ ControlState GetCalibrationRadiusAtAngle(double angle) const;
+
+ // Sets the calibration data of the provided ReshapableInput.
+ // Caller should hold the "StateLock".
+ void ApplyResults(ControllerEmu::ReshapableInput* stick);
+
+ Common::DVec2 GetCenter() const;
+
+private:
+ ControllerEmu::ReshapableInput::CalibrationData m_calibration_data;
+
+ std::optional<Common::DVec2> m_center = std::nullopt;
+
+ Common::DVec2 m_prev_point{};
+};
+
} // namespace ciface::MappingCommon