| 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/JoystickTypes.h" |
| 12 |
|
| 13 |
namespace KODI |
| 14 |
{ |
| 15 |
namespace JOYSTICK |
| 16 |
{ |
| 17 |
/*! |
| 18 |
* \ingroup joystick |
| 19 |
* |
| 20 |
* \brief Interface defining methods to handle joystick events for raw driver |
| 21 |
* elements (buttons, hats, axes) |
| 22 |
*/ |
| 23 |
class IDriverHandler |
| 24 |
{ |
| 25 |
public: |
| 26 |
virtual ~IDriverHandler() = default; |
| 27 |
|
| 28 |
/*! |
| 29 |
* \brief Handle button motion |
| 30 |
* |
| 31 |
* \param buttonIndex The index of the button as reported by the driver |
| 32 |
* \param bPressed true for press motion, false for release motion |
| 33 |
* |
| 34 |
* \return True if a press was handled, false otherwise |
| 35 |
*/ |
| 36 |
virtual bool OnButtonMotion(unsigned int buttonIndex, bool bPressed) = 0; |
| 37 |
|
| 38 |
/*! |
| 39 |
* \brief Handle hat motion |
| 40 |
* |
| 41 |
* \param hatIndex The index of the hat as reported by the driver |
| 42 |
* \param state The direction the hat is now being pressed |
| 43 |
* |
| 44 |
* \return True if the new direction was handled, false otherwise |
| 45 |
*/ |
| 46 |
virtual bool OnHatMotion(unsigned int hatIndex, HAT_STATE state) = 0; |
| 47 |
|
| 48 |
/*! |
| 49 |
* \brief Handle axis motion |
| 50 |
* |
| 51 |
* If a joystick feature requires multiple axes (analog sticks, accelerometers), |
| 52 |
* they can be buffered for later processing. |
| 53 |
* |
| 54 |
* \param axisIndex The index of the axis as reported by the driver |
| 55 |
* \param position The position of the axis in the closed interval [-1.0, 1.0] |
| 56 |
* \param center The center point of the axis (either -1, 0 or 1) |
| 57 |
* \param range The maximum distance the axis can move (either 1 or 2) |
| 58 |
* |
| 59 |
* \return True if the motion was handled, false otherwise |
| 60 |
*/ |
| 61 |
virtual bool OnAxisMotion(unsigned int axisIndex, |
| 62 |
float position, |
| 63 |
int center, |
| 64 |
unsigned int range) = 0; |
| 65 |
|
| 66 |
/*! |
| 67 |
* \brief Handle buffered input motion for features that require multiple axes |
| 68 |
* |
| 69 |
* OnInputFrame() is called at the end of the frame when all axis motions |
| 70 |
* have been reported. This has several uses, including: |
| 71 |
* |
| 72 |
* - Combining multiple axes into a single analog stick or accelerometer event |
| 73 |
* - Imitating an analog feature with a digital button so that events can be |
| 74 |
* dispatched every frame. |
| 75 |
*/ |
| 76 |
virtual void OnInputFrame(void) = 0; |
| 77 |
}; |
| 78 |
} // namespace JOYSTICK |
| 79 |
} // namespace KODI |