diff src/video/windib/SDL_dibevents.c @ 4162:3b7fc3416601 SDL-1.2

GAPI fixes from Stefan Klug
author Sam Lantinga <slouken@libsdl.org>
date Mon, 16 Feb 2009 22:32:34 +0000
parents a1b03ba2fcd0
children a6f635e5eaa6
line wrap: on
line diff
--- a/src/video/windib/SDL_dibevents.c	Fri Jan 30 01:40:44 2009 +0000
+++ b/src/video/windib/SDL_dibevents.c	Mon Feb 16 22:32:34 2009 +0000
@@ -30,8 +30,16 @@
 #include "../../events/SDL_sysevents.h"
 #include "../../events/SDL_events_c.h"
 #include "../wincommon/SDL_lowvideo.h"
+#include "SDL_gapidibvideo.h"
+#include "SDL_vkeys.h"
+
+#ifdef SDL_VIDEO_DRIVER_GAPI
+#include "../gapi/SDL_gapivideo.h"
+#endif
+
+#ifdef SDL_VIDEO_DRIVER_WINDIB
 #include "SDL_dibvideo.h"
-#include "SDL_vkeys.h"
+#endif
 
 #ifndef WM_APP
 #define WM_APP	0x8000
@@ -44,6 +52,7 @@
 /* The translation table from a Microsoft VK keysym to a SDL keysym */
 static SDLKey VK_keymap[SDLK_LAST];
 static SDL_keysym *TranslateKey(WPARAM vkey, UINT scancode, SDL_keysym *keysym, int pressed);
+static SDLKey Arrows_keymap[4];
 
 /* Masks for processing the windows KEYDOWN and KEYUP messages */
 #define REPEATED_KEYMASK	(1<<30)
@@ -59,22 +68,21 @@
 static WNDPROCTYPE userWindowProc = NULL;
 
 
-#ifdef _WIN32_WCE
+#ifdef SDL_VIDEO_DRIVER_GAPI
 
-WPARAM rotateKey(WPARAM key,SDL_ScreenOrientation direction) 
+WPARAM rotateKey(WPARAM key,int direction) 
 {
-	if (direction != SDL_ORIENTATION_LEFT)
-		return key;
-
+	if(direction ==0 ) return key;
+	
 	switch (key) {
 		case 0x26: /* up */
-			return 0x27;
+			return Arrows_keymap[(2 + direction) % 4];
 		case 0x27: /* right */
-			return 0x28;
+			return Arrows_keymap[(1 + direction) % 4];
 		case 0x28: /* down */
-			return 0x25;
+			return Arrows_keymap[direction % 4];
 		case 0x25: /* left */
-			return 0x26;
+			return Arrows_keymap[(3 + direction) % 4];
 	}
 
 	return key;
@@ -93,14 +101,15 @@
 		case WM_KEYDOWN: {
 			SDL_keysym keysym;
 
-#ifdef _WIN32_WCE
-			// Drop GAPI artefacts
-			if (wParam == 0x84 || wParam == 0x5B)
-				return 0;
+#ifdef SDL_VIDEO_DRIVER_GAPI
+			if(this->hidden->gapiInfo)
+			{
+				// Drop GAPI artefacts
+				if (wParam == 0x84 || wParam == 0x5B)
+					return 0;
 
-			// Rotate key if necessary
-			if (this->hidden->orientation != SDL_ORIENTATION_UP)
-				wParam = rotateKey(wParam, this->hidden->orientation);	
+				wParam = rotateKey(wParam, this->hidden->gapiInfo->coordinateTransform);
+			}
 #endif 
 			/* Ignore repeated keys */
 			if ( lParam&REPEATED_KEYMASK ) {
@@ -167,14 +176,15 @@
 		case WM_KEYUP: {
 			SDL_keysym keysym;
 
-#ifdef _WIN32_WCE
-			// Drop GAPI artifacts
-			if (wParam == 0x84 || wParam == 0x5B)
-				return 0;
-
-			// Rotate key if necessary
-			if (this->hidden->orientation != SDL_ORIENTATION_UP)
-				wParam = rotateKey(wParam, this->hidden->orientation);	
+#ifdef SDL_VIDEO_DRIVER_GAPI
+			if(this->hidden->gapiInfo)
+			{
+				// Drop GAPI artifacts
+				if (wParam == 0x84 || wParam == 0x5B)
+					return 0;
+	
+				wParam = rotateKey(wParam, this->hidden->gapiInfo->coordinateTransform);
+			}
 #endif
 
 			switch (wParam) {
@@ -222,12 +232,11 @@
 				TranslateKey(wParam,HIWORD(lParam),&keysym,0));
 		}
 		return(0);
-
 #if defined(SC_SCREENSAVE) && defined(SC_MONITORPOWER)
 		case WM_SYSCOMMAND: {
 			const DWORD val = (DWORD) (wParam & 0xFFF0);
 			if ((val == SC_SCREENSAVE) || (val == SC_MONITORPOWER)) {
-				if (!allow_screensaver) {
+				if (this->hidden->dibInfo && !allow_screensaver) {
 					/* Note that this doesn't stop anything on Vista
 					   if the screensaver has a password. */
 					return(0);
@@ -430,6 +439,11 @@
 	VK_keymap[VK_SNAPSHOT] = SDLK_PRINT;
 	VK_keymap[VK_CANCEL] = SDLK_BREAK;
 	VK_keymap[VK_APPS] = SDLK_MENU;
+
+	Arrows_keymap[3] = 0x25;
+	Arrows_keymap[2] = 0x26;
+	Arrows_keymap[1] = 0x27;
+	Arrows_keymap[0] = 0x28;
 }
 
 #define EXTKEYPAD(keypad) ((scancode & 0x100)?(mvke):(keypad))
@@ -485,9 +499,19 @@
 	keysym->scancode = (unsigned char) scancode;
 	keysym->mod = KMOD_NONE;
 	keysym->unicode = 0;
+	
+	if ((vkey == VK_RETURN) && (scancode & 0x100)) {
+		/* No VK_ code for the keypad enter key */
+		keysym->sym = SDLK_KP_ENTER;
+	}
+	else {
+		keysym->sym = VK_keymap[SDL_MapVirtualKey(scancode, vkey)];
+	}
+
 	if ( pressed && SDL_TranslateUNICODE ) {
 #ifdef NO_GETKEYBOARDSTATE
 		/* Uh oh, better hope the vkey is close enough.. */
+		if((keysym->sym == vkey) || (vkey > 0x7f))
 		keysym->unicode = vkey;
 #else
 		BYTE	keystate[256];
@@ -501,14 +525,6 @@
 #endif /* NO_GETKEYBOARDSTATE */
 	}
 
-	if ((vkey == VK_RETURN) && (scancode & 0x100)) {
-		/* No VK_ code for the keypad enter key */
-		keysym->sym = SDLK_KP_ENTER;
-	}
-	else {
-		keysym->sym = VK_keymap[SDL_MapVirtualKey(scancode, vkey)];
-	}
-
 #if 0
 	{
 		HKL     hLayoutCurrent = GetKeyboardLayout(0);