BsRenderWindowManager.h 4.1 KB

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