BsRenderWindow.h 10 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303
  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. : vsync(false), vsyncInterval(1), fullscreen(false), 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. /** Resize the window to specified width and height in pixels. */
  89. void resize(CoreAccessor& accessor, UINT32 width, UINT32 height);
  90. /** Move the window to specified screen coordinates. */
  91. void move(CoreAccessor& accessor, INT32 left, INT32 top);
  92. /** Hide the window. (Does not destroy it, just hides it). */
  93. void hide(CoreAccessor& accessor);
  94. /** Shows a previously hidden window. */
  95. void show(CoreAccessor& accessor);
  96. /** @copydoc RenderWindowCore::minimize */
  97. void minimize(CoreAccessor& accessor);
  98. /** @copydoc RenderWindowCore::maximize */
  99. void maximize(CoreAccessor& accessor);
  100. /** @copydoc RenderWindowCore::restore */
  101. void restore(CoreAccessor& accessor);
  102. /** @copydoc RenderWindowCore::setFullscreen(UINT32, UINT32, float, UINT32) */
  103. void setFullscreen(CoreAccessor& accessor, UINT32 width, UINT32 height, float refreshRate = 60.0f, UINT32 monitorIdx = 0);
  104. /** @copydoc RenderWindowCore::setFullscreen(const VideoMode&) */
  105. void setFullscreen(CoreAccessor& accessor, const VideoMode& mode);
  106. /** @copydoc RenderWindowCore::setWindowed */
  107. void setWindowed(CoreAccessor& accessor, UINT32 width, UINT32 height);
  108. /** Retrieves a core implementation of a render window usable only from the core thread. */
  109. SPtr<RenderWindowCore> getCore() const;
  110. /** Returns properties that describe the render window. */
  111. const RenderWindowProperties& getProperties() const;
  112. /**
  113. * Creates a new render window using the specified options. Optionally makes the created window a child of another
  114. * window.
  115. */
  116. static RenderWindowPtr create(RENDER_WINDOW_DESC& desc, RenderWindowPtr parentWindow = nullptr);
  117. protected:
  118. friend class RenderWindowManager;
  119. RenderWindow(const RENDER_WINDOW_DESC& desc, UINT32 windowId);
  120. /** Returns render window properties that may be edited. */
  121. RenderWindowProperties& getMutableProperties();
  122. /** @copydoc RenderTarget::createCore */
  123. SPtr<CoreObjectCore> createCore() const override;
  124. /** Updates window properties from the synced property data. */
  125. virtual void syncProperties() = 0;
  126. protected:
  127. RENDER_WINDOW_DESC mDesc;
  128. UINT32 mWindowId;
  129. };
  130. /** @} */
  131. /** @addtogroup RenderAPI-Internal
  132. * @{
  133. */
  134. /**
  135. * Provides access to internal render window implementation usable only from the core thread.
  136. *
  137. * @note Core thread only.
  138. */
  139. class BS_CORE_EXPORT RenderWindowCore : public RenderTargetCore
  140. {
  141. public:
  142. RenderWindowCore(const RENDER_WINDOW_DESC& desc, UINT32 windowId);
  143. virtual ~RenderWindowCore();
  144. /**
  145. * Switches the window to fullscreen mode. Child windows cannot go into fullscreen mode.
  146. *
  147. * @param[in] width Width of the window frame buffer in pixels.
  148. * @param[in] height Height of the window frame buffer in pixels.
  149. * @param[in] refreshRate Refresh rate of the window in Hertz.
  150. * @param[in] monitorIdx Index of the monitor to go fullscreen on.
  151. *
  152. * @note If the exact provided mode isn't available, closest one is used instead.
  153. */
  154. virtual void setFullscreen(UINT32 width, UINT32 height, float refreshRate = 60.0f, UINT32 monitorIdx = 0) { }
  155. /**
  156. * Switches the window to fullscreen mode. Child windows cannot go into fullscreen mode.
  157. *
  158. * @param[in] videoMode Mode retrieved from VideoModeInfo in RenderAPI.
  159. */
  160. virtual void setFullscreen(const VideoMode& mode) { }
  161. /**
  162. * Switches the window to windowed mode.
  163. *
  164. * @param[in] Window width in pixels.
  165. * @param[in] Window height in pixels.
  166. */
  167. virtual void setWindowed(UINT32 width, UINT32 height) { }
  168. /** Hide or show the window. */
  169. virtual void setHidden(bool hidden);
  170. /**
  171. * Makes the render target active or inactive. (for example in the case of a window, it will hide or restore the
  172. * window).
  173. */
  174. virtual void setActive(bool state);
  175. /** Minimizes the window to the taskbar. */
  176. virtual void minimize() { }
  177. /** Maximizes the window over the entire current screen. */
  178. virtual void maximize() { }
  179. /** Restores the window to original position and size if it is minimized or maximized. */
  180. virtual void restore() { }
  181. /** Change the size of the window. */
  182. virtual void resize(UINT32 width, UINT32 height) = 0;
  183. /** Reposition the window. */
  184. virtual void move(INT32 left, INT32 top) = 0;
  185. /** Returns properties that describe the render window. */
  186. const RenderWindowProperties& getProperties() const;
  187. /**
  188. * Called when window is moved or resized.
  189. *
  190. * @note Core thread.
  191. */
  192. virtual void _windowMovedOrResized();
  193. /**
  194. * Called when window has received focus.
  195. *
  196. * @note Core thread.
  197. */
  198. virtual void _windowFocusReceived();
  199. /**
  200. * Called when window has lost focus.
  201. *
  202. * @note Core thread.
  203. */
  204. virtual void _windowFocusLost();
  205. /**
  206. * Called when window has been maximized.
  207. *
  208. * @note Core thread.
  209. */
  210. virtual void _notifyMaximized();
  211. /**
  212. * Called when window has been minimized.
  213. *
  214. * @note Core thread.
  215. */
  216. virtual void _notifyMinimized();
  217. /**
  218. * Called when window has been restored from minimized or maximized state.
  219. *
  220. * @note Core thread.
  221. */
  222. virtual void _notifyRestored();
  223. protected:
  224. friend class RenderWindow;
  225. friend class RenderWindowManager;
  226. friend class RenderWindowCoreManager;
  227. /**
  228. * Returns window properties that are always kept in sync between core and sim threads.
  229. *
  230. * @note Used for keeping up what are the most up to date settings.
  231. */
  232. virtual RenderWindowProperties& getSyncedProperties() = 0;
  233. /** Updates window properties from the synced property data. */
  234. virtual void syncProperties() = 0;
  235. RENDER_WINDOW_DESC mDesc;
  236. SpinLock mLock;
  237. UINT32 mWindowId;
  238. };
  239. /** @} */
  240. }