ScummVM API documentation
keymap.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_KEYMAP_H
23#define COMMON_KEYMAP_H
24
25#include "common/scummsys.h"
26
27#include "backends/keymapper/hardware-input.h"
28
29#include "common/config-manager.h"
30#include "common/func.h"
31#include "common/hashmap.h"
32#include "common/hash-ptr.h"
33#include "common/list.h"
34#include "common/str-array.h"
35
36namespace Common {
37
38const char *const kStandardActionsKeymapName = "standard-actions";
39
40struct Action;
41struct Event;
42struct HardwareInput;
43class HardwareInputSet;
44class KeymapperDefaultBindings;
45
47 bool operator()(const HardwareInput& x, const HardwareInput& y) const {
48 return (x.type == y.type)
49 && (x.key.keycode == y.key.keycode)
50 && (x.key.flags == y.key.flags)
51 && (x.inputCode == y.inputCode);
52 }
53};
54
56 uint operator()(const HardwareInput& x) const {
57 uint hash = 7;
58 hash = 31 * hash + x.type;
59 hash = 31 * hash + x.key.keycode;
60 hash = 31 * hash + x.key.flags;
61 hash = 31 * hash + x.inputCode;
62 return hash;
63 }
64};
65
66class Keymap {
67public:
68 enum KeymapType {
69 kKeymapTypeGlobal,
70 kKeymapTypeGui,
71 kKeymapTypeGame
72 };
73
74 enum KeymapMatch {
75 kKeymapMatchNone,
76 kKeymapMatchPartial,
77 kKeymapMatchExact
78 };
79
81
82 Keymap(KeymapType type, const String &id, const U32String &description);
83 Keymap(KeymapType type, const String &id, const String &description);
84 ~Keymap();
85 void setConfigDomain(ConfigManager::Domain *configDomain);
86 void setHardwareInputs(HardwareInputSet *hardwareInputSet);
87 void setBackendDefaultBindings(const KeymapperDefaultBindings *backendDefaultBindings);
88
95 void registerMapping(Action *action, const HardwareInput &input);
96
103
108 void resetMapping(Action *action);
109
114
121 KeymapMatch getMappedActions(const Event &event, ActionArray &actions) const;
122
130 void addAction(Action *action);
131
135 const ActionArray &getActions() const { return _actions; }
136
144
150
156
157 const String &getId() const { return _id; }
158 const U32String &getDescription() const { return _description; }
159 KeymapType getType() const { return _type; }
160
161 bool isPartialMatchAllowed() const { return _partialMatchAllowed; }
162 void setPartialMatchAllowed(bool partialMatchAllowed) { _partialMatchAllowed = partialMatchAllowed; }
163
167 bool isEnabled() const { return _enabled; }
168 void setEnabled(bool enabled) { _enabled = enabled; }
169
172 return Array<Keymap *>(1, keymap);
173 }
174
175private:
176
177 const Action *findAction(const char *id) const;
178
179 void registerMappings(Action *action, const StringArray &hwInputIds);
180 bool areMappingsIdentical(const Array<HardwareInput> &inputs, const StringArray &mapping);
181
183
184 KeymapType _type;
185 String _id;
186 U32String _description;
187 bool _partialMatchAllowed;
188 bool _enabled;
189
190 ActionArray _actions;
191 HardwareActionMap _hwActionMap;
192
193 ConfigManager::Domain *_configDomain;
194 HardwareInputSet *_hardwareInputSet;
195 const KeymapperDefaultBindings *_backendDefaultBindings;
196};
197
198typedef Array<Keymap *> KeymapArray;
199
200} // End of namespace Common
201
202#endif // #ifndef COMMON_KEYMAP_H
Definition: config-manager.h:59
Definition: hardware-input.h:199
Definition: keymap.h:66
static Array< Keymap * > arrayOf(Keymap *keymap)
Definition: keymap.h:171
void unregisterMapping(Action *action)
Array< HardwareInput > getActionMapping(const Action *action) const
KeymapMatch getMappedActions(const Event &event, ActionArray &actions) const
void resetMapping(Action *action)
const ActionArray & getActions() const
Definition: keymap.h:135
void loadMappings()
void saveMappings()
bool isEnabled() const
Definition: keymap.h:167
void registerMapping(Action *action, const HardwareInput &input)
void addAction(Action *action)
StringArray getActionDefaultMappings(Action *action)
Definition: keymapper-defaults.h:32
Definition: str.h:59
Definition: ustr.h:57
Definition: algorithm.h:29
Definition: action.h:41
Definition: events.h:218
Definition: keymap.h:46
Definition: keymap.h:55
Definition: hardware-input.h:54