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

kenny-d at users.sourceforge.net kenny-d at users.sourceforge.net
Sat Jul 19 02:57:38 CEST 2008


Revision: 33107
          http://scummvm.svn.sourceforge.net/scummvm/?rev=33107&view=rev
Author:   kenny-d
Date:     2008-07-19 00:57:37 +0000 (Sat, 19 Jul 2008)

Log Message:
-----------
Keymap class implemented. KeymapManager and Keymapper classes started

Modified Paths:
--------------
    scummvm/branches/gsoc2008-vkeybd/dists/msvc8/scummvm.vcproj

Added 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
    scummvm/branches/gsoc2008-vkeybd/backends/common/keymapper.h

Added: scummvm/branches/gsoc2008-vkeybd/backends/common/keymap-manager.cpp
===================================================================
--- scummvm/branches/gsoc2008-vkeybd/backends/common/keymap-manager.cpp	                        (rev 0)
+++ scummvm/branches/gsoc2008-vkeybd/backends/common/keymap-manager.cpp	2008-07-19 00:57:37 UTC (rev 33107)
@@ -0,0 +1,29 @@
+#include "backends/common/keymap-manager.h"
+
+namespace Common {
+
+void KeymapManager::registerGlobalKeymap(const String& name, const Keymap& map) {
+	if (name.size() == 0) {
+		warning("Name must be specified when registering global keymap");
+		return;
+	}
+	insertEntry(name, "", map);
+}
+
+void KeymapManager::registerKeymap(const String& name, const String& domain, const Keymap& map) {
+	if (name.size() == 0 || domain.size() == 0) {
+		warning("Name and domain must be specified when registering keymap");
+		return;
+	}
+	insertEntry(name, domain, map);
+}
+
+void KeymapManager::insertEntry(const String& name, const String& domain, const Keymap& map) {
+	Entry *ent = new Entry;
+	ent->_name = name;
+	ent->_domain = domain;
+	ent->_keymap = new Keymap(map);
+	_keymaps.push_back(ent);
+}
+ 
+} // end of namespace Common
\ No newline at end of file


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

Added: scummvm/branches/gsoc2008-vkeybd/backends/common/keymap-manager.h
===================================================================
--- scummvm/branches/gsoc2008-vkeybd/backends/common/keymap-manager.h	                        (rev 0)
+++ scummvm/branches/gsoc2008-vkeybd/backends/common/keymap-manager.h	2008-07-19 00:57:37 UTC (rev 33107)
@@ -0,0 +1,33 @@
+#ifndef COMMON_KEYMAP_MANAGER
+#define COMMON_KEYMAP_MANAGER
+
+#include "backends/common/keymap.h"
+
+namespace Common {
+
+class KeymapManager {
+public:
+
+	KeymapManager();
+
+	void registerGlobalKeymap(const String& name, const Keymap& map);
+
+	void registerKeymap(const String& name, const String& domain, const Keymap& map);
+
+private:
+
+	struct Entry {
+		String _name;
+		String _domain;
+		Keymap *_keymap;
+	};
+
+	void insertEntry(const String& name, const String& domain, const Keymap& map);
+
+	List<Entry*> _keymaps;
+
+};
+
+} // end of namespace Common
+
+#endif
\ No newline at end of file


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

Added: scummvm/branches/gsoc2008-vkeybd/backends/common/keymap.cpp
===================================================================
--- scummvm/branches/gsoc2008-vkeybd/backends/common/keymap.cpp	                        (rev 0)
+++ scummvm/branches/gsoc2008-vkeybd/backends/common/keymap.cpp	2008-07-19 00:57:37 UTC (rev 33107)
@@ -0,0 +1,54 @@
+#include "backends/common/keymap.h"
+
+namespace Common {
+
+Keymap::Keymap(const Keymap& km) : _actions(km._actions), _keymap() {
+	for (uint i = 0; i < _actions.size(); i++) {
+		if (_actions[i]._hwKey) {
+			_keymap[_actions[i]._hwKey->key] = &_actions[i];
+		}
+	}
+}
+
+void Keymap::addAction(const UserAction& action) {
+	_actions.push_back(action);
+	_actions[_actions.size()-1]._hwKey = 0;
+}
+
+void Keymap::mapKeyToAction(UserAction *action, HardwareKey *key) {
+	for (uint i = 0; i < _actions.size(); i++) {
+		if (&_actions[i] == action) {
+			internalMapKey(action, key);
+			return;
+		}
+	}
+	error("UserAction not contained in KeyMap\n");
+}
+
+void Keymap::mapKeyToAction(uint idx, HardwareKey *key) {
+	if (idx >= _actions.size())
+		error("Key map index out of bounds!\n");
+	internalMapKey(&_actions[idx], key);
+}
+
+void Keymap::internalMapKey(UserAction *action, HardwareKey *hwKey) {
+	HashMap<KeyState, UserAction*>::iterator it;
+	it = _keymap.find(hwKey->key);
+	// if key is already mapped to an action then un-map it
+	if (it != _keymap.end())
+		it->_value->_hwKey = 0;
+
+	action->_hwKey = hwKey;
+	_keymap[hwKey->key] = action;
+}
+
+UserAction *Keymap::getMappedAction(KeyState ks) {
+	HashMap<KeyState, UserAction*>::iterator it;
+	it = _keymap.find(ks);
+	if (it == _keymap.end())
+		return 0;
+	else
+		return it->_value;
+}
+
+} // end of namespace Common
\ No newline at end of file


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

