[Scummvm-cvs-logs] SF.net SVN: scummvm:[33988] scummvm/branches/gsoc2008-vkeybd

kenny-d at users.sourceforge.net kenny-d at users.sourceforge.net
Mon Aug 18 16:45:43 CEST 2008


Revision: 33988
          http://scummvm.svn.sourceforge.net/scummvm/?rev=33988&view=rev
Author:   kenny-d
Date:     2008-08-18 14:45:42 +0000 (Mon, 18 Aug 2008)

Log Message:
-----------
Removed KeymapManager class. Automatic mapping now done in Keymap. Rest of KeymapManager functionality is implemented in Keymapper.

Modified Paths:
--------------
    scummvm/branches/gsoc2008-vkeybd/backends/keymapper/keymap.cpp
    scummvm/branches/gsoc2008-vkeybd/backends/keymapper/keymap.h
    scummvm/branches/gsoc2008-vkeybd/backends/keymapper/keymapper.cpp
    scummvm/branches/gsoc2008-vkeybd/backends/keymapper/keymapper.h
    scummvm/branches/gsoc2008-vkeybd/backends/keymapper/remap-dialog.cpp
    scummvm/branches/gsoc2008-vkeybd/dists/msvc8/scummvm.vcproj

Removed Paths:
-------------
    scummvm/branches/gsoc2008-vkeybd/backends/keymapper/keymap-manager.cpp
    scummvm/branches/gsoc2008-vkeybd/backends/keymapper/keymap-manager.h

Deleted: scummvm/branches/gsoc2008-vkeybd/backends/keymapper/keymap-manager.cpp
===================================================================
--- scummvm/branches/gsoc2008-vkeybd/backends/keymapper/keymap-manager.cpp	2008-08-18 12:44:54 UTC (rev 33987)
+++ scummvm/branches/gsoc2008-vkeybd/backends/keymapper/keymap-manager.cpp	2008-08-18 14:45:42 UTC (rev 33988)
@@ -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

Deleted: scummvm/branches/gsoc2008-vkeybd/backends/keymapper/keymap-manager.h
===================================================================
--- scummvm/branches/gsoc2008-vkeybd/backends/keymapper/keymap-manager.h	2008-08-18 12:44:54 UTC (rev 33987)
+++ scummvm/branches/gsoc2008-vkeybd/backends/keymapper/keymap-manager.h	2008-08-18 14:45:42 UTC (rev 33988)
@@ -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

Modified: scummvm/branches/gsoc2008-vkeybd/backends/keymapper/keymap.cpp
===================================================================
--- scummvm/branches/gsoc2008-vkeybd/backends/keymapper/keymap.cpp	2008-08-18 12:44:54 UTC (rev 33987)
+++ scummvm/branches/gsoc2008-vkeybd/backends/keymapper/keymap.cpp	2008-08-18 14:45:42 UTC (rev 33988)
@@ -166,4 +166,131 @@
 	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

Modified: scummvm/branches/gsoc2008-vkeybd/backends/keymapper/keymap.h
===================================================================
--- scummvm/branches/gsoc2008-vkeybd/backends/keymapper/keymap.h	2008-08-18 12:44:54 UTC (rev 33987)
+++ scummvm/branches/gsoc2008-vkeybd/backends/keymapper/keymap.h	2008-08-18 14:45:42 UTC (rev 33988)
@@ -90,6 +90,9 @@
 	 */
 	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 @@
 
 	void internalMapKey(Action *action, HardwareKey *hwKey);
 
+	Action *getParentMappedAction(KeyState key);
+
 	String _name;
 	Keymap *_parent;
 	List<Action*> _actions;

Modified: scummvm/branches/gsoc2008-vkeybd/backends/keymapper/keymapper.cpp
===================================================================
--- scummvm/branches/gsoc2008-vkeybd/backends/keymapper/keymapper.cpp	2008-08-18 12:44:54 UTC (rev 33987)
+++ scummvm/branches/gsoc2008-vkeybd/backends/keymapper/keymapper.cpp	2008-08-18 14:45:42 UTC (rev 33988)
@@ -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 @@
 	_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 @@
 }
 
 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

Modified: scummvm/branches/gsoc2008-vkeybd/backends/keymapper/keymapper.h
===================================================================
--- scummvm/branches/gsoc2008-vkeybd/backends/keymapper/keymapper.h	2008-08-18 12:44:54 UTC (rev 33987)
+++ scummvm/branches/gsoc2008-vkeybd/backends/keymapper/keymapper.h	2008-08-18 14:45:42 UTC (rev 33988)
@@ -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 @@
 		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 @@
 	 */
 	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,7 +112,16 @@
 	 * 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.
 	 * @param name		name of the keymap to push
@@ -89,13 +137,13 @@
 	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 @@
 	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);
 
+	/**
+	 * Enable/disable the keymapper
+	 */
+	void setEnabled(bool enabled) { _enabled = enabled; }
+
+	/**
+	 * Return a HardwareKey pointer for the given key state
+	 */
 	const HardwareKey *getHardwareKey(const KeyState& key);
 
-	void setEnabled(bool enabled) { _enabled = enabled; }
-
-	KeymapManager *getManager() { return _keymapMan; }
+	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;
 

Modified: scummvm/branches/gsoc2008-vkeybd/backends/keymapper/remap-dialog.cpp
===================================================================
--- scummvm/branches/gsoc2008-vkeybd/backends/keymapper/remap-dialog.cpp	2008-08-18 12:44:54 UTC (rev 33987)
+++ scummvm/branches/gsoc2008-vkeybd/backends/keymapper/remap-dialog.cpp	2008-08-18 14:45:42 UTC (rev 33988)
@@ -61,8 +61,8 @@
 		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 @@
 		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 @@
 
 	_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::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();

Modified: scummvm/branches/gsoc2008-vkeybd/dists/msvc8/scummvm.vcproj
===================================================================
--- scummvm/branches/gsoc2008-vkeybd/dists/msvc8/scummvm.vcproj	2008-08-18 12:44:54 UTC (rev 33987)
+++ scummvm/branches/gsoc2008-vkeybd/dists/msvc8/scummvm.vcproj	2008-08-18 14:45:42 UTC (rev 33988)
@@ -1097,14 +1097,6 @@
 					>
 				</File>
 				<File
-					RelativePath="..\..\backends\keymapper\keymap-manager.cpp"
-					>
-				</File>
-				<File
-					RelativePath="..\..\backends\keymapper\keymap-manager.h"
-					>
-				</File>
-				<File
 					RelativePath="..\..\backends\keymapper\keymap.cpp"
 					>
 				</File>


This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.




More information about the Scummvm-git-logs mailing list