BsRenderWindowManager.h 4.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143
  1. //********************************** Banshee Engine (www.banshee3d.com) **************************************************//
  2. //**************** Copyright (c) 2016 Marko Pintera ([email protected]). All rights reserved. **********************//
  3. #pragma once
  4. #include "BsCorePrerequisites.h"
  5. #include "Utility/BsModule.h"
  6. #include "RenderAPI/BsRenderWindow.h"
  7. #include "Utility/BsEvent.h"
  8. namespace bs
  9. {
  10. /** @addtogroup RenderAPI-Internal
  11. * @{
  12. */
  13. /** Handles creation and internal updates relating to render windows. */
  14. class BS_CORE_EXPORT RenderWindowManager : public Module<RenderWindowManager>
  15. {
  16. /** Holds information about a window that was moved or resized. */
  17. struct MoveOrResizeData
  18. {
  19. INT32 x, y;
  20. UINT32 width, height;
  21. RenderWindow* window;
  22. };
  23. public:
  24. RenderWindowManager();
  25. ~RenderWindowManager();
  26. /**
  27. * Creates a new render window using the specified options. Optionally makes the created window a child of another
  28. * window.
  29. */
  30. SPtr<RenderWindow> create(RENDER_WINDOW_DESC& desc, SPtr<RenderWindow> parentWindow);
  31. /** Called once per frame. Dispatches events. */
  32. void _update();
  33. /** Called by the core thread when window is destroyed. */
  34. void notifyWindowDestroyed(RenderWindow* window);
  35. /** Called by the core thread when window receives focus. */
  36. void notifyFocusReceived(ct::RenderWindow* window);
  37. /** Called by the core thread when window loses focus. */
  38. void notifyFocusLost(ct::RenderWindow* window);
  39. /** Called by the core thread when window is moved or resized. */
  40. void notifyMovedOrResized(ct::RenderWindow* window);
  41. /** Called by the core thread when mouse leaves a window. */
  42. void notifyMouseLeft(ct::RenderWindow* window);
  43. /** Called by the core thread when the user requests for the window to close. */
  44. void notifyCloseRequested(ct::RenderWindow* coreWindow);
  45. /** Called by the sim thread when window properties change. */
  46. void notifySyncDataDirty(ct::RenderWindow* coreWindow);
  47. /** Returns a list of all open render windows. */
  48. Vector<RenderWindow*> getRenderWindows() const;
  49. /** Returns the window that is currently the top-most modal window. Returns null if no modal windows are active. */
  50. RenderWindow* getTopMostModal() const;
  51. /** Event that is triggered when a window gains focus. */
  52. Event<void(RenderWindow&)> onFocusGained;
  53. /** Event that is triggered when a window loses focus. */
  54. Event<void(RenderWindow&)> onFocusLost;
  55. /** Event that is triggered when mouse leaves a window. */
  56. Event<void(RenderWindow&)> onMouseLeftWindow;
  57. protected:
  58. friend class RenderWindow;
  59. /** Finds a sim thread equivalent of the provided core thread window implementation. */
  60. RenderWindow* getNonCore(const ct::RenderWindow* window) const;
  61. /** @copydoc create */
  62. virtual SPtr<RenderWindow> createImpl(RENDER_WINDOW_DESC& desc, UINT32 windowId, const SPtr<RenderWindow>& parentWindow) = 0;
  63. protected:
  64. mutable Mutex mWindowMutex;
  65. Map<UINT32, RenderWindow*> mWindows;
  66. Vector<RenderWindow*> mModalWindowStack;
  67. RenderWindow* mWindowInFocus;
  68. RenderWindow* mNewWindowInFocus;
  69. Vector<MoveOrResizeData> mMovedOrResizedWindows;
  70. Vector<RenderWindow*> mMouseLeftWindows;
  71. Vector<RenderWindow*> mCloseRequestedWindows;
  72. UnorderedSet<RenderWindow*> mDirtyProperties;
  73. };
  74. namespace ct
  75. {
  76. /**
  77. * Handles creation and internal updates relating to render windows.
  78. *
  79. * @note Core thread only.
  80. */
  81. class BS_CORE_EXPORT RenderWindowManager : public Module<RenderWindowManager>
  82. {
  83. public:
  84. RenderWindowManager();
  85. /** Creates a new render window using the specified options. */
  86. SPtr<RenderWindow> create(RENDER_WINDOW_DESC& desc);
  87. /** Called once per frame. Dispatches events. */
  88. void _update();
  89. /** Called by the core thread when window properties change. */
  90. void notifySyncDataDirty(RenderWindow* window);
  91. /** Returns a list of all open render windows. */
  92. Vector<RenderWindow*> getRenderWindows() const;
  93. protected:
  94. friend class RenderWindow;
  95. friend class bs::RenderWindow;
  96. friend class bs::RenderWindowManager;
  97. /** @copydoc create */
  98. virtual SPtr<RenderWindow> createInternal(RENDER_WINDOW_DESC& desc, UINT32 windowId) = 0;
  99. /** Called whenever a window is created. */
  100. void windowCreated(RenderWindow* window);
  101. /** Called by the core thread when window is destroyed. */
  102. void windowDestroyed(RenderWindow* window);
  103. mutable Mutex mWindowMutex;
  104. Vector<RenderWindow*> mCreatedWindows;
  105. UnorderedSet<RenderWindow*> mDirtyProperties;
  106. std::atomic_uint mNextWindowId;
  107. };
  108. }
  109. /** @} */
  110. }