summaryrefslogtreecommitdiffstats
path: root/xbmc/peripherals/addons/AddonInputHandling.h
blob: 295e6d424010d5a85c91cf1ef20aed447037df99 (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
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
/*
 *  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/interfaces/IDriverHandler.h"
#include "input/joysticks/interfaces/IInputReceiver.h"
#include "input/keyboard/interfaces/IKeyboardDriverHandler.h"
#include "input/mouse/interfaces/IMouseDriverHandler.h"

#include <memory>

namespace KODI
{
namespace JOYSTICK
{
class IButtonMap;
class IDriverReceiver;
class IInputHandler;
} // namespace JOYSTICK

namespace KEYBOARD
{
class IKeyboardInputHandler;
}

namespace MOUSE
{
class IMouseInputHandler;
}
} // namespace KODI

namespace PERIPHERALS
{
class CPeripheral;
class CPeripherals;
class CPeripheralAddon;

class CAddonInputHandling : public KODI::JOYSTICK::IDriverHandler,
                            public KODI::JOYSTICK::IInputReceiver,
                            public KODI::KEYBOARD::IKeyboardDriverHandler,
                            public KODI::MOUSE::IMouseDriverHandler
{
public:
  CAddonInputHandling(CPeripherals& manager,
                      CPeripheral* peripheral,
                      std::shared_ptr<CPeripheralAddon> addon,
                      KODI::JOYSTICK::IInputHandler* handler,
                      KODI::JOYSTICK::IDriverReceiver* receiver);

  CAddonInputHandling(CPeripherals& manager,
                      CPeripheral* peripheral,
                      std::shared_ptr<CPeripheralAddon> addon,
                      KODI::KEYBOARD::IKeyboardInputHandler* handler);

  CAddonInputHandling(CPeripherals& manager,
                      CPeripheral* peripheral,
                      std::shared_ptr<CPeripheralAddon> addon,
                      KODI::MOUSE::IMouseInputHandler* handler);

  ~CAddonInputHandling(void) override;

  bool Load();

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

  // implementation of IKeyboardDriverHandler
  bool OnKeyPress(const CKey& key) override;
  void OnKeyRelease(const CKey& key) override;

  // implementation of IMouseDriverHandler
  bool OnPosition(int x, int y) override;
  bool OnButtonPress(KODI::MOUSE::BUTTON_ID button) override;
  void OnButtonRelease(KODI::MOUSE::BUTTON_ID button) override;

  // implementation of IInputReceiver
  bool SetRumbleState(const KODI::JOYSTICK::FeatureName& feature, float magnitude) override;

private:
  // Construction parameters
  CPeripherals& m_manager;
  CPeripheral* const m_peripheral;
  const std::shared_ptr<CPeripheralAddon> m_addon;
  KODI::JOYSTICK::IInputHandler* const m_joystickInputHandler{nullptr};
  KODI::JOYSTICK::IDriverReceiver* const m_joystickDriverReceiver{nullptr};
  KODI::KEYBOARD::IKeyboardInputHandler* m_keyboardInputHandler{nullptr};
  KODI::MOUSE::IMouseInputHandler* const m_mouseInputHandler{nullptr};

  // Input parameters
  std::unique_ptr<KODI::JOYSTICK::IDriverHandler> m_joystickDriverHandler;
  std::unique_ptr<KODI::JOYSTICK::IInputReceiver> m_joystickInputReceiver;
  std::unique_ptr<KODI::KEYBOARD::IKeyboardDriverHandler> m_keyboardDriverHandler;
  std::unique_ptr<KODI::MOUSE::IMouseDriverHandler> m_mouseDriverHandler;
  std::unique_ptr<KODI::JOYSTICK::IButtonMap> m_buttonMap;
};
} // namespace PERIPHERALS