Index: device/gamepad/public/cpp/gamepad.h |
diff --git a/device/gamepad/public/cpp/gamepad.h b/device/gamepad/public/cpp/gamepad.h |
new file mode 100644 |
index 0000000000000000000000000000000000000000..e14d272e8e868adf8cb67a6229b6c80dfeafee6a |
--- /dev/null |
+++ b/device/gamepad/public/cpp/gamepad.h |
@@ -0,0 +1,119 @@ |
+// Copyright 2017 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. |
+ |
+#ifndef DEVICE_GAMEPAD_PUBLIC_CPP_GAMEPAD_H_ |
+#define DEVICE_GAMEPAD_PUBLIC_CPP_GAMEPAD_H_ |
+ |
+#include <stddef.h> |
+ |
+namespace device { |
+ |
+#pragma pack(push, 4) |
+ |
+class GamepadButton { |
+ public: |
+ GamepadButton() : pressed(false), touched(false), value(0.) {} |
+ GamepadButton(bool pressed, bool touched, double value) |
+ : pressed(pressed), touched(touched), value(value) {} |
+ bool pressed; |
+ bool touched; |
+ double value; |
+}; |
+ |
+class GamepadVector { |
+ public: |
+ GamepadVector() : not_null(false) {} |
+ |
+ bool not_null; |
+ float x, y, z; |
+}; |
+ |
+class GamepadQuaternion { |
+ public: |
+ GamepadQuaternion() : not_null(false) {} |
+ |
+ bool not_null; |
+ float x, y, z, w; |
+}; |
+ |
+class GamepadPose { |
+ public: |
+ GamepadPose() : not_null(false) {} |
+ |
+ bool not_null; |
+ |
+ bool has_orientation; |
+ bool has_position; |
+ |
+ GamepadQuaternion orientation; |
+ GamepadVector position; |
+ GamepadVector angular_velocity; |
+ GamepadVector linear_velocity; |
+ GamepadVector angular_acceleration; |
+ GamepadVector linear_acceleration; |
+}; |
+ |
+enum GamepadHand { |
dcheng
2017/04/12 23:33:27
Consider making this scoped, since it looks like a
juncai
2017/04/13 23:55:52
Done.
|
+ kGamepadHandNone = 0, |
+ kGamepadHandLeft = 1, |
+ kGamepadHandRight = 2 |
+}; |
+ |
+// UTF-16 character type |
+#if defined(WIN32) |
+typedef wchar_t UChar; |
dcheng
2017/04/12 23:33:27
Oh... I see.
Nit: prefer using over typedef
juncai
2017/04/13 23:55:52
Done.
|
+#else |
+typedef unsigned short UChar; |
+#endif |
+ |
+// This structure is intentionally POD and fixed size so that it can be shared |
+// memory between hardware polling threads and the rest of the browser. See |
+// also gamepads.h. |
+class Gamepad { |
+ public: |
+ static const size_t kIdLengthCap = 128; |
+ static const size_t kMappingLengthCap = 16; |
+ static const size_t kAxesLengthCap = 16; |
+ static const size_t kButtonsLengthCap = 32; |
+ |
+ Gamepad(); |
+ Gamepad(const Gamepad& other); |
+ |
+ // Is there a gamepad connected at this index? |
+ bool connected; |
+ |
+ // Device identifier (based on manufacturer, model, etc.). |
+ UChar id[kIdLengthCap]; |
+ |
+ // Monotonically increasing value referring to when the data were last |
+ // updated. |
+ unsigned long long timestamp; |
+ |
+ // Number of valid entries in the axes array. |
+ unsigned axes_length; |
+ |
+ // Normalized values representing axes, in the range [-1..1]. |
+ double axes[kAxesLengthCap]; |
+ |
+ // Number of valid entries in the buttons array. |
+ unsigned buttons_length; |
+ |
+ // Button states |
+ GamepadButton buttons[kButtonsLengthCap]; |
+ |
+ // Mapping type (for example "standard") |
+ UChar mapping[kMappingLengthCap]; |
+ |
+ GamepadPose pose; |
+ |
+ GamepadHand hand; |
+ |
+ unsigned display_id; |
+}; |
+ |
+#pragma pack(pop) |
+ |
+} // namespace device |
+ |
+#endif // DEVICE_GAMEPAD_PUBLIC_CPP_GAMEPAD_H_ |