BsRenderWindowManager.h 4.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174
  1. #pragma once
  2. #include "BsCorePrerequisites.h"
  3. #include "BsModule.h"
  4. #include "BsRenderWindow.h"
  5. #include "BsEvent.h"
  6. namespace BansheeEngine
  7. {
  8. /**
  9. * @brief Handles creation and internal updates relating to render windows.
  10. *
  11. * @note Internal class.
  12. */
  13. class BS_CORE_EXPORT RenderWindowManager : public Module<RenderWindowManager>
  14. {
  15. /**
  16. * @brief Holds information about a window that was moved or resized.
  17. */
  18. struct MoveOrResizeData
  19. {
  20. INT32 x, y;
  21. UINT32 width, height;
  22. RenderWindow* window;
  23. };
  24. public:
  25. RenderWindowManager();
  26. ~RenderWindowManager();
  27. /**
  28. * @brief Creates a new render window using the specified options. Optionally
  29. * makes the created window a child of another window.
  30. */
  31. RenderWindowPtr create(RENDER_WINDOW_DESC& desc, RenderWindowPtr parentWindow);
  32. /**
  33. * @brief Called once per frame. Dispatches events.
  34. *
  35. * @note Internal method.
  36. */
  37. void _update();
  38. /**
  39. * @brief Called by the core thread when window is destroyed.
  40. */
  41. void notifyWindowDestroyed(RenderWindow* window);
  42. /**
  43. * @brief Called by the core thread when window receives focus.
  44. */
  45. void notifyFocusReceived(RenderWindowCore* window);
  46. /**
  47. * @brief Called by the core thread when window loses focus.
  48. */
  49. void notifyFocusLost(RenderWindowCore* window);
  50. /**
  51. * @brief Called by the core thread when window is moved or resized.
  52. */
  53. void notifyMovedOrResized(RenderWindowCore* window);
  54. /**
  55. * @brief Called by the sim thread when window properties change.
  56. */
  57. void notifySyncDataDirty(RenderWindowCore* coreWindow);
  58. /**
  59. * @brief Returns a list of all open render windows.
  60. */
  61. Vector<RenderWindow*> getRenderWindows() const;
  62. /**
  63. * @brief Event that is triggered when a window gains focus.
  64. */
  65. Event<void(RenderWindow&)> onFocusGained;
  66. /**
  67. * @brief Event that is triggered when a window loses focus.
  68. */
  69. Event<void(RenderWindow&)> onFocusLost;
  70. /**
  71. * @brief Event that is triggered when mouse leaves a window.
  72. */
  73. Event<void(RenderWindow&)> onMouseLeftWindow;
  74. protected:
  75. friend class RenderWindow;
  76. /**
  77. * @brief Called by the core thread when mouse leaves a window.
  78. */
  79. void windowMouseLeft(RenderWindowCore* window);
  80. /**
  81. * @brief Finds a sim thread equivalent of the provided core thread window implementation.
  82. */
  83. RenderWindow* getNonCore(const RenderWindowCore* window) const;
  84. /**
  85. * @copydoc create
  86. */
  87. virtual RenderWindowPtr createImpl(RENDER_WINDOW_DESC& desc, UINT32 windowId, const RenderWindowPtr& parentWindow) = 0;
  88. protected:
  89. BS_MUTEX(mWindowMutex);
  90. Map<UINT32, RenderWindow*> mWindows;
  91. RenderWindow* mWindowInFocus;
  92. RenderWindow* mNewWindowInFocus;
  93. Vector<MoveOrResizeData> mMovedOrResizedWindows;
  94. Vector<RenderWindow*> mMouseLeftWindows;
  95. UnorderedSet<RenderWindow*> mDirtyProperties;
  96. };
  97. /**
  98. * @brief Handles creation and internal updates relating to render windows.
  99. *
  100. * @note Core thread only.
  101. */
  102. class BS_CORE_EXPORT RenderWindowCoreManager : public Module<RenderWindowCoreManager>
  103. {
  104. public:
  105. RenderWindowCoreManager();
  106. /**
  107. * @copydoc RenderWindowCoreManager::create
  108. */
  109. SPtr<RenderWindowCore> create(RENDER_WINDOW_DESC& desc);
  110. /**
  111. * @brief Called once per frame. Dispatches events.
  112. *
  113. * @note Internal method.
  114. */
  115. void _update();
  116. /**
  117. * @brief Called by the core thread when window properties change.
  118. */
  119. void notifySyncDataDirty(RenderWindowCore* window);
  120. /**
  121. * @brief Returns a list of all open render windows.
  122. */
  123. Vector<RenderWindowCore*> getRenderWindows() const;
  124. protected:
  125. friend class RenderWindowCore;
  126. friend class RenderWindow;
  127. friend class RenderWindowManager;
  128. /**
  129. * @copydoc create
  130. */
  131. virtual SPtr<RenderWindowCore> createInternal(RENDER_WINDOW_DESC& desc, UINT32 windowId) = 0;
  132. /**
  133. * @brief Called whenever a window is created.
  134. */
  135. void windowCreated(RenderWindowCore* window);
  136. /**
  137. * @brief Called by the core thread when window is destroyed.
  138. */
  139. void windowDestroyed(RenderWindowCore* window);
  140. BS_MUTEX(mWindowMutex);
  141. Vector<RenderWindowCore*> mCreatedWindows;
  142. UnorderedSet<RenderWindowCore*> mDirtyProperties;
  143. std::atomic_uint mNextWindowId;
  144. };
  145. }