summaryrefslogtreecommitdiffstats
path: root/xbmc/input/joysticks/generic/InputHandling.h
blob: 772d9d10bbe5a2963ae515b43dcea0c24f3e2218 (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
/*
 *  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 "FeatureHandling.h"
#include "input/joysticks/JoystickTypes.h"
#include "input/joysticks/interfaces/IDriverHandler.h"

#include <map>

namespace KODI
{
namespace JOYSTICK
{
class CDriverPrimitive;
class CGUIDialogNewJoystick;
class IInputHandler;
class IButtonMap;

/*!
 * \ingroup joystick
 * \brief Class to translate input from the driver into higher-level features
 *
 * Raw driver input arrives for three elements: buttons, hats and axes. When
 * driver input is handled by this class, it translates the raw driver
 * elements into physical joystick features, such as buttons, analog sticks,
 * etc.
 *
 * A button map is used to translate driver primitives to controller features.
 * The button map has been abstracted away behind the IButtonMap
 * interface so that it can be provided by an add-on.
 */
class CInputHandling : public IDriverHandler
{
public:
  CInputHandling(IInputHandler* handler, IButtonMap* buttonMap);

  ~CInputHandling() override;

  // implementation of IDriverHandler
  bool OnButtonMotion(unsigned int buttonIndex, bool bPressed) override;
  bool OnHatMotion(unsigned int hatIndex, HAT_STATE state) override;
  bool OnAxisMotion(unsigned int axisIndex,
                    float position,
                    int center,
                    unsigned int range) override;
  void OnInputFrame() override;

private:
  bool OnDigitalMotion(const CDriverPrimitive& source, bool bPressed);
  bool OnAnalogMotion(const CDriverPrimitive& source, float magnitude);

  CJoystickFeature* CreateFeature(const FeatureName& featureName);

  IInputHandler* const m_handler;
  IButtonMap* const m_buttonMap;

  std::map<FeatureName, FeaturePtr> m_features;

  static CGUIDialogNewJoystick* const m_dialog;
};
} // namespace JOYSTICK
} // namespace KODI