xbmc
GameClientJoystick.h
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 
37 {
38 public:
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
Interface for classes that can provide input.
Definition: IInputProvider.h:21
void OnButtonHold(const std::string &feature, unsigned int holdTimeMs) override
A digital button has been pressed for more than one event frame.
Definition: GameClientJoystick.h:60
Interface between Kodi and Game add-ons.
Definition: GameClient.h:116
Definition: AudioDecoder.h:18
std::shared_ptr< CController > ControllerPtr
Smart pointer to a game controller (CController)
Definition: ControllerTypes.h:25
Handles game controller events for games.
Definition: GameClientJoystick.h:36
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: GameClientJoystick.h:75