kodi
AddonInputHandling.h
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/interfaces/IDriverHandler.h"
12 #include "input/joysticks/interfaces/IInputReceiver.h"
13 #include "input/keyboard/interfaces/IKeyboardDriverHandler.h"
14 #include "input/mouse/interfaces/IMouseDriverHandler.h"
15 
16 #include <memory>
17 
18 namespace KODI
19 {
20 namespace JOYSTICK
21 {
22 class IButtonMap;
23 class IDriverReceiver;
24 class IInputHandler;
25 } // namespace JOYSTICK
26 
27 namespace KEYBOARD
28 {
29 class IKeyboardInputHandler;
30 }
31 
32 namespace MOUSE
33 {
34 class IMouseInputHandler;
35 }
36 } // namespace KODI
37 
38 namespace PERIPHERALS
39 {
40 class CPeripheral;
41 class CPeripheralAddon;
42 
50 {
51 public:
52  CAddonInputHandling(CPeripheral* peripheral,
53  std::shared_ptr<CPeripheralAddon> addon,
56 
57  CAddonInputHandling(CPeripheral* peripheral,
58  std::shared_ptr<CPeripheralAddon> addon,
60 
61  CAddonInputHandling(CPeripheral* peripheral,
62  std::shared_ptr<CPeripheralAddon> addon,
64 
65  ~CAddonInputHandling(void) override;
66 
67  bool Load();
68 
69  // implementation of IDriverHandler
70  bool OnButtonMotion(unsigned int buttonIndex, bool bPressed) override;
71  bool OnHatMotion(unsigned int hatIndex, KODI::JOYSTICK::HAT_STATE state) override;
72  bool OnAxisMotion(unsigned int axisIndex,
73  float position,
74  int center,
75  unsigned int range) override;
76  void OnInputFrame(void) override;
77 
78  // implementation of IKeyboardDriverHandler
79  bool OnKeyPress(const CKey& key) override;
80  void OnKeyRelease(const CKey& key) override;
81 
82  // implementation of IMouseDriverHandler
83  bool OnPosition(int x, int y) override;
84  bool OnButtonPress(KODI::MOUSE::BUTTON_ID button) override;
85  void OnButtonRelease(KODI::MOUSE::BUTTON_ID button) override;
86 
87  // implementation of IInputReceiver
88  bool SetRumbleState(const KODI::JOYSTICK::FeatureName& feature, float magnitude) override;
89 
90 private:
91  // Construction parameters
92  CPeripheral* const m_peripheral;
93  const std::shared_ptr<CPeripheralAddon> m_addon;
94  KODI::JOYSTICK::IInputHandler* const m_joystickInputHandler{nullptr};
95  KODI::JOYSTICK::IDriverReceiver* const m_joystickDriverReceiver{nullptr};
96  KODI::KEYBOARD::IKeyboardInputHandler* m_keyboardInputHandler{nullptr};
97  KODI::MOUSE::IMouseInputHandler* const m_mouseInputHandler{nullptr};
98 
99  // Input parameters
100  std::unique_ptr<KODI::JOYSTICK::IDriverHandler> m_joystickDriverHandler;
101  std::unique_ptr<KODI::JOYSTICK::IInputReceiver> m_joystickInputReceiver;
102  std::unique_ptr<KODI::KEYBOARD::IKeyboardDriverHandler> m_keyboardDriverHandler;
103  std::unique_ptr<KODI::MOUSE::IMouseDriverHandler> m_mouseDriverHandler;
104  std::unique_ptr<KODI::JOYSTICK::IButtonMap> m_buttonMap;
105 };
106 } // namespace PERIPHERALS
Definition: IInputHandler.h:16
Definition: AddonInputHandling.h:46
BUTTON_ID
Buttons on a mouse.
Definition: MouseTypes.h:26
Definition: RetroPlayerInput.h:15
Interface defining methods to handle joystick events for raw driver elements (buttons, hats, axes)
Definition: IDriverHandler.h:23
Interface for handling input events for keyboards.
Definition: IKeyboardInputHandler.h:28
Definition: AudioDecoder.h:18
Interface for handling mouse events.
Definition: IMouseInputHandler.h:24
Interface for handling input events for game controllers.
Definition: IInputHandler.h:26
Interface for handling mouse driver events.
Definition: IMouseDriverHandler.h:22
Interface for handling keyboard events.
Definition: IKeyboardDriverHandler.h:22
Definition: Peripheral.h:71
Interface for sending input events to game controllers.
Definition: IInputReceiver.h:22
Definition: Key.h:17
Interface for sending input events to joystick drivers.
Definition: IDriverReceiver.h:20