OLD | NEW |
(Empty) | |
| 1 // Copyright (c) 2014 The Chromium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. |
| 4 |
| 5 #include "content/browser/gamepad/gamepad_standard_mappings.h" |
| 6 |
| 7 namespace content { |
| 8 |
| 9 blink::WebGamepadButton AxisToButton(float input) { |
| 10 float value = (input + 1.f) / 2.f; |
| 11 return blink::WebGamepadButton( |
| 12 value > kDefaultButtonPressedThreshold, value); |
| 13 } |
| 14 |
| 15 blink::WebGamepadButton AxisNegativeAsButton(float input) { |
| 16 float value = (input < -0.5f) ? 1.f : 0.f; |
| 17 return blink::WebGamepadButton( |
| 18 value > kDefaultButtonPressedThreshold, value); |
| 19 } |
| 20 |
| 21 blink::WebGamepadButton AxisPositiveAsButton(float input) { |
| 22 float value = (input > 0.5f) ? 1.f : 0.f; |
| 23 return blink::WebGamepadButton( |
| 24 value > kDefaultButtonPressedThreshold, value); |
| 25 } |
| 26 |
| 27 void DpadFromAxis(blink::WebGamepad* mapped, float dir) { |
| 28 bool up = false; |
| 29 bool right = false; |
| 30 bool down = false; |
| 31 bool left = false; |
| 32 |
| 33 // Dpad is mapped as a direction on one axis, where -1 is up and it |
| 34 // increases clockwise to 1, which is up + left. It's set to a large (> 1.f) |
| 35 // number when nothing is depressed, except on start up, sometimes it's 0.0 |
| 36 // for no data, rather than the large number. |
| 37 if (dir != 0.0f) { |
| 38 up = (dir >= -1.f && dir < -0.7f) || (dir >= .95f && dir <= 1.f); |
| 39 right = dir >= -.75f && dir < -.1f; |
| 40 down = dir >= -.2f && dir < .45f; |
| 41 left = dir >= .4f && dir <= 1.f; |
| 42 } |
| 43 |
| 44 mapped->buttons[kButtonDpadUp].pressed = up; |
| 45 mapped->buttons[kButtonDpadUp].value = up ? 1.f : 0.f; |
| 46 mapped->buttons[kButtonDpadRight].pressed = right; |
| 47 mapped->buttons[kButtonDpadRight].value = right ? 1.f : 0.f; |
| 48 mapped->buttons[kButtonDpadDown].pressed = down; |
| 49 mapped->buttons[kButtonDpadDown].value = down ? 1.f : 0.f; |
| 50 mapped->buttons[kButtonDpadLeft].pressed = left; |
| 51 mapped->buttons[kButtonDpadLeft].value = left ? 1.f : 0.f; |
| 52 } |
| 53 |
| 54 } // namespace content |
OLD | NEW |