| 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 |
|
| 32 |
/*! |
| 33 |
* \ingroup games |
| 34 |
*/ |
| 35 |
class CPortInput : public JOYSTICK::IInputHandler, public KEYMAP::IKeymapEnvironment |
| 36 |
{ |
| 37 |
public: |
| 38 |
CPortInput(JOYSTICK::IInputHandler* gameInput); |
| 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 |