1 /*************************************************************************/ 2 /* app.h */ 3 /*************************************************************************/ 4 /* This file is part of: */ 5 /* GODOT ENGINE */ 6 /* https://godotengine.org */ 7 /*************************************************************************/ 8 /* Copyright (c) 2007-2020 Juan Linietsky, Ariel Manzur. */ 9 /* Copyright (c) 2014-2020 Godot Engine contributors (cf. AUTHORS.md). */ 10 /* */ 11 /* Permission is hereby granted, free of charge, to any person obtaining */ 12 /* a copy of this software and associated documentation files (the */ 13 /* "Software"), to deal in the Software without restriction, including */ 14 /* without limitation the rights to use, copy, modify, merge, publish, */ 15 /* distribute, sublicense, and/or sell copies of the Software, and to */ 16 /* permit persons to whom the Software is furnished to do so, subject to */ 17 /* the following conditions: */ 18 /* */ 19 /* The above copyright notice and this permission notice shall be */ 20 /* included in all copies or substantial portions of the Software. */ 21 /* */ 22 /* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, */ 23 /* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF */ 24 /* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.*/ 25 /* IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY */ 26 /* CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, */ 27 /* TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE */ 28 /* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */ 29 /*************************************************************************/ 30 31 #pragma once 32 33 #include <string> 34 35 #include <wrl.h> 36 37 // ANGLE doesn't provide a specific lib for GLES3, so we keep using GLES2 38 #include "GLES2/gl2.h" 39 #include "os_uwp.h" 40 41 /** clang-format does not play nice with this C++/CX hybrid, needs investigation. */ 42 /* clang-format off */ 43 44 namespace GodotUWP 45 { 46 ref class App sealed : public Windows::ApplicationModel::Core::IFrameworkView 47 { 48 public: 49 App(); 50 51 // IFrameworkView Methods. 52 virtual void Initialize(Windows::ApplicationModel::Core::CoreApplicationView^ applicationView); 53 virtual void SetWindow(Windows::UI::Core::CoreWindow^ window); 54 virtual void Load(Platform::String^ entryPoint); 55 virtual void Run(); 56 virtual void Uninitialize(); 57 58 property Windows::Foundation::EventRegistrationToken MouseMovedToken { get()59 Windows::Foundation::EventRegistrationToken get() { return this->mouseMovedToken; } set(Windows::Foundation::EventRegistrationToken p_token)60 void set(Windows::Foundation::EventRegistrationToken p_token) { this->mouseMovedToken = p_token; } 61 } 62 63 private: 64 void RecreateRenderer(); 65 66 // Application lifecycle event handlers. 67 void OnActivated(Windows::ApplicationModel::Core::CoreApplicationView^ applicationView, Windows::ApplicationModel::Activation::IActivatedEventArgs^ args); 68 69 // Window event handlers. 70 void OnWindowSizeChanged(Windows::UI::Core::CoreWindow^ sender, Windows::UI::Core::WindowSizeChangedEventArgs^ args); 71 void OnVisibilityChanged(Windows::UI::Core::CoreWindow^ sender, Windows::UI::Core::VisibilityChangedEventArgs^ args); 72 void OnWindowClosed(Windows::UI::Core::CoreWindow^ sender, Windows::UI::Core::CoreWindowEventArgs^ args); 73 74 void pointer_event(Windows::UI::Core::CoreWindow^ sender, Windows::UI::Core::PointerEventArgs^ args, bool p_pressed, bool p_is_wheel = false); 75 void OnPointerPressed(Windows::UI::Core::CoreWindow^ sender, Windows::UI::Core::PointerEventArgs^ args); 76 void OnPointerReleased(Windows::UI::Core::CoreWindow^ sender, Windows::UI::Core::PointerEventArgs^ args); 77 void OnPointerMoved(Windows::UI::Core::CoreWindow^ sender, Windows::UI::Core::PointerEventArgs^ args); 78 void OnMouseMoved(Windows::Devices::Input::MouseDevice^ mouse_device, Windows::Devices::Input::MouseEventArgs^ args); 79 void OnPointerWheelChanged(Windows::UI::Core::CoreWindow^ sender, Windows::UI::Core::PointerEventArgs^ args); 80 81 Windows::System::Threading::Core::SignalNotifier^ mouseChangedNotifier; 82 Windows::Foundation::EventRegistrationToken mouseMovedToken; 83 void OnMouseModeChanged(Windows::System::Threading::Core::SignalNotifier^ signalNotifier, bool timedOut); 84 85 void key_event(Windows::UI::Core::CoreWindow^ sender, bool p_pressed, Windows::UI::Core::KeyEventArgs^ key_args = nullptr, Windows::UI::Core::CharacterReceivedEventArgs^ char_args = nullptr); 86 void OnKeyDown(Windows::UI::Core::CoreWindow^ sender, Windows::UI::Core::KeyEventArgs^ args); 87 void OnKeyUp(Windows::UI::Core::CoreWindow^ sender, Windows::UI::Core::KeyEventArgs^ args); 88 void OnCharacterReceived(Windows::UI::Core::CoreWindow^ sender, Windows::UI::Core::CharacterReceivedEventArgs^ args); 89 90 void UpdateWindowSize(Windows::Foundation::Size size); 91 void InitializeEGL(Windows::UI::Core::CoreWindow^ window); 92 void CleanupEGL(); 93 94 char** get_command_line(unsigned int* out_argc); 95 96 bool mWindowClosed; 97 bool mWindowVisible; 98 GLsizei mWindowWidth; 99 GLsizei mWindowHeight; 100 101 EGLDisplay mEglDisplay; 102 EGLContext mEglContext; 103 EGLSurface mEglSurface; 104 105 CoreWindow^ window; 106 OS_UWP* os; 107 108 int last_touch_x[32]; // 20 fingers, index 31 reserved for the mouse 109 int last_touch_y[32]; 110 Windows::Foundation::Point last_mouse_pos; 111 }; 112 } 113 114 /* clang-format on */ 115