BsRenderWindowManager.h 3.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141
  1. #pragma once
  2. #include "BsCorePrerequisites.h"
  3. #include "BsModule.h"
  4. #include "BsRenderWindow.h"
  5. #include "BsEvent.h"
  6. namespace BansheeEngine
  7. {
  8. /**
  9. * @brief Handles creation and internal updates relating to render windows.
  10. *
  11. * @note Sim thread only.
  12. */
  13. class BS_CORE_EXPORT RenderWindowManager : public Module<RenderWindowManager>
  14. {
  15. public:
  16. RenderWindowManager();
  17. /**
  18. * @brief Creates a new render window using the specified options. Optionally
  19. * makes the created window a child of another window.
  20. */
  21. RenderWindowPtr create(RENDER_WINDOW_DESC& desc, RenderWindowPtr parentWindow);
  22. /**
  23. * @brief Called once per frame. Dispatches events.
  24. *
  25. * @note Internal method.
  26. */
  27. void _update();
  28. /**
  29. * @brief Returns a list of all open render windows.
  30. */
  31. Vector<RenderWindow*> getRenderWindows() const;
  32. /**
  33. * @brief Event that is triggered when a window gains focus.
  34. */
  35. Event<void(RenderWindow&)> onFocusGained;
  36. /**
  37. * @brief Event that is triggered when a window loses focus.
  38. */
  39. Event<void(RenderWindow&)> onFocusLost;
  40. /**
  41. * @brief Event that is triggered when mouse leaves a window.
  42. */
  43. Event<void(RenderWindow&)> onMouseLeftWindow;
  44. protected:
  45. friend class RenderWindow;
  46. /**
  47. * @brief Called by the core thread when window is destroyed.
  48. */
  49. void windowDestroyed(RenderWindow* window);
  50. /**
  51. * @brief Called by the core thread when window receives focus.
  52. */
  53. void windowFocusReceived(RenderWindowCore* window);
  54. /**
  55. * @brief Called by the core thread when window loses focus.
  56. */
  57. void windowFocusLost(RenderWindowCore* window);
  58. /**
  59. * @brief Called by the core thread when mouse leaves a window.
  60. */
  61. void windowMouseLeft(RenderWindowCore* window);
  62. /**
  63. * @brief Called by the sim thread when window is moved or resized.
  64. */
  65. void windowMovedOrResized(RenderWindow* window);
  66. /**
  67. * @brief Finds a sim thread equivalent of the provided core thread window implementation.
  68. */
  69. RenderWindow* getNonCore(const RenderWindowCore* window) const;
  70. /**
  71. * @copydoc create
  72. */
  73. virtual RenderWindowPtr createImpl(RENDER_WINDOW_DESC& desc, const RenderWindowPtr& parentWindow) = 0;
  74. protected:
  75. BS_MUTEX(mWindowMutex);
  76. Vector<RenderWindow*> mCreatedWindows;
  77. Map<const RenderWindowCore*, RenderWindow*> mCoreToNonCoreMap;
  78. RenderWindow* mWindowInFocus;
  79. RenderWindow* mNewWindowInFocus;
  80. Vector<RenderWindow*> mMovedOrResizedWindows;
  81. Vector<RenderWindow*> mMouseLeftWindows;
  82. };
  83. /**
  84. * @brief Handles creation and internal updates relating to render windows.
  85. *
  86. * @note Core thread only.
  87. */
  88. class BS_CORE_EXPORT RenderWindowCoreManager : public Module<RenderWindowCoreManager>
  89. {
  90. public:
  91. /**
  92. * @copydoc RenderWindowCoreManager::create
  93. */
  94. SPtr<RenderWindowCore> create(RENDER_WINDOW_DESC& desc);
  95. /**
  96. * @brief Returns a list of all open render windows.
  97. */
  98. Vector<RenderWindowCore*> getRenderWindows() const;
  99. protected:
  100. friend class RenderWindowCore;
  101. friend class RenderWindow;
  102. /**
  103. * @copydoc create
  104. */
  105. virtual SPtr<RenderWindowCore> createInternal(RENDER_WINDOW_DESC& desc) = 0;
  106. /**
  107. * @brief Called whenever a window is created.
  108. */
  109. void windowCreated(RenderWindowCore* window);
  110. /**
  111. * @brief Called by the core thread when window is destroyed.
  112. */
  113. void windowDestroyed(RenderWindowCore* window);
  114. BS_MUTEX(mWindowMutex);
  115. Vector<RenderWindowCore*> mCreatedWindows;
  116. };
  117. }