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

kenny-d at users.sourceforge.net kenny-d at users.sourceforge.net
Wed Aug 6 21:21:47 CEST 2008


Revision: 33665
          http://scummvm.svn.sourceforge.net/scummvm/?rev=33665&view=rev
Author:   kenny-d
Date:     2008-08-06 19:21:45 +0000 (Wed, 06 Aug 2008)

Log Message:
-----------
Keymapper WIP:
* Made Keymap class responsible for loading / saving of mappings

Modified Paths:
--------------
    scummvm/branches/gsoc2008-vkeybd/backends/common/keymap-manager.cpp
    scummvm/branches/gsoc2008-vkeybd/backends/common/keymap-manager.h
    scummvm/branches/gsoc2008-vkeybd/backends/common/keymap.cpp
    scummvm/branches/gsoc2008-vkeybd/backends/common/keymap.h

Modified: scummvm/branches/gsoc2008-vkeybd/backends/common/keymap-manager.cpp
===================================================================
--- scummvm/branches/gsoc2008-vkeybd/backends/common/keymap-manager.cpp	2008-08-06 16:03:06 UTC (rev 33664)
+++ scummvm/branches/gsoc2008-vkeybd/backends/common/keymap-manager.cpp	2008-08-06 19:21:45 UTC (rev 33665)
@@ -42,8 +42,10 @@
 
 void KeymapManager::Domain::deleteAllKeyMaps() {
 	KeymapMap::iterator it;
-	for (it = _keymaps.begin(); it != _keymaps.end(); it++)
+	for (it = _keymaps.begin(); it != _keymaps.end(); it++) {
+		//it->_value->saveMappings()
 		delete it->_value;
+	}
 	_keymaps.clear();
 	delete _defaultKeymap;
 }
@@ -109,52 +111,11 @@
 void KeymapManager::initKeymap(ConfigManager::Domain *domain, 
 							   const String& name, 
 							   Keymap *map) {
-	if (!loadKeymap(domain, name, map))
+	map->loadMappings(domain, name, _hardwareKeys);
+	if (isMapComplete(map) == false)
 		automaticMap(map);
 }
 
-bool KeymapManager::loadKeymap(ConfigManager::Domain *domain, 
-							   const String& name, 
-							   Keymap *map) {
-	ConfigManager::Domain::iterator it;	
-	String prefix = "km_" + name + "_";
-	for (it = domain->begin(); it != domain->end(); it++) {
-		const String& key = it->_key;
-		if (!key.hasPrefix(prefix.c_str()))
-			continue;
-
-		// parse Action ID
-		const char *actionIdStart = key.c_str() + prefix.size();
-		char *err;
-		int32 actionId = (int32) strtol(actionIdStart, &err, 0);
-		if (err == actionIdStart) {
-			warning("'%s' is not a valid Action ID", err);
-			continue;
-		}
-		Action *ua = map->getAction(actionId);
-		if (!ua) {
-			warning("'%s' keymap does not contain Action with ID %d", 
-				name.c_str(), (int)actionId);
-			continue;
-		}
-
-		// parse HardwareKey ID
-		int32 hwKeyId = (int32) strtol(it->_value.c_str(), &err, 0);
-		if (err == it->_value.c_str()) {
-			warning("'%s' is not a valid HardwareKey ID", err);
-			continue;
-		}
-		const HardwareKey *hwKey = _hardwareKeys->findHardwareKey(hwKeyId);
-		if (!hwKey) {
-			warning("HardwareKey with ID %d not known", (int)hwKeyId);
-			continue;
-		}
-
-		ua->mapKey(hwKey);
-	}
-	return isMapComplete(map);
-}
-
 bool KeymapManager::isMapComplete(const Keymap *map) {
 	const List<Action*>& actions = map->getActions();
 	List<Action*>::const_iterator it;
@@ -170,24 +131,6 @@
 	return allMapped || (numberMapped == _hardwareKeys->count());
 }
 
-void KeymapManager::saveKeymap(ConfigManager::Domain *domain, 
-							   const String& name, 
-							   const Keymap *map) {
-	const List<Action*>& actions = map->getActions();
-	List<Action*>::const_iterator it;
-	char buf[11];
-	for (it = actions.begin(); it != actions.end(); it++) {
-		String key("km_");
-		sprintf(buf, "%d", (*it)->id);
-		key += name + "_" + buf;
-		if ((*it)->getMappedKey())
-			sprintf(buf, "%d", (*it)->getMappedKey()->id);
-		else
-			strcpy(buf, "");
-		domain->setVal(key, buf);
-	}
-}
-
 void KeymapManager::automaticMap(Keymap *map) {
 	List<Action*> actions(map->getActions()), unmapped;
 	List<Action*>::iterator actIt;

Modified: scummvm/branches/gsoc2008-vkeybd/backends/common/keymap-manager.h
===================================================================
--- scummvm/branches/gsoc2008-vkeybd/backends/common/keymap-manager.h	2008-08-06 16:03:06 UTC (rev 33664)
+++ scummvm/branches/gsoc2008-vkeybd/backends/common/keymap-manager.h	2008-08-06 19:21:45 UTC (rev 33665)
@@ -28,7 +28,6 @@
 
 #include "backends/common/hardware-key.h"
 #include "backends/common/keymap.h"
-#include "common/config-manager.h"
 #include "common/hash-str.h"
 #include "common/hashmap.h"
 
@@ -76,8 +75,6 @@
 private:
 
 	void initKeymap(ConfigManager::Domain *domain, const String& name, Keymap *keymap);
-	bool loadKeymap(ConfigManager::Domain *domain, const String& name, Keymap *keymap);
-	void saveKeymap(ConfigManager::Domain *domain, const String& name, const Keymap *keymap);
 	void automaticMap(Keymap *map);
 	bool isMapComplete(const Keymap *map);
 

Modified: scummvm/branches/gsoc2008-vkeybd/backends/common/keymap.cpp
===================================================================
--- scummvm/branches/gsoc2008-vkeybd/backends/common/keymap.cpp	2008-08-06 16:03:06 UTC (rev 33664)
+++ scummvm/branches/gsoc2008-vkeybd/backends/common/keymap.cpp	2008-08-06 19:21:45 UTC (rev 33665)
@@ -92,4 +92,58 @@
 		return it->_value;
 }
 
