BsRenderWindow.h 11 KB

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