[Scummvm-cvs-logs] SF.net SVN: scummvm:[38887] scummvm/trunk/engines/sci/gfx/gfx_driver.cpp

thebluegr at users.sourceforge.net thebluegr at users.sourceforge.net
Wed Feb 25 21:40:05 CET 2009


Revision: 38887
          http://scummvm.svn.sourceforge.net/scummvm/?rev=38887&view=rev
Author:   thebluegr
Date:     2009-02-25 20:40:05 +0000 (Wed, 25 Feb 2009)

Log Message:
-----------
Initial fix for the keypad keys. We still don't know the initial state of the caps lock etc keys, so an appropriate method will need to be added to OSystem

Modified Paths:
--------------
    scummvm/trunk/engines/sci/gfx/gfx_driver.cpp

Modified: scummvm/trunk/engines/sci/gfx/gfx_driver.cpp
===================================================================
--- scummvm/trunk/engines/sci/gfx/gfx_driver.cpp	2009-02-25 19:52:17 UTC (rev 38886)
+++ scummvm/trunk/engines/sci/gfx/gfx_driver.cpp	2009-02-25 20:40:05 UTC (rev 38887)
@@ -42,6 +42,14 @@
 
 #define S ((struct _scummvm_driver_state *)(drv->state))
 
+enum modifierKeysStates {
+	capslockState = 0,
+	numlockState = 1,
+	scrollockState = 2
+};
+
+bool modifierStates[3];
+
 static int
 scummvm_init_specific(gfx_driver_t *drv, int xfact, int yfact, int bytespp) {
 	int i;
@@ -81,6 +89,12 @@
 }
 
 static int scummvm_init(gfx_driver_t *drv) {
+	// FIXME: This is wrong. The initial states of capslock etc are not known initially
+	//
+	// The best solution likely would be to add code to the EventManager class
+	// for tracking which keys are pressed and which are not...
+	modifierStates[capslockState] = modifierStates[numlockState] = modifierStates[scrollockState] = false;
+
 	return scummvm_init_specific(drv, 1, 1, GFX_COLOR_MODE_INDEX);
 }
 
@@ -332,30 +346,41 @@
 		input.buckybits =
 		    ((modifiers & Common::KBD_ALT) ? SCI_EVM_ALT : 0) |
 		    ((modifiers & Common::KBD_CTRL) ? SCI_EVM_CTRL : 0) |
-		    ((modifiers & Common::KBD_SHIFT) ? SCI_EVM_LSHIFT | SCI_EVM_RSHIFT : 0);
+		    ((modifiers & Common::KBD_SHIFT) ? SCI_EVM_LSHIFT | SCI_EVM_RSHIFT : 0) |
+			(modifierStates[capslockState] ? SCI_EVM_CAPSLOCK : 0) |
+			(modifierStates[numlockState] ? SCI_EVM_NUMLOCK : 0) |
+			(modifierStates[scrollockState] ? SCI_EVM_SCRLOCK : 0);
 
 		// We add the modifier key status to buckybits
 		// SDL sends a keydown event if a modifier key is turned on and a keyup event if it's off
-		//
-		// FIXME: This code is semi-bogus. It only records the modifier key being *pressed*.
-		// It does not track correctly whether capslock etc. is active. To do that, we
-		// would have to record the fact that the modifier was pressed in global var,
-		// and also watch for Common::EVENT_KEYUP events.
-		// But this is still not quite good enough, because not all events might
-		// pass through here (e.g. the GUI might be running with its own event loop).
-		//
-		// The best solution likely would be to add code to the EventManager class
-		// for tracking which keys are pressed and which are not...
-		if (ev.type == Common::EVENT_KEYDOWN) {
+		if (ev.type == Common::EVENT_KEYDOWN || ev.type == Common::EVENT_KEYUP) {
  			switch (ev.kbd.keycode) {
 			case Common::KEYCODE_CAPSLOCK:
-				input.buckybits |= SCI_EVM_CAPSLOCK;
+				if (ev.type == Common::EVENT_KEYDOWN) {
+					input.buckybits |= SCI_EVM_CAPSLOCK;
+					modifierStates[capslockState] = true;
+				} else {
+					input.buckybits &= ~SCI_EVM_CAPSLOCK;
+					modifierStates[capslockState] = false;
+				}
 				break;
 			case Common::KEYCODE_NUMLOCK:
-				input.buckybits |= SCI_EVM_NUMLOCK;
+				if (ev.type == Common::EVENT_KEYDOWN) {
+					input.buckybits |= SCI_EVM_NUMLOCK;
+					modifierStates[numlockState] = true;
+				} else {
+					input.buckybits &= ~SCI_EVM_NUMLOCK;
+					modifierStates[numlockState] = false;
+				}
 				break;
 			case Common::KEYCODE_SCROLLOCK:
-				input.buckybits |= SCI_EVM_SCRLOCK;
+				if (ev.type == Common::EVENT_KEYDOWN) {
+					input.buckybits |= SCI_EVM_SCRLOCK;
+					modifierStates[scrollockState] = true;
+				} else {
+					input.buckybits &= ~SCI_EVM_SCRLOCK;
+					modifierStates[scrollockState] = false;
+				}
 				break;
 			default:
 				break;
@@ -425,7 +450,27 @@
 				case Common::KEYCODE_DELETE:
 					input.data = SCI_K_DELETE;
 					break;
-					//TODO: SCI_K_CENTER
+				// Keypad keys
+				case Common::KEYCODE_KP8:	// up
+					if (!modifierStates[numlockState])
+						input.data = SCI_K_UP;
+					break;
+				case Common::KEYCODE_KP2:	// down
+					if (!modifierStates[numlockState])
+						input.data = SCI_K_DOWN;
+					break;
+				case Common::KEYCODE_KP6:	// right
+					if (!modifierStates[numlockState])
+						input.data = SCI_K_RIGHT;
+					break;
+				case Common::KEYCODE_KP4:	// left
+					if (!modifierStates[numlockState])
+						input.data = SCI_K_LEFT;
+					break;
+				case Common::KEYCODE_KP5:	// center
+					if (!modifierStates[numlockState])
+						input.data = SCI_K_CENTER;
+					break;
 				default:
 					input.type = SCI_EVT_NONE;
 					break;


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