Added: scummvm/branches/gsoc2008-vkeybd/backends/common/keymap.h
===================================================================
--- scummvm/branches/gsoc2008-vkeybd/backends/common/keymap.h	                        (rev 0)
+++ scummvm/branches/gsoc2008-vkeybd/backends/common/keymap.h	2008-07-19 00:57:37 UTC (rev 33107)
@@ -0,0 +1,177 @@
+#ifndef COMMON_KEYMAP
+#define COMMON_KEYMAP
+
+#include "common/array.h"
+#include "common/events.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 {
+	/** 
+	* The KeyState that is generated by the back-end 
+	* when this hardware key is pressed.
+	*/
+	KeyState key;
+
+	/** Human readable description */
+	String description; 
+
+	UserActionCategory preferredCategory;
+	UserActionType preferredType;
+	int 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 {
+	/** Events to be sent when mapped key is pressed */
+	List<Event> events;
+	/** Human readable description */
+	String description;
+	UserActionCategory category;
+	UserActionType type;
+	int priority;
+	int group;
+	int flags;
+
+	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;
+	}
+
+	friend class Keymap;
+
+	HardwareKey *mappedKey() { return _hwKey; }
+private:
+	/** 
+	* Key that is mapped to this UserAction, only KeyMap can set this
+	*/
+	HardwareKey *_hwKey;
+};
+
+/**
+ * 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>
+	: public UnaryFunction<KeyState, uint> {
+
+	uint operator()(const KeyState &val) const { 
+		return (uint)(val.keycode * (val.flags << 1));
+	}
+};
+
+class Keymap {
+public:
+
+	Keymap() {}
+	Keymap(const Keymap& km);
+
+	/**
+	 * Adds a new UserAction to this Map, 
+	 * adding it at the back of the internal array
+	 * @param action the UserAction to add
+	 */
+	void addAction(const UserAction& action);
+
+	/**
+	* Maps a HardwareKey to the given UserAction
+	* @param action must point to a UserAction in this Keymap
+	* @param key pointer to HardwareKey to map
+	* @note if action does not point to a UserAction in this Keymap a
+	*       fatal error will occur
+	*/
+	void mapKeyToAction(UserAction *action, HardwareKey *key);
+
+	/**
+	 * Maps a HardwareKey to the UserAction at the given index
+	 * @param index Index of UserAction in the internal array
+	 * @param key pointer to HardwareKey to map
+	 */
+	void mapKeyToAction(uint index, HardwareKey *key);
+
+	/**
+	 * Get a read-only array of all the UserActions contained in this Keymap
+	 */
+	const Array<UserAction>& getUserActions() { return _actions; }
+
+	/**
+	 * Find the UserAction that a key is mapped to
+	 * @param key the key that is mapped to the required UserAction
+	 * @return a pointer to the UserAction or 0 if no
+	 */
+	UserAction *getMappedAction(KeyState key);
+
+private:
+
+	void internalMapKey(UserAction *action, HardwareKey *hwKey);
+
+	Array<UserAction> _actions;
+	HashMap<KeyState, UserAction*> _keymap; 
+
+};
+
+
+} // end of namespace Common
+
+#endif
\ No newline at end of file


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

Added: scummvm/branches/gsoc2008-vkeybd/backends/common/keymapper.h
===================================================================
--- scummvm/branches/gsoc2008-vkeybd/backends/common/keymapper.h	                        (rev 0)
+++ scummvm/branches/gsoc2008-vkeybd/backends/common/keymapper.h	2008-07-19 00:57:37 UTC (rev 33107)
@@ -0,0 +1,23 @@
+#ifndef COMMON_KEYMAPPER
+#define COMMON_KEYMAPPER
+
+#include "backends/common/keymap-manager.h"
+
+namespace Common {
+
+class Keymapper {
+public:
+
+	Keymapper();
+
+	
+
+private:
+
+	KeymapManager _manager;
+
+	List<HardwareKey> _hardwareKeys;
+
+};
+
+} // end of namespace Common
\ No newline at end of file


Property changes on: scummvm/branches/gsoc2008-vkeybd/backends/common/keymapper.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/dists/msvc8/scummvm.vcproj
===================================================================
--- scummvm/branches/gsoc2008-vkeybd/dists/msvc8/scummvm.vcproj	2008-07-18 22:44:11 UTC (rev 33106)
+++ scummvm/branches/gsoc2008-vkeybd/dists/msvc8/scummvm.vcproj	2008-07-19 00:57:37 UTC (rev 33107)
@@ -1057,6 +1057,26 @@
 				Name="common"
 				>
 				<File
+					RelativePath="..\..\backends\common\keymap-manager.cpp"
+					>
+				</File>
+				<File
+					RelativePath="..\..\backends\common\keymap-manager.h"
+					>
+				</File>
+				<File
+					RelativePath="..\..\backends\common\keymap.cpp"
+					>
+				</File>
+				<File
+					RelativePath="..\..\backends\common\keymap.h"
+					>
+				</File>
+				<File
+					RelativePath="..\..\backends\common\keymapper.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