Debian Codegraph @

src/input/InputManager.h

raw
1 /*
2 * Copyright (C) 2015-2021 Team Kodi (https://kodi.tv)
3 *
4 * SPDX-License-Identifier: GPL-2.0-or-later
5 * See LICENSE.md for more information.
6 */
7
8 #pragma once
9
10 #include "InputTypes.h"
11 #include "ControllerLayout.h"
12 #include "LibretroDevice.h"
13
14 #include <kodi/addon-instance/Game.h>
15 #include <mutex>
16
17 #include <map>
18 #include <memory>
19 #include <stdint.h>
20 #include <string>
21 #include <vector>
22
23 struct retro_controller_info;
24 struct retro_input_descriptor;
25
26 namespace LIBRETRO
27 {
28 typedef uint64_t libretro_device_caps_t;
29
30 class CInputManager
31 {
32 private:
33 CInputManager(void) { }
34
35 public:
36 static CInputManager& Get(void);
37
38 /*!
39 * \brief Get the devices supported by the libretro wrapper
40 *
41 * \return A bitmask of libretro devices that this class supports
42 */
43 libretro_device_caps_t GetDeviceCaps(void) const;
44
45 /*!
46 * \brief
47 */
48 void SetControllerLayouts(const std::vector<kodi::addon::GameControllerLayout>& controllers);
49
50 /*!
51 * \brief Enable the keyboard
52 *
53 * \param controllerId The keyboard's controller ID
54 *
55 * \return True if keyboard was enabled, false otherwise
56 */
57 bool EnableKeyboard(const std::string &controller);
58
59 /*!
60 * \brief Disable the keyboard and free any resources it held
61 */
62 void DisableKeyboard();
63
64 /*!
65 * \brief Enable mouse input
66 *
67 * \param controllerId The mouse's controller ID
68 *
69 * \return True if mouse input was enabled, false otherwise
70 */
71 bool EnableMouse(const std::string &controllerId);
72
73 /*!
74 * \brief Disable the mouse and free any resources it held
75 */
76 void DisableMouse();
77
78 /*!
79 * \brief Called when a device has been connected to a port
80 */
81 libretro_device_t ConnectController(const std::string &address, const std::string &controllerId);
82
83 /*!
84 * \brief Called when a device has been disconnected from a port
85 */
86 bool DisconnectController(const std::string &address);
87
88 /*!
89 * \brief Get the port number associated with the specified address
90 *
91 * \return The port number, or -1 if the address has no port number
92 */
93 int GetPortIndex(const std::string &address) const;
94
95 /*!
96 * \brief Get the port number that we should use when setting the
97 * controller port
98 *
99 * \param address The port address
100 * \param[out] connectionPort The port used to change connections, or
101 * untouched if this function returns false
102 *
103 * \return True if a connection port was specified, false otherwise
104 */
105 bool GetConnectionPortIndex(const std::string &address, int& connectionPort) const;
106
107 std::string GetAddress(unsigned int port) const;
108
109 /*!
110 * \brief Get the libretro device abstraction for the device connected to
111 * the specified address
112 */
113 libretro_device_t GetDeviceType(const std::string &address) const;
114
115 /*!
116 * \brief Close all ports
117 */
118 void ClosePorts(void);
119
120 /*!
121 * \brief Enable or disable the port's analog sensors (enabled by default)
122 *
123 * \param port The port
124 * \param bEnabled True to enable port's analog sensors, false to disable
125 */
126 void EnableAnalogSensors(unsigned int port, bool bEnabled);
127
128 /*!
129 * \brief Called when an input event has occurred
130 */
131 bool InputEvent(const game_input_event& event);
132
133 /*!
134 * \brief Parse libretro input descriptors and output to the log
135 */
136 void LogInputDescriptors(const retro_input_descriptor* descriptors) const;
137
138 /*!
139 * \brief Return the controller ID that the specified port is connected to
140 */
141 std::string ControllerID(unsigned int port) const;
142
143 bool ButtonState(libretro_device_t device, unsigned int port, unsigned int buttonIndex) const;
144 float AnalogButtonState(unsigned int port, unsigned int buttonIndex) const;
145 int DeltaX(libretro_device_t device, unsigned int port);
146 int DeltaY(libretro_device_t device, unsigned int port);
147 bool AnalogStickState(unsigned int port, unsigned int analogStickIndex, float& x, float& y) const;
148 bool AbsolutePointerState(unsigned int port, unsigned int pointerIndex, float& x, float& y) const;
149 bool AccelerometerState(unsigned int port, float& x, float& y, float& z) const;
150
151 /*!
152 * \brief Inform the frontend of controller info
153 */
154 void SetControllerInfo(const retro_controller_info* info);
155
156 private:
157 DevicePtr m_keyboard;
158 DevicePtr m_mouse;
159 DeviceVector m_controllers;
160 std::map<std::string, std::unique_ptr<CControllerLayout>> m_controllerLayouts;
161 };
162 }