1 #pragma once
2 
3 #include <set>
4 
5 #include "pch.h"
6 #include "Common/DeviceResources.h"
7 #include "PPSSPP_UWPMain.h"
8 
9 namespace UWP {
10 	struct Touch {
11 		bool inUse = false;
12 		unsigned uid;
13 	};
14 
15 	class TouchMapper {
16 	public:
TouchId(unsigned touch)17 		int TouchId(unsigned touch) {
18 			for (int touchIx = 0; touchIx < maxTouches; touchIx++)
19 				if (touches[touchIx].inUse && touches[touchIx].uid == touch)
20 					return touchIx;
21 			return -1;
22 		}
23 
AddNewTouch(unsigned touch)24 		int AddNewTouch(unsigned touch) {
25 			for (int touchIx = 0; touchIx < maxTouches; touchIx++) {
26 				if (!touches[touchIx].inUse) {
27 					touches[touchIx].inUse = true;
28 					touches[touchIx].uid = touch;
29 					return touchIx;
30 				}
31 			}
32 			return -1;
33 		}
34 
RemoveTouch(unsigned touch)35 		int RemoveTouch(unsigned touch) {
36 			for (int touchIx = 0; touchIx < maxTouches; touchIx++) {
37 				if (touches[touchIx].inUse && touches[touchIx].uid == touch) {
38 					touches[touchIx].inUse = false;
39 					return touchIx;
40 				}
41 			}
42 			return -1;
43 		}
44 
45 	private:
46 		enum { maxTouches = 11 };
47 		Touch touches[maxTouches]{};
48 	};
49 
50 	enum class HardwareButton {
51 		BACK,
52 	};
53 
54 	// Main entry point for our app. Connects the app with the Windows shell and handles application lifecycle events.
55 	ref class App sealed : public Windows::ApplicationModel::Core::IFrameworkView {
56 	public:
57 		App();
58 
59 		// IFrameworkView Methods.
60 		virtual void Initialize(Windows::ApplicationModel::Core::CoreApplicationView^ applicationView);
61 		virtual void SetWindow(Windows::UI::Core::CoreWindow^ window);
62 		virtual void Load(Platform::String^ entryPoint);
63 		virtual void Run();
64 		virtual void Uninitialize();
65 
66 		bool HasBackButton();
67 
68 	protected:
69 		// Application lifecycle event handlers.
70 		void OnActivated(Windows::ApplicationModel::Core::CoreApplicationView^ applicationView, Windows::ApplicationModel::Activation::IActivatedEventArgs^ args);
71 		void OnSuspending(Platform::Object^ sender, Windows::ApplicationModel::SuspendingEventArgs^ args);
72 		void OnResuming(Platform::Object^ sender, Platform::Object^ args);
73 
74 		// Window event handlers.
75 		void OnWindowSizeChanged(Windows::UI::Core::CoreWindow^ sender, Windows::UI::Core::WindowSizeChangedEventArgs^ args);
76 		void OnVisibilityChanged(Windows::UI::Core::CoreWindow^ sender, Windows::UI::Core::VisibilityChangedEventArgs^ args);
77 		void OnWindowClosed(Windows::UI::Core::CoreWindow^ sender, Windows::UI::Core::CoreWindowEventArgs^ args);
78 
79 		// DisplayInformation event handlers.
80 		void OnDpiChanged(Windows::Graphics::Display::DisplayInformation^ sender, Platform::Object^ args);
81 		void OnOrientationChanged(Windows::Graphics::Display::DisplayInformation^ sender, Platform::Object^ args);
82 		void OnDisplayContentsInvalidated(Windows::Graphics::Display::DisplayInformation^ sender, Platform::Object^ args);
83 
84 		// Input
85 		void OnKeyDown(Windows::UI::Core::CoreWindow^ sender, Windows::UI::Core::KeyEventArgs^ args);
86 		void OnKeyUp(Windows::UI::Core::CoreWindow^ sender, Windows::UI::Core::KeyEventArgs^ args);
87 
88 		void OnPointerMoved(Windows::UI::Core::CoreWindow^ sender, Windows::UI::Core::PointerEventArgs^ args);
89 		void OnPointerEntered(Windows::UI::Core::CoreWindow^ sender, Windows::UI::Core::PointerEventArgs^ args);
90 		void OnPointerExited(Windows::UI::Core::CoreWindow^ sender, Windows::UI::Core::PointerEventArgs^ args);
91 		void OnPointerPressed(Windows::UI::Core::CoreWindow^ sender, Windows::UI::Core::PointerEventArgs^ args);
92 		void OnPointerReleased(Windows::UI::Core::CoreWindow^ sender, Windows::UI::Core::PointerEventArgs^ args);
93 		void OnPointerCaptureLost(Windows::UI::Core::CoreWindow^ sender, Windows::UI::Core::PointerEventArgs^ args);
94 		void OnPointerWheelChanged(Windows::UI::Core::CoreWindow^ sender, Windows::UI::Core::PointerEventArgs^ args);
95 
96 		void App_BackRequested(Platform::Object^ sender, Windows::UI::Core::BackRequestedEventArgs^ e);
97 
98 	private:
99 		std::shared_ptr<DX::DeviceResources> m_deviceResources;
100 		std::set<HardwareButton> m_hardwareButtons;
101 		std::unique_ptr<PPSSPP_UWPMain> m_main;
102 		bool m_windowClosed;
103 		bool m_windowVisible;
104 
105 		bool m_isPhone = false;
106 		TouchMapper touchMap_;
107 	};
108 }
109 
110 ref class Direct3DApplicationSource sealed : Windows::ApplicationModel::Core::IFrameworkViewSource
111 {
112 public:
113 	virtual Windows::ApplicationModel::Core::IFrameworkView^ CreateView();
114 };
115