BsRenderWindow.h 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345
  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 ct::RenderWindow;
  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 ct::RenderWindow::minimize
  115. *
  116. * @note This is an @ref asyncMethod "asynchronous method".
  117. */
  118. void minimize();
  119. /**
  120. * @copydoc ct::RenderWindow::maximize
  121. *
  122. * @note This is an @ref asyncMethod "asynchronous method".
  123. */
  124. void maximize();
  125. /**
  126. * @copydoc ct::RenderWindow::restore
  127. *
  128. * @note This is an @ref asyncMethod "asynchronous method".
  129. */
  130. void restore();
  131. /**
  132. * @copydoc ct::RenderWindow::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 ct::RenderWindow::setFullscreen(const VideoMode&)
  139. *
  140. * @note This is an @ref asyncMethod "asynchronous method".
  141. */
  142. void setFullscreen(const VideoMode& videoMode);
  143. /**
  144. * @copydoc ct::RenderWindow::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<ct::RenderWindow> 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<ct::CoreObject> 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. namespace ct
  175. {
  176. /** @addtogroup RenderAPI-Internal
  177. * @{
  178. */
  179. /** Core thread counterpart of bs::RenderWindow. */
  180. class BS_CORE_EXPORT RenderWindow : public RenderTarget
  181. {
  182. public:
  183. RenderWindow(const RENDER_WINDOW_DESC& desc, UINT32 windowId);
  184. virtual ~RenderWindow();
  185. /**
  186. * Switches the window to fullscreen mode. Child windows cannot go into fullscreen mode.
  187. *
  188. * @param[in] width Width of the window frame buffer in pixels.
  189. * @param[in] height Height of the window frame buffer in pixels.
  190. * @param[in] refreshRate Refresh rate of the window in Hertz.
  191. * @param[in] monitorIdx Index of the monitor to go fullscreen on.
  192. *
  193. * @note If the exact provided mode isn't available, closest one is used instead.
  194. */
  195. virtual void setFullscreen(UINT32 width, UINT32 height, float refreshRate = 60.0f, UINT32 monitorIdx = 0) { }
  196. /**
  197. * Switches the window to fullscreen mode. Child windows cannot go into fullscreen mode.
  198. *
  199. * @param[in] videoMode Mode retrieved from VideoModeInfo in RenderAPI.
  200. */
  201. virtual void setFullscreen(const VideoMode& videoMode) { }
  202. /**
  203. * Switches the window to windowed mode.
  204. *
  205. * @param[in] width Window width in pixels.
  206. * @param[in] height Window height in pixels.
  207. */
  208. virtual void setWindowed(UINT32 width, UINT32 height) { }
  209. /** Hide or show the window. */
  210. virtual void setHidden(bool hidden);
  211. /**
  212. * Makes the render target active or inactive. (for example in the case of a window, it will hide or restore the
  213. * window).
  214. */
  215. virtual void setActive(bool state);
  216. /** Minimizes the window to the taskbar. */
  217. virtual void minimize() { }
  218. /** Maximizes the window over the entire current screen. */
  219. virtual void maximize() { }
  220. /** Restores the window to original position and size if it is minimized or maximized. */
  221. virtual void restore() { }
  222. /** Change the size of the window. */
  223. virtual void resize(UINT32 width, UINT32 height) = 0;
  224. /** Reposition the window. */
  225. virtual void move(INT32 left, INT32 top) = 0;
  226. /** Returns properties that describe the render window. */
  227. const RenderWindowProperties& getProperties() const;
  228. /**
  229. * Called when window is moved or resized.
  230. *
  231. * @note Core thread.
  232. */
  233. virtual void _windowMovedOrResized();
  234. /**
  235. * Called when window has received focus.
  236. *
  237. * @note Core thread.
  238. */
  239. virtual void _windowFocusReceived();
  240. /**
  241. * Called when window has lost focus.
  242. *
  243. * @note Core thread.
  244. */
  245. virtual void _windowFocusLost();
  246. /**
  247. * Called when window has been maximized.
  248. *
  249. * @note Core thread.
  250. */
  251. virtual void _notifyMaximized();
  252. /**
  253. * Called when window has been minimized.
  254. *
  255. * @note Core thread.
  256. */
  257. virtual void _notifyMinimized();
  258. /**
  259. * Called when window has been restored from minimized or maximized state.
  260. *
  261. * @note Core thread.
  262. */
  263. virtual void _notifyRestored();
  264. protected:
  265. friend class bs::RenderWindow;
  266. friend class bs::RenderWindowManager;
  267. friend class RenderWindowManager;
  268. /**
  269. * Returns window properties that are always kept in sync between core and sim threads.
  270. *
  271. * @note Used for keeping up what are the most up to date settings.
  272. */
  273. virtual RenderWindowProperties& getSyncedProperties() = 0;
  274. /** Updates window properties from the synced property data. */
  275. virtual void syncProperties() = 0;
  276. RENDER_WINDOW_DESC mDesc;
  277. SpinLock mLock;
  278. UINT32 mWindowId;
  279. };
  280. /** @} */
  281. }
  282. }