Debian Codegraph @

xbmc/input/joysticks/JoystickUtils.h

raw
1 /*
2 * Copyright (C) 2014-2024 Team Kodi
3 * This file is part of Kodi - https://kodi.tv
4 *
5 * SPDX-License-Identifier: GPL-2.0-or-later
6 * See LICENSES/README.md for more information.
7 */
8
9 #pragma once
10
11 #include "JoystickTypes.h"
12
13 #include <string>
14 #include <vector>
15
16 /// \ingroup joystick
17 /// \{
18
19 namespace KODI
20 {
21 namespace JOYSTICK
22 {
23
24 inline HAT_DIRECTION& operator|=(HAT_DIRECTION& lhs, HAT_DIRECTION rhs)
25 {
26 return lhs = static_cast<HAT_DIRECTION>(static_cast<int>(lhs) | static_cast<int>(rhs));
27 }
28
29 inline HAT_STATE& operator|=(HAT_STATE& lhs, HAT_STATE rhs)
30 {
31 return lhs = static_cast<HAT_STATE>(static_cast<int>(lhs) | static_cast<int>(rhs));
32 }
33
34 inline bool operator&(HAT_STATE lhs, HAT_DIRECTION rhs)
35 {
36 return (static_cast<int>(lhs) & static_cast<int>(rhs)) ? true : false;
37 }
38
39 inline SEMIAXIS_DIRECTION operator*(SEMIAXIS_DIRECTION lhs, int rhs)
40 {
41 return static_cast<SEMIAXIS_DIRECTION>(static_cast<int>(lhs) * rhs);
42 }
43
44 inline float operator*(float lhs, SEMIAXIS_DIRECTION rhs)
45 {
46 return lhs * static_cast<int>(rhs);
47 }
48
49 class CJoystickUtils
50 {
51 public:
52 /*!
53 * \brief Create a key name used to index an action in the keymap
54 *
55 * \param feature The feature name
56 *
57 * \return A valid name for a key in the joystick keymap
58 */
59 static std::string MakeKeyName(const FeatureName& feature);
60
61 /*!
62 * \brief Create a key name used to index an action in the keymap
63 *
64 * \param feature The feature name
65 * \param dir The direction for analog sticks
66 *
67 * \return A valid name for a key in the joystick keymap
68 */
69 static std::string MakeKeyName(const FeatureName& feature, ANALOG_STICK_DIRECTION dir);
70
71 /*!
72 * \brief Create a key name used to index an action in the keymap
73 *
74 * \param feature The feature name
75 * \param dir The direction for a wheel to turn
76 *
77 * \return A valid name for a key in the joystick keymap
78 */
79 static std::string MakeKeyName(const FeatureName& feature, WHEEL_DIRECTION dir);
80
81 /*!
82 * \brief Create a key name used to index an action in the keymap
83 *
84 * \param feature The feature name
85 * \param dir The direction for a throttle to move
86 *
87 * \return A valid name for a key in the joystick keymap
88 */
89 static std::string MakeKeyName(const FeatureName& feature, THROTTLE_DIRECTION dir);
90
91 /*!
92 * \brief Return a vector of the four cardinal directions
93 */
94 static const std::vector<ANALOG_STICK_DIRECTION>& GetAnalogStickDirections();
95
96 /*!
97 * \brief Return a vector of the two wheel directions
98 */
99 static const std::vector<WHEEL_DIRECTION>& GetWheelDirections();
100
101 /*!
102 * \brief Return a vector of the two throttle directions
103 */
104 static const std::vector<THROTTLE_DIRECTION>& GetThrottleDirections();
105 };
106
107 } // namespace JOYSTICK
108 } // namespace KODI
109
110 /// \}