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

Unified Diff: content/browser/gamepad/gamepad_standard_mappings.cc

Issue 165983005: Updating Gamepad API to match latest spec (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Fixed typo in GamepadProviderTest Created 6 years, 10 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 side-by-side diff with in-line comments
Download patch
Index: content/browser/gamepad/gamepad_standard_mappings.cc
diff --git a/content/browser/gamepad/gamepad_standard_mappings.cc b/content/browser/gamepad/gamepad_standard_mappings.cc
new file mode 100644
index 0000000000000000000000000000000000000000..78c0ad87ed44e0825c59278a503db2169e4a54b4
--- /dev/null
+++ b/content/browser/gamepad/gamepad_standard_mappings.cc
@@ -0,0 +1,54 @@
+// Copyright (c) 2014 The Chromium Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style license that can be
+// found in the LICENSE file.
+
+#include "content/browser/gamepad/gamepad_standard_mappings.h"
+
+namespace content {
+
+blink::WebGamepadButton AxisToButton(float input) {
+ float value = (input + 1.f) / 2.f;
+ return blink::WebGamepadButton(
+ value > kDefaultButtonPressedThreshold, value);
+}
+
+blink::WebGamepadButton AxisNegativeAsButton(float input) {
+ float value = (input < -0.5f) ? 1.f : 0.f;
+ return blink::WebGamepadButton(
+ value > kDefaultButtonPressedThreshold, value);
+}
+
+blink::WebGamepadButton AxisPositiveAsButton(float input) {
+ float value = (input > 0.5f) ? 1.f : 0.f;
+ return blink::WebGamepadButton(
+ value > kDefaultButtonPressedThreshold, value);
+}
+
+void DpadFromAxis(blink::WebGamepad* mapped, float dir) {
+ bool up = false;
+ bool right = false;
+ bool down = false;
+ bool left = false;
+
+ // Dpad is mapped as a direction on one axis, where -1 is up and it
+ // increases clockwise to 1, which is up + left. It's set to a large (> 1.f)
+ // number when nothing is depressed, except on start up, sometimes it's 0.0
+ // for no data, rather than the large number.
+ if (dir != 0.0f) {
+ up = (dir >= -1.f && dir < -0.7f) || (dir >= .95f && dir <= 1.f);
+ right = dir >= -.75f && dir < -.1f;
+ down = dir >= -.2f && dir < .45f;
+ left = dir >= .4f && dir <= 1.f;
+ }
+
+ mapped->buttons[kButtonDpadUp].pressed = up;
+ mapped->buttons[kButtonDpadUp].value = up ? 1.f : 0.f;
+ mapped->buttons[kButtonDpadRight].pressed = right;
+ mapped->buttons[kButtonDpadRight].value = right ? 1.f : 0.f;
+ mapped->buttons[kButtonDpadDown].pressed = down;
+ mapped->buttons[kButtonDpadDown].value = down ? 1.f : 0.f;
+ mapped->buttons[kButtonDpadLeft].pressed = left;
+ mapped->buttons[kButtonDpadLeft].value = left ? 1.f : 0.f;
+}
+
+} // namespace content
« no previous file with comments | « content/browser/gamepad/gamepad_standard_mappings.h ('k') | content/browser/gamepad/gamepad_standard_mappings_linux.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698