BsRenderWindow.h 11 KB

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