1 // Copyright 2019 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 #ifndef DEVICE_VR_UTIL_GAMEPAD_BUILDER_H_ 5 #define DEVICE_VR_UTIL_GAMEPAD_BUILDER_H_ 6 7 #include <string> 8 9 #include "base/macros.h" 10 #include "device/gamepad/public/cpp/gamepads.h" 11 #include "device/vr/public/mojom/isolated_xr_service.mojom.h" 12 13 namespace device { 14 15 class GamepadBuilder { 16 public: 17 18 // Helper struct that we don't want to pollute the device namespace 19 struct ButtonData { 20 enum class Type { kButton, kThumbstick, kTouchpad }; 21 22 bool touched = false; 23 bool pressed = false; 24 double value = 0.0; 25 26 Type type = Type::kButton; 27 double x_axis = 0.0; 28 double y_axis = 0.0; 29 }; 30 31 GamepadBuilder(const std::string& gamepad_id, 32 GamepadMapping mapping, 33 device::mojom::XRHandedness handedness); 34 virtual ~GamepadBuilder(); 35 36 virtual bool IsValid() const; 37 virtual base::Optional<Gamepad> GetGamepad(); 38 39 void AddButton(const GamepadButton& button); 40 void AddButton(const ButtonData& data); 41 void AddAxis(double value, double deadzone = 0.0); 42 void AddPlaceholderAxes(); 43 void AddPlaceholderButton(); 44 void RemovePlaceholderButton(); 45 46 protected: 47 void AddAxes(const ButtonData& data); 48 GetHandedness()49 GamepadHand GetHandedness() const { return gamepad_.hand; } GetMapping()50 GamepadMapping GetMapping() const { return gamepad_.mapping; } 51 52 Gamepad gamepad_; 53 54 private: 55 DISALLOW_COPY_AND_ASSIGN(GamepadBuilder); 56 }; 57 58 } // namespace device 59 60 #endif // DEVICE_VR_UTIL_GAMEPAD_BUILDER_H_ 61