瀏覽代碼

More UWP stuff

Ivan Safrin 10 年之前
父節點
當前提交
dae76cbc1e

+ 97 - 0
build/windows/universal/TemplateApp/App.cpp

@@ -9,6 +9,7 @@ using namespace Windows::ApplicationModel;
 using namespace Windows::ApplicationModel::Core;
 using namespace Windows::ApplicationModel::Activation;
 using namespace Windows::Foundation::Collections;
+using namespace Windows::System::Threading;
 using namespace Windows::UI::Core;
 using namespace Windows::UI::Input;
 using namespace Windows::System;
@@ -51,8 +52,91 @@ void App::Initialize(CoreApplicationView^ applicationView)
 
 	CoreApplication::Resuming +=
 		ref new Windows::Foundation::EventHandler<Platform::Object^>(this, &App::OnResuming);
+
+
+}
+
+
+void App::OnPointerPressed(CoreWindow^ sender, PointerEventArgs^ args)
+{
+
+	PointerPoint^ currentPoint = args->CurrentPoint;
+	Polycode::UWPEvent touchEvent;
+
+	if (currentPoint->PointerDevice->PointerDeviceType == Windows::Devices::Input::PointerDeviceType::Touch) {
+		touchEvent.eventCode = Polycode::InputEvent::EVENT_MOUSEDOWN;
+		touchEvent.mouseX = currentPoint->Position.X;
+		touchEvent.mouseY = currentPoint->Position.Y;
+
+		if (currentPoint->Properties->IsLeftButtonPressed) {
+			touchEvent.mouseButton = 0;
+		}
+		else if (currentPoint->Properties->IsMiddleButtonPressed) {
+			touchEvent.mouseButton = 1;
+		} else {
+			touchEvent.mouseButton = 2;
+		}
+	}
+	else {
+		touchEvent.eventCode = Polycode::InputEvent::EVENT_TOUCHES_BEGAN;
+		touchEvent.touch.position = Vector2(currentPoint->Position.X, currentPoint->Position.Y);
+		touchEvent.touch.id = currentPoint->PointerId;
+
+		if (currentPoint->PointerDevice->PointerDeviceType == Windows::Devices::Input::PointerDeviceType::Touch) {
+			touchEvent.touch.type = TouchInfo::TYPE_TOUCH;
+		}
+		else if (currentPoint->PointerDevice->PointerDeviceType == Windows::Devices::Input::PointerDeviceType::Pen) {
+			touchEvent.touch.type = TouchInfo::TYPE_PEN;
+		}
+	}
+}
+
+void App::OnPointerMoved(CoreWindow^ sender, PointerEventArgs^ args)
+{
+	// Get the intermediate points and process them in your gestureRecognizer
+	IVector<PointerPoint^>^ pointerPoints = PointerPoint::GetIntermediatePoints(args->CurrentPoint->PointerId);
+
 }
 
+void App::OnPointerReleased(CoreWindow^ sender, PointerEventArgs^ args)
+{
+	// Get the current point and process it in your gestureRecognizer
+	PointerPoint^ pointerPoint = args->CurrentPoint;
+	
+	PointerPoint^ currentPoint = args->CurrentPoint;
+	Polycode::UWPEvent touchEvent;
+
+	if (currentPoint->PointerDevice->PointerDeviceType == Windows::Devices::Input::PointerDeviceType::Touch) {
+		touchEvent.eventCode = Polycode::InputEvent::EVENT_MOUSEUP;
+		touchEvent.mouseX = currentPoint->Position.X;
+		touchEvent.mouseY = currentPoint->Position.Y;
+
+		if (currentPoint->Properties->IsLeftButtonPressed) {
+			touchEvent.mouseButton = 0;
+		}
+		else if (currentPoint->Properties->IsMiddleButtonPressed) {
+			touchEvent.mouseButton = 1;
+		}
+		else {
+			touchEvent.mouseButton = 2;
+		}
+	}
+	else {
+		touchEvent.eventCode = Polycode::InputEvent::EVENT_TOUCHES_ENDED;
+		touchEvent.touch.position = Vector2(currentPoint->Position.X, currentPoint->Position.Y);
+		touchEvent.touch.id = currentPoint->PointerId;
+
+		if (currentPoint->PointerDevice->PointerDeviceType == Windows::Devices::Input::PointerDeviceType::Touch) {
+			touchEvent.touch.type = TouchInfo::TYPE_TOUCH;
+		}
+		else if (currentPoint->PointerDevice->PointerDeviceType == Windows::Devices::Input::PointerDeviceType::Pen) {
+			touchEvent.touch.type = TouchInfo::TYPE_PEN;
+		}
+	}
+
+}
+
+
 // Called when the CoreWindow object is created (or re-created).
 void App::SetWindow(CoreWindow^ window)
 {
@@ -65,6 +149,19 @@ void App::SetWindow(CoreWindow^ window)
 	window->Closed += 
 		ref new TypedEventHandler<CoreWindow^, CoreWindowEventArgs^>(this, &App::OnWindowClosed);
 
+	window->PointerPressed +=
+		ref new TypedEventHandler<CoreWindow^, PointerEventArgs^>(this, &App::OnPointerPressed);
+
+	window->PointerMoved +=
+		ref new TypedEventHandler<CoreWindow^, PointerEventArgs^>(this, &App::OnPointerMoved);
+
+	window->PointerReleased +=
+		ref new TypedEventHandler<CoreWindow^, PointerEventArgs^>(this, &App::OnPointerReleased);
+
+
+
+
+
 	DisplayInformation^ currentDisplayInformation = DisplayInformation::GetForCurrentView();
 
 	currentDisplayInformation->DpiChanged +=

+ 6 - 0
build/windows/universal/TemplateApp/App.h

@@ -44,6 +44,11 @@ namespace TemplateApp
 		void OnOrientationChanged(Windows::Graphics::Display::DisplayInformation^ sender, Platform::Object^ args);
 		void OnDisplayContentsInvalidated(Windows::Graphics::Display::DisplayInformation^ sender, Platform::Object^ args);
 
+		void OnPointerPressed(Windows::UI::Core::CoreWindow^ sender, Windows::UI::Core::PointerEventArgs^ args);
+		void OnPointerMoved(Windows::UI::Core::CoreWindow^ sender, Windows::UI::Core::PointerEventArgs^ args);
+		void OnPointerReleased(Windows::UI::Core::CoreWindow^ sender, Windows::UI::Core::PointerEventArgs^ args);
+
+
 	private:
 		bool m_windowClosed;
 		bool m_windowVisible;
@@ -56,6 +61,7 @@ namespace TemplateApp
 
 		EGLint lastPanelWidth;
 		EGLint lastPanelHeight;
+
 	};
 }
 

