Преглед изворни кода

Added winxp/vista fallback for multitouch functions

* the "GetTouchInputInfo" function in "user32.lib" is only available on windows 7 or greater, see: http://msdn.microsoft.com/en-us/library/windows/desktop/dd371582(v=vs.85).aspx

* polycode will still build on winxp, but any code that uses it fails at runtime with the error: "The procedure entry point GetTouchInputInfo could not be located in the dynamic link library user32.lib"

* using a preprocessor directive wouldn't be helpful here, as that would require always building two release of polycode and any games that use it (one with multitouch support and one without)

* instead, we can check for the existence of any multitouch functions at runtime and fall back to null behavior if they are not available, as described here: http://msdn.microsoft.com/en-us/library/ms683212(v=vs.85).aspx

* removed WINDOWS_TOUCH_SUPPORT preprocessor directive

* added initTouch() for determining multitouch support at runtime

* added check to handleTouchEvent() to return immediately if multitouch is not supported (this may be not be needed, as multitouch events probably won't fire on a system that doesn't support it, right?)
Danny Warren пре 13 година
родитељ
комит
40fb920e56

+ 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();