Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(113)

Side by Side Diff: content/browser/gamepad/gamepad_standard_mappings.cc

Issue 2081583002: Migrating majority of gamepad from content/browser/ to device/ (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Next attempt Created 4 years, 5 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
(Empty)
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
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 blink::WebGamepadButton ButtonFromButtonAndAxis(
28 blink::WebGamepadButton button, float axis) {
29 float value = (axis + 1.f) / 2.f;
30 return blink::WebGamepadButton(button.pressed, value);
31 }
32
33 blink::WebGamepadButton NullButton() {
34 return blink::WebGamepadButton(false, 0.0);
35 }
36
37 void DpadFromAxis(blink::WebGamepad* mapped, float dir) {
38 bool up = false;
39 bool right = false;
40 bool down = false;
41 bool left = false;
42
43 // Dpad is mapped as a direction on one axis, where -1 is up and it
44 // increases clockwise to 1, which is up + left. It's set to a large (> 1.f)
45 // number when nothing is depressed, except on start up, sometimes it's 0.0
46 // for no data, rather than the large number.
47 if (dir != 0.0f) {
48 up = (dir >= -1.f && dir < -0.7f) || (dir >= .95f && dir <= 1.f);
49 right = dir >= -.75f && dir < -.1f;
50 down = dir >= -.2f && dir < .45f;
51 left = dir >= .4f && dir <= 1.f;
52 }
53
54 mapped->buttons[BUTTON_INDEX_DPAD_UP].pressed = up;
55 mapped->buttons[BUTTON_INDEX_DPAD_UP].value = up ? 1.f : 0.f;
56 mapped->buttons[BUTTON_INDEX_DPAD_RIGHT].pressed = right;
57 mapped->buttons[BUTTON_INDEX_DPAD_RIGHT].value = right ? 1.f : 0.f;
58 mapped->buttons[BUTTON_INDEX_DPAD_DOWN].pressed = down;
59 mapped->buttons[BUTTON_INDEX_DPAD_DOWN].value = down ? 1.f : 0.f;
60 mapped->buttons[BUTTON_INDEX_DPAD_LEFT].pressed = left;
61 mapped->buttons[BUTTON_INDEX_DPAD_LEFT].value = left ? 1.f : 0.f;
62 }
63
64 } // namespace content
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698