BsRenderWindowManager.h 4.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134
  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 "BsModule.h"
  6. #include "BsRenderWindow.h"
  7. #include "BsEvent.h"
  8. namespace BansheeEngine
  9. {
  10. /** @cond INTERNAL */
  11. /** @addtogroup RenderAPI
  12. * @{
  13. */
  14. /** Handles creation and internal updates relating to render windows. */
  15. class BS_CORE_EXPORT RenderWindowManager : public Module<RenderWindowManager>
  16. {
  17. /** Holds information about a window that was moved or resized. */
  18. struct MoveOrResizeData
  19. {
  20. INT32 x, y;
  21. UINT32 width, height;
  22. RenderWindow* window;
  23. };
  24. public:
  25. RenderWindowManager();
  26. ~RenderWindowManager();
  27. /**
  28. * Creates a new render window using the specified options. Optionally makes the created window a child of another
  29. * window.
  30. */
  31. RenderWindowPtr create(RENDER_WINDOW_DESC& desc, RenderWindowPtr parentWindow);
  32. /** Called once per frame. Dispatches events. */
  33. void _update();
  34. /** Called by the core thread when window is destroyed. */
  35. void notifyWindowDestroyed(RenderWindow* window);
  36. /** Called by the core thread when window receives focus. */
  37. void notifyFocusReceived(RenderWindowCore* window);
  38. /** Called by the core thread when window loses focus. */
  39. void notifyFocusLost(RenderWindowCore* window);
  40. /** Called by the core thread when window is moved or resized. */
  41. void notifyMovedOrResized(RenderWindowCore* window);
  42. /** Called by the sim thread when window properties change. */
  43. void notifySyncDataDirty(RenderWindowCore* coreWindow);
  44. /** Returns a list of all open render windows. */
  45. Vector<RenderWindow*> getRenderWindows() const;
  46. /** Event that is triggered when a window gains focus. */
  47. Event<void(RenderWindow&)> onFocusGained;
  48. /** Event that is triggered when a window loses focus. */
  49. Event<void(RenderWindow&)> onFocusLost;
  50. /** Event that is triggered when mouse leaves a window. */
  51. Event<void(RenderWindow&)> onMouseLeftWindow;
  52. protected:
  53. friend class RenderWindow;
  54. /** Called by the core thread when mouse leaves a window. */
  55. void windowMouseLeft(RenderWindowCore* window);
  56. /** Finds a sim thread equivalent of the provided core thread window implementation. */
  57. RenderWindow* getNonCore(const RenderWindowCore* window) const;
  58. /** @copydoc create */
  59. virtual RenderWindowPtr createImpl(RENDER_WINDOW_DESC& desc, UINT32 windowId, const RenderWindowPtr& parentWindow) = 0;
  60. protected:
  61. BS_MUTEX(mWindowMutex);
  62. Map<UINT32, RenderWindow*> mWindows;
  63. RenderWindow* mWindowInFocus;
  64. RenderWindow* mNewWindowInFocus;
  65. Vector<MoveOrResizeData> mMovedOrResizedWindows;
  66. Vector<RenderWindow*> mMouseLeftWindows;
  67. UnorderedSet<RenderWindow*> mDirtyProperties;
  68. };
  69. /**
  70. * Handles creation and internal updates relating to render windows.
  71. *
  72. * @note Core thread only.
  73. */
  74. class BS_CORE_EXPORT RenderWindowCoreManager : public Module<RenderWindowCoreManager>
  75. {
  76. public:
  77. RenderWindowCoreManager();
  78. /** @copydoc RenderWindowCoreManager::create */
  79. SPtr<RenderWindowCore> create(RENDER_WINDOW_DESC& desc);
  80. /** Called once per frame. Dispatches events. */
  81. void _update();
  82. /** Called by the core thread when window properties change. */
  83. void notifySyncDataDirty(RenderWindowCore* window);
  84. /** Returns a list of all open render windows. */
  85. Vector<RenderWindowCore*> getRenderWindows() const;
  86. protected:
  87. friend class RenderWindowCore;
  88. friend class RenderWindow;
  89. friend class RenderWindowManager;
  90. /** @copydoc create */
  91. virtual SPtr<RenderWindowCore> createInternal(RENDER_WINDOW_DESC& desc, UINT32 windowId) = 0;
  92. /** Called whenever a window is created. */
  93. void windowCreated(RenderWindowCore* window);
  94. /** Called by the core thread when window is destroyed. */
  95. void windowDestroyed(RenderWindowCore* window);
  96. BS_MUTEX(mWindowMutex);
  97. Vector<RenderWindowCore*> mCreatedWindows;
  98. UnorderedSet<RenderWindowCore*> mDirtyProperties;
  99. std::atomic_uint mNextWindowId;
  100. };
  101. /** @} */
  102. /** @endcond */
  103. }