kodi
IInputHandler.h
1 /*
2  * Copyright (C) 2014-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 "input/joysticks/JoystickTypes.h"
12 
13 #include <string>
14 
15 namespace KODI
16 {
17 namespace JOYSTICK
18 {
19 class IInputReceiver;
20 
27 {
28 public:
29  virtual ~IInputHandler() = default;
30 
36  virtual std::string ControllerID(void) const = 0;
37 
45  virtual bool HasFeature(const FeatureName& feature) const = 0;
46 
58  virtual bool AcceptsInput(const FeatureName& feature) const = 0;
59 
68  virtual bool OnButtonPress(const FeatureName& feature, bool bPressed) = 0;
69 
79  virtual void OnButtonHold(const FeatureName& feature, unsigned int holdTimeMs) = 0;
80 
91  virtual bool OnButtonMotion(const FeatureName& feature,
92  float magnitude,
93  unsigned int motionTimeMs) = 0;
94 
106  virtual bool OnAnalogStickMotion(const FeatureName& feature,
107  float x,
108  float y,
109  unsigned int motionTimeMs) = 0;
110 
121  virtual bool OnAccelerometerMotion(const FeatureName& feature, float x, float y, float z)
122  {
123  return false;
124  }
125 
137  virtual bool OnWheelMotion(const FeatureName& feature,
138  float position,
139  unsigned int motionTimeMs) = 0;
140 
152  virtual bool OnThrottleMotion(const FeatureName& feature,
153  float position,
154  unsigned int motionTimeMs) = 0;
155 
159  virtual void OnInputFrame() = 0;
160 
161  // Input receiver interface
162  void SetInputReceiver(IInputReceiver* receiver) { m_receiver = receiver; }
163  void ResetInputReceiver(void) { m_receiver = nullptr; }
164  IInputReceiver* InputReceiver(void) { return m_receiver; }
165 
166 private:
167  IInputReceiver* m_receiver = nullptr;
168 };
169 } // namespace JOYSTICK
170 } // namespace KODI
virtual bool OnButtonMotion(const FeatureName &feature, float magnitude, unsigned int motionTimeMs)=0
An analog button (trigger or a pressure-sensitive button) has changed state.
virtual void OnInputFrame()=0
Called at the end of the frame that provided input.
virtual bool HasFeature(const FeatureName &feature) const =0
Return true if the input handler accepts the given feature.
virtual bool OnThrottleMotion(const FeatureName &feature, float position, unsigned int motionTimeMs)=0
A throttle has changed state.
virtual void OnButtonHold(const FeatureName &feature, unsigned int holdTimeMs)=0
A digital button has been pressed for more than one event frame.
virtual bool OnAnalogStickMotion(const FeatureName &feature, float x, float y, unsigned int motionTimeMs)=0
An analog stick has moved.
Definition: AudioDecoder.h:18
virtual bool AcceptsInput(const FeatureName &feature) const =0
Return true if the input handler is currently accepting input for the given feature.
Interface for handling input events for game controllers.
Definition: IInputHandler.h:26
virtual bool OnWheelMotion(const FeatureName &feature, float position, unsigned int motionTimeMs)=0
A wheel has changed state.
virtual bool OnButtonPress(const FeatureName &feature, bool bPressed)=0
A digital button has been pressed or released.
Interface for sending input events to game controllers.
Definition: IInputReceiver.h:22
virtual std::string ControllerID(void) const =0
The add-on ID of the game controller associated with this input handler.
virtual bool OnAccelerometerMotion(const FeatureName &feature, float x, float y, float z)
An accelerometer&#39;s state has changed.
Definition: IInputHandler.h:121