Debian Codegraph @

xbmc/games/addons/input/GameClientJoystick.h

raw
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 "games/controllers/ControllerTypes.h"
12 #include "input/joysticks/interfaces/IInputHandler.h"
13 #include "peripherals/PeripheralTypes.h"
14
15 #include <memory>
16
17 namespace KODI
18 {
19 namespace JOYSTICK
20 {
21 class IInputProvider;
22 }
23
24 namespace GAME
25 {
26 class CGameClient;
27 class CPortInput;
28
29 /*!
30 * \ingroup games
31 *
32 * \brief Handles game controller events for games.
33 *
34 * Listens to game controller events and forwards them to the games (as game_input_event).
35 */
36 class CGameClientJoystick : public JOYSTICK::IInputHandler
37 {
38 public:
39 /*!
40 * \brief Constructor.
41 * \param addon The game client implementation.
42 * \param port The port this game controller is associated with.
43 * \param controller The game controller which is used (for controller mapping).
44 * \param dllStruct The emulator or game to which the events are sent.
45 */
46 CGameClientJoystick(CGameClient& addon,
47 const std::string& portAddress,
48 const ControllerPtr& controller);
49
50 ~CGameClientJoystick() override;
51
52 void RegisterInput(JOYSTICK::IInputProvider* inputProvider);
53 void UnregisterInput(JOYSTICK::IInputProvider* inputProvider);
54
55 // Implementation of IInputHandler
56 std::string ControllerID() const override;
57 bool HasFeature(const std::string& feature) const override;
58 bool AcceptsInput(const std::string& feature) const override;
59 bool OnButtonPress(const std::string& feature, bool bPressed) override;
60 void OnButtonHold(const std::string& feature, unsigned int holdTimeMs) override {}
61 bool OnButtonMotion(const std::string& feature,
62 float magnitude,
63 unsigned int motionTimeMs) override;
64 bool OnAnalogStickMotion(const std::string& feature,
65 float x,
66 float y,
67 unsigned int motionTimeMs) override;
68 bool OnAccelerometerMotion(const std::string& feature, float x, float y, float z) override;
69 bool OnWheelMotion(const std::string& feature,
70 float position,
71 unsigned int motionTimeMs) override;
72 bool OnThrottleMotion(const std::string& feature,
73 float position,
74 unsigned int motionTimeMs) override;
75 void OnInputFrame() override {}
76
77 // Input accessors
78 const std::string& GetPortAddress() const { return m_portAddress; }
79 ControllerPtr GetController() const { return m_controller; }
80 std::string GetControllerAddress() const;
81 PERIPHERALS::PeripheralPtr GetSource() const { return m_sourcePeripheral; }
82 std::string GetSourceLocation() const;
83 float GetActivation() const;
84
85 // Input mutators
86 void SetSource(PERIPHERALS::PeripheralPtr sourcePeripheral);
87 void ClearSource();
88
89 // Input handlers
90 bool SetRumble(const std::string& feature, float magnitude);
91
92 private:
93 // Construction parameters
94 CGameClient& m_gameClient;
95 const std::string m_portAddress;
96 const ControllerPtr m_controller;
97
98 // Input parameters
99 std::unique_ptr<CPortInput> m_portInput;
100 PERIPHERALS::PeripheralPtr m_sourcePeripheral;
101 };
102 } // namespace GAME
103 } // namespace KODI