BsRenderWindow.h 10 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 "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. /** True if window is running in fullscreen mode. */
  50. bool isFullScreen = false;
  51. /** Horizontal origin of the window in pixels. */
  52. INT32 left = 0;
  53. /** Vertical origin of the window in pixels. */
  54. INT32 top = 0;
  55. /** Indicates whether the window currently has keyboard focus. */
  56. bool hasFocus = false;
  57. /** True if the window is hidden. */
  58. bool isHidden = false;
  59. /** True if the window is modal (blocks interaction with any non-modal window until closed). */
  60. bool isModal = false;
  61. /** True if the window is maximized. */
  62. bool isMaximized = false;
  63. };
  64. /**
  65. * Operating system window with a specific position, size and style. Each window serves as a surface that can be
  66. * rendered into by RenderAPI operations.
  67. */
  68. class BS_CORE_EXPORT RenderWindow : public RenderTarget
  69. {
  70. public:
  71. virtual ~RenderWindow() { }
  72. /** Converts screen position into window local position. */
  73. virtual Vector2I screenToWindowPos(const Vector2I& screenPos) const = 0;
  74. /** Converts window local position to screen position. */
  75. virtual Vector2I windowToScreenPos(const Vector2I& windowPos) const = 0;
  76. /**
  77. * Resize the window to specified width and height in pixels.
  78. *
  79. * @param[in] width Width of the window in pixels.
  80. * @param[in] height Height of the window in pixels.
  81. */
  82. void resize(UINT32 width, UINT32 height);
  83. /**
  84. * Move the window to specified screen coordinates.
  85. *
  86. * @param[in] left Position of the left border of the window on the screen.
  87. * @param[in] top Position of the top border of the window on the screen.
  88. *
  89. * @note This is an @ref asyncMethod "asynchronous method".
  90. */
  91. void move(INT32 left, INT32 top);
  92. /**
  93. * Hides the window.
  94. *
  95. * @note This is an @ref asyncMethod "asynchronous method".
  96. */
  97. void hide();
  98. /**
  99. * Shows a previously hidden window.
  100. *
  101. * @note This is an @ref asyncMethod "asynchronous method".
  102. */
  103. void show();
  104. /**
  105. * @copydoc ct::RenderWindow::minimize
  106. *
  107. * @note This is an @ref asyncMethod "asynchronous method".
  108. */
  109. void minimize();
  110. /**
  111. * @copydoc ct::RenderWindow::maximize
  112. *
  113. * @note This is an @ref asyncMethod "asynchronous method".
  114. */
  115. void maximize();
  116. /**
  117. * @copydoc ct::RenderWindow::restore
  118. *
  119. * @note This is an @ref asyncMethod "asynchronous method".
  120. */
  121. void restore();
  122. /**
  123. * @copydoc ct::RenderWindow::setFullscreen(UINT32, UINT32, float, UINT32)
  124. *
  125. * @note This is an @ref asyncMethod "asynchronous method".
  126. */
  127. void setFullscreen(UINT32 width, UINT32 height, float refreshRate = 60.0f, UINT32 monitorIdx = 0);
  128. /**
  129. * @copydoc ct::RenderWindow::setFullscreen(const VideoMode&)
  130. *
  131. * @note This is an @ref asyncMethod "asynchronous method".
  132. */
  133. void setFullscreen(const VideoMode& videoMode);
  134. /**
  135. * @copydoc ct::RenderWindow::setWindowed
  136. *
  137. * @note This is an @ref asyncMethod "asynchronous method".
  138. */
  139. void setWindowed(UINT32 width, UINT32 height);
  140. /** Retrieves a core implementation of a render window usable only from the core thread. */
  141. SPtr<ct::RenderWindow> getCore() const;
  142. /** Returns properties that describe the render window. */
  143. const RenderWindowProperties& getProperties() const;
  144. /** Closes and destroys the window. */
  145. void destroy() override;
  146. /**
  147. * Creates a new render window using the specified options. Optionally makes the created window a child of another
  148. * window.
  149. */
  150. static SPtr<RenderWindow> create(RENDER_WINDOW_DESC& desc, SPtr<RenderWindow> parentWindow = nullptr);
  151. protected:
  152. friend class RenderWindowManager;
  153. RenderWindow(const RENDER_WINDOW_DESC& desc, UINT32 windowId);
  154. /** Returns render window properties that may be edited. */
  155. RenderWindowProperties& getMutableProperties();
  156. /** @copydoc RenderTarget::createCore */
  157. SPtr<ct::CoreObject> createCore() const override;
  158. /** Updates window properties from the synced property data. */
  159. virtual void syncProperties() = 0;
  160. protected:
  161. RENDER_WINDOW_DESC mDesc;
  162. UINT32 mWindowId;
  163. };
  164. /** @} */
  165. namespace ct
  166. {
  167. /** @addtogroup RenderAPI-Internal
  168. * @{
  169. */
  170. /** Core thread counterpart of bs::RenderWindow. */
  171. class BS_CORE_EXPORT RenderWindow : public RenderTarget
  172. {
  173. public:
  174. RenderWindow(const RENDER_WINDOW_DESC& desc, UINT32 windowId);
  175. virtual ~RenderWindow();
  176. /**
  177. * Switches the window to fullscreen mode. Child windows cannot go into fullscreen mode.
  178. *
  179. * @param[in] width Width of the window frame buffer in pixels.
  180. * @param[in] height Height of the window frame buffer in pixels.
  181. * @param[in] refreshRate Refresh rate of the window in Hertz.
  182. * @param[in] monitorIdx Index of the monitor to go fullscreen on.
  183. *
  184. * @note If the exact provided mode isn't available, closest one is used instead.
  185. */
  186. virtual void setFullscreen(UINT32 width, UINT32 height, float refreshRate = 60.0f, UINT32 monitorIdx = 0) { }
  187. /**
  188. * Switches the window to fullscreen mode. Child windows cannot go into fullscreen mode.
  189. *
  190. * @param[in] videoMode Mode retrieved from VideoModeInfo in RenderAPI.
  191. */
  192. virtual void setFullscreen(const VideoMode& videoMode) { }
  193. /**
  194. * Switches the window to windowed mode.
  195. *
  196. * @param[in] width Window width in pixels.
  197. * @param[in] height Window height in pixels.
  198. */
  199. virtual void setWindowed(UINT32 width, UINT32 height) { }
  200. /** Hide or show the window. */
  201. virtual void setHidden(bool hidden);
  202. /**
  203. * Makes the render target active or inactive. (for example in the case of a window, it will hide or restore the
  204. * window).
  205. */
  206. virtual void setActive(bool state);
  207. /** Minimizes the window to the taskbar. */
  208. virtual void minimize() { }
  209. /** Maximizes the window over the entire current screen. */
  210. virtual void maximize() { }
  211. /** Restores the window to original position and size if it is minimized or maximized. */
  212. virtual void restore() { }
  213. /** Change the size of the window. */
  214. virtual void resize(UINT32 width, UINT32 height) = 0;
  215. /** Reposition the window. */
  216. virtual void move(INT32 left, INT32 top) = 0;
  217. /** Returns properties that describe the render window. */
  218. const RenderWindowProperties& getProperties() const;
  219. /**
  220. * Called when window is moved or resized.
  221. *
  222. * @note Core thread.
  223. */
  224. virtual void _windowMovedOrResized();
  225. /**
  226. * Called when window has received focus.
  227. *
  228. * @note Core thread.
  229. */
  230. virtual void _windowFocusReceived();
  231. /**
  232. * Called when window has lost focus.
  233. *
  234. * @note Core thread.
  235. */
  236. virtual void _windowFocusLost();
  237. /**
  238. * Called when window has been maximized.
  239. *
  240. * @note Core thread.
  241. */
  242. virtual void _notifyMaximized();
  243. /**
  244. * Called when window has been minimized.
  245. *
  246. * @note Core thread.
  247. */
  248. virtual void _notifyMinimized();
  249. /**
  250. * Called when window has been restored from minimized or maximized state.
  251. *
  252. * @note Core thread.
  253. */
  254. virtual void _notifyRestored();
  255. /**
  256. * Called when the mouse leaves the window.
  257. *
  258. * @note Core thread.
  259. */
  260. virtual void _notifyMouseLeft();
  261. protected:
  262. friend class bs::RenderWindow;
  263. friend class RenderWindowManager;
  264. friend class bs::RenderWindowManager;
  265. /**
  266. * Returns window properties that are always kept in sync between core and sim threads.
  267. *
  268. * @note Used for keeping up what are the most up to date settings.
  269. */
  270. virtual RenderWindowProperties& getSyncedProperties() = 0;
  271. /** Updates window properties from the synced property data. */
  272. virtual void syncProperties() = 0;
  273. RENDER_WINDOW_DESC mDesc;
  274. SpinLock mLock;
  275. UINT32 mWindowId;
  276. };
  277. /** @} */
  278. }
  279. }