BsRenderWindow.h 10 KB

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