summaryrefslogtreecommitdiffstats
path: root/xbmc/input/joysticks/interfaces/IDriverHandler.h
blob: 48e4da5c0c0bfdbb1a927b1795245e281a8c8b71 (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
/*
 *  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 "input/joysticks/JoystickTypes.h"

namespace KODI
{
namespace JOYSTICK
{
/*!
 * \brief Interface defining methods to handle joystick events for raw driver
 *        elements (buttons, hats, axes)
 */
class IDriverHandler
{
public:
  virtual ~IDriverHandler() = default;

  /*!
   * \brief Handle button motion
   *
   * \param buttonIndex The index of the button as reported by the driver
   * \param bPressed    true for press motion, false for release motion
   *
   * \return True if a press was handled, false otherwise
   */
  virtual bool OnButtonMotion(unsigned int buttonIndex, bool bPressed) = 0;

  /*!
   * \brief Handle hat motion
   *
   * \param hatIndex     The index of the hat as reported by the driver
   * \param state        The direction the hat is now being pressed
   *
   * \return True if the new direction was handled, false otherwise
   */
  virtual bool OnHatMotion(unsigned int hatIndex, HAT_STATE state) = 0;

  /*!
   * \brief Handle axis motion
   *
   * If a joystick feature requires multiple axes (analog sticks, accelerometers),
   * they can be buffered for later processing.
   *
   * \param axisIndex   The index of the axis as reported by the driver
   * \param position    The position of the axis in the closed interval [-1.0, 1.0]
   * \param center      The center point of the axis (either -1, 0 or 1)
   * \param range       The maximum distance the axis can move (either 1 or 2)
   *
   * \return True if the motion was handled, false otherwise
   */
  virtual bool OnAxisMotion(unsigned int axisIndex,
                            float position,
                            int center,
                            unsigned int range) = 0;

  /*!
   * \brief Handle buffered input motion for features that require multiple axes
   *
   * OnInputFrame() is called at the end of the frame when all axis motions
   * have been reported. This has several uses, including:
   *
   *  - Combining multiple axes into a single analog stick or accelerometer event
   *  - Imitating an analog feature with a digital button so that events can be
   *    dispatched every frame.
   */
  virtual void OnInputFrame(void) = 0;
};
} // namespace JOYSTICK
} // namespace KODI