summaryrefslogtreecommitdiffstats
path: root/xbmc/input/joysticks/JoystickUtils.h
blob: 49095d247ca81e7e6b35b10cf536b3b4ede1cb72 (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
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
/*
 *  Copyright (C) 2014-2018 Team Kodi
 *  This file is part of Kodi - https://kodi.tv
 *
 *  SPDX-License-Identifier: GPL-2.0-or-later
 *  See LICENSES/README.md for more information.
 */

#pragma once

#include "JoystickTypes.h"

#include <string>
#include <vector>

/// \ingroup joystick
/// \{

namespace KODI
{
namespace JOYSTICK
{

inline HAT_DIRECTION& operator|=(HAT_DIRECTION& lhs, HAT_DIRECTION rhs)
{
  return lhs = static_cast<HAT_DIRECTION>(static_cast<int>(lhs) | static_cast<int>(rhs));
}

inline HAT_STATE& operator|=(HAT_STATE& lhs, HAT_STATE rhs)
{
  return lhs = static_cast<HAT_STATE>(static_cast<int>(lhs) | static_cast<int>(rhs));
}

inline bool operator&(HAT_STATE lhs, HAT_DIRECTION rhs)
{
  return (static_cast<int>(lhs) & static_cast<int>(rhs)) ? true : false;
}

inline SEMIAXIS_DIRECTION operator*(SEMIAXIS_DIRECTION lhs, int rhs)
{
  return static_cast<SEMIAXIS_DIRECTION>(static_cast<int>(lhs) * rhs);
}

inline float operator*(float lhs, SEMIAXIS_DIRECTION rhs)
{
  return lhs * static_cast<int>(rhs);
}

class CJoystickUtils
{
public:
  /*!
   * \brief Create a key name used to index an action in the keymap
   *
   * \param feature  The feature name
   *
   * \return A valid name for a key in the joystick keymap
   */
  static std::string MakeKeyName(const FeatureName& feature);

  /*!
   * \brief Create a key name used to index an action in the keymap
   *
   * \param feature  The feature name
   * \param dir      The direction for analog sticks
   *
   * \return A valid name for a key in the joystick keymap
   */
  static std::string MakeKeyName(const FeatureName& feature, ANALOG_STICK_DIRECTION dir);

  /*!
   * \brief Create a key name used to index an action in the keymap
   *
   * \param feature  The feature name
   * \param dir      The direction for a wheel to turn
   *
   * \return A valid name for a key in the joystick keymap
   */
  static std::string MakeKeyName(const FeatureName& feature, WHEEL_DIRECTION dir);

  /*!
   * \brief Create a key name used to index an action in the keymap
   *
   * \param feature  The feature name
   * \param dir      The direction for a throttle to move
   *
   * \return A valid name for a key in the joystick keymap
   */
  static std::string MakeKeyName(const FeatureName& feature, THROTTLE_DIRECTION dir);

  /*!
   * \brief Return a vector of the four cardinal directions
   */
  static const std::vector<ANALOG_STICK_DIRECTION>& GetAnalogStickDirections();

  /*!
   * \brief Return a vector of the two wheel directions
   */
  static const std::vector<WHEEL_DIRECTION>& GetWheelDirections();

  /*!
   * \brief Return a vector of the two throttle directions
   */
  static const std::vector<THROTTLE_DIRECTION>& GetThrottleDirections();
};

} // namespace JOYSTICK
} // namespace KODI

/// \}