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