[Scummvm-cvs-logs] SF.net SVN: scummvm: [27679] scummvm/trunk/engines/gob

drmccoy at users.sourceforge.net drmccoy at users.sourceforge.net
Sat Jun 23 19:00:27 CEST 2007


Revision: 27679
          http://scummvm.svn.sourceforge.net/scummvm/?rev=27679&view=rev
Author:   drmccoy
Date:     2007-06-23 10:00:27 -0700 (Sat, 23 Jun 2007)

Log Message:
-----------
Fixed the FIXME (by making Util::_keyBuffer an array of Common::KeyState)

Modified Paths:
--------------
    scummvm/trunk/engines/gob/util.cpp
    scummvm/trunk/engines/gob/util.h

Modified: scummvm/trunk/engines/gob/util.cpp
===================================================================
--- scummvm/trunk/engines/gob/util.cpp	2007-06-23 16:51:06 UTC (rev 27678)
+++ scummvm/trunk/engines/gob/util.cpp	2007-06-23 17:00:27 UTC (rev 27679)
@@ -40,8 +40,6 @@
 
 Util::Util(GobEngine *vm) : _vm(vm) {
 	_mouseButtons = 0;
-	for (int i = 0; i < KEYBUFSIZE; i++)
-		_keyBuffer[i] = 0;
 	_keyBufferHead = 0;
 	_keyBufferTail = 0;
 	_fastMode = 0;
@@ -114,7 +112,7 @@
 					_fastMode ^= 2;
 				break;
 			}
-			addKeyToBuffer(event.kbd.ascii);
+			addKeyToBuffer(event.kbd);
 			break;
 		case Common::EVENT_KEYUP:
 			break;
@@ -145,7 +143,7 @@
 	return (_keyBufferHead == _keyBufferTail);
 }
 
