BsRenderWindow.h 11 KB

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