BsRenderWindowManager.h 4.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139
  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. /** Event that is triggered when a window gains focus. */
  50. Event<void(RenderWindow&)> onFocusGained;
  51. /** Event that is triggered when a window loses focus. */
  52. Event<void(RenderWindow&)> onFocusLost;
  53. /** Event that is triggered when mouse leaves a window. */
  54. Event<void(RenderWindow&)> onMouseLeftWindow;
  55. protected:
  56. friend class RenderWindow;
  57. /** Finds a sim thread equivalent of the provided core thread window implementation. */
  58. RenderWindow* getNonCore(const ct::RenderWindow* window) const;
  59. /** @copydoc create */
  60. virtual SPtr<RenderWindow> createImpl(RENDER_WINDOW_DESC& desc, UINT32 windowId, const SPtr<RenderWindow>& parentWindow) = 0;
  61. protected:
  62. mutable Mutex mWindowMutex;
  63. Map<UINT32, RenderWindow*> mWindows;
  64. RenderWindow* mWindowInFocus;
  65. RenderWindow* mNewWindowInFocus;
  66. Vector<MoveOrResizeData> mMovedOrResizedWindows;
  67. Vector<RenderWindow*> mMouseLeftWindows;
  68. Vector<RenderWindow*> mCloseRequestedWindows;
  69. UnorderedSet<RenderWindow*> mDirtyProperties;
  70. };
  71. namespace ct
  72. {
  73. /**
  74. * Handles creation and internal updates relating to render windows.
  75. *
  76. * @note Core thread only.
  77. */
  78. class BS_CORE_EXPORT RenderWindowManager : public Module<RenderWindowManager>
  79. {
  80. public:
  81. RenderWindowManager();
  82. /** Creates a new render window using the specified options. */
  83. SPtr<RenderWindow> create(RENDER_WINDOW_DESC& desc);
  84. /** Called once per frame. Dispatches events. */
  85. void _update();
  86. /** Called by the core thread when window properties change. */
  87. void notifySyncDataDirty(RenderWindow* window);
  88. /** Returns a list of all open render windows. */
  89. Vector<RenderWindow*> getRenderWindows() const;
  90. protected:
  91. friend class RenderWindow;
  92. friend class bs::RenderWindow;
  93. friend class bs::RenderWindowManager;
  94. /** @copydoc create */
  95. virtual SPtr<RenderWindow> createInternal(RENDER_WINDOW_DESC& desc, UINT32 windowId) = 0;
  96. /** Called whenever a window is created. */
  97. void windowCreated(RenderWindow* window);
  98. /** Called by the core thread when window is destroyed. */
  99. void windowDestroyed(RenderWindow* window);
  100. mutable Mutex mWindowMutex;
  101. Vector<RenderWindow*> mCreatedWindows;
  102. UnorderedSet<RenderWindow*> mDirtyProperties;
  103. std::atomic_uint mNextWindowId;
  104. };
  105. }
  106. /** @} */
  107. }