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