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