Sfoglia il codice sorgente

Merged Windows pen pull request

Ivan Safrin 10 anni fa
parent
commit
c4b0b0d0cc

+ 5 - 0
Core/Contents/Include/PolyCoreInput.h

@@ -171,6 +171,11 @@ namespace Polycode {
 		*/
 		bool simulateTouchWithMouse;
 
+		/**
+		* If set to true, simulated touches will have type TYPE_PEN.
+		*/
+		bool simulateTouchAsPen;
+
         /**
          * If set to true, will fire mouse events on touch input. Defaults to false.
          */

+ 20 - 4
Core/Contents/Include/PolyInputEvent.h

@@ -29,11 +29,27 @@ THE SOFTWARE.
 namespace Polycode {
 
 	class TouchInfo { 
-		public:			
+		public:
+			static const int TYPEBASE = 0x500;
+			static const int TYPE_TOUCH = TYPEBASE + 0;
+			static const int TYPE_PEN = TYPEBASE + 1;
+
+			TouchInfo();
+
 			int id;
 			Vector2 position;
+			int type;
 	};	
 
+	/*
+	class PointerInfo {
+	public:
+		int id;
+		Vector2 position;
+		int flag;
+	};
+	*/
+
 	/**
 	* Event dispatched by CoreInput. This event is dispatched by CoreInput when input happens.
 	*/
@@ -73,8 +89,7 @@ namespace Polycode {
 		static const int EVENT_TOUCHES_BEGAN = EVENTBASE_INPUTEVENT+20;
 		static const int EVENT_TOUCHES_MOVED = EVENTBASE_INPUTEVENT+21;
 		static const int EVENT_TOUCHES_ENDED = EVENTBASE_INPUTEVENT+22;
-		
-		
+
 		//@}
 		// ----------------------------------------------------------------------------------------------------------------
 		
@@ -110,7 +125,8 @@ namespace Polycode {
 		
 		std::vector<TouchInfo> touches;
 		TouchInfo touch;
-		
+		int touchType;
+
 		unsigned int joystickDeviceID;
 		float joystickAxisValue;
 		unsigned int joystickButton;

+ 8 - 0
Core/Contents/Include/PolyWinCore.h

@@ -95,8 +95,12 @@
 
 #define EXTENDED_KEYMASK	(1<<24)
 
+//#define NO_TOUCH_API
+//#define NO_PEN_API
+
 #ifdef _MINGW
 #define NO_TOUCH_API 1
+#define NO_PEN_API 1
 #endif
 
 #define POLYCODE_CORE Win32Core
@@ -116,6 +120,7 @@ namespace Polycode {
 		int mouseY;
 		TouchInfo touch;
 		std::vector<TouchInfo> touches;
+		int touchType;
 		PolyKEY keyCode;
 		wchar_t unicodeChar;		
 		char mouseButton;	
@@ -193,6 +198,7 @@ public:
 		void handleMouseDown(int mouseCode,LPARAM lParam, WPARAM wParam);
 		void handleMouseUp(int mouseCode,LPARAM lParam, WPARAM wParam);
 		void handleTouchEvent(LPARAM lParam, WPARAM wParam);
+		void handlePointerUpdate(LPARAM lParam, WPARAM wParam);
 
 		bool isMultiTouchEnabled() { return hasMultiTouch; }
 
@@ -285,6 +291,8 @@ public:
 
 		// Tracks whether the system supports multitouch at runtime
 		bool hasMultiTouch;
+
+		std::vector<TouchInfo> pointerTouches;
 		
 #ifndef NO_TOUCH_API
 		// Create generic reference to any multitouch functions we need, so that we

+ 17 - 8
Core/Contents/PolycodeView/MSVC/PolycodeView.cpp

@@ -97,16 +97,25 @@ LRESULT CALLBACK WndProc(HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam)
 			core->handleMouseUp(CoreInput::MOUSE_BUTTON2, lParam,wParam);
 	break;
 
-#ifndef NO_TOUCH_API
-	case WM_TOUCH:
-		if(core) {
-			if(core->isMultiTouchEnabled()) {
-				core->handleTouchEvent(lParam, wParam);
+#ifndef NO_TOUCH_API 
+	#ifdef NO_PEN_API
+		case WM_TOUCH:
+			if(core) {
+				if(core->isMultiTouchEnabled()) {
+					core->handleTouchEvent(lParam, wParam);
+				}
 			}
-		}
-	break;
+		break;
+	#else
+		case WM_POINTERUPDATE:
+		case WM_POINTERUP:
+		case WM_POINTERDOWN:
+			if (core)
+				core->handlePointerUpdate(lParam, wParam);
+		break;
+	#endif
 #endif
-
+	
 	case WM_MBUTTONDOWN:
 		if(core)
 			core->handleMouseDown(CoreInput::MOUSE_BUTTON3, lParam,wParam);

+ 15 - 1
Core/Contents/Source/PolyCoreInput.cpp

@@ -40,6 +40,7 @@ namespace Polycode {
 	CoreInput::CoreInput() : EventDispatcher() {
 		clearInput();
 		simulateTouchWithMouse = false;
+		simulateTouchAsPen = false;
 		simulateMouseWithTouch = false;
 		ignoreOffScreenTouch = false;
         keyRepeat = true;
@@ -174,7 +175,10 @@ namespace Polycode {
 		if(simulateTouchWithMouse) {
 			TouchInfo touch;
 			touch.position = mousePosition;
-			touch.id = 0;			
+			touch.id = 0;
+			if (simulateTouchAsPen){
+				touch.type = TouchInfo::TYPE_PEN;
+			}
 			std::vector<TouchInfo> touches;
 			touches.push_back(touch);
 			
@@ -206,7 +210,11 @@ namespace Polycode {
 			TouchInfo touch;
 			touch.position = mousePosition;
 			touch.id = 0;			
+			if (simulateTouchAsPen){
+				touch.type = TouchInfo::TYPE_PEN;
+			}
 			std::vector<TouchInfo> touches;
+
 			touches.push_back(touch);
 			if(mouseButtons[MOUSE_BUTTON1]) {
                 touchesMoved(touch, touches, ticks);
@@ -286,6 +294,12 @@ namespace Polycode {
 			setMousePosition(touch.position.x, touch.position.y, ticks);
 		}
 	}
+
+
+
+
+
+
 	
 	void CoreInput::touchesEnded(TouchInfo touch, std::vector<TouchInfo> touches, int ticks) {
 		if(ignoreOffScreenTouch) {

+ 3 - 0
Core/Contents/Source/PolyInputEvent.cpp

@@ -24,6 +24,9 @@
 
 namespace Polycode {
 
+TouchInfo::TouchInfo() : type(TYPE_TOUCH) {
+}
+
 InputEvent::InputEvent() : Event() {
 	eventType = "InputEvent";
 }

+ 112 - 37
Core/Contents/Source/PolyWinCore.cpp

@@ -40,6 +40,9 @@
 
 #include <tchar.h>
 
+#include <iostream>   // std::cout
+#include <string>     // std::string, std::to_string
+
 #if defined(_MINGW)
 #ifndef MAPVK_VSC_TO_VK_EX
 #define MAPVK_VSC_TO_VK_EX 3
@@ -648,38 +651,38 @@ void Win32Core::handleKeyUp(LPARAM lParam, WPARAM wParam) {
 
 #ifndef NO_TOUCH_API
 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);
-	HTOUCHINPUT hInput       = (HTOUCHINPUT)lParam;
-    TOUCHINPUT *pInputs      = new TOUCHINPUT[iNumContacts];
-       
-    if(pInputs != NULL) {
-		if(GetTouchInputInfoFunc(hInput, iNumContacts, pInputs, sizeof(TOUCHINPUT))) {
-
-			std::vector<TouchInfo> touches;
-			for(int i = 0; i < iNumContacts; i++) {
-				TOUCHINPUT ti = pInputs[i];
-				TouchInfo touchInfo;
-				touchInfo.id = (int) ti.dwID;
-
-				POINT pt;
-				pt.x = TOUCH_COORD_TO_PIXEL(ti.x);
-				pt.y = TOUCH_COORD_TO_PIXEL(ti.y);
-				ScreenToClient(hWnd, &pt);
-				touchInfo.position.x = pt.x; 
-				touchInfo.position.y = pt.y;
-
-				touches.push_back(touchInfo);
-			}
-              for(int i = 0; i < iNumContacts; i++) {
+		// Bail out now if multitouch is not available on this system
+		if (hasMultiTouch == false)
+		{
+			return;
+		}
+
+		lockMutex(eventMutex);
+
+		int iNumContacts = LOWORD(wParam);
+		HTOUCHINPUT hInput = (HTOUCHINPUT)lParam;
+		TOUCHINPUT *pInputs = new TOUCHINPUT[iNumContacts];
+
+		if (pInputs != NULL) {
+			if (GetTouchInputInfoFunc(hInput, iNumContacts, pInputs, sizeof(TOUCHINPUT))) {
+
+				std::vector<TouchInfo> touches;
+				for (int i = 0; i < iNumContacts; i++) {
+					TOUCHINPUT ti = pInputs[i];
+					TouchInfo touchInfo;
+					touchInfo.id = (int)ti.dwID;
+
+					POINT pt;
+					pt.x = TOUCH_COORD_TO_PIXEL(ti.x);
+					pt.y = TOUCH_COORD_TO_PIXEL(ti.y);
+					ScreenToClient(hWnd, &pt);
+					touchInfo.position.x = pt.x;
+					touchInfo.position.y = pt.y;
+
+					touches.push_back(touchInfo);
+				}
+				for (int i = 0; i < iNumContacts; i++) {
 					TOUCHINPUT ti = pInputs[i];
 					if (ti.dwFlags & TOUCHEVENTF_UP) {
 						Win32Event newEvent;
@@ -687,15 +690,17 @@ void Win32Core::handleTouchEvent(LPARAM lParam, WPARAM wParam) {
 						newEvent.eventCode = InputEvent::EVENT_TOUCHES_ENDED;
 						newEvent.touches = touches;
 						newEvent.touch = touches[i];
-						win32Events.push_back(newEvent);	
-					} else if(ti.dwFlags & TOUCHEVENTF_MOVE) {
+						win32Events.push_back(newEvent);
+					}
+					else if (ti.dwFlags & TOUCHEVENTF_MOVE) {
 						Win32Event newEvent;
 						newEvent.eventGroup = Win32Event::INPUT_EVENT;
 						newEvent.eventCode = InputEvent::EVENT_TOUCHES_MOVED;
 						newEvent.touches = touches;
 						newEvent.touch = touches[i];
 						win32Events.push_back(newEvent);
-					} else if(ti.dwFlags & TOUCHEVENTF_DOWN) {
+					}
+					else if (ti.dwFlags & TOUCHEVENTF_DOWN) {
 						Win32Event newEvent;
 						newEvent.eventGroup = Win32Event::INPUT_EVENT;
 						newEvent.eventCode = InputEvent::EVENT_TOUCHES_BEGAN;
@@ -703,10 +708,79 @@ void Win32Core::handleTouchEvent(LPARAM lParam, WPARAM wParam) {
 						newEvent.touch = touches[i];
 						win32Events.push_back(newEvent);
 					}
-			  }
+				}
+			}
+		}
+		unlockMutex(eventMutex);
+	}
+#endif
+
+#ifndef NO_PEN_API
+void Win32Core::handlePointerUpdate(LPARAM lParam, WPARAM wParam) {
+
+	lockMutex(eventMutex);
+
+	POINTER_PEN_INFO    penInfo;
+	POINTER_INFO        pointerInfo;
+	UINT32              pointerId = GET_POINTERID_WPARAM(wParam);
+	POINTER_INPUT_TYPE  pointerType = PT_POINTER;
+	TouchInfo			tempInfo;
+
+	if (!GetPointerType(pointerId, &pointerType))
+	{} // failure
+	else { // success
+
+		switch (pointerType){
+		case PT_TOUCH:
+		//case PT_MOUSE:
+		//case PT_TOUCHPAD:
+			GetPointerInfo(pointerId, &pointerInfo);
+			tempInfo.type = TouchInfo::TYPE_TOUCH;
+			break;
+		case PT_PEN:
+			!GetPointerPenInfo(pointerId, &penInfo);
+			pointerInfo = penInfo.pointerInfo;
+			tempInfo.type = TouchInfo::TYPE_PEN;
+			break;
 		}
+
+		tempInfo.id = GET_POINTERID_WPARAM(wParam);
+		tempInfo.position.x = pointerInfo.ptPixelLocation.x;
+		tempInfo.position.y = pointerInfo.ptPixelLocation.y;
+
+		Win32Event newEvent;
+		newEvent.eventGroup = Win32Event::INPUT_EVENT;
+
+		if (pointerInfo.pointerFlags & POINTER_FLAG_UPDATE){
+			newEvent.eventCode = InputEvent::EVENT_TOUCHES_MOVED;
+			for (int i = 0; i < pointerTouches.size(); i++) {
+				if (pointerTouches[i].id == tempInfo.id) {
+					pointerTouches[i].position = tempInfo.position;
+					break;
+				}
+			}
+		}
+		else if (pointerInfo.pointerFlags & POINTER_FLAG_DOWN){
+			newEvent.eventCode = InputEvent::EVENT_TOUCHES_BEGAN;
+			pointerTouches.push_back(tempInfo);
+		}
+		else if (pointerInfo.pointerFlags & POINTER_FLAG_UP){
+			newEvent.eventCode = InputEvent::EVENT_TOUCHES_ENDED;
+			for (int i = 0; i < pointerTouches.size(); i++) {
+				if (pointerTouches[i].id == tempInfo.id) {
+					pointerTouches.erase(pointerTouches.begin() + i);
+					break;
+				}
+			}
+		}
+		
+		newEvent.touches = pointerTouches;
+
+		newEvent.touch = tempInfo;
+		win32Events.push_back(newEvent);
 	}
-	unlockMutex(eventMutex);	
+
+	unlockMutex(eventMutex);
 }
 #endif
 
@@ -720,6 +794,7 @@ void Win32Core::handleMouseMove(LPARAM lParam, WPARAM wParam) {
 	win32Events.push_back(newEvent);
 	unlockMutex(eventMutex);
 }
+
 void Win32Core::handleMouseWheel(LPARAM lParam, WPARAM wParam) {
 	lockMutex(eventMutex);
 	Win32Event newEvent;
@@ -836,7 +911,7 @@ void Win32Core::checkEvents() {
 					break;
 					case InputEvent::EVENT_KEYUP:
 						input->setKeyState(event.keyCode, (char)event.unicodeChar, false, getTicks());
-					break;						
+					break;
 				}
 			break;
 		}