app.h 5.6 KB

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