[Scummvm-cvs-logs] SF.net SVN: scummvm: [27627] scummvm/trunk/engines/sword1

fingolfin at users.sourceforge.net fingolfin at users.sourceforge.net
Fri Jun 22 23:34:04 CEST 2007


Revision: 27627
          http://scummvm.svn.sourceforge.net/scummvm/?rev=27627&view=rev
Author:   fingolfin
Date:     2007-06-22 14:34:03 -0700 (Fri, 22 Jun 2007)

Log Message:
-----------
Made BS1 track the full KeyState upon KEYDOWN events (this makes it possible to remove to workaround for Mac keyboards)

Modified Paths:
--------------
    scummvm/trunk/engines/sword1/control.cpp
    scummvm/trunk/engines/sword1/control.h

Modified: scummvm/trunk/engines/sword1/control.cpp
===================================================================
--- scummvm/trunk/engines/sword1/control.cpp	2007-06-22 21:32:49 UTC (rev 27626)
+++ scummvm/trunk/engines/sword1/control.cpp	2007-06-22 21:34:03 UTC (rev 27627)
@@ -204,7 +204,7 @@
 			_system->copyRectToScreen(_screenBuf, 640, 0, 0, 640, 480);
 		}
 		delay(300);
-		if (_keyPressed) {
+		if (_keyPressed.keycode) {
 			if (!Common::File::exists(fName)) {
 				memset(_screenBuf, 0, 640 * 480);
 				renderText(_lStrings[STR_INCORRECT_CD], 320, 230, TEXT_CENTER);
@@ -224,7 +224,8 @@
 uint8 Control::runPanel(void) {
 	_mouseDown = false;
 	_restoreBuf = NULL;
-	_keyPressed = _numButtons = 0;
+	_keyPressed.keycode = Common::KEYCODE_INVALID;
+	_numButtons = 0;
 	_screenBuf = (uint8*)malloc(640 * 480);
 	memset(_screenBuf, 0, 640 * 480);
 	_system->copyRectToScreen(_screenBuf, 640, 0, 0, 640, 480);
@@ -283,7 +284,7 @@
 					_cursorVisible = false;
 					_cursorTick = 0;
 				}
-				if (_keyPressed)
+				if (_keyPressed.keycode)
 					handleSaveKey(_keyPressed);
 				else if (_cursorVisible != visible)
 					showSavegameNames();
@@ -328,10 +329,9 @@
 	}
 
 	uint8 flag = 0;
-	if (_keyPressed == 27)
+	if (_keyPressed.keycode == Common::KEYCODE_ESCAPE)
 		flag = kButtonCancel;
-	// 3 is num keypad Enter on Macs. See FR #1273746
-	else if (_keyPressed == '\r' || _keyPressed == '\n' || _keyPressed == 3)
+	else if (_keyPressed.keycode == Common::KEYCODE_RETURN || _keyPressed.keycode == Common::KEYCODE_KP_ENTER)
 		flag = kButtonOk;
 
 	if (flag) {
@@ -622,9 +622,9 @@
 		buttons[0]->draw();
 		buttons[1]->draw();
 		delay(1000 / 12);
-		if (_keyPressed == 27)
+		if (_keyPressed.keycode == Common::KEYCODE_ESCAPE)
 			retVal = 2;
-		else if (_keyPressed == '\r' || _keyPressed == '\n')
+		else if (_keyPressed.keycode == Common::KEYCODE_RETURN || _keyPressed.keycode == Common::KEYCODE_KP_ENTER)
 			retVal = 1;
 		if (_mouseState & BS1L_BUTTON_DOWN) {
 			if (buttons[0]->wasClicked(_mouseX, _mouseY))
@@ -649,7 +649,7 @@
 	return retVal == 1;
 }
 
-bool Control::keyAccepted(uint8 key) {
+bool Control::keyAccepted(uint16 ascii) {
 	// this routine needs changes for Czech keys... No idea how to do that, though.
 	// FIXME: It is not a good idea to put non-ASCII chars into a C source file,
 	// since there is no way to specify which encoding you are using. 
@@ -658,22 +658,22 @@
 	// do not at all specify which encoding keyboard events use, so this
 	// check here is probably not portable anyway...
 	static const char allowedSpecials[] = "\xE9\xE8\xE1\xE0\xFA\xF9\xE4\xF6\xFC\xC4\xD6\xDC\xDF,.:-()?! \"\'";
-	if (((key >= 'A') && (key <= 'Z')) ||
-		((key >= 'a') && (key <= 'z')) ||
-		((key >= '0') && (key <= '9')) ||
-		strchr(allowedSpecials, key))
+	if (((ascii >= 'A') && (ascii <= 'Z')) ||
+		((ascii >= 'a') && (ascii <= 'z')) ||
+		((ascii >= '0') && (ascii <= '9')) ||
+		strchr(allowedSpecials, ascii))
 		return true;
 	else
 		return false;
 }
 
-void Control::handleSaveKey(uint8 key) {
+void Control::handleSaveKey(Common::KeyState kbd) {
 	if (_selectedSavegame < 255) {
 		uint8 len = strlen((char*)_saveNames[_selectedSavegame]);
-		if ((key == 8) && len)  // backspace
+		if ((kbd.keycode == Common::KEYCODE_BACKSPACE) && len)  // backspace
 			_saveNames[_selectedSavegame][len - 1] = '\0';
-		else if (keyAccepted(key) && (len < 31)) {
-			_saveNames[_selectedSavegame][len] = key;
+		else if (keyAccepted(kbd.ascii) && (len < 31)) {
+			_saveNames[_selectedSavegame][len] = kbd.ascii;
 			_saveNames[_selectedSavegame][len + 1] = '\0';
 		}
 		showSavegameNames();
@@ -1037,7 +1037,7 @@
 
 	uint32 now = _system->getMillis();
 	uint32 endTime = now + msecs;
-	_keyPressed = 0;	//reset
+	_keyPressed.keycode = Common::KEYCODE_INVALID;	//reset
 	_mouseState = 0;
 
 	do {
@@ -1045,13 +1045,7 @@
 		while (eventMan->pollEvent(event)) {
 			switch (event.type) {
 			case Common::EVENT_KEYDOWN:
-
-				// Make sure backspace works right (this fixes a small issue on OS X)
-				if (event.kbd.keycode == Common::KEYCODE_BACKSPACE) {
-printf("Mac backspace workaround, was %d\n", event.kbd.ascii);
-					_keyPressed = 8;
-				} else
-					_keyPressed = (byte)event.kbd.ascii;
+				_keyPressed = event.kbd;
 				// we skip the rest of the delay and return immediately
 				// to handle keyboard input
 				return;

Modified: scummvm/trunk/engines/sword1/control.h
===================================================================
--- scummvm/trunk/engines/sword1/control.h	2007-06-22 21:32:49 UTC (rev 27626)
+++ scummvm/trunk/engines/sword1/control.h	2007-06-22 21:34:03 UTC (rev 27627)
@@ -27,6 +27,7 @@
 #define SWORD1_CONTROL_H
 
 #include "common/scummsys.h"
+#include "common/events.h"
 #include "sword1/sworddefs.h"
 
 class OSystem;
@@ -118,8 +119,8 @@
 	void saveNameSelect(uint8 id, bool saving);
 	bool saveToFile(void);
 	bool restoreFromFile(void);
-	bool keyAccepted(uint8 key);
-	void handleSaveKey(uint8 key);
+	bool keyAccepted(uint16 ascii);
+	void handleSaveKey(Common::KeyState kbd);
 
 	void renderVolumeBar(uint8 id, uint8 volL, uint8 volR);
 	uint16 getTextWidth(const uint8 *str);
@@ -141,7 +142,7 @@
 	Sound *_sound;
 	uint8 *_font, *_redFont;
 	uint8 *_screenBuf;
-	uint8 _keyPressed;
+	Common::KeyState _keyPressed;
 	void delay(uint32 msecs);
 	uint16 _mouseX, _mouseY, _mouseState;
 	bool _mouseDown;


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