+void Keymap::loadMappings(ConfigManager::Domain *domain, const String& name, const HardwareKeySet *hwKeys) {
+	ConfigManager::Domain::iterator it;	
+	String prefix = "km_" + name + "_";
+	for (it = domain->begin(); it != domain->end(); it++) {
+		const String& key = it->_key;
+		if (!key.hasPrefix(prefix.c_str()))
+			continue;
+
+		// parse Action ID
+		const char *actionIdStart = key.c_str() + prefix.size();
+		char *err;
+		int32 actionId = (int32) strtol(actionIdStart, &err, 0);
+		if (err == actionIdStart) {
+			warning("'%s' is not a valid Action ID", err);
+			continue;
+		}
+		Action *ua = getAction(actionId);
+		if (!ua) {
+			warning("'%s' keymap does not contain Action with ID %d", 
+				name.c_str(), (int)actionId);
+			continue;
+		}
+
+		// parse HardwareKey ID
+		int32 hwKeyId = (int32) strtol(it->_value.c_str(), &err, 0);
+		if (err == it->_value.c_str()) {
+			warning("'%s' is not a valid HardwareKey ID", err);
+			continue;
+		}
+		const HardwareKey *hwKey = hwKeys->findHardwareKey(hwKeyId);
+		if (!hwKey) {
+			warning("HardwareKey with ID %d not known", (int)hwKeyId);
+			continue;
+		}
+
+		ua->mapKey(hwKey);
+	}
+}
+
+void Keymap::saveMappings(ConfigManager::Domain *domain, const String& name) {
+	List<Action*>::const_iterator it;
+	char buf[11];
+	for (it = _actions.begin(); it != _actions.end(); it++) {
+		String key("km_");
+		sprintf(buf, "%d", (*it)->id);
+		key += name + "_" + buf;
+		if ((*it)->getMappedKey())
+			sprintf(buf, "%d", (*it)->getMappedKey()->id);
+		else
+			strcpy(buf, "");
+		domain->setVal(key, buf);
+	}
+}
+
 } // end of namespace Common

Modified: scummvm/branches/gsoc2008-vkeybd/backends/common/keymap.h
===================================================================
--- scummvm/branches/gsoc2008-vkeybd/backends/common/keymap.h	2008-08-06 16:03:06 UTC (rev 33664)
+++ scummvm/branches/gsoc2008-vkeybd/backends/common/keymap.h	2008-08-06 19:21:45 UTC (rev 33665)
@@ -26,6 +26,7 @@
 #ifndef COMMON_KEYMAP
 #define COMMON_KEYMAP
 
+#include "common/config-manager.h"
 #include "common/func.h"
 #include "common/hashmap.h"
 #include "common/keyboard.h"
@@ -35,6 +36,7 @@
 namespace Common {
 
 struct HardwareKey;
+class HardwareKeySet;
 
 /**
  * Hash function for KeyState
@@ -74,11 +76,26 @@
 
 	/**
 	 * Find the Action that a key is mapped to
-	 * @param key the key that is mapped to the required Action
-	 * @return a pointer to the Action or 0 if no
+	 * @param key	the key that is mapped to the required Action
+	 * @return		a pointer to the Action or 0 if no
 	 */
 	Action *getMappedAction(const KeyState& ks) const;
 
+	/**
+	 * Load this keymap's mappings from the given config domain and hardware key set
+	 * @param domain	config domain to load keymap from
+	 * @param name		name of the keymap to load
+	 * @param hwKeys	the set to retrieve hardware key pointers from
+	 */
+	void loadMappings(ConfigManager::Domain *domain, const String& name, const HardwareKeySet *hwKeys);
+
+	/**
+	 * Save this keymap's mappings to the given config domain
+	 * @param domain	config domain to save keymap to
+	 * @param name		name to save the keymap under
+	 */
+	void saveMappings(ConfigManager::Domain *domain, const String& name);
+
 private:
 	friend struct Action;
 	/**


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