Speech bubbles can point down right.
[scummvm-innocent.git] / backends / keymapper / keymapper.h
blobf492882ca28b5f794bfd8f9ef53df5c9806f2720
1 /* ScummVM - Graphic Adventure Engine
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.
7 * This program is free software; you can redistribute it and/or
8 * modify it under the terms of the GNU General Public License
9 * as published by the Free Software Foundation; either version 2
10 * of the License, or (at your option) any later version.
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.
17 * You should have received a copy of the GNU General Public License
18 * along with this program; if not, write to the Free Software
19 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
21 * $URL$
22 * $Id$
26 #ifndef COMMON_KEYMAPPER_H
27 #define COMMON_KEYMAPPER_H
29 #include "common/scummsys.h"
31 #ifdef ENABLE_KEYMAPPER
33 #include "common/events.h"
34 #include "common/list.h"
35 #include "common/hashmap.h"
36 #include "common/stack.h"
37 #include "backends/keymapper/hardware-key.h"
38 #include "backends/keymapper/keymap.h"
40 namespace Common {
42 class Keymapper : public Common::EventMapper, private Common::ArtificialEventSource {
43 public:
45 struct MapRecord {
46 Keymap* keymap;
47 bool inherit;
48 bool global;
51 /* Nested class that represents a set of keymaps */
52 class Domain : public HashMap<String, Keymap*,
53 IgnoreCase_Hash, IgnoreCase_EqualTo> {
54 public:
55 Domain() : _configDomain(0) {}
56 ~Domain() {
57 deleteAllKeyMaps();
60 void setConfigDomain(ConfigManager::Domain *confDom) {
61 _configDomain = confDom;
63 ConfigManager::Domain *getConfigDomain() {
64 return _configDomain;
67 void addKeymap(Keymap *map);
69 void deleteAllKeyMaps();
71 Keymap *getKeymap(const String& name);
73 private:
74 ConfigManager::Domain *_configDomain;
77 Keymapper(EventManager *eventMan);
78 ~Keymapper();
80 /**
81 * Registers a HardwareKeySet with the Keymapper
82 * @note should only be called once (during backend initialisation)
84 void registerHardwareKeySet(HardwareKeySet *keys);
86 /**
87 * Get a list of all registered HardwareKeys
89 const List<const HardwareKey*> &getHardwareKeys() const {
90 assert(_hardwareKeys);
91 return _hardwareKeys->getHardwareKeys();
94 /**
95 * Add a keymap to the global domain.
96 * If a saved key setup exists for it in the ini file it will be used.
97 * Else, the key setup will be automatically mapped.
99 void addGlobalKeymap(Keymap *keymap);
102 * Add a keymap to the game domain.
103 * @see addGlobalKeyMap
104 * @note initGame() should be called before any game keymaps are added.
106 void addGameKeymap(Keymap *keymap);
109 * Should be called at end of game to tell Keymapper to deactivate and free
110 * any game keymaps that are loaded.
112 void cleanupGameKeymaps();
115 * Obtain a keymap of the given name from the keymapper.
116 * Game keymaps have priority over global keymaps
117 * @param name name of the keymap to return
118 * @param global set to true if returned keymap is global, false if game
120 Keymap *getKeymap(const String& name, bool &global);
123 * Push a new keymap to the top of the active stack, activating
124 * it for use.
125 * @param name name of the keymap to push
126 * @param inherit if true keymapper will iterate down the
127 * stack if it cannot find a key in the new map
128 * @return true if succesful
130 bool pushKeymap(const String& name, bool inherit = false);
133 * Pop the top keymap off the active stack.
135 void popKeymap();
137 // Implementation of the EventMapper interface
138 bool notifyEvent(const Common::Event &ev);
139 bool pollEvent(Common::Event &ev) { return Common::ArtificialEventSource::pollEvent(ev); }
142 * @brief Map a key press event.
143 * If the active keymap contains a Action mapped to the given key, then
144 * the Action's events are pushed into the EventManager's event queue.
145 * @param key key that was pressed
146 * @param keyDown true for key down, false for key up
147 * @return true if key was mapped
149 bool mapKey(const KeyState& key, bool keyDown);
152 * @brief Map a key down event.
153 * @see mapKey
155 bool mapKeyDown(const KeyState& key);
158 * @brief Map a key up event.
159 * @see mapKey
161 bool mapKeyUp(const KeyState& key);
164 * Enable/disable the keymapper
166 void setEnabled(bool enabled) { _enabled = enabled; }
169 * Return a HardwareKey pointer for the given key state
171 const HardwareKey *findHardwareKey(const KeyState& key);
173 Domain& getGlobalDomain() { return _globalDomain; }
174 Domain& getGameDomain() { return _gameDomain; }
175 const Stack<MapRecord>& getActiveStack() const { return _activeMaps; }
177 private:
179 void initKeymap(Domain &domain, Keymap *keymap);
181 Domain _globalDomain;
182 Domain _gameDomain;
184 HardwareKeySet *_hardwareKeys;
186 void pushKeymap(Keymap *newMap, bool inherit, bool global);
188 Action *getAction(const KeyState& key);
189 void executeAction(const Action *act, bool keyDown);
191 EventManager *_eventMan;
193 bool _enabled;
195 Stack<MapRecord> _activeMaps;
196 HashMap<KeyState, Action*> _keysDown;
200 } // end of namespace Common
202 #endif // #ifdef ENABLE_KEYMAPPER
204 #endif // #ifndef COMMON_KEYMAPPER_H