diff options
Diffstat (limited to 'chromium/device/gamepad/gamepad_standard_mappings.cc')
-rw-r--r-- | chromium/device/gamepad/gamepad_standard_mappings.cc | 30 |
1 files changed, 18 insertions, 12 deletions
diff --git a/chromium/device/gamepad/gamepad_standard_mappings.cc b/chromium/device/gamepad/gamepad_standard_mappings.cc index e30498514cb..94645a0fbfa 100644 --- a/chromium/device/gamepad/gamepad_standard_mappings.cc +++ b/chromium/device/gamepad/gamepad_standard_mappings.cc @@ -6,25 +6,31 @@ namespace device { -GamepadButton AxisToButton(float input) { - float value = (input + 1.f) / 2.f; +namespace { + +const float kButtonAxisDeadzone = 0.01f; + +GamepadButton ValueToButton(float value) { bool pressed = value > GamepadButton::kDefaultButtonPressedThreshold; - bool touched = value > 0.0f; + bool touched = value > 0.f; return GamepadButton(pressed, touched, value); } +} // namespace + +GamepadButton AxisToButton(float input) { + float value = (input + 1.f) / 2.f; + return ValueToButton(value); +} + GamepadButton AxisNegativeAsButton(float input) { - float value = (input < -0.5f) ? 1.f : 0.f; - bool pressed = value > GamepadButton::kDefaultButtonPressedThreshold; - bool touched = value > 0.0f; - return GamepadButton(pressed, touched, value); + float value = input < -kButtonAxisDeadzone ? -input : 0.f; + return ValueToButton(value); } GamepadButton AxisPositiveAsButton(float input) { - float value = (input > 0.5f) ? 1.f : 0.f; - bool pressed = value > GamepadButton::kDefaultButtonPressedThreshold; - bool touched = value > 0.0f; - return GamepadButton(pressed, touched, value); + float value = input > kButtonAxisDeadzone ? input : 0.f; + return ValueToButton(value); } GamepadButton ButtonFromButtonAndAxis(GamepadButton button, float axis) { @@ -33,7 +39,7 @@ GamepadButton ButtonFromButtonAndAxis(GamepadButton button, float axis) { } GamepadButton NullButton() { - return GamepadButton(false, false, 0.0); + return GamepadButton(); } void DpadFromAxis(Gamepad* mapped, float dir) { |