BsRenderWindow.h 12 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 "BsRenderTarget.h"
  6. #include "BsVideoModeInfo.h"
  7. #include "BsVector2I.h"
  8. namespace BansheeEngine
  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. * Render target specialization that allows you to render into window frame buffer(s).
  75. *
  76. * @note Sim thread only. Retrieve core implementation from getCore() for core thread only functionality.
  77. */
  78. class BS_CORE_EXPORT RenderWindow : public RenderTarget
  79. {
  80. public:
  81. virtual ~RenderWindow() { }
  82. /** @copydoc RenderTarget::destroy */
  83. virtual void destroy() override;
  84. /** Converts screen position into window local position. */
  85. virtual Vector2I screenToWindowPos(const Vector2I& screenPos) const = 0;
  86. /** Converts window local position to screen position. */
  87. virtual Vector2I windowToScreenPos(const Vector2I& windowPos) const = 0;
  88. /**
  89. * Resize the window to specified width and height in pixels.
  90. *
  91. * @param[in] accessor Accessor on which will this command be queued for execution.
  92. * @param[in] width Width of the window in pixels.
  93. * @param[in] height Height of the window in pixels.
  94. */
  95. void resize(CoreAccessor& accessor, UINT32 width, UINT32 height);
  96. /**
  97. * Move the window to specified screen coordinates.
  98. *
  99. * @param[in] accessor Accessor on which will this command be queued for execution.
  100. * @param[in] left Position of the left border of the window on the screen.
  101. * @param[in] top Position of the top border of the window on the screen.
  102. */
  103. void move(CoreAccessor& accessor, INT32 left, INT32 top);
  104. /**
  105. * Hide the window. (Does not destroy it, just hides it).
  106. *
  107. * @param[in] accessor Accessor on which will this command be queued for execution.
  108. */
  109. void hide(CoreAccessor& accessor);
  110. /**
  111. * Shows a previously hidden window.
  112. *
  113. * @param[in] accessor Accessor on which will this command be queued for execution.
  114. */
  115. void show(CoreAccessor& accessor);
  116. /**
  117. * @copydoc RenderWindowCore::minimize
  118. *
  119. * @param[in] accessor Accessor on which will this command be queued for execution.
  120. */
  121. void minimize(CoreAccessor& accessor);
  122. /**
  123. * @copydoc RenderWindowCore::maximize
  124. *
  125. * @param[in] accessor Accessor on which will this command be queued for execution.
  126. */
  127. void maximize(CoreAccessor& accessor);
  128. /**
  129. * @copydoc RenderWindowCore::restore
  130. *
  131. * @param[in] accessor Accessor on which will this command be queued for execution.
  132. */
  133. void restore(CoreAccessor& accessor);
  134. /**
  135. * @copydoc RenderWindowCore::setFullscreen(UINT32, UINT32, float, UINT32)
  136. *
  137. * @param[in] accessor Accessor on which will this command be queued for execution.
  138. */
  139. void setFullscreen(CoreAccessor& accessor, UINT32 width, UINT32 height, float refreshRate = 60.0f, UINT32 monitorIdx = 0);
  140. /**
  141. * @copydoc RenderWindowCore::setFullscreen(const VideoMode&)
  142. *
  143. * @param[in] accessor Accessor on which will this command be queued for execution.
  144. */
  145. void setFullscreen(CoreAccessor& accessor, const VideoMode& videoMode);
  146. /**
  147. * @copydoc RenderWindowCore::setWindowed
  148. *
  149. * @param[in] accessor Accessor on which will this command be queued for execution.
  150. */
  151. void setWindowed(CoreAccessor& accessor, UINT32 width, UINT32 height);
  152. /** Retrieves a core implementation of a render window usable only from the core thread. */
  153. SPtr<RenderWindowCore> getCore() const;
  154. /** Returns properties that describe the render window. */
  155. const RenderWindowProperties& getProperties() const;
  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<CoreObjectCore> 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. /** @addtogroup RenderAPI-Internal
  176. * @{
  177. */
  178. /**
  179. * Provides access to internal render window implementation usable only from the core thread.
  180. *
  181. * @note Core thread only.
  182. */
  183. class BS_CORE_EXPORT RenderWindowCore : public RenderTargetCore
  184. {
  185. public:
  186. RenderWindowCore(const RENDER_WINDOW_DESC& desc, UINT32 windowId);
  187. virtual ~RenderWindowCore();
  188. /**
  189. * Switches the window to fullscreen mode. Child windows cannot go into fullscreen mode.
  190. *
  191. * @param[in] width Width of the window frame buffer in pixels.
  192. * @param[in] height Height of the window frame buffer in pixels.
  193. * @param[in] refreshRate Refresh rate of the window in Hertz.
  194. * @param[in] monitorIdx Index of the monitor to go fullscreen on.
  195. *
  196. * @note If the exact provided mode isn't available, closest one is used instead.
  197. */
  198. virtual void setFullscreen(UINT32 width, UINT32 height, float refreshRate = 60.0f, UINT32 monitorIdx = 0) { }
  199. /**
  200. * Switches the window to fullscreen mode. Child windows cannot go into fullscreen mode.
  201. *
  202. * @param[in] videoMode Mode retrieved from VideoModeInfo in RenderAPI.
  203. */
  204. virtual void setFullscreen(const VideoMode& videoMode) { }
  205. /**
  206. * Switches the window to windowed mode.
  207. *
  208. * @param[in] width Window width in pixels.
  209. * @param[in] height Window height in pixels.
  210. */
  211. virtual void setWindowed(UINT32 width, UINT32 height) { }
  212. /** Hide or show the window. */
  213. virtual void setHidden(bool hidden);
  214. /**
  215. * Makes the render target active or inactive. (for example in the case of a window, it will hide or restore the
  216. * window).
  217. */
  218. virtual void setActive(bool state);
  219. /** Minimizes the window to the taskbar. */
  220. virtual void minimize() { }
  221. /** Maximizes the window over the entire current screen. */
  222. virtual void maximize() { }
  223. /** Restores the window to original position and size if it is minimized or maximized. */
  224. virtual void restore() { }
  225. /** Change the size of the window. */
  226. virtual void resize(UINT32 width, UINT32 height) = 0;
  227. /** Reposition the window. */
  228. virtual void move(INT32 left, INT32 top) = 0;
  229. /** Returns properties that describe the render window. */
  230. const RenderWindowProperties& getProperties() const;
  231. /**
  232. * Called when window is moved or resized.
  233. *
  234. * @note Core thread.
  235. */
  236. virtual void _windowMovedOrResized();
  237. /**
  238. * Called when window has received focus.
  239. *
  240. * @note Core thread.
  241. */
  242. virtual void _windowFocusReceived();
  243. /**
  244. * Called when window has lost focus.
  245. *
  246. * @note Core thread.
  247. */
  248. virtual void _windowFocusLost();
  249. /**
  250. * Called when window has been maximized.
  251. *
  252. * @note Core thread.
  253. */
  254. virtual void _notifyMaximized();
  255. /**
  256. * Called when window has been minimized.
  257. *
  258. * @note Core thread.
  259. */
  260. virtual void _notifyMinimized();
  261. /**
  262. * Called when window has been restored from minimized or maximized state.
  263. *
  264. * @note Core thread.
  265. */
  266. virtual void _notifyRestored();
  267. protected:
  268. friend class RenderWindow;
  269. friend class RenderWindowManager;
  270. friend class RenderWindowCoreManager;
  271. /**
  272. * Returns window properties that are always kept in sync between core and sim threads.
  273. *
  274. * @note Used for keeping up what are the most up to date settings.
  275. */
  276. virtual RenderWindowProperties& getSyncedProperties() = 0;
  277. /** Updates window properties from the synced property data. */
  278. virtual void syncProperties() = 0;
  279. RENDER_WINDOW_DESC mDesc;
  280. SpinLock mLock;
  281. UINT32 mWindowId;
  282. };
  283. /** @} */
  284. }