BsRenderWindowManager.h 4.2 KB

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