diff src/video/win32/SDL_win32events.c @ 4919:716b2cbf4c9e

First pass at Windows multi-touch gesture support
author Sam Lantinga <slouken@libsdl.org>
date Tue, 30 Nov 2010 17:58:51 -0800
parents 50d0bff24d81
children 0d1bb1ce9d15
line wrap: on
line diff
--- a/src/video/win32/SDL_win32events.c	Tue Nov 30 12:38:46 2010 -0800
+++ b/src/video/win32/SDL_win32events.c	Tue Nov 30 17:58:51 2010 -0800
@@ -27,6 +27,7 @@
 #include "SDL_syswm.h"
 #include "SDL_vkeys.h"
 #include "../../events/SDL_events_c.h"
+#include "../../events/SDL_touch_c.h"
 
 
 
@@ -55,12 +56,10 @@
 #ifndef WM_INPUT
 #define WM_INPUT 0x00ff
 #endif
-#ifndef WM_GESTURE
-#define WM_GESTURE 0x0119
-#endif
 #ifndef WM_TOUCH
 #define WM_TOUCH 0x0240
-#endif
+#endif
+
 
 static WPARAM
 RemapVKEY(WPARAM wParam, LPARAM lParam)
@@ -519,41 +518,70 @@
         }
         returnCode = 0;
         break;
+
 	case WM_TOUCH:
-		{
-			//printf("Got Touch Event!\n");
-    
-#ifdef WMMSG_DEBUG
-			FILE *log = fopen("wmmsg.txt", "a");
-			fprintf(log, "Received Touch Message: %p ", hwnd);
-			if (msg > MAX_WMMSG) {
-				fprintf(log, "%d", msg);
-			} else {
-				fprintf(log, "%s", wmtab[msg]);
-			}
-			fprintf(log, "WM_TOUCH = %d -- 0x%X, 0x%X\n",msg, wParam, lParam);
-			fclose(log);
-#endif
-    
+		{
+			UINT i, num_inputs = LOWORD(wParam);
+			PTOUCHINPUT inputs = SDL_stack_alloc(TOUCHINPUT, num_inputs);
+			if (data->videodata->GetTouchInputInfo((HTOUCHINPUT)lParam, num_inputs, inputs, sizeof(TOUCHINPUT))) {
+				RECT rect;
+				float x, y;
+
+				if (!GetClientRect(hwnd, &rect) ||
+				    (rect.right == rect.left && rect.bottom == rect.top)) {
+					break;
+				}
+				ClientToScreen(hwnd, (LPPOINT) & rect);
+				ClientToScreen(hwnd, (LPPOINT) & rect + 1);
+				rect.top *= 100;
+				rect.left *= 100;
+				rect.bottom *= 100;
+				rect.right *= 100;
+
+				for (i = 0; i < num_inputs; ++i) {
+					PTOUCHINPUT input = &inputs[i];
+
+					SDL_TouchID touchId = (SDL_TouchID)input->hSource;
+					if (!SDL_GetTouch(touchId)) {
+						SDL_Touch touch;
+
+						touch.id = touchId;
+						touch.x_min = 0;
+						touch.x_max = 1;
+						touch.native_xres = touch.x_max - touch.x_min;
+						touch.y_min = 0;
+						touch.y_max = 1;
+						touch.native_yres = touch.y_max - touch.y_min;
+						touch.pressure_min = 0;
+						touch.pressure_max = 1;
+						touch.native_pressureres = touch.pressure_max - touch.pressure_min;
+
+						if (SDL_AddTouch(&touch, "") < 0) {
+							continue;
+						}
+					}
+
+					// Get the normalized coordinates for the window
+					x = (float)(input->x - rect.left)/(rect.right - rect.left);
+					y = (float)(input->y - rect.top)/(rect.bottom - rect.top);
+
+					if (input->dwFlags & TOUCHEVENTF_DOWN) {
+						SDL_SendFingerDown(touchId, input->dwID, SDL_TRUE, x, y, 1);
+					}
+					if (input->dwFlags & TOUCHEVENTF_MOVE) {
+						SDL_SendTouchMotion(touchId, input->dwID, SDL_FALSE, x, y, 1);
+					}
+					if (input->dwFlags & TOUCHEVENTF_UP) {
+						SDL_SendFingerDown(touchId, input->dwID, SDL_FALSE, x, y, 1);
+					}
+				}
+			}
+			SDL_stack_free(inputs);
+
+			data->videodata->CloseTouchInputHandle((HTOUCHINPUT)lParam);
+			return 0;
 		}
 		break;
-	case WM_GESTURE:
-		{
-			//printf("Got Touch Event!\n");
-    
-#ifdef WMMSG_DEBUG
-			FILE *log = fopen("wmmsg.txt", "a");
-			fprintf(log, "Received Gesture Message: %p ", hwnd);
-			if (msg > MAX_WMMSG) {
-				fprintf(log, "%d", msg);
-			} else {
-				fprintf(log, "%s", wmtab[msg]);
-			}
-			fprintf(log, "WM_GESTURE = %d -- 0x%X, 0x%X\n",msg, wParam, lParam);
-			fclose(log);
-#endif
-		}
-		break;		
 	}
 
     /* If there's a window proc, assume it's going to handle messages */