aboutsummaryrefslogtreecommitdiff
path: root/backends
diff options
context:
space:
mode:
authorStephen Kennedy2008-08-18 14:45:42 +0000
committerStephen Kennedy2008-08-18 14:45:42 +0000
commit565fa728e7956bd1a8aecd55ee7ae6928fb5dd99 (patch)
treee400478e0ef900f7f027053d120973996803b401 /backends
parent049ac6c42b83dba3bf165e5be7c3416d1f7d959f (diff)
downloadscummvm-rg350-565fa728e7956bd1a8aecd55ee7ae6928fb5dd99.tar.gz
scummvm-rg350-565fa728e7956bd1a8aecd55ee7ae6928fb5dd99.tar.bz2
scummvm-rg350-565fa728e7956bd1a8aecd55ee7ae6928fb5dd99.zip
Removed KeymapManager class. Automatic mapping now done in Keymap. Rest of KeymapManager functionality is implemented in Keymapper.
svn-id: r33988
Diffstat (limited to 'backends')
-rw-r--r--backends/keymapper/keymap-manager.cpp234
-rw-r--r--backends/keymapper/keymap-manager.h105
-rw-r--r--backends/keymapper/keymap.cpp127
-rw-r--r--backends/keymapper/keymap.h5
-rw-r--r--backends/keymapper/keymapper.cpp76
-rw-r--r--backends/keymapper/keymapper.h92
-rw-r--r--backends/keymapper/remap-dialog.cpp10
7 files changed, 278 insertions, 371 deletions
diff --git a/backends/keymapper/keymap-manager.cpp b/backends/keymapper/keymap-manager.cpp
deleted file mode 100644
index f57c0e5504..0000000000
--- a/backends/keymapper/keymap-manager.cpp
+++ /dev/null
@@ -1,234 +0,0 @@
-/* ScummVM - Graphic Adventure Engine
-*
-* ScummVM is the legal property of its developers, whose names
-* are too numerous to list here. Please refer to the COPYRIGHT
-* file distributed with this source distribution.
-*
-* This program is free software; you can redistribute it and/or
-* modify it under the terms of the GNU General Public License
-* as published by the Free Software Foundation; either version 2
-* of the License, or (at your option) any later version.
-*
-* This program is distributed in the hope that it will be useful,
-* but WITHOUT ANY WARRANTY; without even the implied warranty of
-* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
-* GNU General Public License for more details.
-*
-* You should have received a copy of the GNU General Public License
-* along with this program; if not, write to the Free Software
-* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
-*
-* $URL$
-* $Id$
-*
-*/
-
-#include "backends/keymapper/keymap-manager.h"
-#include "common/algorithm.h"
-
-namespace Common {
-
-void KeymapManager::Domain::addKeymap(Keymap *map) {
- KeymapMap::iterator it = _keymaps.find(map->getName());
- if (it != _keymaps.end())
- delete _keymaps[map->getName()];
- _keymaps[map->getName()] = map;
-}
-
-void KeymapManager::Domain::deleteAllKeyMaps() {
- KeymapMap::iterator it;
- for (it = _keymaps.begin(); it != _keymaps.end(); it++)
- delete it->_value;
- _keymaps.clear();
-}
-
-Keymap *KeymapManager::Domain::getKeymap(const String& name) {
- KeymapMap::iterator it = _keymaps.find(name);
- if (it != _keymaps.end())
- return it->_value;
- else
- return 0;
-}
-
-KeymapManager::KeymapManager() {
- _hardwareKeys = 0;
- _globalDomain.setConfigDomain(ConfMan.getDomain(ConfigManager::kApplicationDomain));
-}
-
-KeymapManager::~KeymapManager() {
- delete _hardwareKeys;
-}
-
-void KeymapManager::registerHardwareKeySet(HardwareKeySet *keys) {
- if (_hardwareKeys)
- error("Hardware key set already registered!");
- _hardwareKeys = keys;
-}
-
-void KeymapManager::registerGlobalKeymap(Keymap *map) {
- initKeymap(_globalDomain.getConfigDomain(), map);
- _globalDomain.addKeymap(map);
-}
-
-void KeymapManager::refreshGameDomain() {
- if (_gameDomain.getConfigDomain() != ConfMan.getActiveDomain()) {
- _gameDomain.deleteAllKeyMaps();
- _gameDomain.setConfigDomain(ConfMan.getActiveDomain());
- }
-}
-
-void KeymapManager::registerGameKeymap(Keymap *map) {
- refreshGameDomain();
- initKeymap(_gameDomain.getConfigDomain(), map);
- _gameDomain.addKeymap(map);
-}
-
-void KeymapManager::initKeymap(ConfigManager::Domain *domain,
- Keymap *map) {
- map->setConfigDomain(domain);
- map->loadMappings(_hardwareKeys);
- if (map->isComplete(_hardwareKeys) == false)
- automaticMap(map);
-}
-
-// TODO:
-// - current weaknesses:
-// - if an action finds a key with required type / category but a parent
-// action with higher priority is using it, that key is never used
-void KeymapManager::automaticMap(Keymap *map) {
- // Create local copies of action and key lists.
- List<Action*> actions(map->getActions());
- List<const HardwareKey*> keys(_hardwareKeys->getHardwareKeys());
-
- List<Action*>::iterator actIt;
- List<const HardwareKey*>::iterator keyIt, selectedKey;
-
- // Remove actions and keys from local lists that have already been mapped.
- actIt = actions.begin();
- while (actIt != actions.end()) {
- Action *act = *actIt;
- const HardwareKey *key = act->getMappedKey();
- if (key) {
- keys.remove(key);
- actIt = actions.erase(actIt);
- } else {
- ++actIt;
- }
- }
-
- // Sort remaining actions by priority.
- ActionPriorityComp priorityComp;
- sort(actions.begin(), actions.end(), priorityComp);
-
- // First mapping pass:
- // - Match if a key's preferred type or category is same as the action's.
- // - Priority is given to:
- // - keys that match type over category.
- // - keys that have not been used by parent maps.
- // - If a key has been used by a parent map the new action must have a
- // higher priority than the parent action.
- // - As soon as the number of skipped actions equals the number of keys
- // remaining we stop matching. This means that the second pass will assign keys
- // to these higher priority skipped actions.
- uint skipped = 0;
- actIt = actions.begin();
- while (actIt != actions.end() && skipped < keys.size()) {
- selectedKey = keys.end();
- int matchRank = 0;
- Action *act = *actIt;
- for (keyIt = keys.begin(); keyIt != keys.end(); ++keyIt) {
- if ((*keyIt)->preferredType == act->type) {
- Action *parentAct = getParentMappedAction(map, (*keyIt)->key);
- if (!parentAct) {
- selectedKey = keyIt;
- break;
- } else if (parentAct->priority <= act->priority && matchRank < 3) {
- selectedKey = keyIt;
- matchRank = 3;
- }
- } else if ((*keyIt)->preferredCategory == act->category && matchRank < 2) {
- Action *parentAct = getParentMappedAction(map, (*keyIt)->key);
- if (!parentAct) {
- selectedKey = keyIt;
- matchRank = 2;
- } else if (parentAct->priority <= act->priority && matchRank < 1) {
- selectedKey = keyIt;
- matchRank = 1;
- }
- }
- }
- if (selectedKey != keys.end()) {
- // Map action and delete action & key from local lists.
- act->mapKey(*selectedKey);
- keys.erase(selectedKey);
- actIt = actions.erase(actIt);
- } else {
- // Skip action (will be mapped in next pass).
- ++actIt;
- ++skipped;
- }
- }
-
- // Second mapping pass:
- // - Maps any remaining actions to keys
- // - priority given to:
- // - keys that have no parent action
- // - keys whose parent action has lower priority than the new action
- // - keys whose parent action has the lowest priority
- // - is guarantees to match a key if one is available
- for (actIt = actions.begin(); actIt != actions.end(); ++actIt) {
- selectedKey = keys.end();
- int matchRank = 0;
- int lowestPriority = 0;
- Action *act = *actIt;
- for (keyIt = keys.begin(); keyIt != keys.end(); ++keyIt) {
- Action *parentAct = getParentMappedAction(map, (*keyIt)->key);
- if (!parentAct) {
- selectedKey = keyIt;
- break;
- } else if (matchRank < 2) {
- if (parentAct->priority <= act->priority) {
- matchRank = 2;
- selectedKey = keyIt;
- } else if (parentAct->priority < lowestPriority || matchRank == 0) {
- matchRank = 1;
- lowestPriority = parentAct->priority;
- selectedKey = keyIt;
- }
- }
- }
- if (selectedKey != keys.end()) {
- act->mapKey(*selectedKey);
- keys.erase(selectedKey);
- } else {// no match = no keys left
- break;
- }
- }
- map->saveMappings();
- ConfMan.flushToDisk();
-}
-
-Action *KeymapManager::getParentMappedAction(Keymap *map, KeyState key) {
- Keymap *parent = map->getParent();
- if (parent) {
- Action *act = parent->getMappedAction(key);
- if (act)
- return act;
- else
- return getParentMappedAction(parent, key);
- } else {
- return 0;
- }
-}
-
-Keymap *KeymapManager::getKeymap(const String& name, bool *global) {
- Keymap *keymap = _gameDomain.getKeymap(name);
- *global = false;
- if (!keymap) {
- keymap = _globalDomain.getKeymap(name);
- *global = true;
- }
- return keymap;
-}
-
-} // end of namespace Common
diff --git a/backends/keymapper/keymap-manager.h b/backends/keymapper/keymap-manager.h
deleted file mode 100644
index b9afaee80b..0000000000
--- a/backends/keymapper/keymap-manager.h
+++ /dev/null
@@ -1,105 +0,0 @@
-/* ScummVM - Graphic Adventure Engine
-*
-* ScummVM is the legal property of its developers, whose names
-* are too numerous to list here. Please refer to the COPYRIGHT
-* file distributed with this source distribution.
-*
-* This program is free software; you can redistribute it and/or
-* modify it under the terms of the GNU General Public License
-* as published by the Free Software Foundation; either version 2
-* of the License, or (at your option) any later version.
-*
-* This program is distributed in the hope that it will be useful,
-* but WITHOUT ANY WARRANTY; without even the implied warranty of
-* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
-* GNU General Public License for more details.
-*
-* You should have received a copy of the GNU General Public License
-* along with this program; if not, write to the Free Software
-* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
-*
-* $URL$
-* $Id$
-*
-*/
-
-#ifndef COMMON_KEYMAP_MANAGER
-#define COMMON_KEYMAP_MANAGER
-
-#include "backends/keymapper/hardware-key.h"
-#include "backends/keymapper/keymap.h"
-#include "common/hash-str.h"
-#include "common/hashmap.h"
-
-namespace Common {
-
-class KeymapManager {
-public:
-
- class Domain {
- typedef HashMap<String, Keymap*,
- IgnoreCase_Hash, IgnoreCase_EqualTo> KeymapMap;
-
- public:
- Domain() : _configDomain(0) {}
- ~Domain() {
- deleteAllKeyMaps();
- }
-
- void setConfigDomain(ConfigManager::Domain *confDom) {
- _configDomain = confDom;
- }
- ConfigManager::Domain *getConfigDomain() {
- return _configDomain;
- }
-
- void addKeymap(Keymap *map);
-
- void deleteAllKeyMaps();
-
- Keymap *getKeymap(const String& name);
-
- typedef KeymapMap::iterator iterator;
- typedef KeymapMap::const_iterator const_iterator;
- iterator begin() { return _keymaps.begin(); }
- const_iterator begin() const { return _keymaps.begin(); }
- iterator end() { return _keymaps.end(); }
- const_iterator end() const { return _keymaps.end(); }
-
- uint32 count() { return _keymaps.size(); }
- private:
- ConfigManager::Domain *_configDomain;
- KeymapMap _keymaps;
- };
-
- KeymapManager();
- ~KeymapManager();
-
- void registerHardwareKeySet(HardwareKeySet *keys);
- HardwareKeySet *getHardwareKeySet() { return _hardwareKeys; }
-
- void registerGlobalKeymap(Keymap *map);
-
- void refreshGameDomain();
- void registerGameKeymap(Keymap *map);
-
- Keymap *getKeymap(const String& name, bool *global);
-
- Domain& getGlobalDomain() { return _globalDomain; }
- Domain& getGameDomain() { return _gameDomain; }
-
-private:
-
- void initKeymap(ConfigManager::Domain *domain, Keymap *keymap);
- void automaticMap(Keymap *map);
- Action *getParentMappedAction(Keymap *map, KeyState key);
-
- Domain _globalDomain;
- Domain _gameDomain;
-
- HardwareKeySet *_hardwareKeys;
-};
-
-} // end of namespace Common
-
-#endif
diff --git a/backends/keymapper/keymap.cpp b/backends/keymapper/keymap.cpp
index 6a4e946210..904495dc6f 100644
--- a/backends/keymapper/keymap.cpp
+++ b/backends/keymapper/keymap.cpp
@@ -166,4 +166,131 @@ bool Keymap::isComplete(const HardwareKeySet *hwKeys) {
return allMapped || (numberMapped == hwKeys->count());
}
+// TODO:
+// - current weaknesses:
+// - if an action finds a key with required type / category but a parent
+// action with higher priority is using it, that key is never used
+void Keymap::automaticMapping(HardwareKeySet *hwKeys) {
+ // Create copies of action and key lists.
+ List<Action*> actions(_actions);
+ List<const HardwareKey*> keys(hwKeys->getHardwareKeys());
+
+ List<Action*>::iterator actIt;
+ List<const HardwareKey*>::iterator keyIt, selectedKey;
+
+ // Remove actions and keys from local lists that have already been mapped.
+ actIt = actions.begin();
+ while (actIt != actions.end()) {
+ Action *act = *actIt;
+ const HardwareKey *key = act->getMappedKey();
+ if (key) {
+ keys.remove(key);
+ actIt = actions.erase(actIt);
+ } else {
+ ++actIt;
+ }
+ }
+
+ // Sort remaining actions by priority.
+ ActionPriorityComp priorityComp;
+ sort(actions.begin(), actions.end(), priorityComp);
+
+ // First mapping pass:
+ // - Match if a key's preferred type or category is same as the action's.
+ // - Priority is given to:
+ // - keys that match type over category.
+ // - keys that have not been used by parent maps.
+ // - If a key has been used by a parent map the new action must have a
+ // higher priority than the parent action.
+ // - As soon as the number of skipped actions equals the number of keys
+ // remaining we stop matching. This means that the second pass will assign keys
+ // to these higher priority skipped actions.
+ uint skipped = 0;
+ actIt = actions.begin();
+ while (actIt != actions.end() && skipped < keys.size()) {
+ selectedKey = keys.end();
+ int matchRank = 0;
+ Action *act = *actIt;
+ for (keyIt = keys.begin(); keyIt != keys.end(); ++keyIt) {
+ if ((*keyIt)->preferredType == act->type) {
+ Action *parentAct = getParentMappedAction((*keyIt)->key);
+ if (!parentAct) {
+ selectedKey = keyIt;
+ break;
+ } else if (parentAct->priority <= act->priority && matchRank < 3) {
+ selectedKey = keyIt;
+ matchRank = 3;
+ }
+ } else if ((*keyIt)->preferredCategory == act->category && matchRank < 2) {
+ Action *parentAct = getParentMappedAction((*keyIt)->key);
+ if (!parentAct) {
+ selectedKey = keyIt;
+ matchRank = 2;
+ } else if (parentAct->priority <= act->priority && matchRank < 1) {
+ selectedKey = keyIt;
+ matchRank = 1;
+ }
+ }
+ }
+ if (selectedKey != keys.end()) {
+ // Map action and delete action & key from local lists.
+ act->mapKey(*selectedKey);
+ keys.erase(selectedKey);
+ actIt = actions.erase(actIt);
+ } else {
+ // Skip action (will be mapped in next pass).
+ ++actIt;
+ ++skipped;
+ }
+ }
+
+ // Second mapping pass:
+ // - Maps any remaining actions to keys
+ // - priority given to:
+ // - keys that have no parent action
+ // - keys whose parent action has lower priority than the new action
+ // - keys whose parent action has the lowest priority
+ // - is guarantees to match a key if one is available
+ for (actIt = actions.begin(); actIt != actions.end(); ++actIt) {
+ selectedKey = keys.end();
+ int matchRank = 0;
+ int lowestPriority = 0;
+ Action *act = *actIt;
+ for (keyIt = keys.begin(); keyIt != keys.end(); ++keyIt) {
+ Action *parentAct = getParentMappedAction((*keyIt)->key);
+ if (!parentAct) {
+ selectedKey = keyIt;
+ break;
+ } else if (matchRank < 2) {
+ if (parentAct->priority <= act->priority) {
+ matchRank = 2;
+ selectedKey = keyIt;
+ } else if (parentAct->priority < lowestPriority || matchRank == 0) {
+ matchRank = 1;
+ lowestPriority = parentAct->priority;
+ selectedKey = keyIt;
+ }
+ }
+ }
+ if (selectedKey != keys.end()) {
+ act->mapKey(*selectedKey);
+ keys.erase(selectedKey);
+ } else {// no match = no keys left
+ break;
+ }
+ }
+}
+
+Action *Keymap::getParentMappedAction(KeyState key) {
+ if (_parent) {
+ Action *act = _parent->getMappedAction(key);
+ if (act)
+ return act;
+ else
+ return _parent->getParentMappedAction(key);
+ } else {
+ return 0;
+ }
+}
+
} // end of namespace Common
diff --git a/backends/keymapper/keymap.h b/backends/keymapper/keymap.h
index 3dda238373..438660fd4b 100644
--- a/backends/keymapper/keymap.h
+++ b/backends/keymapper/keymap.h
@@ -90,6 +90,9 @@ public:
*/
void saveMappings();
+
+ void automaticMapping(HardwareKeySet *hwKeys);
+
/**
* Returns true if all UserAction's in Keymap are mapped, or,
* all HardwareKey's from the given set have been used up.
@@ -129,6 +132,8 @@ private:
void internalMapKey(Action *action, HardwareKey *hwKey);
+ Action *getParentMappedAction(KeyState key);
+
String _name;
Keymap *_parent;
List<Action*> _actions;
diff --git a/backends/keymapper/keymapper.cpp b/backends/keymapper/keymapper.cpp
index e011b215f0..acb706c70f 100644
--- a/backends/keymapper/keymapper.cpp
+++ b/backends/keymapper/keymapper.cpp
@@ -27,32 +27,76 @@
#include "common/config-manager.h"
namespace Common {
-Keymapper::Keymapper(EventManager *evtMgr) {
- _eventMan = evtMgr;
- _keymapMan = new KeymapManager();
- _enabled = true;
+void Keymapper::Domain::addKeymap(Keymap *map) {
+ KeymapMap::iterator it = _keymaps.find(map->getName());
+ if (it != _keymaps.end())
+ delete _keymaps[map->getName()];
+ _keymaps[map->getName()] = map;
+}
+
+void Keymapper::Domain::deleteAllKeyMaps() {
+ KeymapMap::iterator it;
+ for (it = _keymaps.begin(); it != _keymaps.end(); it++)
+ delete it->_value;
+ _keymaps.clear();
+}
+
+Keymap *Keymapper::Domain::getKeymap(const String& name) {
+ KeymapMap::iterator it = _keymaps.find(name);
+ if (it != _keymaps.end())
+ return it->_value;
+ else
+ return 0;
+}
+
+Keymapper::Keymapper(EventManager *evtMgr)
+ : _eventMan(evtMgr), _enabled(true), _hardwareKeys(0) {
+ _globalDomain.setConfigDomain(ConfMan.getDomain(ConfigManager::kApplicationDomain));
}
Keymapper::~Keymapper() {
- delete _keymapMan;
+ delete _hardwareKeys;
}
void Keymapper::registerHardwareKeySet(HardwareKeySet *keys) {
- _keymapMan->registerHardwareKeySet(keys);
+ if (_hardwareKeys)
+ error("Hardware key set already registered!");
+ _hardwareKeys = keys;
}
void Keymapper::addGlobalKeymap(Keymap *keymap) {
- _keymapMan->registerGlobalKeymap(keymap);
+ initKeymap(_globalDomain.getConfigDomain(), keymap);
+ _globalDomain.addKeymap(keymap);
+}
+
+void Keymapper::refreshGameDomain() {
+ if (_gameDomain.getConfigDomain() != ConfMan.getActiveDomain()) {
+ cleanupGameKeymaps();
+ _gameDomain.setConfigDomain(ConfMan.getActiveDomain());
+ }
}
void Keymapper::addGameKeymap(Keymap *keymap) {
if (ConfMan.getActiveDomain() == 0)
error("Call to Keymapper::addGameKeymap when no game loaded");
- _keymapMan->registerGameKeymap(keymap);
+ refreshGameDomain();
+ initKeymap(_gameDomain.getConfigDomain(), keymap);
+ _gameDomain.addKeymap(keymap);
+}
+
+void Keymapper::initKeymap(ConfigManager::Domain *domain, Keymap *map) {
+ map->setConfigDomain(domain);
+ map->loadMappings(_hardwareKeys);
+ if (map->isComplete(_hardwareKeys) == false) {
+ map->automaticMapping(_hardwareKeys);
+ map->saveMappings();
+ ConfMan.flushToDisk();
+ }
}
void Keymapper::cleanupGameKeymaps() {
+ _gameDomain.deleteAllKeyMaps();
Stack<MapRecord> newStack;
for (int i = 0; i < _activeMaps.size(); i++) {
if (!_activeMaps[i].global)
@@ -61,9 +105,19 @@ void Keymapper::cleanupGameKeymaps() {
_activeMaps = newStack;
}
+Keymap *Keymapper::getKeymap(const String& name, bool &global) {
+ Keymap *keymap = _gameDomain.getKeymap(name);
+ global = false;
+ if (!keymap) {
+ keymap = _globalDomain.getKeymap(name);
+ global = true;
+ }
+ return keymap;
+}
+
bool Keymapper::pushKeymap(const String& name, bool inherit) {
bool global;
- Keymap *newMap = _keymapMan->getKeymap(name, &global);
+ Keymap *newMap = getKeymap(name, global);
if (!newMap) {
warning("Keymap '%s' not registered", name.c_str());
return false;
@@ -141,9 +195,7 @@ bool Keymapper::mapKey(const KeyState& key, bool isKeyDown) {
}
const HardwareKey *Keymapper::getHardwareKey(const KeyState& key) {
- HardwareKeySet *keyset = _keymapMan->getHardwareKeySet();
- if (!keyset) return 0;
- return keyset->findHardwareKey(key);
+ return (_hardwareKeys) ? _hardwareKeys->findHardwareKey(key) : 0;
}
} // end of namespace Common
diff --git a/backends/keymapper/keymapper.h b/backends/keymapper/keymapper.h
index fc76a7d45c..78ab2d2203 100644
--- a/backends/keymapper/keymapper.h
+++ b/backends/keymapper/keymapper.h
@@ -31,7 +31,6 @@
#include "common/stack.h"
#include "backends/keymapper/hardware-key.h"
#include "backends/keymapper/keymap.h"
-#include "backends/keymapper/keymap-manager.h"
namespace Common {
@@ -44,6 +43,42 @@ public:
bool global;
};
+ /* Nested class that represents a set of keymaps */
+ class Domain {
+ typedef HashMap<String, Keymap*,
+ IgnoreCase_Hash, IgnoreCase_EqualTo> KeymapMap;
+
+ public:
+ Domain() : _configDomain(0) {}
+ ~Domain() {
+ deleteAllKeyMaps();
+ }
+
+ void setConfigDomain(ConfigManager::Domain *confDom) {
+ _configDomain = confDom;
+ }
+ ConfigManager::Domain *getConfigDomain() {
+ return _configDomain;
+ }
+
+ void addKeymap(Keymap *map);
+
+ void deleteAllKeyMaps();
+
+ Keymap *getKeymap(const String& name);
+
+ typedef KeymapMap::iterator iterator;
+ typedef KeymapMap::const_iterator const_iterator;
+ iterator begin() { return _keymaps.begin(); }
+ const_iterator begin() const { return _keymaps.begin(); }
+ iterator end() { return _keymaps.end(); }
+ const_iterator end() const { return _keymaps.end(); }
+ uint32 count() { return _keymaps.size(); }
+ private:
+ ConfigManager::Domain *_configDomain;
+ KeymapMap _keymaps;
+ };
+
Keymapper(EventManager *eventMan);
~Keymapper();
@@ -53,6 +88,10 @@ public:
*/
void registerHardwareKeySet(HardwareKeySet *keys);
+ /**
+ * Get the HardwareKeySet that is registered with the Keymapper
+ */
+ HardwareKeySet *getHardwareKeySet() { return _hardwareKeys; }
/**
* Add a keymap to the global domain.
@@ -73,6 +112,15 @@ public:
* any game keymaps that are loaded.
*/
void cleanupGameKeymaps();
+
+ /**
+ * Obtain a keymap of the given name from the keymapper.
+ * Game keymaps have priority over global keymaps
+ * @param name name of the keymap to return
+ * @param global set to true if returned keymap is global, false if game
+ */
+ Keymap *getKeymap(const String& name, bool &global);
+
/**
* Push a new keymap to the top of the active stack, activating
* it for use.
@@ -89,13 +137,13 @@ public:
void popKeymap();
/**
- * @brief Map a key press event.
- * If the active keymap contains a Action mapped to the given key, then
- * the Action's events are pushed into the EventManager's event queue.
- * @param key key that was pressed
- * @param isKeyDown true for key down, false for key up
- * @return true if key was mapped
- */
+ * @brief Map a key press event.
+ * If the active keymap contains a Action mapped to the given key, then
+ * the Action's events are pushed into the EventManager's event queue.
+ * @param key key that was pressed
+ * @param isKeyDown true for key down, false for key up
+ * @return true if key was mapped
+ */
bool mapKey(const KeyState& key, bool isKeyDown);
/**
@@ -105,26 +153,40 @@ public:
bool mapKeyDown(const KeyState& key);
/**
- * @brief Map a key up event.
- * @see mapKey
- */
+ * @brief Map a key up event.
+ * @see mapKey
+ */
bool mapKeyUp(const KeyState& key);
- const HardwareKey *getHardwareKey(const KeyState& key);
-
+ /**
+ * Enable/disable the keymapper
+ */
void setEnabled(bool enabled) { _enabled = enabled; }
- KeymapManager *getManager() { return _keymapMan; }
+ /**
+ * Return a HardwareKey pointer for the given key state
+ */
+ const HardwareKey *getHardwareKey(const KeyState& key);
+
+ Domain& getGlobalDomain() { return _globalDomain; }
+ Domain& getGameDomain() { return _gameDomain; }
Stack<MapRecord>& getActiveStack() { return _activeMaps; }
private:
+ void initKeymap(ConfigManager::Domain *domain, Keymap *keymap);
+ void refreshGameDomain();
+
+ Domain _globalDomain;
+ Domain _gameDomain;
+
+ HardwareKeySet *_hardwareKeys;
+
void pushKeymap(Keymap *newMap, bool inherit, bool global);
typedef List<HardwareKey*>::iterator Iterator;
EventManager *_eventMan;
- KeymapManager *_keymapMan;
bool _enabled;
diff --git a/backends/keymapper/remap-dialog.cpp b/backends/keymapper/remap-dialog.cpp
index 09d976a766..2becfe3f59 100644
--- a/backends/keymapper/remap-dialog.cpp
+++ b/backends/keymapper/remap-dialog.cpp
@@ -61,8 +61,8 @@ void RemapDialog::open() {
divider = true;
}
- KeymapManager::Domain *_globalKeymaps = &_keymapper->getManager()->getGlobalDomain();
- KeymapManager::Domain *_gameKeymaps = 0;
+ Keymapper::Domain *_globalKeymaps = &_keymapper->getGlobalDomain();
+ Keymapper::Domain *_gameKeymaps = 0;
int keymapCount = 0;
if (_globalKeymaps->count() == 0)
@@ -71,7 +71,7 @@ void RemapDialog::open() {
keymapCount += _globalKeymaps->count();
if (ConfMan.getActiveDomain() != 0) {
- _gameKeymaps = &_keymapper->getManager()->getGameDomain();
+ _gameKeymaps = &_keymapper->getGameDomain();
if (_gameKeymaps->count() == 0)
_gameKeymaps = 0;
else
@@ -80,7 +80,7 @@ void RemapDialog::open() {
_keymapTable = (Keymap**)malloc(sizeof(Keymap*) * keymapCount);
- KeymapManager::Domain::iterator it;
+ Keymapper::Domain::iterator it;
uint32 idx = 0;
if (_globalKeymaps) {
if (divider) _kmPopUp->appendEntry("");
@@ -238,7 +238,7 @@ void RemapDialog::handleTickle() {
void RemapDialog::loadKeymap() {
_currentActions.clear();
if (_activeKeymaps->size() > 0 && _kmPopUp->getSelected() == 0) {
- List<const HardwareKey*> freeKeys (_keymapper->getManager()->getHardwareKeySet()->getHardwareKeys());
+ List<const HardwareKey*> freeKeys (_keymapper->getHardwareKeySet()->getHardwareKeys());
// add most active keymap's keys
Keymapper::MapRecord top = _activeKeymaps->top();