| 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 "FeatureHandling.h" |
| 12 |
#include "input/joysticks/JoystickTypes.h" |
| 13 |
#include "input/joysticks/interfaces/IDriverHandler.h" |
| 14 |
|
| 15 |
#include <map> |
| 16 |
|
| 17 |
namespace KODI |
| 18 |
{ |
| 19 |
namespace JOYSTICK |
| 20 |
{ |
| 21 |
class CDriverPrimitive; |
| 22 |
class CGUIDialogNewJoystick; |
| 23 |
class IInputHandler; |
| 24 |
class IButtonMap; |
| 25 |
|
| 26 |
/*! |
| 27 |
* \ingroup joystick |
| 28 |
* |
| 29 |
* \brief Class to translate input from the driver into higher-level features |
| 30 |
* |
| 31 |
* Raw driver input arrives for three elements: buttons, hats and axes. When |
| 32 |
* driver input is handled by this class, it translates the raw driver |
| 33 |
* elements into physical joystick features, such as buttons, analog sticks, |
| 34 |
* etc. |
| 35 |
* |
| 36 |
* A button map is used to translate driver primitives to controller features. |
| 37 |
* The button map has been abstracted away behind the IButtonMap |
| 38 |
* interface so that it can be provided by an add-on. |
| 39 |
*/ |
| 40 |
class CInputHandling : public IDriverHandler |
| 41 |
{ |
| 42 |
public: |
| 43 |
CInputHandling(IInputHandler* handler, IButtonMap* buttonMap); |
| 44 |
|
| 45 |
~CInputHandling() override; |
| 46 |
|
| 47 |
// implementation of IDriverHandler |
| 48 |
bool OnButtonMotion(unsigned int buttonIndex, bool bPressed) override; |
| 49 |
bool OnHatMotion(unsigned int hatIndex, HAT_STATE state) override; |
| 50 |
bool OnAxisMotion(unsigned int axisIndex, |
| 51 |
float position, |
| 52 |
int center, |
| 53 |
unsigned int range) override; |
| 54 |
void OnInputFrame() override; |
| 55 |
|
| 56 |
private: |
| 57 |
bool OnDigitalMotion(const CDriverPrimitive& source, bool bPressed); |
| 58 |
bool OnAnalogMotion(const CDriverPrimitive& source, float magnitude); |
| 59 |
|
| 60 |
CJoystickFeature* CreateFeature(const FeatureName& featureName); |
| 61 |
|
| 62 |
IInputHandler* const m_handler; |
| 63 |
IButtonMap* const m_buttonMap; |
| 64 |
|
| 65 |
std::map<FeatureName, FeaturePtr> m_features; |
| 66 |
|
| 67 |
static CGUIDialogNewJoystick* const m_dialog; |
| 68 |
}; |
| 69 |
} // namespace JOYSTICK |
| 70 |
} // namespace KODI |