app.h 5.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115
  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. #pragma once
  31. #include <string>
  32. #include <wrl.h>
  33. // ANGLE doesn't provide a specific lib for GLES3, so we keep using GLES2
  34. #include "GLES2/gl2.h"
  35. #include "os_uwp.h"
  36. /** clang-format does not play nice with this C++/CX hybrid, needs investigation. */
  37. /* clang-format off */
  38. namespace GodotUWP
  39. {
  40. ref class App sealed : public Windows::ApplicationModel::Core::IFrameworkView
  41. {
  42. public:
  43. App();
  44. // IFrameworkView Methods.
  45. virtual void Initialize(Windows::ApplicationModel::Core::CoreApplicationView^ applicationView);
  46. virtual void SetWindow(Windows::UI::Core::CoreWindow^ window);
  47. virtual void Load(Platform::String^ entryPoint);
  48. virtual void Run();
  49. virtual void Uninitialize();
  50. property Windows::Foundation::EventRegistrationToken MouseMovedToken {
  51. Windows::Foundation::EventRegistrationToken get() { return this->mouseMovedToken; }
  52. void set(Windows::Foundation::EventRegistrationToken p_token) { this->mouseMovedToken = p_token; }
  53. }
  54. private:
  55. void RecreateRenderer();
  56. // Application lifecycle event handlers.
  57. void OnActivated(Windows::ApplicationModel::Core::CoreApplicationView^ applicationView, Windows::ApplicationModel::Activation::IActivatedEventArgs^ args);
  58. // Window event handlers.
  59. void OnWindowSizeChanged(Windows::UI::Core::CoreWindow^ sender, Windows::UI::Core::WindowSizeChangedEventArgs^ args);
  60. void OnVisibilityChanged(Windows::UI::Core::CoreWindow^ sender, Windows::UI::Core::VisibilityChangedEventArgs^ args);
  61. void OnWindowClosed(Windows::UI::Core::CoreWindow^ sender, Windows::UI::Core::CoreWindowEventArgs^ args);
  62. void pointer_event(Windows::UI::Core::CoreWindow^ sender, Windows::UI::Core::PointerEventArgs^ args, bool p_pressed, bool p_is_wheel = false);
  63. void OnPointerPressed(Windows::UI::Core::CoreWindow^ sender, Windows::UI::Core::PointerEventArgs^ args);
  64. void OnPointerReleased(Windows::UI::Core::CoreWindow^ sender, Windows::UI::Core::PointerEventArgs^ args);
  65. void OnPointerMoved(Windows::UI::Core::CoreWindow^ sender, Windows::UI::Core::PointerEventArgs^ args);
  66. void OnMouseMoved(Windows::Devices::Input::MouseDevice^ mouse_device, Windows::Devices::Input::MouseEventArgs^ args);
  67. void OnPointerWheelChanged(Windows::UI::Core::CoreWindow^ sender, Windows::UI::Core::PointerEventArgs^ args);
  68. Windows::System::Threading::Core::SignalNotifier^ mouseChangedNotifier;
  69. Windows::Foundation::EventRegistrationToken mouseMovedToken;
  70. void OnMouseModeChanged(Windows::System::Threading::Core::SignalNotifier^ signalNotifier, bool timedOut);
  71. 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);
  72. void OnKeyDown(Windows::UI::Core::CoreWindow^ sender, Windows::UI::Core::KeyEventArgs^ args);
  73. void OnKeyUp(Windows::UI::Core::CoreWindow^ sender, Windows::UI::Core::KeyEventArgs^ args);
  74. void OnCharacterReceived(Windows::UI::Core::CoreWindow^ sender, Windows::UI::Core::CharacterReceivedEventArgs^ args);
  75. void UpdateWindowSize(Windows::Foundation::Size size);
  76. void InitializeEGL(Windows::UI::Core::CoreWindow^ window);
  77. void CleanupEGL();
  78. char** get_command_line(unsigned int* out_argc);
  79. bool mWindowClosed;
  80. bool mWindowVisible;
  81. GLsizei mWindowWidth;
  82. GLsizei mWindowHeight;
  83. EGLDisplay mEglDisplay;
  84. EGLContext mEglContext;
  85. EGLSurface mEglSurface;
  86. CoreWindow^ window;
  87. OS_UWP* os;
  88. int last_touch_x[32]; // 20 fingers, index 31 reserved for the mouse
  89. int last_touch_y[32];
  90. Windows::Foundation::Point last_mouse_pos;
  91. };
  92. }
  93. /* clang-format on */