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 
36 namespace Common {
37 
38 const char *const kStandardActionsKeymapName = "standard-actions";
39 
40 struct Action;
41 struct Event;
42 struct HardwareInput;
43 class HardwareInputSet;
44 class 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 
66 class Keymap {
67 public:
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 
102  void unregisterMapping(Action *action);
103 
108  void resetMapping(Action *action);
109 
113  Array<HardwareInput> getActionMapping(const Action *action) const;
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 
143  StringArray getActionDefaultMappings(Action *action);
144 
149  void loadMappings();
150 
155  void saveMappings();
156 
157  const String &getId() const { return _id; }
158  const U32String &getDescription() const { return _description; }
159  KeymapType getType() const { return _type; }
160 
164  bool isEnabled() const { return _enabled; }
165  void setEnabled(bool enabled) { _enabled = enabled; }
166 
168  static Array<Keymap *> arrayOf(Keymap *keymap) {
169  return Array<Keymap *>(1, keymap);
170  }
171 
172 private:
173 
174  const Action *findAction(const char *id) const;
175 
176  void registerMappings(Action *action, const StringArray &hwInputIds);
177  bool areMappingsIdentical(const Array<HardwareInput> &inputs, const StringArray &mapping);
178 
180 
181  KeymapType _type;
182  String _id;
183  U32String _description;
184 
185  bool _enabled;
186 
187  ActionArray _actions;
188  HardwareActionMap _hwActionMap;
189 
190  ConfigManager::Domain *_configDomain;
191  HardwareInputSet *_hardwareInputSet;
192  const KeymapperDefaultBindings *_backendDefaultBindings;
193 };
194 
196 
197 } // End of namespace Common
198 
199 #endif // #ifndef COMMON_KEYMAP_H
Definition: keymap.h:66
Definition: str.h:59
Definition: action.h:41
Definition: hardware-input.h:54
byte flags
Definition: keyboard.h:323
bool isEnabled() const
Definition: keymap.h:164
static Array< Keymap * > arrayOf(Keymap *keymap)
Definition: keymap.h:168
KeyCode keycode
Definition: keyboard.h:299
HardwareInputCode inputCode
Definition: hardware-input.h:69
Definition: ustr.h:57
const ActionArray & getActions() const
Definition: keymap.h:135
Definition: events.h:199
Definition: hardware-input.h:199
Definition: algorithm.h:29
Definition: keymapper-defaults.h:32
Definition: config-manager.h:59
KeyState key
Definition: hardware-input.h:76
Definition: keymap.h:55
HardwareInputType type
Definition: hardware-input.h:62
Definition: keymap.h:46