From 23b72d08d247205969300f3e22119f129ec8e15b Mon Sep 17 00:00:00 2001 From: Stenzek Date: Wed, 17 Jan 2024 18:10:02 +1000 Subject: [PATCH] ImGuiOverlays: Fix analog input display --- pcsx2/ImGui/ImGuiOverlays.cpp | 32 ++++++++++++++++++++++--------- pcsx2/SIO/Pad/PadBase.h | 2 +- pcsx2/SIO/Pad/PadDualshock2.cpp | 18 ++++++++--------- pcsx2/SIO/Pad/PadDualshock2.h | 2 +- pcsx2/SIO/Pad/PadGuitar.cpp | 4 ++-- pcsx2/SIO/Pad/PadGuitar.h | 2 +- pcsx2/SIO/Pad/PadNotConnected.cpp | 2 +- pcsx2/SIO/Pad/PadNotConnected.h | 2 +- pcsx2/SIO/Pad/PadPopn.cpp | 4 ++-- pcsx2/SIO/Pad/PadPopn.h | 2 +- 10 files changed, 42 insertions(+), 28 deletions(-) diff --git a/pcsx2/ImGui/ImGuiOverlays.cpp b/pcsx2/ImGui/ImGuiOverlays.cpp index 787c694ab0..58a1c681c6 100644 --- a/pcsx2/ImGui/ImGuiOverlays.cpp +++ b/pcsx2/ImGui/ImGuiOverlays.cpp @@ -38,6 +38,7 @@ #include #include #include +#include #include #include #include @@ -509,14 +510,25 @@ void ImGuiManager::DrawInputsOverlay() { case InputBindingInfo::Type::Axis: case InputBindingInfo::Type::HalfAxis: + { + // axes are only shown if not resting/past deadzone. values are normalized. + const float value = pad->GetEffectiveInput(bind); + const float abs_value = std::abs(value); + if (abs_value >= (254.0f / 255.0f)) + text.append_fmt(" {}", bi.icon_name ? bi.icon_name : bi.name); + else if (abs_value >= (1.0f / 255.0f)) + text.append_fmt(" {}: {:.2f}", bi.icon_name ? bi.icon_name : bi.name, value); + } + break; + case InputBindingInfo::Type::Button: { - // axes are only shown if not resting/past deadzone - const u8 value = pad->GetEffectiveInput(bind); - if (value >= 254) + // buttons display the value from 0 through 255. + const float value = pad->GetEffectiveInput(bind); + if (value >= 254.0f) text.append_fmt(" {}", bi.icon_name ? bi.icon_name : bi.name); - else if (value >= 1) - text.append_fmt(" {}: {}", bi.icon_name ? bi.icon_name : bi.name, value); + else if (value > 0.0f) + text.append_fmt(" {}: {:.0f}", bi.icon_name ? bi.icon_name : bi.name, value); } break; @@ -554,7 +566,7 @@ void ImGuiManager::DrawInputsOverlay() case InputBindingInfo::Type::Axis: case InputBindingInfo::Type::HalfAxis: { - // axes are always shown + // axes are only shown if not resting/past deadzone. values are normalized. const float value = static_cast(USB::GetDeviceBindValue(port, bi.bind_index)); if (value >= (254.0f / 255.0f)) text.append_fmt(" {}", bi.icon_name ? bi.icon_name : bi.name); @@ -565,10 +577,12 @@ void ImGuiManager::DrawInputsOverlay() case InputBindingInfo::Type::Button: { - // buttons only shown when active - const float value = static_cast(USB::GetDeviceBindValue(port, bi.bind_index)); - if (value >= 0.5f) + // buttons display the value from 0 through 255. values are normalized, so denormalize them. + const float value = static_cast(USB::GetDeviceBindValue(port, bi.bind_index)) * 255.0f; + if (value >= 254.0f) text.append_fmt(" {}", bi.icon_name ? bi.icon_name : bi.name); + else if (value > 0.0f) + text.append_fmt(" {}: {:.0f}", bi.icon_name ? bi.icon_name : bi.name, value); } break; diff --git a/pcsx2/SIO/Pad/PadBase.h b/pcsx2/SIO/Pad/PadBase.h index eee8993169..acfb2af514 100644 --- a/pcsx2/SIO/Pad/PadBase.h +++ b/pcsx2/SIO/Pad/PadBase.h @@ -47,7 +47,7 @@ public: // Public members virtual void SetButtonDeadzone(float deadzone) = 0; virtual void SetAnalogInvertL(bool x, bool y) = 0; virtual void SetAnalogInvertR(bool x, bool y) = 0; - virtual u8 GetEffectiveInput(u32 index) const = 0; + virtual float GetEffectiveInput(u32 index) const = 0; virtual u8 GetRawInput(u32 index) const = 0; virtual std::tuple GetRawLeftAnalog() const = 0; virtual std::tuple GetRawRightAnalog() const = 0; diff --git a/pcsx2/SIO/Pad/PadDualshock2.cpp b/pcsx2/SIO/Pad/PadDualshock2.cpp index 5ed1d20297..b2f211fe64 100644 --- a/pcsx2/SIO/Pad/PadDualshock2.cpp +++ b/pcsx2/SIO/Pad/PadDualshock2.cpp @@ -785,7 +785,7 @@ void PadDualshock2::SetAnalogInvertR(bool x, bool y) this->analogs.ryInvert = y; } -u8 PadDualshock2::GetEffectiveInput(u32 index) const +float PadDualshock2::GetEffectiveInput(u32 index) const { if (!IsAnalogKey(index)) return GetRawInput(index); @@ -793,28 +793,28 @@ u8 PadDualshock2::GetEffectiveInput(u32 index) const switch (index) { case Inputs::PAD_L_LEFT: - return (analogs.lx > 0 && analogs.lx < 127) ? analogs.lx : 0; + return (analogs.lx < 127) ? -((127 - analogs.lx) / 127.0f) : 0; case Inputs::PAD_L_RIGHT: - return (analogs.lx >= 128) ? analogs.lx : 0; + return (analogs.lx > 127) ? ((analogs.lx - 127) / 128.0f) : 0; case Inputs::PAD_L_UP: - return (analogs.ly > 0 && analogs.ly < 127) ? analogs.ly : 0; + return (analogs.ly < 127) ? -((127 - analogs.ly) / 127.0f) : 0; case Inputs::PAD_L_DOWN: - return (analogs.ly >= 128) ? analogs.ly : 0; + return (analogs.ly > 127) ? ((analogs.ly - 127) / 128.0f) : 0; case Inputs::PAD_R_LEFT: - return (analogs.rx > 0 && analogs.rx < 127) ? analogs.rx : 0; + return (analogs.rx < 127) ? -((127 - analogs.rx) / 127.0f) : 0; case Inputs::PAD_R_RIGHT: - return (analogs.rx >= 128) ? analogs.rx : 0; + return (analogs.rx > 127) ? ((analogs.rx - 127) / 128.0f) : 0; case Inputs::PAD_R_UP: - return (analogs.ry > 0 && analogs.ry < 127) ? analogs.ry : 0; + return (analogs.ry < 127) ? -((127 - analogs.ry) / 127.0f) : 0; case Inputs::PAD_R_DOWN: - return (analogs.ry >= 128) ? analogs.ry : 0; + return (analogs.ry > 127) ? ((analogs.ry - 127) / 128.0f) : 0; default: return 0; diff --git a/pcsx2/SIO/Pad/PadDualshock2.h b/pcsx2/SIO/Pad/PadDualshock2.h index d58afa986e..83e8597490 100644 --- a/pcsx2/SIO/Pad/PadDualshock2.h +++ b/pcsx2/SIO/Pad/PadDualshock2.h @@ -125,7 +125,7 @@ public: void SetButtonDeadzone(float deadzone) override; void SetAnalogInvertL(bool x, bool y) override; void SetAnalogInvertR(bool x, bool y) override; - u8 GetEffectiveInput(u32 index) const override; + float GetEffectiveInput(u32 index) const override; u8 GetRawInput(u32 index) const override; std::tuple GetRawLeftAnalog() const override; std::tuple GetRawRightAnalog() const override; diff --git a/pcsx2/SIO/Pad/PadGuitar.cpp b/pcsx2/SIO/Pad/PadGuitar.cpp index 7a52c2ec72..76caf4450e 100644 --- a/pcsx2/SIO/Pad/PadGuitar.cpp +++ b/pcsx2/SIO/Pad/PadGuitar.cpp @@ -355,9 +355,9 @@ void PadGuitar::SetAnalogInvertR(bool x, bool y) { } -u8 PadGuitar::GetEffectiveInput(u32 index) const +float PadGuitar::GetEffectiveInput(u32 index) const { - return GetRawInput(index); + return GetRawInput(index) / 255.0f; } u8 PadGuitar::GetRawInput(u32 index) const diff --git a/pcsx2/SIO/Pad/PadGuitar.h b/pcsx2/SIO/Pad/PadGuitar.h index a3692d62da..88a07ba4e5 100644 --- a/pcsx2/SIO/Pad/PadGuitar.h +++ b/pcsx2/SIO/Pad/PadGuitar.h @@ -66,7 +66,7 @@ public: void SetButtonDeadzone(float deadzone) override; void SetAnalogInvertL(bool x, bool y) override; void SetAnalogInvertR(bool x, bool y) override; - u8 GetEffectiveInput(u32 index) const override; + float GetEffectiveInput(u32 index) const override; u8 GetRawInput(u32 index) const override; std::tuple GetRawLeftAnalog() const override; std::tuple GetRawRightAnalog() const override; diff --git a/pcsx2/SIO/Pad/PadNotConnected.cpp b/pcsx2/SIO/Pad/PadNotConnected.cpp index 5b62c29ca1..f233a722f7 100644 --- a/pcsx2/SIO/Pad/PadNotConnected.cpp +++ b/pcsx2/SIO/Pad/PadNotConnected.cpp @@ -76,7 +76,7 @@ void PadNotConnected::SetAnalogInvertR(bool x, bool y) } -u8 PadNotConnected::GetEffectiveInput(u32 index) const +float PadNotConnected::GetEffectiveInput(u32 index) const { return 0; } diff --git a/pcsx2/SIO/Pad/PadNotConnected.h b/pcsx2/SIO/Pad/PadNotConnected.h index 990ecf3c8d..06d812244f 100644 --- a/pcsx2/SIO/Pad/PadNotConnected.h +++ b/pcsx2/SIO/Pad/PadNotConnected.h @@ -23,7 +23,7 @@ public: void SetButtonDeadzone(float deadzone) override; void SetAnalogInvertL(bool x, bool y) override; void SetAnalogInvertR(bool x, bool y) override; - u8 GetEffectiveInput(u32 index) const override; + float GetEffectiveInput(u32 index) const override; u8 GetRawInput(u32 index) const override; std::tuple GetRawLeftAnalog() const override; std::tuple GetRawRightAnalog() const override; diff --git a/pcsx2/SIO/Pad/PadPopn.cpp b/pcsx2/SIO/Pad/PadPopn.cpp index 5ba10fba27..9de81e8219 100644 --- a/pcsx2/SIO/Pad/PadPopn.cpp +++ b/pcsx2/SIO/Pad/PadPopn.cpp @@ -441,9 +441,9 @@ void PadPopn::SetAnalogInvertR(bool x, bool y) { } -u8 PadPopn::GetEffectiveInput(u32 index) const +float PadPopn::GetEffectiveInput(u32 index) const { - return GetRawInput(index); + return GetRawInput(index) / 255.0f; } u8 PadPopn::GetRawInput(u32 index) const diff --git a/pcsx2/SIO/Pad/PadPopn.h b/pcsx2/SIO/Pad/PadPopn.h index 9c83199f55..98b60f197b 100644 --- a/pcsx2/SIO/Pad/PadPopn.h +++ b/pcsx2/SIO/Pad/PadPopn.h @@ -89,7 +89,7 @@ public: void SetButtonDeadzone(float deadzone) override; void SetAnalogInvertL(bool x, bool y) override; void SetAnalogInvertR(bool x, bool y) override; - u8 GetEffectiveInput(u32 index) const override; + float GetEffectiveInput(u32 index) const override; u8 GetRawInput(u32 index) const override; std::tuple GetRawLeftAnalog() const override; std::tuple GetRawRightAnalog() const override;