app.h 5.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116
  1. /**************************************************************************/
  2. /* app.h */
  3. /**************************************************************************/
  4. /* This file is part of: */
  5. /* GODOT ENGINE */
  6. /* https://godotengine.org */
  7. /**************************************************************************/
  8. /* Copyright (c) 2014-present Godot Engine contributors (see AUTHORS.md). */
  9. /* Copyright (c) 2007-2014 Juan Linietsky, Ariel Manzur. */
  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 OnWindowActivated(CoreWindow ^ sender, WindowActivatedEventArgs ^ args);
  62. void OnWindowClosed(Windows::UI::Core::CoreWindow^ sender, Windows::UI::Core::CoreWindowEventArgs^ args);
  63. void pointer_event(Windows::UI::Core::CoreWindow^ sender, Windows::UI::Core::PointerEventArgs^ args, bool p_pressed, bool p_is_wheel = false);
  64. void OnPointerPressed(Windows::UI::Core::CoreWindow^ sender, Windows::UI::Core::PointerEventArgs^ args);
  65. void OnPointerReleased(Windows::UI::Core::CoreWindow^ sender, Windows::UI::Core::PointerEventArgs^ args);
  66. void OnPointerMoved(Windows::UI::Core::CoreWindow^ sender, Windows::UI::Core::PointerEventArgs^ args);
  67. void OnMouseMoved(Windows::Devices::Input::MouseDevice^ mouse_device, Windows::Devices::Input::MouseEventArgs^ args);
  68. void OnPointerWheelChanged(Windows::UI::Core::CoreWindow^ sender, Windows::UI::Core::PointerEventArgs^ args);
  69. Windows::System::Threading::Core::SignalNotifier^ mouseChangedNotifier;
  70. Windows::Foundation::EventRegistrationToken mouseMovedToken;
  71. void OnMouseModeChanged(Windows::System::Threading::Core::SignalNotifier^ signalNotifier, bool timedOut);
  72. 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);
  73. void OnKeyDown(Windows::UI::Core::CoreWindow^ sender, Windows::UI::Core::KeyEventArgs^ args);
  74. void OnKeyUp(Windows::UI::Core::CoreWindow^ sender, Windows::UI::Core::KeyEventArgs^ args);
  75. void OnCharacterReceived(Windows::UI::Core::CoreWindow^ sender, Windows::UI::Core::CharacterReceivedEventArgs^ args);
  76. void UpdateWindowSize(Windows::Foundation::Size size);
  77. void InitializeEGL(Windows::UI::Core::CoreWindow^ window);
  78. void CleanupEGL();
  79. char** get_command_line(unsigned int* out_argc);
  80. bool mWindowClosed;
  81. bool mWindowVisible;
  82. GLsizei mWindowWidth;
  83. GLsizei mWindowHeight;
  84. EGLDisplay mEglDisplay;
  85. EGLContext mEglContext;
  86. EGLSurface mEglSurface;
  87. CoreWindow^ window;
  88. OS_UWP* os;
  89. int last_touch_x[32]; // 20 fingers, index 31 reserved for the mouse
  90. int last_touch_y[32];
  91. Windows::Foundation::Point last_mouse_pos;
  92. };
  93. }
  94. /* clang-format on */