xbmc
IInputHandler.h
1 /*
2  * Copyright (C) 2014-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 
12 
13 #include <string>
14 
15 namespace KODI
16 {
17 namespace JOYSTICK
18 {
19 class IInputReceiver;
20 
26 {
27 public:
28  virtual ~IInputHandler() = default;
29 
35  virtual std::string ControllerID(void) const = 0;
36 
44  virtual bool HasFeature(const FeatureName& feature) const = 0;
45 
57  virtual bool AcceptsInput(const FeatureName& feature) const = 0;
58 
67  virtual bool OnButtonPress(const FeatureName& feature, bool bPressed) = 0;
68 
78  virtual void OnButtonHold(const FeatureName& feature, unsigned int holdTimeMs) = 0;
79 
90  virtual bool OnButtonMotion(const FeatureName& feature,
91  float magnitude,
92  unsigned int motionTimeMs) = 0;
93 
105  virtual bool OnAnalogStickMotion(const FeatureName& feature,
106  float x,
107  float y,
108  unsigned int motionTimeMs) = 0;
109 
120  virtual bool OnAccelerometerMotion(const FeatureName& feature, float x, float y, float z)
121  {
122  return false;
123  }
124 
136  virtual bool OnWheelMotion(const FeatureName& feature,
137  float position,
138  unsigned int motionTimeMs) = 0;
139 
151  virtual bool OnThrottleMotion(const FeatureName& feature,
152  float position,
153  unsigned int motionTimeMs) = 0;
154 
158  virtual void OnInputFrame() = 0;
159 
160  // Input receiver interface
161  void SetInputReceiver(IInputReceiver* receiver) { m_receiver = receiver; }
162  void ResetInputReceiver(void) { m_receiver = nullptr; }
163  IInputReceiver* InputReceiver(void) { return m_receiver; }
164 
165 private:
166  IInputReceiver* m_receiver = nullptr;
167 };
168 } // namespace JOYSTICK
169 } // 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.
Controller configuration window.
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:25
std::string FeatureName
Name of a physical feature belonging to the joystick.
Definition: JoystickTypes.h:28
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:21
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:120