BsRenderWindowManager.h 3.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163
  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. 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 core thread when window properties change.
  56. */
  57. void notifyPropertiesDirty(RenderWindowCore* window);
  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. * @brief Adds a new dirty property entry.
  86. */
  87. void setDirtyProperties(RenderWindowCore* coreWindow);
  88. /**
  89. * @copydoc create
  90. */
  91. virtual RenderWindowPtr createImpl(RENDER_WINDOW_DESC& desc, const RenderWindowPtr& parentWindow) = 0;
  92. protected:
  93. BS_MUTEX(mWindowMutex);
  94. Vector<RenderWindow*> mCreatedWindows;
  95. Map<const RenderWindowCore*, RenderWindow*> mCoreToNonCoreMap;
  96. RenderWindow* mWindowInFocus;
  97. RenderWindow* mNewWindowInFocus;
  98. Vector<RenderWindow*> mMovedOrResizedWindows;
  99. Vector<RenderWindow*> mMouseLeftWindows;
  100. Map<RenderWindow*, DirtyPropertyData> mDirtyProperties;
  101. };
  102. /**
  103. * @brief Handles creation and internal updates relating to render windows.
  104. *
  105. * @note Core thread only.
  106. */
  107. class BS_CORE_EXPORT RenderWindowCoreManager : public Module<RenderWindowCoreManager>
  108. {
  109. public:
  110. /**
  111. * @copydoc RenderWindowCoreManager::create
  112. */
  113. SPtr<RenderWindowCore> create(RENDER_WINDOW_DESC& desc);
  114. /**
  115. * @brief Returns a list of all open render windows.
  116. */
  117. Vector<RenderWindowCore*> getRenderWindows() const;
  118. protected:
  119. friend class RenderWindowCore;
  120. friend class RenderWindow;
  121. /**
  122. * @copydoc create
  123. */
  124. virtual SPtr<RenderWindowCore> createInternal(RENDER_WINDOW_DESC& desc) = 0;
  125. /**
  126. * @brief Called whenever a window is created.
  127. */
  128. void windowCreated(RenderWindowCore* window);
  129. /**
  130. * @brief Called by the core thread when window is destroyed.
  131. */
  132. void windowDestroyed(RenderWindowCore* window);
  133. BS_MUTEX(mWindowMutex);
  134. Vector<RenderWindowCore*> mCreatedWindows;
  135. };
  136. }