ImGuiOverlays: Fix analog input display

This commit is contained in:
Stenzek 2024-01-17 18:10:02 +10:00 committed by Connor McLaughlin
parent 227049b6f2
commit 23b72d08d2
10 changed files with 42 additions and 28 deletions

View File

@ -38,6 +38,7 @@
#include <chrono>
#include <cmath>
#include <deque>
#include <limits>
#include <mutex>
#include <span>
#include <tuple>
@ -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<float>(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<float>(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<float>(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;

View File

@ -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<u8, u8> GetRawLeftAnalog() const = 0;
virtual std::tuple<u8, u8> GetRawRightAnalog() const = 0;

View File

@ -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;

View File

@ -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<u8, u8> GetRawLeftAnalog() const override;
std::tuple<u8, u8> GetRawRightAnalog() const override;

View File

@ -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

View File

@ -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<u8, u8> GetRawLeftAnalog() const override;
std::tuple<u8, u8> GetRawRightAnalog() const override;

View File

@ -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;
}

View File

@ -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<u8, u8> GetRawLeftAnalog() const override;
std::tuple<u8, u8> GetRawRightAnalog() const override;

View File

@ -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

View File

@ -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<u8, u8> GetRawLeftAnalog() const override;
std::tuple<u8, u8> GetRawRightAnalog() const override;