Debian Codegraph @

xbmc/games/controllers/windows/IConfigurationWindow.h

raw
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
11 #include "games/controllers/ControllerTypes.h"
12 #include "input/InputTypes.h"
13 #include "input/joysticks/JoystickTypes.h"
14
15 #include <string>
16 #include <vector>
17
18 class CEvent;
19
20 namespace KODI
21 {
22 namespace GAME
23 {
24 class CPhysicalFeature;
25
26 /*!
27 * \ingroup games
28 *
29 * \brief A list populated by installed controllers for the controller
30 * configuration window
31 *
32 * The configuration window presents a list of controllers. Also on the screen
33 * is a list of features (\ref IFeatureList) belonging to that controller.
34 *
35 * The configuration utility reacts to several events:
36 *
37 * 1) When a controller is focused, the feature list is populated with the
38 * controller's features.
39 *
40 * 2) When a feature is selected, the user is prompted for controller input.
41 * This initiates a "wizard" (\ref IConfigurationWizard) that walks the
42 * user through the subsequent features.
43 *
44 * 3) When the wizard's active feature loses focus, the wizard is cancelled
45 * and the prompt for input ends.
46 */
47 class IControllerList
48 {
49 public:
50 virtual ~IControllerList() = default;
51
52 /*!
53 * \brief Initialize the resource
54 *
55 * \return true if the resource is initialized and can be used
56 * false if the resource failed to initialize and must not be used
57 */
58 virtual bool Initialize(void) = 0;
59
60 /*!
61 * \brief Deinitialize the resource
62 */
63 virtual void Deinitialize(void) = 0;
64
65 /*!
66 * \brief Refresh the contents of the list
67 *
68 * \param controllerId The controller to focus, or empty to leave focus unchanged
69 *
70 * \return True if the list was changed
71 */
72 virtual bool Refresh(const std::string& controllerId) = 0;
73
74 /*
75 * \brief The specified controller has been focused
76 *
77 * \param controllerIndex The index of the controller being focused
78 */
79 virtual void OnFocus(unsigned int controllerIndex) = 0;
80
81 /*!
82 * \brief The specified controller has been selected
83 *
84 * \param controllerIndex The index of the controller being selected
85 */
86 virtual void OnSelect(unsigned int controllerIndex) = 0;
87
88 /*!
89 * \brief Get the index of the focused controller
90 *
91 * \return The index of the focused controller, or -1 if no controller has been focused yet
92 */
93 virtual int GetFocusedController() const = 0;
94
95 /*!
96 * \brief Reset the focused controller
97 */
98 virtual void ResetController(void) = 0;
99 };
100
101 /*!
102 * \ingroup games
103 *
104 * \brief A list populated by the controller's features
105 *
106 * The feature list is populated by features (\ref IFeatureButton) belonging
107 * to the current controller selected in the controller list
108 * (\ref IControllerList).
109 */
110 class IFeatureList
111 {
112 public:
113 virtual ~IFeatureList() = default;
114
115 /*!
116 * \brief Initialize the resource
117 * \return true if the resource is initialized and can be used
118 * false if the resource failed to initialize and must not be used
119 */
120 virtual bool Initialize(void) = 0;
121
122 /*!
123 * \brief Deinitialize the resource
124 * \remark This must be called if Initialize() returned true
125 */
126 virtual void Deinitialize(void) = 0;
127
128 /*!
129 * \brief Check if the feature type has any buttons in the GUI
130 * \param The type of the feature being added to the GUI
131 * \return True if the type is support, false otherwise
132 */
133 virtual bool HasButton(JOYSTICK::FEATURE_TYPE type) const = 0;
134
135 /*!
136 * \brief Load the features for the specified controller
137 * \param controller The controller to load
138 */
139 virtual void Load(const ControllerPtr& controller) = 0;
140
141 /*!
142 * \brief Focus has been set to the specified GUI button
143 * \param buttonIndex The index of the button being focused
144 */
145 virtual void OnFocus(unsigned int buttonIndex) = 0;
146
147 /*!
148 * \brief The specified GUI button has been selected
149 * \param buttonIndex The index of the button being selected
150 */
151 virtual void OnSelect(unsigned int buttonIndex) = 0;
152 };
153
154 /*!
155 * \ingroup games
156 *
157 * \brief A GUI button in a feature list (\ref IFeatureList)
158 */
159 class IFeatureButton
160 {
161 public:
162 virtual ~IFeatureButton() = default;
163
164 /*!
165 * \brief Get the feature represented by this button
166 */
167 virtual const CPhysicalFeature& Feature(void) const = 0;
168
169 /*!
170 * \brief Allow the wizard to include this feature in a list of buttons
171 * to map
172 */
173 virtual bool AllowWizard() const { return true; }
174
175 /*!
176 * \brief Prompt the user for a single input element
177 * \param waitEvent The event to block on while prompting for input
178 * \return true if input was received (event fired), false if the prompt timed out
179 *
180 * After the button has finished prompting the user for all the input
181 * elements it requires, this will return false until Reset() is called.
182 */
183 virtual bool PromptForInput(CEvent& waitEvent) = 0;
184
185 /*!
186 * \brief Check if the button supports further calls to PromptForInput()
187 * \return true if the button requires no more input elements from the user
188 */
189 virtual bool IsFinished(void) const = 0;
190
191 /*!
192 * \brief Get the direction of the next analog stick or relative pointer
193 * prompt
194 * \return The next direction to be prompted, or UNKNOWN if this isn't a
195 * cardinal feature or the prompt is finished
196 */
197 virtual INPUT::CARDINAL_DIRECTION GetCardinalDirection(void) const = 0;
198
199 /*!
200 * \brief Get the direction of the next wheel prompt
201 * \return The next direction to be prompted, or UNKNOWN if this isn't a
202 * wheel or the prompt is finished
203 */
204 virtual JOYSTICK::WHEEL_DIRECTION GetWheelDirection(void) const = 0;
205
206 /*!
207 * \brief Get the direction of the next throttle prompt
208 * \return The next direction to be prompted, or UNKNOWN if this isn't a
209 * throttle or the prompt is finished
210 */
211 virtual JOYSTICK::THROTTLE_DIRECTION GetThrottleDirection(void) const = 0;
212
213 /*!
214 * \brief True if the button is waiting for a key press
215 */
216 virtual bool NeedsKey() const { return false; }
217
218 /*!
219 * \brief Set the pressed key that the user will be prompted to map
220 *
221 * \param key The key that was pressed
222 */
223 virtual void SetKey(const CPhysicalFeature& key) {}
224
225 /*!
226 * \brief Reset button after prompting for input has finished
227 */
228 virtual void Reset(void) = 0;
229 };
230
231 /*!
232 * \ingroup games
233 *
234 * \brief A wizard to direct user input
235 *
236 * The wizard is run for the current controller selected in the controller list
237 * (\ref IControllerList). It prompts the user for input for each feature
238 * (\ref IFeatureButton) in the feature list (\ref IFeatureList).
239 */
240 class IConfigurationWizard
241 {
242 public:
243 virtual ~IConfigurationWizard() = default;
244
245 /*!
246 * \brief Start the wizard for the specified buttons
247 * \param controllerId The controller ID being mapped
248 * \param buttons The buttons to map
249 */
250 virtual void Run(const std::string& strControllerId,
251 const std::vector<IFeatureButton*>& buttons) = 0;
252
253 /*!
254 * \brief Callback for feature losing focus
255 * \param button The feature button losing focus
256 */
257 virtual void OnUnfocus(IFeatureButton* button) = 0;
258
259 /*!
260 * \brief Abort a running wizard
261 * \param bWait True if the call should block until the wizard is fully aborted
262 * \return true if aborted, or false if the wizard wasn't running
263 */
264 virtual bool Abort(bool bWait = true) = 0;
265
266 /*!
267 * \brief Register a key by its keycode
268 * \param key A key with a valid keycode
269 *
270 * This should be called before Run(). It allows the user to choose a key
271 * to map instead of scrolling through a long list.
272 */
273 virtual void RegisterKey(const CPhysicalFeature& key) = 0;
274
275 /*!
276 * \brief Unregister all registered keys
277 */
278 virtual void UnregisterKeys() = 0;
279 };
280 } // namespace GAME
281 } // namespace KODI