Răsfoiți Sursa

Merge pull request #112 from dannywarren/multitouch_winxp_compatibility

Added winxp/vista fallback for multitouch functions
Ivan Safrin 13 ani în urmă
părinte
comite
51e064da25

+ 0 - 2
Core/Contents/Include/PolyGlobals.h

@@ -24,8 +24,6 @@ THE SOFTWARE.
 
 // Polycode CORE LIBRARY CONFIGURATION SECTION
 
-#define WINDOWS_TOUCH_SUPPORT
-
 // Compile support for lua bindings.
 //#define _COMPILE_LUA
 

+ 12 - 5
Core/Contents/Include/PolyWinCore.h

@@ -179,10 +179,7 @@ public:
 		void handleMouseWheel(LPARAM lParam, WPARAM wParam);
 		void handleMouseDown(int mouseCode,LPARAM lParam, WPARAM wParam);
 		void handleMouseUp(int mouseCode,LPARAM lParam, WPARAM wParam);
-
-		#ifdef WINDOWS_TOUCH_SUPPORT
-			void handleTouchEvent(LPARAM lParam, WPARAM wParam);
-		#endif
+		void handleTouchEvent(LPARAM lParam, WPARAM wParam);
 
 		void setVideoMode(int xRes, int yRes, bool fullScreen, bool vSync, int aaLevel, int anisotropyLevel);
 		
@@ -213,6 +210,7 @@ public:
 		void shutdownGamepad();
 		void Gamepad_processEvents();
 
+		void initTouch();
 
 		// NEED TO IMPLEMENT:
 
@@ -255,6 +253,15 @@ public:
 		unsigned int PixelFormat;
 		PIXELFORMATDESCRIPTOR pfd;
 		
-
+		// Tracks whether the system supports multitouch at runtime
+		bool hasMultiTouch;
+		
+		// Create generic reference to any multitouch functions we need, so that we
+		// can make them available at runtime if the operating system supports it
+		// while still allowing fallback for older systems
+		// See: http://msdn.microsoft.com/en-us/library/ms683212(v=vs.85).aspx
+		typedef bool (WINAPI *GetTouchInputInfoType)(HTOUCHINPUT,UINT,PTOUCHINPUT,int);
+		GetTouchInputInfoType GetTouchInputInfoFunc;
+		
 	};
 }

+ 23 - 5
Core/Contents/Source/PolyWinCore.cpp

@@ -60,6 +60,7 @@ Win32Core::Win32Core(PolycodeViewBase *view, int xRes, int yRes, bool fullScreen
 
 	initKeymap();
 	initGamepad();
+	initTouch();
 
 	hDC = NULL;
 	hRC = NULL;
@@ -428,9 +429,14 @@ void Win32Core::handleKeyUp(LPARAM lParam, WPARAM wParam) {
 	unlockMutex(eventMutex);
 }
 
-#ifdef WINDOWS_TOUCH_SUPPORT
-
 void Win32Core::handleTouchEvent(LPARAM lParam, WPARAM wParam) {
+	
+	// Bail out now if multitouch is not available on this system
+	if ( hasMultiTouch == false )
+	{
+		return;
+	}
+	
 	lockMutex(eventMutex);
 
 	int iNumContacts = LOWORD(wParam);
@@ -438,7 +444,7 @@ void Win32Core::handleTouchEvent(LPARAM lParam, WPARAM wParam) {
     TOUCHINPUT *pInputs      = new TOUCHINPUT[iNumContacts];
        
     if(pInputs != NULL) {
-		if(GetTouchInputInfo(hInput, iNumContacts, pInputs, sizeof(TOUCHINPUT))) {
+		if(GetTouchInputInfoFunc(hInput, iNumContacts, pInputs, sizeof(TOUCHINPUT))) {
 
 			std::vector<TouchInfo> touches;
 			for(int i = 0; i < iNumContacts; i++) {
@@ -482,8 +488,6 @@ void Win32Core::handleTouchEvent(LPARAM lParam, WPARAM wParam) {
 	unlockMutex(eventMutex);	
 }
 
-#endif
-
 void Win32Core::handleMouseMove(LPARAM lParam, WPARAM wParam) {
 	lockMutex(eventMutex);
 	Win32Event newEvent;
@@ -801,6 +805,20 @@ void Win32Core::shutdownGamepad() {
 
 }
 
+void Win32Core::initTouch() {
+	
+	// Check for windows multitouch support at runtime
+	// This could be done easily during preprocessing but would require building
+	// multiple releases of polycode for both winxp/vista and win7
+	GetTouchInputInfoFunc = (GetTouchInputInfoType) GetProcAddress(GetModuleHandle(TEXT("user32.lib")), "GetTouchInputInfo");
+	
+	// If the above multitouch functions were found, then set a flag so we don't
+	// have to check again later
+	hasMultiTouch = ( GetTouchInputInfoFunc == NULL ) ? false : true;
+	
+}
+
+
 DWORD WINAPI Win32LaunchThread(LPVOID data) {
 	Threaded *threaded = (Threaded*)data;
 	threaded->runThread();