summaryrefslogtreecommitdiff
path: root/chromium/device/vr/util/gamepad_builder.h
blob: 923430b4275a96ebccdb37229e5a192a99bb4459 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
// Copyright 2019 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_VR_UTIL_GAMEPAD_BUILDER_H_
#define DEVICE_VR_UTIL_GAMEPAD_BUILDER_H_

#include <string>

#include "base/macros.h"
#include "device/gamepad/public/cpp/gamepads.h"
#include "device/vr/public/mojom/isolated_xr_service.mojom.h"

namespace device {

class GamepadBuilder {
 public:

  // Helper struct that we don't want to pollute the device namespace
  struct ButtonData {
    enum class Type { kButton, kThumbstick, kTouchpad };

    bool touched = false;
    bool pressed = false;
    double value = 0.0;

    Type type = Type::kButton;
    double x_axis = 0.0;
    double y_axis = 0.0;
  };

  GamepadBuilder(const std::string& gamepad_id,
                 GamepadMapping mapping,
                 device::mojom::XRHandedness handedness);
  virtual ~GamepadBuilder();

  virtual bool IsValid() const;
  virtual base::Optional<Gamepad> GetGamepad();

  void AddButton(const GamepadButton& button);
  void AddButton(const ButtonData& data);
  void AddAxis(double value, double deadzone = 0.0);
  void AddPlaceholderAxes();
  void AddPlaceholderButton();
  void RemovePlaceholderButton();

 protected:
  void AddAxes(const ButtonData& data);

  GamepadHand GetHandedness() const { return gamepad_.hand; }
  GamepadMapping GetMapping() const { return gamepad_.mapping; }

  Gamepad gamepad_;

 private:
  DISALLOW_COPY_AND_ASSIGN(GamepadBuilder);
};

}  // namespace device

#endif  // DEVICE_VR_UTIL_GAMEPAD_BUILDER_H_