kodi
AgentJoystick.h
1 /*
2 * Copyright (C) 2023-2024 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 namespace KODI
16 {
17 namespace GAME
18 {
19 class CControllerActivity;
20 
27 {
28 public:
29  CAgentJoystick(PERIPHERALS::PeripheralPtr peripheral);
30 
31  ~CAgentJoystick() override;
32 
33  void Initialize();
34  void Deinitialize();
35  void ClearButtonState();
36 
37  // Input parameters
38  float GetActivation() const;
39  ControllerPtr Appearance() const { return m_controllerAppearance; }
40 
41  // Implementation of IJoystickHandler
42  std::string ControllerID() const override;
43  bool HasFeature(const std::string& feature) const override;
44  bool AcceptsInput(const std::string& feature) const override;
45  bool OnButtonPress(const std::string& feature, bool bPressed) override;
46  void OnButtonHold(const std::string& feature, unsigned int holdTimeMs) override;
47  bool OnButtonMotion(const std::string& feature,
48  float magnitude,
49  unsigned int motionTimeMs) override;
50  bool OnAnalogStickMotion(const std::string& feature,
51  float x,
52  float y,
53  unsigned int motionTimeMs) override;
54  bool OnAccelerometerMotion(const std::string& feature, float x, float y, float z) override
55  {
56  return false;
57  }
58  bool OnWheelMotion(const std::string& feature,
59  float position,
60  unsigned int motionTimeMs) override;
61  bool OnThrottleMotion(const std::string& feature,
62  float position,
63  unsigned int motionTimeMs) override;
64  void OnInputFrame() override;
65 
66 private:
67  // Construction parameters
68  const PERIPHERALS::PeripheralPtr m_peripheral;
69 
70  // Input state
71  std::unique_ptr<CControllerActivity> m_controllerActivity;
72  ControllerPtr m_controllerAppearance;
73 };
74 } // namespace GAME
75 } // namespace KODI
bool OnWheelMotion(const std::string &feature, float position, unsigned int motionTimeMs) override
A wheel has changed state.
Definition: AgentJoystick.cpp:108
std::string ControllerID() const override
The add-on ID of the game controller associated with this input handler.
Definition: AgentJoystick.cpp:62
bool OnAnalogStickMotion(const std::string &feature, float x, float y, unsigned int motionTimeMs) override
An analog stick has moved.
Definition: AgentJoystick.cpp:99
bool OnButtonPress(const std::string &feature, bool bPressed) override
A digital button has been pressed or released.
Definition: AgentJoystick.cpp:80
bool OnThrottleMotion(const std::string &feature, float position, unsigned int motionTimeMs) override
A throttle has changed state.
Definition: AgentJoystick.cpp:116
bool HasFeature(const std::string &feature) const override
Return true if the input handler accepts the given feature.
Definition: AgentJoystick.cpp:70
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 game agent functionality.
Definition: AgentJoystick.h:26
bool AcceptsInput(const std::string &feature) const override
Return true if the input handler is currently accepting input for the given feature.
Definition: AgentJoystick.cpp:75
Interface for handling input events for game controllers.
Definition: IInputHandler.h:26
bool OnButtonMotion(const std::string &feature, float magnitude, unsigned int motionTimeMs) override
An analog button (trigger or a pressure-sensitive button) has changed state.
Definition: AgentJoystick.cpp:91
void OnInputFrame() override
Called at the end of the frame that provided input.
Definition: AgentJoystick.cpp:124
bool OnAccelerometerMotion(const std::string &feature, float x, float y, float z) override
An accelerometer&#39;s state has changed.
Definition: AgentJoystick.h:54
void OnButtonHold(const std::string &feature, unsigned int holdTimeMs) override
A digital button has been pressed for more than one event frame.
Definition: AgentJoystick.cpp:86