ScummVM API documentation
hardware-input.h
1/* ScummVM - Graphic Adventure Engine
2 *
3 * ScummVM is the legal property of its developers, whose names
4 * are too numerous to list here. Please refer to the COPYRIGHT
5 * file distributed with this source distribution.
6 *
7 * This program is free software: you can redistribute it and/or modify
8 * it under the terms of the GNU General Public License as published by
9 * the Free Software Foundation, either version 3 of the License, or
10 * (at your option) any later version.
11 *
12 * This program is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 * GNU General Public License for more details.
16 *
17 * You should have received a copy of the GNU General Public License
18 * along with this program. If not, see <http://www.gnu.org/licenses/>.
19 *
20 */
21
22#ifndef COMMON_HARDWARE_KEY_H
23#define COMMON_HARDWARE_KEY_H
24
25#include "common/scummsys.h"
26
27#include "common/array.h"
28#include "common/events.h"
29#include "common/keyboard.h"
30#include "common/str.h"
31
32namespace Common {
33
34typedef uint32 HardwareInputCode;
35
49};
50
57
60
63
69 HardwareInputCode inputCode;
70
77
80
81 static HardwareInput createCustom(const String &i, HardwareInputCode ic, const U32String &desc) {
82 return createSimple(kHardwareInputTypeCustom, i, ic, desc);
83 }
84
85 static HardwareInput createKeyboard(const String &i, KeyState ky, const U32String &desc) {
86 HardwareInput hardwareInput;
87 hardwareInput.id = i;
88 hardwareInput.description = desc;
89 hardwareInput.type = kHardwareInputTypeKeyboard;
90 hardwareInput.inputCode = 0;
91 hardwareInput.key = ky;
92 return hardwareInput;
93 }
94
95 static HardwareInput createJoystickButton(const String &i, uint8 button, const U32String &desc) {
96 return createSimple(kHardwareInputTypeJoystickButton, i, button, desc);
97 }
98
99 static HardwareInput createJoystickHalfAxis(const String &i, uint8 axis, bool positiveHalf, const U32String &desc) {
100 return createSimple(kHardwareInputTypeJoystickHalfAxis, i, axis * 2 + (positiveHalf ? 1 : 0), desc);
101 }
102
103 static HardwareInput createMouse(const String &i, uint8 button, const U32String &desc) {
104 return createSimple(kHardwareInputTypeMouse, i, button, desc);
105 }
106
107private:
108 static HardwareInput createSimple(HardwareInputType type, const String &i, HardwareInputCode ic, const U32String &desc) {
109 HardwareInput hardwareInput;
110 hardwareInput.id = i;
111 hardwareInput.description = desc;
112 hardwareInput.type = type;
113 hardwareInput.inputCode = ic;
114 return hardwareInput;
115 }
116};
117
122 const char *hwId;
123 HardwareInputCode code;
124 const char *desc;
125
126 static const HardwareInputTableEntry *findWithCode(const HardwareInputTableEntry *_entries, HardwareInputCode code) {
127 for (const HardwareInputTableEntry *hw = _entries; hw->hwId; hw++) {
128 if (hw->code == code) {
129 return hw;
130 }
131 }
132 return nullptr;
133 }
134
135 static const HardwareInputTableEntry *findWithId(const HardwareInputTableEntry *_entries, const String &id) {
136 for (const HardwareInputTableEntry *hw = _entries; hw->hwId; hw++) {
137 if (id.equals(hw->hwId)) {
138 return hw;
139 }
140 }
141 return nullptr;
142 }
143};
144
149 const char *hwId;
150 KeyCode keycode;
151 const char *desc;
152};
153
158 byte flag;
159 const char *id;
160 const char *desc;
161};
162
169
171 const char *hwId;
172 HardwareInputCode code;
173 AxisType type;
174 const char *desc;
175
176 static const AxisTableEntry *findWithCode(const AxisTableEntry *_entries, HardwareInputCode code) {
177 for (const AxisTableEntry *hw = _entries; hw->hwId; hw++) {
178 if (hw->code == code) {
179 return hw;
180 }
181 }
182 return nullptr;
183 }
184
185 static const AxisTableEntry *findWithId(const AxisTableEntry *_entries, const String &id) {
186 for (const AxisTableEntry *hw = _entries; hw->hwId; hw++) {
187 if (id.equals(hw->hwId)) {
188 return hw;
189 }
190 }
191 return nullptr;
192 }
193};
194
195
200public:
201 virtual ~HardwareInputSet();
202
210 virtual HardwareInput findHardwareInput(const String &id) const = 0;
211
220 virtual HardwareInput findHardwareInput(const Event &event) const = 0;
221};
222
229public:
230 KeyboardHardwareInputSet(const KeyTableEntry *keys, const ModifierTableEntry *modifiers);
231
232 // HardwareInputSet API
233 HardwareInput findHardwareInput(const String &id) const override;
234 HardwareInput findHardwareInput(const Event &event) const override;
235
237 static KeyState normalizeKeyState(const KeyState &keystate);
238
239private:
240 const KeyTableEntry *_keys;
241 const ModifierTableEntry *_modifiers;
242};
243
250public:
252
253 // HardwareInputSet API
254 HardwareInput findHardwareInput(const String &id) const override;
255 HardwareInput findHardwareInput(const Event &event) const override;
256
257private:
258 const HardwareInputTableEntry *_buttonEntries;
259};
260
265public:
266 JoystickHardwareInputSet(const HardwareInputTableEntry *buttonEntries, const AxisTableEntry *axisEntries);
267
268 // HardwareInputSet API
269 HardwareInput findHardwareInput(const String &id) const override;
270 HardwareInput findHardwareInput(const Event &event) const override;
271
272private:
273 const HardwareInputTableEntry *_buttonEntries;
274 const AxisTableEntry *_axisEntries;
275};
276
283public:
284 CustomHardwareInputSet(const HardwareInputTableEntry *hardwareEntries);
285
286 // HardwareInputSet API
287 HardwareInput findHardwareInput(const String &id) const override;
288 HardwareInput findHardwareInput(const Event &event) const override;
289
290private:
291 const HardwareInputTableEntry *_hardwareEntries;
292};
293
298public:
300
301 // HardwareInputSet API
302 HardwareInput findHardwareInput(const String &id) const override;
303 HardwareInput findHardwareInput(const Event &event) const override;
304
310 void addHardwareInputSet(HardwareInputSet *hardwareInputSet);
311
312private:
313 Array<HardwareInputSet *> _inputSets;
314};
315
317extern const KeyTableEntry defaultKeys[];
318
321
324
327
330
331} // End of namespace Common
332
333#endif // #ifndef COMMON_HARDWARE_KEY_H
Definition: array.h:52
Definition: hardware-input.h:297
HardwareInput findHardwareInput(const Event &event) const override
HardwareInput findHardwareInput(const String &id) const override
void addHardwareInputSet(HardwareInputSet *hardwareInputSet)
Definition: hardware-input.h:282
HardwareInput findHardwareInput(const Event &event) const override
HardwareInput findHardwareInput(const String &id) const override
Definition: hardware-input.h:199
virtual HardwareInput findHardwareInput(const Event &event) const =0
virtual HardwareInput findHardwareInput(const String &id) const =0
Definition: hardware-input.h:264
HardwareInput findHardwareInput(const String &id) const override
HardwareInput findHardwareInput(const Event &event) const override
Definition: hardware-input.h:228
static KeyState normalizeKeyState(const KeyState &keystate)
HardwareInput findHardwareInput(const String &id) const override
HardwareInput findHardwareInput(const Event &event) const override
Definition: hardware-input.h:249
HardwareInput findHardwareInput(const Event &event) const override
HardwareInput findHardwareInput(const String &id) const override
Definition: str.h:59
Definition: ustr.h:57
Definition: algorithm.h:29
HardwareInputType
Definition: hardware-input.h:36
@ kHardwareInputTypeMouse
Definition: hardware-input.h:42
@ kHardwareInputTypeJoystickButton
Definition: hardware-input.h:44
@ kHardwareInputTypeJoystickHalfAxis
Definition: hardware-input.h:46
@ kHardwareInputTypeKeyboard
Definition: hardware-input.h:40
@ kHardwareInputTypeInvalid
Definition: hardware-input.h:38
@ kHardwareInputTypeCustom
Definition: hardware-input.h:48
const ModifierTableEntry defaultModifiers[]
const HardwareInputTableEntry defaultMouseButtons[]
const AxisTableEntry defaultJoystickAxes[]
const HardwareInputTableEntry defaultJoystickButtons[]
const KeyTableEntry defaultKeys[]
AxisType
Definition: hardware-input.h:163
@ kAxisTypeFull
Definition: hardware-input.h:165
@ kAxisTypeHalf
Definition: hardware-input.h:167
Definition: hardware-input.h:170
Definition: events.h:218
Definition: hardware-input.h:54
String id
Definition: hardware-input.h:56
U32String description
Definition: hardware-input.h:59
KeyState key
Definition: hardware-input.h:76
HardwareInputType type
Definition: hardware-input.h:62
HardwareInputCode inputCode
Definition: hardware-input.h:69
Definition: hardware-input.h:121
Definition: keyboard.h:294
Definition: hardware-input.h:148
Definition: hardware-input.h:157