BsRenderWindowManager.h 4.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129
  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. public:
  17. RenderWindowManager();
  18. ~RenderWindowManager();
  19. /**
  20. * Creates a new render window using the specified options. Optionally makes the created window a child of another
  21. * window.
  22. */
  23. SPtr<RenderWindow> create(RENDER_WINDOW_DESC& desc, SPtr<RenderWindow> parentWindow);
  24. /** Called once per frame. Dispatches events. */
  25. void _update();
  26. /** Called by the core thread when window is destroyed. */
  27. void notifyWindowDestroyed(RenderWindow* window);
  28. /** Called by the core thread when window receives focus. */
  29. void notifyFocusReceived(ct::RenderWindow* window);
  30. /** Called by the core thread when window loses focus. */
  31. void notifyFocusLost(ct::RenderWindow* window);
  32. /** Called by the core thread when window is moved or resized. */
  33. void notifyMovedOrResized(ct::RenderWindow* window);
  34. /** Called by the core thread when mouse leaves a window. */
  35. void notifyMouseLeft(ct::RenderWindow* window);
  36. /** Called by the core thread when the user requests for the window to close. */
  37. void notifyCloseRequested(ct::RenderWindow* coreWindow);
  38. /** Called by the sim thread when window properties change. */
  39. void notifySyncDataDirty(ct::RenderWindow* coreWindow);
  40. /** Returns a list of all open render windows. */
  41. Vector<RenderWindow*> getRenderWindows() const;
  42. /** Returns the window that is currently the top-most modal window. Returns null if no modal windows are active. */
  43. RenderWindow* getTopMostModal() const;
  44. /** Event that is triggered when a window gains focus. */
  45. Event<void(RenderWindow&)> onFocusGained;
  46. /** Event that is triggered when a window loses focus. */
  47. Event<void(RenderWindow&)> onFocusLost;
  48. /** Event that is triggered when mouse leaves a window. */
  49. Event<void(RenderWindow&)> onMouseLeftWindow;
  50. protected:
  51. friend class RenderWindow;
  52. /** Finds a sim thread equivalent of the provided core thread window implementation. */
  53. RenderWindow* getNonCore(const ct::RenderWindow* window) const;
  54. /** @copydoc create */
  55. virtual SPtr<RenderWindow> createImpl(RENDER_WINDOW_DESC& desc, UINT32 windowId, const SPtr<RenderWindow>& parentWindow) = 0;
  56. protected:
  57. mutable Mutex mWindowMutex;
  58. Map<UINT32, RenderWindow*> mWindows;
  59. Vector<RenderWindow*> mModalWindowStack;
  60. RenderWindow* mWindowInFocus;
  61. RenderWindow* mNewWindowInFocus;
  62. Vector<RenderWindow*> mMovedOrResizedWindows;
  63. Vector<RenderWindow*> mMouseLeftWindows;
  64. Vector<RenderWindow*> mCloseRequestedWindows;
  65. UnorderedSet<RenderWindow*> mDirtyProperties;
  66. };
  67. namespace ct
  68. {
  69. /**
  70. * Handles creation and internal updates relating to render windows.
  71. *
  72. * @note Core thread only.
  73. */
  74. class BS_CORE_EXPORT RenderWindowManager : public Module<RenderWindowManager>
  75. {
  76. public:
  77. RenderWindowManager();
  78. /** Called once per frame. Dispatches events. */
  79. void _update();
  80. /** Called by the core thread when window properties change. */
  81. void notifySyncDataDirty(RenderWindow* window);
  82. /** Returns a list of all open render windows. */
  83. Vector<RenderWindow*> getRenderWindows() const;
  84. protected:
  85. friend class RenderWindow;
  86. friend class bs::RenderWindow;
  87. friend class bs::RenderWindowManager;
  88. /** Called whenever a window is created. */
  89. void windowCreated(RenderWindow* window);
  90. /** Called by the core thread when window is destroyed. */
  91. void windowDestroyed(RenderWindow* window);
  92. mutable Mutex mWindowMutex;
  93. Vector<RenderWindow*> mCreatedWindows;
  94. UnorderedSet<RenderWindow*> mDirtyProperties;
  95. std::atomic_uint mNextWindowId;
  96. };
  97. }
  98. /** @} */
  99. }