BsRenderWindow.h 10 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296
  1. #pragma once
  2. #include "BsCorePrerequisites.h"
  3. #include "BsRenderTarget.h"
  4. #include "BsVideoModeInfo.h"
  5. #include "BsVector2I.h"
  6. namespace BansheeEngine
  7. {
  8. /** @addtogroup RenderAPI
  9. * @{
  10. */
  11. /** Structure that is used for initializing a render window. */
  12. struct BS_CORE_EXPORT RENDER_WINDOW_DESC
  13. {
  14. RENDER_WINDOW_DESC()
  15. : vsync(false), vsyncInterval(1), fullscreen(false), hidden(false), depthBuffer(true)
  16. , multisampleCount(0), multisampleHint(""), gamma(false), left(-1), top(-1)
  17. , title(""), border(WindowBorder::Normal), outerDimensions(false), enableDoubleClick(true)
  18. , toolWindow(false), modal(false), hideUntilSwap(false)
  19. { }
  20. VideoMode videoMode; /**< A set of frame buffer options. */
  21. bool fullscreen; /**< Should the window be opened in fullscreen mode. */
  22. bool vsync; /**< Should the window wait for vertical sync before swapping buffers. */
  23. UINT32 vsyncInterval; /**< Determines how many vsync intervals occur per frame. FPS = refreshRate/interval. Usually 1 when vsync active. */
  24. bool hidden; /**< Should the window be hidden initially. */
  25. bool depthBuffer; /**< Should the window be created with a depth/stencil buffer. */
  26. UINT32 multisampleCount; /**< If higher than 1, texture containing multiple samples per pixel is created. */
  27. String multisampleHint; /**< Hint about what kind of multisampling to use. Render system specific. */
  28. bool gamma; /**< Should the written color pixels be gamma corrected before write. */
  29. INT32 left; /**< Window origin on X axis in pixels. -1 == screen center. Relative to monitor provided in videoMode. */
  30. INT32 top; /**< Window origin on Y axis in pixels. -1 == screen center. Relative to monitor provided in videoMode. */
  31. String title; /**< Title of the window. */
  32. WindowBorder border; /**< Type of border to create the window with. */
  33. bool outerDimensions; /**< Do our dimensions include space for things like title-bar and border. */
  34. bool enableDoubleClick; /**< Does window accept double-clicks. */
  35. bool toolWindow; /**< Tool windows have a different style than normal windows and can be created with no border or title bar. */
  36. bool modal; /**< When a modal window is open all other windows will be locked until modal window is closed. */
  37. bool hideUntilSwap; /** < Window will be created as hidden and only be shown when the first framebuffer swap happens. */
  38. NameValuePairList platformSpecific; /**< Platform-specific creation options. */
  39. };
  40. /** Contains various properties that describe a render window. */
  41. class BS_CORE_EXPORT RenderWindowProperties : public RenderTargetProperties
  42. {
  43. public:
  44. RenderWindowProperties(const RENDER_WINDOW_DESC& desc);
  45. virtual ~RenderWindowProperties() { }
  46. /** Gets the horizontal origin of the window in pixels. */
  47. INT32 getLeft() const { return mLeft; }
  48. /** Gets the vertical origin of the window in pixels. */
  49. INT32 getTop() const { return mTop; }
  50. /** Indicates whether the window currently has keyboard focus. */
  51. bool hasFocus() const { return mHasFocus; }
  52. /** Returns true if window is running in fullscreen mode. */
  53. bool isFullScreen() const { return mIsFullScreen; }
  54. /** Returns true if the window is modal (blocks interaction with any non-modal window until closed). */
  55. bool isModal() const { return mIsModal; }
  56. /** Returns true if the window is hidden. */
  57. bool isHidden() const { return mHidden; }
  58. /** Returns true if the window is maximized. */
  59. bool isMaximized() const { return mIsMaximized; }
  60. protected:
  61. friend class RenderWindowCore;
  62. friend class RenderWindow;
  63. bool mIsFullScreen = false;
  64. INT32 mLeft = 0;
  65. INT32 mTop = 0;
  66. bool mHasFocus = false;
  67. bool mHidden = false;
  68. bool mIsModal = false;
  69. bool mIsMaximized = false;
  70. };
  71. /** @cond INTERNAL */
  72. /**
  73. * Provides access to internal render window implementation usable only from the core thread.
  74. *
  75. * @note Core thread only.
  76. */
  77. class BS_CORE_EXPORT RenderWindowCore : public RenderTargetCore
  78. {
  79. public:
  80. RenderWindowCore(const RENDER_WINDOW_DESC& desc, UINT32 windowId);
  81. virtual ~RenderWindowCore();
  82. /**
  83. * Switches the window to fullscreen mode. Child windows cannot go into fullscreen mode.
  84. *
  85. * @param[in] width Width of the window frame buffer in pixels.
  86. * @param[in] height Height of the window frame buffer in pixels.
  87. * @param[in] refreshRate Refresh rate of the window in Hertz.
  88. * @param[in] monitorIdx Index of the monitor to go fullscreen on.
  89. *
  90. * @note If the exact provided mode isn't available, closest one is used instead.
  91. */
  92. virtual void setFullscreen(UINT32 width, UINT32 height, float refreshRate = 60.0f, UINT32 monitorIdx = 0) { }
  93. /**
  94. * Switches the window to fullscreen mode. Child windows cannot go into fullscreen mode.
  95. *
  96. * @param[in] videoMode Mode retrieved from VideoModeInfo in RenderAPI.
  97. */
  98. virtual void setFullscreen(const VideoMode& mode) { }
  99. /**
  100. * Switches the window to windowed mode.
  101. *
  102. * @param[in] Window width in pixels.
  103. * @param[in] Window height in pixels.
  104. */
  105. virtual void setWindowed(UINT32 width, UINT32 height) { }
  106. /** Hide or show the window. */
  107. virtual void setHidden(bool hidden);
  108. /** Makes the render target active or inactive. (e.g. for a window, it will hide or restore the window). */
  109. virtual void setActive(bool state);
  110. /** Minimizes the window to the taskbar. */
  111. virtual void minimize() { }
  112. /** Maximizes the window over the entire current screen. */
  113. virtual void maximize() { }
  114. /** Restores the window to original position and size if it is minimized or maximized. */
  115. virtual void restore() { }
  116. /** Change the size of the window. */
  117. virtual void resize(UINT32 width, UINT32 height) = 0;
  118. /** Reposition the window. */
  119. virtual void move(INT32 left, INT32 top) = 0;
  120. /** Returns properties that describe the render window. */
  121. const RenderWindowProperties& getProperties() const;
  122. /**
  123. * Called when window is moved or resized.
  124. *
  125. * @note Core thread.
  126. */
  127. virtual void _windowMovedOrResized();
  128. /**
  129. * Called when window has received focus.
  130. *
  131. * @note Core thread.
  132. */
  133. virtual void _windowFocusReceived();
  134. /**
  135. * Called when window has lost focus.
  136. *
  137. * @note Core thread.
  138. */
  139. virtual void _windowFocusLost();
  140. /**
  141. * Called when window has been maximized.
  142. *
  143. * @note Core thread.
  144. */
  145. virtual void _notifyMaximized();
  146. /**
  147. * Called when window has been minimized.
  148. *
  149. * @note Core thread.
  150. */
  151. virtual void _notifyMinimized();
  152. /**
  153. * Called when window has been restored from minimized or maximized state.
  154. *
  155. * @note Core thread.
  156. */
  157. virtual void _notifyRestored();
  158. protected:
  159. friend class RenderWindow;
  160. friend class RenderWindowManager;
  161. friend class RenderWindowCoreManager;
  162. /**
  163. * Returns window properties that are always kept in sync between core and sim threads.
  164. *
  165. * @note Used for keeping up what are the most up to date settings.
  166. */
  167. virtual RenderWindowProperties& getSyncedProperties() = 0;
  168. /** Updates window properties from the synced property data. */
  169. virtual void syncProperties() = 0;
  170. RENDER_WINDOW_DESC mDesc;
  171. SpinLock mLock;
  172. UINT32 mWindowId;
  173. };
  174. /** @endcond */
  175. /**
  176. * Render target specialization that allows you to render into window frame buffer(s).
  177. *
  178. * @note Sim thread only. Retrieve core implementation from getCore() for core thread only functionality.
  179. */
  180. class BS_CORE_EXPORT RenderWindow : public RenderTarget
  181. {
  182. public:
  183. virtual ~RenderWindow() { }
  184. /** @copydoc RenderTarget::destroy */
  185. virtual void destroy() override;
  186. /** Converts screen position into window local position. */
  187. virtual Vector2I screenToWindowPos(const Vector2I& screenPos) const = 0;
  188. /** Converts window local position to screen position. */
  189. virtual Vector2I windowToScreenPos(const Vector2I& windowPos) const = 0;
  190. /** Resize the window to specified width and height in pixels. */
  191. void resize(CoreAccessor& accessor, UINT32 width, UINT32 height);
  192. /** Move the window to specified screen coordinates. */
  193. void move(CoreAccessor& accessor, INT32 left, INT32 top);
  194. /** Hide the window. (Does not destroy it, just hides it). */
  195. void hide(CoreAccessor& accessor);
  196. /** Shows a previously hidden window. */
  197. void show(CoreAccessor& accessor);
  198. /** @copydoc RenderWindowCore::minimize */
  199. void minimize(CoreAccessor& accessor);
  200. /** @copydoc RenderWindowCore::maximize */
  201. void maximize(CoreAccessor& accessor);
  202. /** @copydoc RenderWindowCore::restore */
  203. void restore(CoreAccessor& accessor);
  204. /** @copydoc RenderWindowCore::setFullscreen(UINT32, UINT32, float, UINT32) */
  205. void setFullscreen(CoreAccessor& accessor, UINT32 width, UINT32 height, float refreshRate = 60.0f, UINT32 monitorIdx = 0);
  206. /** @copydoc RenderWindowCore::setFullscreen(const VideoMode&) */
  207. void setFullscreen(CoreAccessor& accessor, const VideoMode& mode);
  208. /** @copydoc RenderWindowCore::setWindowed */
  209. void setWindowed(CoreAccessor& accessor, UINT32 width, UINT32 height);
  210. /** Retrieves a core implementation of a render window usable only from the core thread. */
  211. SPtr<RenderWindowCore> getCore() const;
  212. /** Returns properties that describe the render window. */
  213. const RenderWindowProperties& getProperties() const;
  214. /**
  215. * Creates a new render window using the specified options. Optionally makes the created window a child of another
  216. * window.
  217. */
  218. static RenderWindowPtr create(RENDER_WINDOW_DESC& desc, RenderWindowPtr parentWindow = nullptr);
  219. protected:
  220. friend class RenderWindowManager;
  221. RenderWindow(const RENDER_WINDOW_DESC& desc, UINT32 windowId);
  222. /** Returns render window properties that may be edited. */
  223. RenderWindowProperties& getMutableProperties();
  224. /** @copydoc RenderTarget::createCore */
  225. SPtr<CoreObjectCore> createCore() const override;
  226. /** Updates window properties from the synced property data. */
  227. virtual void syncProperties() = 0;
  228. protected:
  229. RENDER_WINDOW_DESC mDesc;
  230. UINT32 mWindowId;
  231. };
  232. /** @} */
  233. }