kodi
PortInput.h
1 /*
2  * Copyright (C) 2017-2018 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/IInputHandler.h"
12 #include "input/keymaps/interfaces/IKeymapEnvironment.h"
13 
14 #include <memory>
15 
16 namespace KODI
17 {
18 namespace JOYSTICK
19 {
20 class IInputProvider;
21 } // namespace JOYSTICK
22 
23 namespace KEYMAP
24 {
25 class CKeymapHandling;
26 } // namespace KEYMAP
27 
28 namespace GAME
29 {
30 class CControllerActivity;
31 
36 {
37 public:
39  ~CPortInput() override;
40 
41  void RegisterInput(JOYSTICK::IInputProvider* provider);
42  void UnregisterInput(JOYSTICK::IInputProvider* provider);
43 
44  // Input parameters
45  float GetActivation() const;
46 
47  // Implementation of IInputHandler
48  std::string ControllerID() const override;
49  bool HasFeature(const std::string& feature) const override { return true; }
50  bool AcceptsInput(const std::string& feature) const override;
51  bool OnButtonPress(const std::string& feature, bool bPressed) override;
52  void OnButtonHold(const std::string& feature, unsigned int holdTimeMs) override;
53  bool OnButtonMotion(const std::string& feature,
54  float magnitude,
55  unsigned int motionTimeMs) override;
56  bool OnAnalogStickMotion(const std::string& feature,
57  float x,
58  float y,
59  unsigned int motionTimeMs) override;
60  bool OnAccelerometerMotion(const std::string& feature, float x, float y, float z) override;
61  bool OnWheelMotion(const std::string& feature,
62  float position,
63  unsigned int motionTimeMs) override;
64  bool OnThrottleMotion(const std::string& feature,
65  float position,
66  unsigned int motionTimeMs) override;
67  void OnInputFrame() override;
68 
69  // Implementation of IKeymapEnvironment
70  int GetWindowID() const override;
71  void SetWindowID(int windowId) override {}
72  int GetFallthrough(int windowId) const override { return -1; }
73  bool UseGlobalFallthrough() const override { return false; }
74  bool UseEasterEgg() const override { return false; }
75 
76 private:
77  // Construction parameters
78  JOYSTICK::IInputHandler* const m_gameInput;
79 
80  // Handles input to Kodi
81  std::unique_ptr<KEYMAP::CKeymapHandling> m_appInput;
82 
83  // Prevents input falling through to Kodi when not handled by the game
84  std::unique_ptr<JOYSTICK::IInputHandler> m_inputSink;
85 
86  // Records controller activity
87  std::unique_ptr<CControllerActivity> m_controllerActivity;
88 };
89 } // namespace GAME
90 } // namespace KODI
int GetFallthrough(int windowId) const override
Get the fallthrough window to when a key definition is missing.
Definition: PortInput.h:72
bool HasFeature(const std::string &feature) const override
Return true if the input handler accepts the given feature.
Definition: PortInput.h:49
Interface for classes that can provide input.
Definition: IInputProvider.h:22
void SetWindowID(int windowId) override
Set the window ID.
Definition: PortInput.h:71
bool UseGlobalFallthrough() const override
Specify if the global keymap should be used when the window and fallback window are undefined...
Definition: PortInput.h:73
bool UseEasterEgg() const override
Specify if the agent should monitor for easter egg presses.
Definition: PortInput.h:74
Customizes the environment in which keymapping is performed.
Definition: IKeymapEnvironment.h:27
Definition: PortInput.h:35
Definition: AudioDecoder.h:18
Interface for handling input events for game controllers.
Definition: IInputHandler.h:26