| 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 "input/joysticks/DriverPrimitive.h" |
| 12 |
#include "input/joysticks/JoystickTypes.h" |
| 13 |
|
| 14 |
#include <string> |
| 15 |
#include <vector> |
| 16 |
|
| 17 |
namespace KODI |
| 18 |
{ |
| 19 |
namespace JOYSTICK |
| 20 |
{ |
| 21 |
/*! |
| 22 |
* \ingroup joystick |
| 23 |
* |
| 24 |
* \brief Button map interface to translate between the driver's raw |
| 25 |
* button/hat/axis elements and physical joystick features. |
| 26 |
* |
| 27 |
* \sa IButtonMapper |
| 28 |
*/ |
| 29 |
class IButtonMap |
| 30 |
{ |
| 31 |
public: |
| 32 |
virtual ~IButtonMap() = default; |
| 33 |
|
| 34 |
/*! |
| 35 |
* \brief The add-on ID of the game controller associated with this button map |
| 36 |
* |
| 37 |
* The controller ID provided by the implementation serves as the context |
| 38 |
* for the feature names below. |
| 39 |
* |
| 40 |
* \return The ID of this button map's game controller add-on |
| 41 |
*/ |
| 42 |
virtual std::string ControllerID(void) const = 0; |
| 43 |
|
| 44 |
/*! |
| 45 |
* \brief The Location of the peripheral associated with this button map |
| 46 |
* |
| 47 |
* \return The peripheral's location |
| 48 |
*/ |
| 49 |
virtual std::string Location(void) const = 0; |
| 50 |
|
| 51 |
/*! |
| 52 |
* \brief Load the button map into memory |
| 53 |
* |
| 54 |
* \return True if button map is ready to start translating buttons, false otherwise |
| 55 |
*/ |
| 56 |
virtual bool Load(void) = 0; |
| 57 |
|
| 58 |
/*! |
| 59 |
* \brief Reset the button map to its defaults, or clear button map if no defaults |
| 60 |
*/ |
| 61 |
virtual void Reset(void) = 0; |
| 62 |
|
| 63 |
/*! |
| 64 |
* \brief Check if the button map is empty |
| 65 |
* |
| 66 |
* \return True if the button map is empty, false if it has features |
| 67 |
*/ |
| 68 |
virtual bool IsEmpty(void) const = 0; |
| 69 |
|
| 70 |
/*! |
| 71 |
* \brief Get the ID of the controller profile that best represents the |
| 72 |
* appearance of the peripheral |
| 73 |
* |
| 74 |
* \return The controller ID, or empty if the appearance is unknown |
| 75 |
*/ |
| 76 |
virtual std::string GetAppearance() const = 0; |
| 77 |
|
| 78 |
/*! |
| 79 |
* \brief Set the ID of the controller that best represents the appearance |
| 80 |
* of the peripheral |
| 81 |
* |
| 82 |
* \param controllerId The controller ID, or empty to unset the appearance |
| 83 |
* |
| 84 |
* \return True if the appearance was set, false on error |
| 85 |
*/ |
| 86 |
virtual bool SetAppearance(const std::string& controllerId) const = 0; |
| 87 |
|
| 88 |
/*! |
| 89 |
* \brief Get the feature associated with a driver primitive |
| 90 |
* |
| 91 |
* Multiple primitives can be mapped to the same feature. For example, |
| 92 |
* analog sticks use one primitive for each direction. |
| 93 |
* |
| 94 |
* \param primitive The driver primitive |
| 95 |
* \param feature The name of the resolved joystick feature, or |
| 96 |
* invalid if false is returned |
| 97 |
* |
| 98 |
* \return True if the driver primitive is associated with a feature, false otherwise |
| 99 |
*/ |
| 100 |
virtual bool GetFeature(const CDriverPrimitive& primitive, FeatureName& feature) = 0; |
| 101 |
|
| 102 |
/*! |
| 103 |
* \brief Get the type of the feature for the given name |
| 104 |
* |
| 105 |
* \param feature The feature to look up |
| 106 |
* |
| 107 |
* \return The feature's type |
| 108 |
*/ |
| 109 |
virtual FEATURE_TYPE GetFeatureType(const FeatureName& feature) = 0; |
| 110 |
|
| 111 |
/*! |
| 112 |
* \brief Get the driver primitive for a scalar feature |
| 113 |
* |
| 114 |
* When a feature can be represented by a single driver primitive, it is |
| 115 |
* called a scalar feature. |
| 116 |
* |
| 117 |
* - This includes buttons and triggers, because they can be mapped to a |
| 118 |
* single button/hat/semiaxis |
| 119 |
* |
| 120 |
* - This does not include analog sticks, because they require two axes |
| 121 |
* and four driver primitives (one for each semiaxis) |
| 122 |
* |
| 123 |
* \param feature Must be a scalar feature (a feature that only |
| 124 |
* requires a single driver primitive) |
| 125 |
* \param primitive The resolved driver primitive |
| 126 |
* |
| 127 |
* \return True if the feature resolved to a driver primitive, false if the |
| 128 |
* feature didn't resolve or isn't a scalar feature |
| 129 |
*/ |
| 130 |
virtual bool GetScalar(const FeatureName& feature, CDriverPrimitive& primitive) = 0; |
| 131 |
|
| 132 |
/*! |
| 133 |
* \brief Add or update a scalar feature |
| 134 |
* |
| 135 |
* \param feature Must be a scalar feature |
| 136 |
* \param primitive The feature's driver primitive |
| 137 |
* |
| 138 |
* \return True if the feature was updated, false if the feature is |
| 139 |
* unchanged or failure occurs |
| 140 |
*/ |
| 141 |
virtual void AddScalar(const FeatureName& feature, const CDriverPrimitive& primitive) = 0; |
| 142 |
|
| 143 |
/*! |
| 144 |
* \brief Get an analog stick direction from the button map |
| 145 |
* |
| 146 |
* \param feature Must be an analog stick or this will return false |
| 147 |
* \param direction The direction whose primitive is to be retrieved |
| 148 |
* \param[out] primitive The primitive mapped to the specified direction |
| 149 |
* |
| 150 |
* \return True if the feature and direction resolved to a driver primitive |
| 151 |
*/ |
| 152 |
virtual bool GetAnalogStick(const FeatureName& feature, |
| 153 |
ANALOG_STICK_DIRECTION direction, |
| 154 |
CDriverPrimitive& primitive) = 0; |
| 155 |
|
| 156 |
/*! |
| 157 |
* \brief Add or update an analog stick direction |
| 158 |
* |
| 159 |
* \param feature Must be an analog stick or this will return false |
| 160 |
* \param direction The direction being mapped |
| 161 |
* \param primitive The driver primitive for the specified analog stick and direction |
| 162 |
* |
| 163 |
* \return True if the analog stick was updated, false otherwise |
| 164 |
*/ |
| 165 |
virtual void AddAnalogStick(const FeatureName& feature, |
| 166 |
ANALOG_STICK_DIRECTION direction, |
| 167 |
const CDriverPrimitive& primitive) = 0; |
| 168 |
|
| 169 |
/*! |
| 170 |
* \brief Get a relative pointer direction from the button map |
| 171 |
* |
| 172 |
* \param feature Must be a relative pointer stick or this will return false |
| 173 |
* \param direction The direction whose primitive is to be retrieved |
| 174 |
* \param[out] primitive The primitive mapped to the specified direction |
| 175 |
* |
| 176 |
* \return True if the feature and direction resolved to a driver primitive |
| 177 |
*/ |
| 178 |
virtual bool GetRelativePointer(const FeatureName& feature, |
| 179 |
RELATIVE_POINTER_DIRECTION direction, |
| 180 |
CDriverPrimitive& primitive) = 0; |
| 181 |
|
| 182 |
/*! |
| 183 |
* \brief Add or update a relative pointer direction |
| 184 |
* |
| 185 |
* \param feature Must be a relative pointer or this will return false |
| 186 |
* \param direction The direction being mapped |
| 187 |
* \param primitive The driver primitive for the specified analog stick and direction |
| 188 |
* |
| 189 |
* \return True if the analog stick was updated, false otherwise |
| 190 |
*/ |
| 191 |
virtual void AddRelativePointer(const FeatureName& feature, |
| 192 |
RELATIVE_POINTER_DIRECTION direction, |
| 193 |
const CDriverPrimitive& primitive) = 0; |
| 194 |
|
| 195 |
/*! |
| 196 |
* \brief Get an accelerometer from the button map |
| 197 |
* |
| 198 |
* \param feature Must be an accelerometer or this will return false |
| 199 |
* \param positiveX The semiaxis mapped to the positive X direction (possibly unknown) |
| 200 |
* \param positiveY The semiaxis mapped to the positive Y direction (possibly unknown) |
| 201 |
* \param positiveZ The semiaxis mapped to the positive Z direction (possibly unknown) |
| 202 |
* |
| 203 |
* \return True if the feature resolved to an accelerometer with at least 1 known axis |
| 204 |
*/ |
| 205 |
virtual bool GetAccelerometer(const FeatureName& feature, |
| 206 |
CDriverPrimitive& positiveX, |
| 207 |
CDriverPrimitive& positiveY, |
| 208 |
CDriverPrimitive& positiveZ) = 0; |
| 209 |
|
| 210 |
/*! |
| 211 |
* \brief Get or update an accelerometer |
| 212 |
* |
| 213 |
* \param feature Must be an accelerometer or this will return false |
| 214 |
* \param positiveX The semiaxis corresponding to the positive X direction |
| 215 |
* \param positiveY The semiaxis corresponding to the positive Y direction |
| 216 |
* \param positiveZ The semiaxis corresponding to the positive Z direction |
| 217 |
* |
| 218 |
* The driver primitives must be mapped to a semiaxis or this function will fail. |
| 219 |
* |
| 220 |
* \return True if the accelerometer was updated, false if unchanged or failure occurred |
| 221 |
*/ |
| 222 |
virtual void AddAccelerometer(const FeatureName& feature, |
| 223 |
const CDriverPrimitive& positiveX, |
| 224 |
const CDriverPrimitive& positiveY, |
| 225 |
const CDriverPrimitive& positiveZ) = 0; |
| 226 |
|
| 227 |
/*! |
| 228 |
* \brief Get a wheel direction from the button map |
| 229 |
* |
| 230 |
* \param feature Must be a wheel or this will return false |
| 231 |
* \param direction The direction whose primitive is to be retrieved |
| 232 |
* \param[out] primitive The primitive mapped to the specified direction |
| 233 |
* |
| 234 |
* \return True if the feature and direction resolved to a driver primitive |
| 235 |
*/ |
| 236 |
virtual bool GetWheel(const FeatureName& feature, |
| 237 |
WHEEL_DIRECTION direction, |
| 238 |
CDriverPrimitive& primitive) = 0; |
| 239 |
|
| 240 |
/*! |
| 241 |
* \brief Add or update a wheel direction |
| 242 |
* |
| 243 |
* \param feature Must be a wheel or this will return false |
| 244 |
* \param direction The direction being mapped |
| 245 |
* \param primitive The driver primitive for the specified analog stick and direction |
| 246 |
* |
| 247 |
* \return True if the analog stick was updated, false otherwise |
| 248 |
*/ |
| 249 |
virtual void AddWheel(const FeatureName& feature, |
| 250 |
WHEEL_DIRECTION direction, |
| 251 |
const CDriverPrimitive& primitive) = 0; |
| 252 |
|
| 253 |
/*! |
| 254 |
* \brief Get a throttle direction from the button map |
| 255 |
* |
| 256 |
* \param feature Must be a throttle or this will return false |
| 257 |
* \param direction The direction whose primitive is to be retrieved |
| 258 |
* \param[out] primitive The primitive mapped to the specified direction |
| 259 |
* |
| 260 |
* \return True if the feature and direction resolved to a driver primitive |
| 261 |
*/ |
| 262 |
virtual bool GetThrottle(const FeatureName& feature, |
| 263 |
THROTTLE_DIRECTION direction, |
| 264 |
CDriverPrimitive& primitive) = 0; |
| 265 |
|
| 266 |
/*! |
| 267 |
* \brief Add or update a throttle direction |
| 268 |
* |
| 269 |
* \param feature Must be a throttle or this will return false |
| 270 |
* \param direction The direction being mapped |
| 271 |
* \param primitive The driver primitive for the specified analog stick and direction |
| 272 |
* |
| 273 |
* \return True if the analog stick was updated, false otherwise |
| 274 |
*/ |
| 275 |
virtual void AddThrottle(const FeatureName& feature, |
| 276 |
THROTTLE_DIRECTION direction, |
| 277 |
const CDriverPrimitive& primitive) = 0; |
| 278 |
|
| 279 |
/*! |
| 280 |
* \brief Get the driver primitive for a keyboard key |
| 281 |
* |
| 282 |
* \param feature Must be a key |
| 283 |
* \param primitive The resolved driver primitive |
| 284 |
* |
| 285 |
* \return True if the feature resolved to a driver primitive, false if the |
| 286 |
* feature didn't resolve or isn't a scalar feature |
| 287 |
*/ |
| 288 |
virtual bool GetKey(const FeatureName& feature, CDriverPrimitive& primitive) = 0; |
| 289 |
|
| 290 |
/*! |
| 291 |
* \brief Add or update a key |
| 292 |
* |
| 293 |
* \param feature Must be a key |
| 294 |
* \param primitive The feature's driver primitive |
| 295 |
* |
| 296 |
* \return True if the feature was updated, false if the feature is |
| 297 |
* unchanged or failure occurs |
| 298 |
*/ |
| 299 |
virtual void AddKey(const FeatureName& feature, const CDriverPrimitive& primitive) = 0; |
| 300 |
|
| 301 |
/*! |
| 302 |
* \brief Set a list of driver primitives to be ignored |
| 303 |
* |
| 304 |
* This is necessary to prevent features from interfering with the button |
| 305 |
* mapping process. This includes accelerometers, as well as PS4 triggers |
| 306 |
* which send both a button press and an analog value. |
| 307 |
* |
| 308 |
* \param primitives The driver primitives to be ignored |
| 309 |
*/ |
| 310 |
virtual void SetIgnoredPrimitives(const std::vector<CDriverPrimitive>& primitives) = 0; |
| 311 |
|
| 312 |
/*! |
| 313 |
* \brief Check if a primitive is in the list of primitives to be ignored |
| 314 |
* |
| 315 |
* \param primitive The primitive to check |
| 316 |
* |
| 317 |
* \return True if the primitive should be ignored in the mapping process |
| 318 |
*/ |
| 319 |
virtual bool IsIgnored(const CDriverPrimitive& primitive) = 0; |
| 320 |
|
| 321 |
/*! |
| 322 |
* \brief Get the properties of an axis |
| 323 |
* |
| 324 |
* \param axisIndex The index of the axis to check |
| 325 |
* \param center[out] The center, if known |
| 326 |
* \param range[out] The range, if known |
| 327 |
* |
| 328 |
* \return True if the properties are known, false otherwise |
| 329 |
*/ |
| 330 |
virtual bool GetAxisProperties(unsigned int axisIndex, int& center, unsigned int& range) = 0; |
| 331 |
|
| 332 |
/*! |
| 333 |
* \brief Save the button map |
| 334 |
*/ |
| 335 |
virtual void SaveButtonMap() = 0; |
| 336 |
|
| 337 |
/*! |
| 338 |
* \brief Revert changes to the button map since the last time it was loaded |
| 339 |
* or committed to disk |
| 340 |
*/ |
| 341 |
virtual void RevertButtonMap() = 0; |
| 342 |
}; |
| 343 |
} // namespace JOYSTICK |
| 344 |
} // namespace KODI |