-void Util::addKeyToBuffer(int16 key) {
+void Util::addKeyToBuffer(const Common::KeyState &key) {
 	if ((_keyBufferHead + 1) % KEYBUFSIZE == _keyBufferTail) {
 		warning("key buffer overflow");
 		return;
@@ -155,7 +153,7 @@
 	_keyBufferHead = (_keyBufferHead + 1) % KEYBUFSIZE;
 }
 
-bool Util::getKeyFromBuffer(int16& key) {
+bool Util::getKeyFromBuffer(Common::KeyState &key) {
 	if (_keyBufferHead == _keyBufferTail) return false;
 
 	key = _keyBuffer[_keyBufferTail];
@@ -164,48 +162,49 @@
 	return true;
 }
 
-int16 Util::translateKey(int16 key) {
-	// FIXME: This currently maps KeyState::ascii values, when
-	// it really should map keycodes! To fix this, addKeyToBuffer()
-	// will have to be called with kbd.keycode instead of kbd.ascii,
-	// and of course this will in turn require subsequent changes...
+int16 Util::translateKey(const Common::KeyState &key) {
 	static struct keyS {
 		int16 from;
 		int16 to;
 	} keys[] = {
-		{Common::KEYCODE_BACKSPACE,   0x0E08}, // Backspace
-		{Common::KEYCODE_SPACE,  0x3920}, // Space
-		{Common::KEYCODE_RETURN,  0x1C0D}, // Enter
-		{Common::KEYCODE_ESCAPE,  0x011B}, // ESC
-		{Common::KEYCODE_DELETE, 0x5300}, // Del
-		{Common::KEYCODE_UP, 0x4800}, // Up arrow
-		{Common::KEYCODE_DOWN, 0x5000}, // Down arrow
-		{Common::KEYCODE_RIGHT, 0x4D00}, // Right arrow
-		{Common::KEYCODE_LEFT, 0x4B00}, // Left arrow
-		{Common::ASCII_F1, 0x3B00}, // F1
-		{Common::ASCII_F2, 0x3C00}, // F2
-		{Common::ASCII_F3, 0x3D00}, // F3
-		{Common::ASCII_F4, 0x3E00}, // F4
-		{Common::ASCII_F5, 0x011B}, // F5
-		{Common::ASCII_F6, 0x4000}, // F6
-		{Common::ASCII_F7, 0x4100}, // F7
-		{Common::ASCII_F8, 0x4200}, // F8
-		{Common::ASCII_F9, 0x4300}, // F9
-		{Common::ASCII_F10, 0x4400}  // F10
+		{Common::KEYCODE_INVALID,   0x0000},
+		{Common::KEYCODE_BACKSPACE, 0x0E08},
+		{Common::KEYCODE_SPACE,     0x3920},
+		{Common::KEYCODE_RETURN,    0x1C0D},
+		{Common::KEYCODE_ESCAPE,    0x011B},
+		{Common::KEYCODE_DELETE,    0x5300},
+		{Common::KEYCODE_UP,        0x4800},
+		{Common::KEYCODE_DOWN,      0x5000},
+		{Common::KEYCODE_RIGHT,     0x4D00},
+		{Common::KEYCODE_LEFT,      0x4B00},
+		{Common::KEYCODE_F1,        0x3B00},
+		{Common::KEYCODE_F2,        0x3C00},
+		{Common::KEYCODE_F3,        0x3D00},
+		{Common::KEYCODE_F4,        0x3E00},
+		{Common::KEYCODE_F5,        0x011B},
+		{Common::KEYCODE_F6,        0x4000},
+		{Common::KEYCODE_F7,        0x4100},
+		{Common::KEYCODE_F8,        0x4200},
+		{Common::KEYCODE_F9,        0x4300},
+		{Common::KEYCODE_F10,       0x4400}
 	};
 
 	for (int i = 0; i < ARRAYSIZE(keys); i++)
-		if (key == keys[i].from)
+		if (key.keycode == keys[i].from)
 			return keys[i].to;
 
-	if ((key < 32) || (key >= 128))
-		return 0;
+	if ((key.keycode >= Common::KEYCODE_SPACE) &&
+	    (key.keycode <= Common::KEYCODE_DELETE)) {
 
-	return key;
+		// Used as a user input in Gobliins 2 notepad, in the save dialog, ...
+		return key.ascii;
+	}
+
+	return 0;
 }
 
 int16 Util::getKey(void) {
-	int16 key;
+	Common::KeyState key;
 
 	while (!getKeyFromBuffer(key)) {
 		processInput();
@@ -217,10 +216,9 @@
 }
 
 int16 Util::checkKey(void) {
-	int16 key;
+	Common::KeyState key;
 
-	if (!getKeyFromBuffer(key))
-		key = 0;
+	getKeyFromBuffer(key);
 
 	return translateKey(key);
 }

Modified: scummvm/trunk/engines/gob/util.h
===================================================================
--- scummvm/trunk/engines/gob/util.h	2007-06-23 16:51:06 UTC (rev 27678)
+++ scummvm/trunk/engines/gob/util.h	2007-06-23 17:00:27 UTC (rev 27679)
@@ -26,6 +26,8 @@
 #ifndef GOB_UTIL_H
 #define GOB_UTIL_H
 
+#include "common/keyboard.h"
+
 #include "gob/video.h"
 
 namespace Gob {
@@ -90,7 +92,7 @@
 
 protected:
 	int16 _mouseButtons;
-	int16 _keyBuffer[KEYBUFSIZE];
+	Common::KeyState _keyBuffer[KEYBUFSIZE];
 	int16 _keyBufferHead;
 	int16 _keyBufferTail;
 
@@ -99,9 +101,9 @@
 	GobEngine *_vm;
 
 	bool keyBufferEmpty();
-	void addKeyToBuffer(int16 key);
-	bool getKeyFromBuffer(int16& key);
-	int16 translateKey(int16 key);
+	void addKeyToBuffer(const Common::KeyState &key);
+	bool getKeyFromBuffer(Common::KeyState &key);
+	int16 translateKey(const Common::KeyState &key);
 	void checkJoystick();
 };
 


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