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 
32 namespace Common {
33 
34 typedef uint32 HardwareInputCode;
35 
49 };
50 
54 struct HardwareInput {
57 
60 
63 
69  HardwareInputCode inputCode;
70 
77 
79  : inputCode(0), type(kHardwareInputTypeInvalid) { }
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 
107 private:
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 
163 enum AxisType {
168 };
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 
200 public:
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 
229 public:
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 
239 private:
240  const KeyTableEntry *_keys;
241  const ModifierTableEntry *_modifiers;
242 };
243 
250 public:
251  MouseHardwareInputSet(const HardwareInputTableEntry *buttonEntries);
252 
253  // HardwareInputSet API
254  HardwareInput findHardwareInput(const String &id) const override;
255  HardwareInput findHardwareInput(const Event &event) const override;
256 
257 private:
258  const HardwareInputTableEntry *_buttonEntries;
259 };
260 
265 public:
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 
272 private:
273  const HardwareInputTableEntry *_buttonEntries;
274  const AxisTableEntry *_axisEntries;
275 };
276 
283 public:
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 
290 private:
291  const HardwareInputTableEntry *_hardwareEntries;
292 };
293 
298 public:
299  ~CompositeHardwareInputSet() override;
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 
312 private:
313  Array<HardwareInputSet *> _inputSets;
314 };
315 
317 extern const KeyTableEntry defaultKeys[];
318 
320 extern const ModifierTableEntry defaultModifiers[];
321 
324 
327 
329 extern const AxisTableEntry defaultJoystickAxes[];
330 
331 } // End of namespace Common
332 
333 #endif // #ifndef COMMON_HARDWARE_KEY_H
const ModifierTableEntry defaultModifiers[]
Definition: str.h:59
String id
Definition: hardware-input.h:56
Definition: array.h:52
Definition: hardware-input.h:54
Definition: hardware-input.h:264
Definition: hardware-input.h:165
const HardwareInputTableEntry defaultJoystickButtons[]
U32String description
Definition: hardware-input.h:59
Definition: hardware-input.h:148
Definition: hardware-input.h:170
const HardwareInputTableEntry defaultMouseButtons[]
Definition: hardware-input.h:228
Definition: hardware-input.h:282
HardwareInputCode inputCode
Definition: hardware-input.h:69
Definition: ustr.h:57
Definition: hardware-input.h:249
Definition: hardware-input.h:42
Definition: events.h:198
Definition: hardware-input.h:199
Definition: algorithm.h:29
Definition: hardware-input.h:40
HardwareInputType
Definition: hardware-input.h:36
KeyState key
Definition: hardware-input.h:76
const KeyTableEntry defaultKeys[]
Definition: keyboard.h:294
Definition: hardware-input.h:297
HardwareInputType type
Definition: hardware-input.h:62
Definition: hardware-input.h:167
const AxisTableEntry defaultJoystickAxes[]
Definition: hardware-input.h:121
AxisType
Definition: hardware-input.h:163
Definition: hardware-input.h:44
Definition: hardware-input.h:157
Definition: hardware-input.h:46
Definition: hardware-input.h:48
Definition: hardware-input.h:38