| 1 |
/* |
| 2 |
* Copyright (C) 2015-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/keyboard/interfaces/IKeyboardInputHandler.h" |
| 12 |
#include "peripherals/PeripheralTypes.h" |
| 13 |
|
| 14 |
namespace KODI |
| 15 |
{ |
| 16 |
namespace KEYBOARD |
| 17 |
{ |
| 18 |
class IKeyboardInputProvider; |
| 19 |
} |
| 20 |
|
| 21 |
namespace GAME |
| 22 |
{ |
| 23 |
class CControllerActivity; |
| 24 |
class CGameClient; |
| 25 |
|
| 26 |
/*! |
| 27 |
* \ingroup games |
| 28 |
* |
| 29 |
* \brief Handles keyboard events for games. |
| 30 |
* |
| 31 |
* Listens to keyboard events and forwards them to the games (as game_input_event). |
| 32 |
*/ |
| 33 |
class CGameClientKeyboard : public KEYBOARD::IKeyboardInputHandler |
| 34 |
{ |
| 35 |
public: |
| 36 |
/*! |
| 37 |
* \brief Constructor registers for keyboard events at CInputManager. |
| 38 |
* \param gameClient The game client implementation. |
| 39 |
* \param controllerId The controller profile used for input |
| 40 |
* \param dllStruct The emulator or game to which the events are sent. |
| 41 |
* \param inputProvider The interface providing us with keyboard input. |
| 42 |
*/ |
| 43 |
CGameClientKeyboard(CGameClient& gameClient, |
| 44 |
std::string controllerId, |
| 45 |
KEYBOARD::IKeyboardInputProvider* inputProvider); |
| 46 |
|
| 47 |
/*! |
| 48 |
* \brief Destructor unregisters from keyboard events from CInputManager. |
| 49 |
*/ |
| 50 |
~CGameClientKeyboard() override; |
| 51 |
|
| 52 |
// implementation of IKeyboardInputHandler |
| 53 |
std::string ControllerID() const override; |
| 54 |
bool HasKey(const KEYBOARD::KeyName& key) const override; |
| 55 |
bool OnKeyPress(const KEYBOARD::KeyName& key, KEYBOARD::Modifier mod, uint32_t unicode) override; |
| 56 |
void OnKeyRelease(const KEYBOARD::KeyName& key, |
| 57 |
KEYBOARD::Modifier mod, |
| 58 |
uint32_t unicode) override; |
| 59 |
|
| 60 |
// Input accessors |
| 61 |
const std::string& GetControllerID() const { return m_controllerId; } |
| 62 |
const PERIPHERALS::PeripheralPtr& GetSource() const { return m_sourcePeripheral; } |
| 63 |
float GetActivation() const; |
| 64 |
|
| 65 |
// Input mutators |
| 66 |
void SetSource(PERIPHERALS::PeripheralPtr sourcePeripheral); |
| 67 |
void ClearSource(); |
| 68 |
|
| 69 |
private: |
| 70 |
// Construction parameters |
| 71 |
CGameClient& m_gameClient; |
| 72 |
const std::string m_controllerId; |
| 73 |
KEYBOARD::IKeyboardInputProvider* const m_inputProvider; |
| 74 |
|
| 75 |
// Input parameters |
| 76 |
PERIPHERALS::PeripheralPtr m_sourcePeripheral; |
| 77 |
std::unique_ptr<CControllerActivity> m_keyboardActivity; |
| 78 |
}; |
| 79 |
} // namespace GAME |
| 80 |
} // namespace KODI |