| 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 "device/gamepad/gamepad_standard_mappings.h" | 5 #include "device/gamepad/gamepad_standard_mappings.h" |
| 6 | 6 |
| 7 namespace device { | 7 namespace device { |
| 8 | 8 |
| 9 blink::WebGamepadButton AxisToButton(float input) { | 9 GamepadButton AxisToButton(float input) { |
| 10 float value = (input + 1.f) / 2.f; | 10 float value = (input + 1.f) / 2.f; |
| 11 bool pressed = value > kDefaultButtonPressedThreshold; | 11 bool pressed = value > kDefaultButtonPressedThreshold; |
| 12 bool touched = value > 0.0f; | 12 bool touched = value > 0.0f; |
| 13 return blink::WebGamepadButton(pressed, touched, value); | 13 return GamepadButton(pressed, touched, value); |
| 14 } | 14 } |
| 15 | 15 |
| 16 blink::WebGamepadButton AxisNegativeAsButton(float input) { | 16 GamepadButton AxisNegativeAsButton(float input) { |
| 17 float value = (input < -0.5f) ? 1.f : 0.f; | 17 float value = (input < -0.5f) ? 1.f : 0.f; |
| 18 bool pressed = value > kDefaultButtonPressedThreshold; | 18 bool pressed = value > kDefaultButtonPressedThreshold; |
| 19 bool touched = value > 0.0f; | 19 bool touched = value > 0.0f; |
| 20 return blink::WebGamepadButton(pressed, touched, value); | 20 return GamepadButton(pressed, touched, value); |
| 21 } | 21 } |
| 22 | 22 |
| 23 blink::WebGamepadButton AxisPositiveAsButton(float input) { | 23 GamepadButton AxisPositiveAsButton(float input) { |
| 24 float value = (input > 0.5f) ? 1.f : 0.f; | 24 float value = (input > 0.5f) ? 1.f : 0.f; |
| 25 bool pressed = value > kDefaultButtonPressedThreshold; | 25 bool pressed = value > kDefaultButtonPressedThreshold; |
| 26 bool touched = value > 0.0f; | 26 bool touched = value > 0.0f; |
| 27 return blink::WebGamepadButton(pressed, touched, value); | 27 return GamepadButton(pressed, touched, value); |
| 28 } | 28 } |
| 29 | 29 |
| 30 blink::WebGamepadButton ButtonFromButtonAndAxis(blink::WebGamepadButton button, | 30 GamepadButton ButtonFromButtonAndAxis(GamepadButton button, float axis) { |
| 31 float axis) { | |
| 32 float value = (axis + 1.f) / 2.f; | 31 float value = (axis + 1.f) / 2.f; |
| 33 return blink::WebGamepadButton(button.pressed, button.touched, value); | 32 return GamepadButton(button.pressed, button.touched, value); |
| 34 } | 33 } |
| 35 | 34 |
| 36 blink::WebGamepadButton NullButton() { | 35 GamepadButton NullButton() { |
| 37 return blink::WebGamepadButton(false, false, 0.0); | 36 return GamepadButton(false, false, 0.0); |
| 38 } | 37 } |
| 39 | 38 |
| 40 void DpadFromAxis(blink::WebGamepad* mapped, float dir) { | 39 void DpadFromAxis(Gamepad* mapped, float dir) { |
| 41 bool up = false; | 40 bool up = false; |
| 42 bool right = false; | 41 bool right = false; |
| 43 bool down = false; | 42 bool down = false; |
| 44 bool left = false; | 43 bool left = false; |
| 45 | 44 |
| 46 // Dpad is mapped as a direction on one axis, where -1 is up and it | 45 // Dpad is mapped as a direction on one axis, where -1 is up and it |
| 47 // increases clockwise to 1, which is up + left. It's set to a large (> 1.f) | 46 // increases clockwise to 1, which is up + left. It's set to a large (> 1.f) |
| 48 // number when nothing is depressed, except on start up, sometimes it's 0.0 | 47 // number when nothing is depressed, except on start up, sometimes it's 0.0 |
| 49 // for no data, rather than the large number. | 48 // for no data, rather than the large number. |
| 50 if (dir != 0.0f) { | 49 if (dir != 0.0f) { |
| (...skipping 11 matching lines...) Expand all Loading... |
| 62 mapped->buttons[BUTTON_INDEX_DPAD_RIGHT].value = right ? 1.f : 0.f; | 61 mapped->buttons[BUTTON_INDEX_DPAD_RIGHT].value = right ? 1.f : 0.f; |
| 63 mapped->buttons[BUTTON_INDEX_DPAD_DOWN].pressed = down; | 62 mapped->buttons[BUTTON_INDEX_DPAD_DOWN].pressed = down; |
| 64 mapped->buttons[BUTTON_INDEX_DPAD_DOWN].touched = down; | 63 mapped->buttons[BUTTON_INDEX_DPAD_DOWN].touched = down; |
| 65 mapped->buttons[BUTTON_INDEX_DPAD_DOWN].value = down ? 1.f : 0.f; | 64 mapped->buttons[BUTTON_INDEX_DPAD_DOWN].value = down ? 1.f : 0.f; |
| 66 mapped->buttons[BUTTON_INDEX_DPAD_LEFT].pressed = left; | 65 mapped->buttons[BUTTON_INDEX_DPAD_LEFT].pressed = left; |
| 67 mapped->buttons[BUTTON_INDEX_DPAD_LEFT].touched = left; | 66 mapped->buttons[BUTTON_INDEX_DPAD_LEFT].touched = left; |
| 68 mapped->buttons[BUTTON_INDEX_DPAD_LEFT].value = left ? 1.f : 0.f; | 67 mapped->buttons[BUTTON_INDEX_DPAD_LEFT].value = left ? 1.f : 0.f; |
| 69 } | 68 } |
| 70 | 69 |
| 71 } // namespace device | 70 } // namespace device |
| OLD | NEW |