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

kenny-d at users.sourceforge.net kenny-d at users.sourceforge.net
Mon Jul 21 02:11:51 CEST 2008


Revision: 33157
          http://scummvm.svn.sourceforge.net/scummvm/?rev=33157&view=rev
Author:   kenny-d
Date:     2008-07-21 00:11:25 +0000 (Mon, 21 Jul 2008)

Log Message:
-----------
Moved UserAction and HardwareKey classes into their own respective header files.
Added HardwareKeySet class to manage a devices set of hardware keys.
Started implementing Keymapper class.

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.h
    scummvm/branches/gsoc2008-vkeybd/backends/common/keymapper.h
    scummvm/branches/gsoc2008-vkeybd/common/keyboard.h
    scummvm/branches/gsoc2008-vkeybd/dists/msvc8/scummvm.vcproj

Added Paths:
-----------
    scummvm/branches/gsoc2008-vkeybd/backends/common/hardware-key.h
    scummvm/branches/gsoc2008-vkeybd/backends/common/keymapper.cpp
    scummvm/branches/gsoc2008-vkeybd/backends/common/user-action.h

Added: scummvm/branches/gsoc2008-vkeybd/backends/common/hardware-key.h
===================================================================
--- scummvm/branches/gsoc2008-vkeybd/backends/common/hardware-key.h	                        (rev 0)
+++ scummvm/branches/gsoc2008-vkeybd/backends/common/hardware-key.h	2008-07-21 00:11:25 UTC (rev 33157)
@@ -0,0 +1,95 @@
+#ifndef COMMON_HARDWAREKEY
+#define COMMON_HARDWAREKEY
+
+#include "backends/common/user-action.h"
+
+namespace Common {
+
+/**
+* Describes an available hardware key 
+*/
+struct HardwareKey {
+	/** unique id used for saving/loading to config */
+	int32 id;
+	/** Human readable description */
+	String description; 
+	/** 
+	* The KeyState that is generated by the back-end 
+	* when this hardware key is pressed.
+	*/
+	KeyState key;
+
+	UserActionCategory preferredCategory;
+	UserActionType preferredType;
+	int16 group;
+
+	HardwareKey(KeyState ks = KeyState(), String des = "",
+		UserActionCategory cat = kGenericUserActionCategory,
+		UserActionType ty = kGenericUserActionType,	int gr = 0) {
+			key = ks;
+			description = des;
+			preferredCategory = cat;
+			preferredType = ty;
+			group = gr;
+	}
+};
+
+
+/**
+ * Simple class to encapsulate a device's set of HardwareKeys.
+ * Each device should extend this and call addHardwareKey a number of times
+ * in its constructor to define the device's available keys.
+ */ 
+class HardwareKeySet {
+public:
+
+	HardwareKeySet() {}
+	~HardwareKeySet() {
+		List<HardwareKey*>::iterator it;
+		for (it = _keys.begin(); it != _keys.end(); it++)
+			delete *it;
+	}
+
+	void addHardwareKey(HardwareKey *key) {
+		checkForKey(key);
+		_keys.push_back(key);
+	}
+
+	const HardwareKey *findHardwareKey(int32 id) const {
+		List<HardwareKey*>::iterator it;
+		for (it = _keys.begin(); it != _keys.end(); it++) {
+			if ((*it)->id == id)
+				return (*it);
+		}
+		return 0;
+	}
+
+	const HardwareKey *findHardwareKey(const KeyState& keystate) const {
+		List<HardwareKey*>::iterator it;
+		for (it = _keys.begin(); it != _keys.end(); it++) {
+			if ((*it)->key == keystate)
+				return (*it);
+		}
+		return 0;
+	}
+
+
+private:
+
+	void checkForKey(HardwareKey *key) {
+		List<HardwareKey*>::iterator it;
+		for (it = _keys.begin(); it != _keys.end(); it++) {
+			if ((*it)->id == key->id)
+				error("HardwareKey with id %d already given!\n", key->id);
+			else if ((*it)->key == key->key)
+				error("HardwareKey with same KeyState already given!\n");
+		}
+	}
+
+	List<HardwareKey*> _keys;
+};
+
+
+} // end of namespace Common
+
+#endif
\ No newline at end of file


Property changes on: scummvm/branches/gsoc2008-vkeybd/backends/common/hardware-key.h
___________________________________________________________________
Added: svn:mime-type
   + text/plain
Added: svn:keywords
   + Date Rev Author URL Id
Added: svn:eol-style
   + native