+ 36 - 0
include/polycode/core/PolyUWPCore.h

@@ -24,6 +24,7 @@ THE SOFTWARE.
 
 #include "polycode/core/PolyGlobals.h"
 #include "polycode/core/PolyCore.h"
+#include "polycode/core/PolyInputEvent.h"
 #include <ppltasks.h>
 
 #include <Windows.Foundation.h>
@@ -57,6 +58,28 @@ namespace Polycode {
 		EGLSurface mEglSurface;
 	};
 
+	class UWPEvent {
+	public:
+		int eventGroup;
+		int eventCode;
+
+		int mouseX;
+		int mouseY;
+
+		std::vector<TouchInfo> touches;
+		TouchInfo touch;
+
+		PolyKEY keyCode;
+		wchar_t unicodeChar;
+
+		char mouseButton;
+
+		static const int EVENTBASE_PLATFORMEVENT = 0x300;
+		static const int INPUT_EVENT = EVENTBASE_PLATFORMEVENT + 0;
+		static const int SYSTEM_FOCUS_EVENT = EVENTBASE_PLATFORMEVENT + 1;
+	};
+
+
 	class UWPCoreMutex : public CoreMutex {
 	public:
 		void lock();
@@ -93,10 +116,23 @@ namespace Polycode {
 		String executeExternalCommand(String command, String args, String inDirectory);
 		bool systemParseFolder(const Polycode::String& pathString, bool showHidden, std::vector<OSFileEntry> &targetVector);
 
+		void handleSystemEvent(UWPEvent systemEvent);
+		void checkEvents();
+		void setDeviceSize(Number x, Number y);
 
+		Number getBackingXRes();
+		Number getBackingYRes();
 
 	private:
 
+		Number deviceWidth;
+		Number deviceHeight;
+
+		int lastMouseY;
+		int lastMouseX;
+
+		std::vector<UWPEvent> systemInputEvents;
+
 		double pcFreq;
 
 		OpenGLGraphicsInterface *graphicsInterface;

二進制
lib/windows/x64/Polycore.lib


二進制
lib/windows/x64/Polycored.lib


+ 94 - 0
src/core/PolyUWPCore.cpp

@@ -57,6 +57,8 @@ UWPCore::UWPCore(PolycodeView *view, int xRes, int yRes, bool fullScreen, bool v
 	QueryPerformanceFrequency(&li);
 	pcFreq = double(li.QuadPart) / 1000.0;
 
+	lastMouseY = 0;
+	lastMouseX = 0;
 
 	fileProviders.push_back(new BasicFileProvider());
 
@@ -70,6 +72,8 @@ UWPCore::UWPCore(PolycodeView *view, int xRes, int yRes, bool fullScreen, bool v
 	setVideoMode(xRes, yRes, fullScreen, vSync, aaLevel, anisotropyLevel, retinaSupport);
 
 	services->getSoundManager()->setAudioInterface(new XAudio2AudioInterface());
+
+	eventMutex = createMutex();
 }
 
 UWPCore::~UWPCore() {
@@ -82,12 +86,81 @@ void UWPCore::Render() {
 	renderer->endFrame();
 }
 
+
+void UWPCore::checkEvents() {
+
+	eventMutex->lock();
+
+	UWPEvent event;
+	for (int i = 0; i < systemInputEvents.size(); i++) {
+		event = systemInputEvents[i];
+		switch (event.eventGroup) {
+		case UWPEvent::INPUT_EVENT:
+			switch (event.eventCode) {
+			case InputEvent::EVENT_MOUSEMOVE:
+				input->setDeltaPosition(lastMouseX - event.mouseX, lastMouseY - event.mouseY);
+				lastMouseX = event.mouseX;
+				lastMouseY = event.mouseY;
+				input->setMousePosition(event.mouseX, event.mouseY, getTicks());
+				break;
+			case InputEvent::EVENT_MOUSEDOWN:
+				input->mousePosition.x = event.mouseX;
+				input->mousePosition.y = event.mouseY;
+				input->setMouseButtonState(event.mouseButton, true, getTicks());
+				break;
+			case InputEvent::EVENT_MOUSEWHEEL_UP:
+				input->mouseWheelUp(getTicks());
+				break;
+			case InputEvent::EVENT_MOUSEWHEEL_DOWN:
+				input->mouseWheelDown(getTicks());
+				break;
+			case InputEvent::EVENT_MOUSEUP:
+				input->setMouseButtonState(event.mouseButton, false, getTicks());
+				break;
+			case InputEvent::EVENT_KEYDOWN:
+				if (!checkSpecialKeyEvents(event.keyCode))
+					input->setKeyState(event.keyCode, event.unicodeChar, true, getTicks());
+				break;
+			case InputEvent::EVENT_KEYUP:
+				input->setKeyState(event.keyCode, event.unicodeChar, false, getTicks());
+				break;
+			case InputEvent::EVENT_TOUCHES_BEGAN:
+				input->touchesBegan(event.touch, event.touches, getTicks());
+				break;
+			case InputEvent::EVENT_TOUCHES_ENDED:
+				input->touchesEnded(event.touch, event.touches, getTicks());
+				break;
+			case InputEvent::EVENT_TOUCHES_MOVED:
+				input->touchesMoved(event.touch, event.touches, getTicks());
+				break;
+			}
+			break;
+		case UWPEvent::SYSTEM_FOCUS_EVENT:
+			switch (event.eventCode) {
+			case Core::EVENT_LOST_FOCUS:
+				loseFocus();
+				break;
+			case Core::EVENT_GAINED_FOCUS:
+				gainFocus();
+				break;
+			}
+			break;
+		}
+	}
+
+	systemInputEvents.clear();
+	eventMutex->unlock();
+
+}
+
 bool UWPCore::systemUpdate() {
 	if (!running) {
 		return false;
 	}
 	doSleep();
 	updateCore();
+
+	checkEvents();
 	return running;
 }
 
@@ -241,6 +314,27 @@ bool UWPCore::systemParseFolder(const Polycode::String& pathString, bool showHid
 	return true; 
 }
 
+void UWPCore::handleSystemEvent(UWPEvent systemEvent) {
+	eventMutex->lock();
+	systemInputEvents.push_back(systemEvent);
+	eventMutex->unlock();
+}
+
 void Core::getScreenInfo(int *width, int *height, int *hz) {
 
+}
+
+void UWPCore::setDeviceSize(Number x, Number y) {
+	deviceWidth = x;
+	deviceHeight = y;
+
+	renderer->setBackingResolutionScale(xRes/deviceWidth, yRes/deviceHeight);
+}
+
+Number UWPCore::getBackingXRes() {
+	return deviceWidth;
+}
+
+Number UWPCore::getBackingYRes() {
+	return deviceHeight;
 }

+ 2 - 2
src/core/PolyXAudio2AudioInterface.cpp

@@ -123,7 +123,7 @@ void XAudio2Stream::runThread() {
 		}
 		
 		fillThread->bufferMutex->lock();
-		if(fillThread->bufferQueue.size() > 1) {
+		if(fillThread->bufferQueue.size() > 0) {
 			XAUDIO2_BUFFER buf = { 0 };
 			buf.AudioBytes = POLY_FRAMES_PER_BUFFER*POLY_NUM_CHANNELS * 2;
 			lastBuffer = fillThread->bufferQueue.front();
@@ -132,7 +132,7 @@ void XAudio2Stream::runThread() {
 			buf.LoopCount = 0;
 			buf.LoopBegin = 0;
 			pSourceVoice->SubmitSourceBuffer(&buf);		
-			delete lastBuffer;
+		//	delete lastBuffer; // FIXME!!
 			fillThread->bufferQueue.pop();
 		}
 		fillThread->bufferMutex->unlock();