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

kenny-d at users.sourceforge.net kenny-d at users.sourceforge.net
Fri Aug 22 12:36:13 CEST 2008


Revision: 34094
          http://scummvm.svn.sourceforge.net/scummvm/?rev=34094&view=rev
Author:   kenny-d
Date:     2008-08-22 10:36:12 +0000 (Fri, 22 Aug 2008)

Log Message:
-----------
Fix for key repeat bug

Modified Paths:
--------------
    scummvm/branches/gsoc2008-vkeybd/backends/keymapper/keymapper.cpp
    scummvm/branches/gsoc2008-vkeybd/backends/keymapper/keymapper.h

Modified: scummvm/branches/gsoc2008-vkeybd/backends/keymapper/keymapper.cpp
===================================================================
--- scummvm/branches/gsoc2008-vkeybd/backends/keymapper/keymapper.cpp	2008-08-22 06:32:12 UTC (rev 34093)
+++ scummvm/branches/gsoc2008-vkeybd/backends/keymapper/keymapper.cpp	2008-08-22 10:36:12 UTC (rev 34094)
@@ -127,6 +127,12 @@
 }
 
 void Keymapper::pushKeymap(Keymap *newMap, bool inherit, bool global) {
+	List<KeyState>::iterator it;
+	for (it = _keysDown.begin(); it != _keysDown.end(); ++it) {
+		Action *action = getAction(*it);
+		if (action) executeAction(action, false);
+	}
+	_keysDown.clear();
 	MapRecord mr = {newMap, inherit, global};
 	_activeMaps.push(mr);
 }
@@ -144,54 +150,68 @@
 	return mapKey(key, false);
 }
 
-bool Keymapper::mapKey(const KeyState& key, bool isKeyDown) {
+bool Keymapper::mapKey(const KeyState& key, bool keyDown) {
 	if (!_enabled) return false;
 	if (_activeMaps.empty()) return false;
 
+	Action *action = getAction(key);
+	if (!action) return false;
+
+	if (keyDown)
+		_keysDown.push_back(key);
+	else
+		_keysDown.remove(key);
+
+	executeAction(action, keyDown);
+	return true;
+}
+
+Action *Keymapper::getAction(const KeyState& key) {
 	Action *action = 0;
-	for (int i = _activeMaps.size() - 1; !action && i >= 0; --i) {
+	for (int i = _activeMaps.size() - 1; i >= 0; --i) {
 		MapRecord mr = _activeMaps[i];
 		action = mr.keymap->getMappedAction(key);
-		if (mr.inherit == false) break;
+		if (action || mr.inherit == false) break;
 	}
-	if (!action) return false;
+	return action;
+}
 
+void Keymapper::executeAction(const Action *action, bool keyDown) {
 	List<Event>::iterator it;
 	for (it = action->events.begin(); it != action->events.end(); ++it) {
 		Event evt = *it;
 		switch (evt.type) {
 		case EVENT_KEYDOWN:
-			if (!isKeyDown) evt.type = EVENT_KEYUP;
+			if (!keyDown) evt.type = EVENT_KEYUP;
 			break;
 		case EVENT_KEYUP:
-			if (isKeyDown) evt.type = EVENT_KEYDOWN;
+			if (keyDown) evt.type = EVENT_KEYDOWN;
 			break;
 		case EVENT_LBUTTONDOWN:
-			if (!isKeyDown) evt.type = EVENT_LBUTTONUP;
+			if (!keyDown) evt.type = EVENT_LBUTTONUP;
 			break;
 		case EVENT_LBUTTONUP:
-			if (isKeyDown) evt.type = EVENT_LBUTTONDOWN;
+			if (keyDown) evt.type = EVENT_LBUTTONDOWN;
 			break;
 		case EVENT_RBUTTONDOWN:
-			if (!isKeyDown) evt.type = EVENT_RBUTTONUP;
+			if (!keyDown) evt.type = EVENT_RBUTTONUP;
 			break;
 		case EVENT_RBUTTONUP:
-			if (isKeyDown) evt.type = EVENT_RBUTTONDOWN;
+			if (keyDown) evt.type = EVENT_RBUTTONDOWN;
 			break;
 		case EVENT_MBUTTONDOWN:
-			if (!isKeyDown) evt.type = EVENT_MBUTTONUP;
+			if (!keyDown) evt.type = EVENT_MBUTTONUP;
 			break;
 		case EVENT_MBUTTONUP:
-			if (isKeyDown) evt.type = EVENT_MBUTTONDOWN;
+			if (keyDown) evt.type = EVENT_MBUTTONDOWN;
 			break;
 		default:
 			// don't deliver other events on key up
-			if (!isKeyDown) continue;
+			if (!keyDown) continue;
 		}
 		evt.mouse = _eventMan->getMousePos();
 		_eventMan->pushEvent(evt);
 	}
-	return true;
 }
 
 const HardwareKey *Keymapper::getHardwareKey(const KeyState& key) {

Modified: scummvm/branches/gsoc2008-vkeybd/backends/keymapper/keymapper.h
===================================================================
--- scummvm/branches/gsoc2008-vkeybd/backends/keymapper/keymapper.h	2008-08-22 06:32:12 UTC (rev 34093)
+++ scummvm/branches/gsoc2008-vkeybd/backends/keymapper/keymapper.h	2008-08-22 10:36:12 UTC (rev 34094)
@@ -141,10 +141,10 @@
 	 * 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
+	 * @param keyDown	true for key down, false for key up
 	 * @return			true if key was mapped
 	 */
-	bool mapKey(const KeyState& key, bool isKeyDown);
+	bool mapKey(const KeyState& key, bool keyDown);
 
 	/**
 	 * @brief Map a key down event.
@@ -183,6 +183,9 @@
 	HardwareKeySet *_hardwareKeys;
 
 	void pushKeymap(Keymap *newMap, bool inherit, bool global);
+	
+	Action *getAction(const KeyState& key);
+	void executeAction(const Action *act, bool keyDown);
 
 	typedef List<HardwareKey*>::iterator Iterator;
 
@@ -191,6 +194,7 @@
 	bool _enabled;
 
 	Stack<MapRecord> _activeMaps;
+	List<KeyState> _keysDown;
 
 };
 


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