summaryrefslogtreecommitdiff
path: root/Source/Core/InputCommon/ControllerEmu/ControlGroup/Cursor.h
blob: c66b2b896cee7851d937351c5c02acd1e184fcd9 (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
61
62
63
// Copyright 2017 Dolphin Emulator Project
// Licensed under GPLv2+
// Refer to the license.txt file included.

#pragma once

#include <chrono>
#include <string>

#include "InputCommon/ControllerEmu/StickGate.h"
#include "InputCommon/ControllerInterface/Device.h"

namespace ControllerEmu
{
class Cursor : public ReshapableInput
{
public:
  struct StateData
  {
    ControlState x{};
    ControlState y{};
    ControlState z{};
  };

  enum
  {
    SETTING_CENTER = ReshapableInput::SETTING_COUNT,
    SETTING_WIDTH,
    SETTING_HEIGHT,
  };

  explicit Cursor(const std::string& name);

  ReshapeData GetReshapableState(bool adjusted) final override;
  ControlState GetGateRadiusAtAngle(double ang) const override;

  StateData GetState(bool adjusted);

private:
  // This is used to reduce the cursor speed for relative input
  // to something that makes sense with the default range.
  static constexpr double STEP_PER_SEC = 0.04 * 200;

  // Smooth out forward/backward movements:
  static constexpr double STEP_Z_PER_SEC = 0.05 * 200;

  static constexpr int AUTO_HIDE_MS = 2500;
  static constexpr double AUTO_HIDE_DEADZONE = 0.001;

  static constexpr double BUTTON_THRESHOLD = 0.5;

  // Not adjusted by width/height/center:
  StateData m_state;

  // Adjusted:
  StateData m_prev_result;

  int m_auto_hide_timer = AUTO_HIDE_MS;

  using Clock = std::chrono::steady_clock;
  Clock::time_point m_last_update;
};
}  // namespace ControllerEmu