Modified: scummvm/branches/gsoc2008-vkeybd/backends/common/keymap-manager.cpp
===================================================================
--- scummvm/branches/gsoc2008-vkeybd/backends/common/keymap-manager.cpp	2008-07-20 23:37:26 UTC (rev 33156)
+++ scummvm/branches/gsoc2008-vkeybd/backends/common/keymap-manager.cpp	2008-07-21 00:11:25 UTC (rev 33157)
@@ -1,15 +1,19 @@
 #include "backends/common/keymap-manager.h"
 
-#define GLOBAL_ID "GLOBAL"
+#define GLOBAL_ID_STR "___GLOBAL"
 
 namespace Common {
 
+KeymapManager::KeymapManager() {
+
+}
+
 bool KeymapManager::registerSuperGlobalKeymap(const Keymap& map) {
-	return registerKeymap(GLOBAL_ID, GLOBAL_ID, map);
+	return registerKeymap(GLOBAL_ID_STR, GLOBAL_ID_STR, map);
 }
 
 bool KeymapManager::registerGlobalKeymap(const String& name, const Keymap& map) {
-	return registerKeymap(name, GLOBAL_ID, map);
+	return registerKeymap(name, GLOBAL_ID_STR, map);
 }
 
 bool KeymapManager::registerKeymap(const String& name, const String& domain, const Keymap& map) {
@@ -26,11 +30,11 @@
 }
 
 bool KeymapManager::unregisterSuperGlobalKeymap() {
-	return unregisterKeymap(GLOBAL_ID, GLOBAL_ID);
+	return unregisterKeymap(GLOBAL_ID_STR, GLOBAL_ID_STR);
 }
 
 bool KeymapManager::unregisterGlobalKeymap(const String& name) {
-	return unregisterKeymap(name, GLOBAL_ID);
+	return unregisterKeymap(name, GLOBAL_ID_STR);
 }
 
 bool KeymapManager::unregisterKeymap(const String& name, const String& domain) {

Modified: scummvm/branches/gsoc2008-vkeybd/backends/common/keymap-manager.h
===================================================================
--- scummvm/branches/gsoc2008-vkeybd/backends/common/keymap-manager.h	2008-07-20 23:37:26 UTC (rev 33156)
+++ scummvm/branches/gsoc2008-vkeybd/backends/common/keymap-manager.h	2008-07-21 00:11:25 UTC (rev 33157)
@@ -2,6 +2,7 @@
 #define COMMON_KEYMAP_MANAGER
 
 #include "backends/common/keymap.h"
+#include "common/list.h"
 
 namespace Common {
 

Modified: scummvm/branches/gsoc2008-vkeybd/backends/common/keymap.h
===================================================================
--- scummvm/branches/gsoc2008-vkeybd/backends/common/keymap.h	2008-07-20 23:37:26 UTC (rev 33156)
+++ scummvm/branches/gsoc2008-vkeybd/backends/common/keymap.h	2008-07-21 00:11:25 UTC (rev 33157)
@@ -1,111 +1,16 @@
 #ifndef COMMON_KEYMAP
 #define COMMON_KEYMAP
 
+#include "backends/common/hardware-key.h"
+#include "backends/common/user-action.h"
 #include "common/array.h"
-#include "common/events.h"
+#include "common/keyboard.h"
 #include "common/func.h"
 #include "common/hashmap.h"
-#include "common/list.h"
 
 namespace Common {
 
-enum UserActionType {
-	kGenericUserActionType,
-
-	// common actions
-	kDirectionUpUserAction,
-	kDirectionDownUserAction,
-	kDirectionLeftUserAction,
-	kDirectionRightUserAction,
-	kLeftClickUserAction,
-	kRightClickUserAction,
-	kSaveUserAction,
-	kMenuUserAction,
-
-	kUserActionTypeMax
-};
-
-enum UserActionCategory {
-	kGenericUserActionCategory,
-	// classes of action - probably need to be slightly more specific than this
-	kInGameUserAction,   // effects the actual gameplay
-	kSystemUserAction,   //show a menu / change volume / etc
-
-	kUserActionCategoryMax
-};
-
 /**
-* Describes an available hardware key 
-*/
-struct HardwareKey {
-	/** unique id used for saving/loading to config */
-	int32 id;
-	/** Human readable description */
-	String description; 
-	/** 
-	* The KeyState that is generated by the back-end 
-	* when this hardware key is pressed.
-	*/
-	KeyState key;
-
-	UserActionCategory preferredCategory;
-	UserActionType preferredType;
-	int16 group;
-
-	HardwareKey(KeyState ks = KeyState(), String des = "",
-			UserActionCategory cat = kGenericUserActionCategory,
-			UserActionType ty = kGenericUserActionType,	int gr = 0) {
-		key = ks;
-		description = des;
-		preferredCategory = cat;
-		preferredType = ty;
-		group = gr;
-	}
-};
-
-struct UserAction {
-	/** unique id used for saving/loading to config */
-	int32 id;
-	/** Human readable description */
-	String description;
-	/** Events to be sent when mapped key is pressed */
-	List<Event> events;
-	UserActionCategory category;
-	UserActionType type;
-	int priority;
-	int group;
-	int flags;
-
-	HardwareKey *hwKey;
-
-	UserAction(	String des = "", 
-				UserActionCategory cat = kGenericUserActionCategory,
-				UserActionType ty = kGenericUserActionType,
-				int pr = 0, int gr = 0, int fl = 0 ) {
-		description = des;
-		category = cat;
-		type = ty;
-		priority = pr;
-		group = gr;
-		flags = fl;
-		hwKey = 0;
-	}
-};
-
-/**
- * EqualTo function for KeyState
- */
-template<> struct EqualTo<KeyState>
-	: public BinaryFunction<KeyState, KeyState, bool> {
-
-	bool operator()(const KeyState &x, const KeyState &y) const { 
-		return (x.keycode == y.keycode)
-			&& (x.ascii == y.ascii)
-			&& (x.flags == y.flags); 
-	}
-};
-
-/**
  * Hash function for KeyState
  */
 template<> struct Hash<KeyState>

Added: scummvm/branches/gsoc2008-vkeybd/backends/common/keymapper.cpp
===================================================================
--- scummvm/branches/gsoc2008-vkeybd/backends/common/keymapper.cpp	                        (rev 0)
+++ scummvm/branches/gsoc2008-vkeybd/backends/common/keymapper.cpp	2008-07-21 00:11:25 UTC (rev 33157)
@@ -0,0 +1,31 @@
+#include "backends/common/keymapper.h"
+#include "backends/common/keymap-manager.h"
+
+namespace Common {
+
+Keymapper::Keymapper(EventManager *evtMgr) {
+	_eventMan = evtMgr;
+	_keymapMan = new KeymapManager();
+	_currentMap = 0;
+	_hardwareKeys = 0;
+}
+
+void Keymapper::registerHardwareKeySet(HardwareKeySet *keys) {
+	if (_hardwareKeys)
+		error("Hardware key set already registered!\n");
+	_hardwareKeys = keys;
+}
+
+const HardwareKeySet *Keymapper::getHardwareKeySet() {
+	return _hardwareKeys;
+}
+
+void Keymapper::addGlobalKeyMap(const String& name, Keymap& keymap) {
+	_keymapMan->registerGlobalKeymap(name, keymap);
+}
+
+void Keymapper::addGameKeyMap(const String& gameid, const String& name, Keymap& keymap) {
+	_keymapMan->registerKeymap(name, gameid, keymap);
+}
+
+} // end of namespace Common


Property changes on: scummvm/branches/gsoc2008-vkeybd/backends/common/keymapper.cpp
___________________________________________________________________
Added: svn:mime-type
   + text/plain
Added: svn:keywords
   + Date Rev Author URL Id
Added: svn:eol-style
   + native

Modified: scummvm/branches/gsoc2008-vkeybd/backends/common/keymapper.h
===================================================================
--- scummvm/branches/gsoc2008-vkeybd/backends/common/keymapper.h	2008-07-20 23:37:26 UTC (rev 33156)
+++ scummvm/branches/gsoc2008-vkeybd/backends/common/keymapper.h	2008-07-21 00:11:25 UTC (rev 33157)
@@ -1,24 +1,34 @@
 #ifndef COMMON_KEYMAPPER
 #define COMMON_KEYMAPPER
 
-#include "backends/common/keymap-manager.h"
+#include "backends/common/keymap.h"
+#include "common/list.h"
 
 namespace Common {
 
+class KeymapManager;
+
 class Keymapper {
 public:
 
-	Keymapper();
+	Keymapper(EventManager *eventMan);
 
-	void addHardwareKey(const HardwareKey& key);
+	void registerHardwareKeySet(HardwareKeySet *keys);
+	const HardwareKeySet *getHardwareKeySet();
 	void addGlobalKeyMap(const String& name, Keymap& keymap);
+	void addGameKeyMap(const String& gameid, const String& name, Keymap& keymap);
 
 private:
 
-	KeymapManager _manager;
+	typedef List<HardwareKey*>::iterator Iterator;
 
-	List<HardwareKey*> _hardwareKeys;
+	EventManager *_eventMan;
+	KeymapManager *_keymapMan;
 
+	Keymap *_currentMap;
+
+	const HardwareKeySet *_hardwareKeys;
+
 };
 
 } // end of namespace Common

Added: scummvm/branches/gsoc2008-vkeybd/backends/common/user-action.h
===================================================================
--- scummvm/branches/gsoc2008-vkeybd/backends/common/user-action.h	                        (rev 0)
+++ scummvm/branches/gsoc2008-vkeybd/backends/common/user-action.h	2008-07-21 00:11:25 UTC (rev 33157)
@@ -0,0 +1,70 @@
+#ifndef COMMON_USERACTION
+#define COMMON_USERACTION
+
+#include "common/events.h"
+#include "common/list.h"
+#include "common/str.h"
+
+namespace Common {
+
+struct HardwareKey;
+
+enum UserActionType {
+	kGenericUserActionType,
+
+	// common actions
+	kDirectionUpUserAction,
+	kDirectionDownUserAction,
+	kDirectionLeftUserAction,
+	kDirectionRightUserAction,
+	kLeftClickUserAction,
+	kRightClickUserAction,
+	kSaveUserAction,
+	kMenuUserAction,
+
+	kUserActionTypeMax
+};
+
+enum UserActionCategory {
+	kGenericUserActionCategory,
+	// classes of action - probably need to be slightly more specific than this
+	kInGameUserAction,   // effects the actual gameplay
+	kSystemUserAction,   //show a menu / change volume / etc
+
+	kUserActionCategoryMax
+};
+
+struct UserAction {
+	/** unique id used for saving/loading to config */
+	int32 id;
+	/** Human readable description */
+	String description;
+	/** Events to be sent when mapped key is pressed */
+	List<Event> events;
+
+	UserActionCategory category;
+	UserActionType type;
+	int priority;
+	int group;
+	int flags;
+
+	/** Hardware key that is mapped to this UserAction */
+	HardwareKey *hwKey;
+
+	UserAction(	String des = "", 
+		UserActionCategory cat = kGenericUserActionCategory,
+		UserActionType ty = kGenericUserActionType,
+		int pr = 0, int gr = 0, int fl = 0 ) {
+			description = des;
+			category = cat;
+			type = ty;
+			priority = pr;
+			group = gr;
+			flags = fl;
+			hwKey = 0;
+	}
+};
+
+} // end of namespace Common
+
+#endif
\ No newline at end of file


Property changes on: scummvm/branches/gsoc2008-vkeybd/backends/common/user-action.h
___________________________________________________________________
Added: svn:mime-type
   + text/plain
Added: svn:keywords
   + Date Rev Author URL Id
Added: svn:eol-style
   + native

Modified: scummvm/branches/gsoc2008-vkeybd/common/keyboard.h
===================================================================
--- scummvm/branches/gsoc2008-vkeybd/common/keyboard.h	2008-07-20 23:37:26 UTC (rev 33156)
+++ scummvm/branches/gsoc2008-vkeybd/common/keyboard.h	2008-07-21 00:11:25 UTC (rev 33157)
@@ -259,6 +259,10 @@
 		keycode = KEYCODE_INVALID;
 		ascii = flags = 0;
 	}
+
+	bool operator ==(const KeyState &x) const {
+		return keycode == x.keycode && ascii == x.ascii && flags == x.flags;
+	}
 };
 
 } // End of namespace Common

Modified: scummvm/branches/gsoc2008-vkeybd/dists/msvc8/scummvm.vcproj
===================================================================
--- scummvm/branches/gsoc2008-vkeybd/dists/msvc8/scummvm.vcproj	2008-07-20 23:37:26 UTC (rev 33156)
+++ scummvm/branches/gsoc2008-vkeybd/dists/msvc8/scummvm.vcproj	2008-07-21 00:11:25 UTC (rev 33157)
@@ -1057,6 +1057,10 @@
 				Name="common"
 				>
 				<File
+					RelativePath="..\..\backends\common\hardware-key.h"
+					>
+				</File>
+				<File
 					RelativePath="..\..\backends\common\keymap-manager.cpp"
 					>
 				</File>
@@ -1073,10 +1077,18 @@
 					>
 				</File>
 				<File
+					RelativePath="..\..\backends\common\keymapper.cpp"
+					>
+				</File>
+				<File
 					RelativePath="..\..\backends\common\keymapper.h"
 					>
 				</File>
 				<File
+					RelativePath="..\..\backends\common\user-action.h"
+					>
+				</File>
+				<File
 					RelativePath="..\..\backends\common\virtual-keyboard-parser.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