| OLD | NEW |
| 1 // Copyright 2014 The Chromium Authors. All rights reserved. | 1 // Copyright 2014 The Chromium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 #include "content/browser/gamepad/gamepad_standard_mappings.h" | 5 #include "device/gamepad/gamepad_standard_mappings.h" |
| 6 | 6 |
| 7 namespace content { | 7 namespace device { |
| 8 | 8 |
| 9 blink::WebGamepadButton AxisToButton(float input) { | 9 blink::WebGamepadButton AxisToButton(float input) { |
| 10 float value = (input + 1.f) / 2.f; | 10 float value = (input + 1.f) / 2.f; |
| 11 return blink::WebGamepadButton( | 11 return blink::WebGamepadButton(value > kDefaultButtonPressedThreshold, value); |
| 12 value > kDefaultButtonPressedThreshold, value); | |
| 13 } | 12 } |
| 14 | 13 |
| 15 blink::WebGamepadButton AxisNegativeAsButton(float input) { | 14 blink::WebGamepadButton AxisNegativeAsButton(float input) { |
| 16 float value = (input < -0.5f) ? 1.f : 0.f; | 15 float value = (input < -0.5f) ? 1.f : 0.f; |
| 17 return blink::WebGamepadButton( | 16 return blink::WebGamepadButton(value > kDefaultButtonPressedThreshold, value); |
| 18 value > kDefaultButtonPressedThreshold, value); | |
| 19 } | 17 } |
| 20 | 18 |
| 21 blink::WebGamepadButton AxisPositiveAsButton(float input) { | 19 blink::WebGamepadButton AxisPositiveAsButton(float input) { |
| 22 float value = (input > 0.5f) ? 1.f : 0.f; | 20 float value = (input > 0.5f) ? 1.f : 0.f; |
| 23 return blink::WebGamepadButton( | 21 return blink::WebGamepadButton(value > kDefaultButtonPressedThreshold, value); |
| 24 value > kDefaultButtonPressedThreshold, value); | |
| 25 } | 22 } |
| 26 | 23 |
| 27 blink::WebGamepadButton ButtonFromButtonAndAxis( | 24 blink::WebGamepadButton ButtonFromButtonAndAxis(blink::WebGamepadButton button, |
| 28 blink::WebGamepadButton button, float axis) { | 25 float axis) { |
| 29 float value = (axis + 1.f) / 2.f; | 26 float value = (axis + 1.f) / 2.f; |
| 30 return blink::WebGamepadButton(button.pressed, value); | 27 return blink::WebGamepadButton(button.pressed, value); |
| 31 } | 28 } |
| 32 | 29 |
| 33 blink::WebGamepadButton NullButton() { | 30 blink::WebGamepadButton NullButton() { |
| 34 return blink::WebGamepadButton(false, 0.0); | 31 return blink::WebGamepadButton(false, 0.0); |
| 35 } | 32 } |
| 36 | 33 |
| 37 void DpadFromAxis(blink::WebGamepad* mapped, float dir) { | 34 void DpadFromAxis(blink::WebGamepad* mapped, float dir) { |
| 38 bool up = false; | 35 bool up = false; |
| (...skipping 15 matching lines...) Expand all Loading... |
| 54 mapped->buttons[BUTTON_INDEX_DPAD_UP].pressed = up; | 51 mapped->buttons[BUTTON_INDEX_DPAD_UP].pressed = up; |
| 55 mapped->buttons[BUTTON_INDEX_DPAD_UP].value = up ? 1.f : 0.f; | 52 mapped->buttons[BUTTON_INDEX_DPAD_UP].value = up ? 1.f : 0.f; |
| 56 mapped->buttons[BUTTON_INDEX_DPAD_RIGHT].pressed = right; | 53 mapped->buttons[BUTTON_INDEX_DPAD_RIGHT].pressed = right; |
| 57 mapped->buttons[BUTTON_INDEX_DPAD_RIGHT].value = right ? 1.f : 0.f; | 54 mapped->buttons[BUTTON_INDEX_DPAD_RIGHT].value = right ? 1.f : 0.f; |
| 58 mapped->buttons[BUTTON_INDEX_DPAD_DOWN].pressed = down; | 55 mapped->buttons[BUTTON_INDEX_DPAD_DOWN].pressed = down; |
| 59 mapped->buttons[BUTTON_INDEX_DPAD_DOWN].value = down ? 1.f : 0.f; | 56 mapped->buttons[BUTTON_INDEX_DPAD_DOWN].value = down ? 1.f : 0.f; |
| 60 mapped->buttons[BUTTON_INDEX_DPAD_LEFT].pressed = left; | 57 mapped->buttons[BUTTON_INDEX_DPAD_LEFT].pressed = left; |
| 61 mapped->buttons[BUTTON_INDEX_DPAD_LEFT].value = left ? 1.f : 0.f; | 58 mapped->buttons[BUTTON_INDEX_DPAD_LEFT].value = left ? 1.f : 0.f; |
| 62 } | 59 } |
| 63 | 60 |
| 64 } // namespace content | 61 } // namespace device |
| OLD | NEW |