BsRenderWindow.h 10 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301
  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. /**
  111. * Makes the render target active or inactive. (for example in the case of a window, it will hide or restore the
  112. * window).
  113. */
  114. virtual void setActive(bool state);
  115. /** Minimizes the window to the taskbar. */
  116. virtual void minimize() { }
  117. /** Maximizes the window over the entire current screen. */
  118. virtual void maximize() { }
  119. /** Restores the window to original position and size if it is minimized or maximized. */
  120. virtual void restore() { }
  121. /** Change the size of the window. */
  122. virtual void resize(UINT32 width, UINT32 height) = 0;
  123. /** Reposition the window. */
  124. virtual void move(INT32 left, INT32 top) = 0;
  125. /** Returns properties that describe the render window. */
  126. const RenderWindowProperties& getProperties() const;
  127. /**
  128. * Called when window is moved or resized.
  129. *
  130. * @note Core thread.
  131. */
  132. virtual void _windowMovedOrResized();
  133. /**
  134. * Called when window has received focus.
  135. *
  136. * @note Core thread.
  137. */
  138. virtual void _windowFocusReceived();
  139. /**
  140. * Called when window has lost focus.
  141. *
  142. * @note Core thread.
  143. */
  144. virtual void _windowFocusLost();
  145. /**
  146. * Called when window has been maximized.
  147. *
  148. * @note Core thread.
  149. */
  150. virtual void _notifyMaximized();
  151. /**
  152. * Called when window has been minimized.
  153. *
  154. * @note Core thread.
  155. */
  156. virtual void _notifyMinimized();
  157. /**
  158. * Called when window has been restored from minimized or maximized state.
  159. *
  160. * @note Core thread.
  161. */
  162. virtual void _notifyRestored();
  163. protected:
  164. friend class RenderWindow;
  165. friend class RenderWindowManager;
  166. friend class RenderWindowCoreManager;
  167. /**
  168. * Returns window properties that are always kept in sync between core and sim threads.
  169. *
  170. * @note Used for keeping up what are the most up to date settings.
  171. */
  172. virtual RenderWindowProperties& getSyncedProperties() = 0;
  173. /** Updates window properties from the synced property data. */
  174. virtual void syncProperties() = 0;
  175. RENDER_WINDOW_DESC mDesc;
  176. SpinLock mLock;
  177. UINT32 mWindowId;
  178. };
  179. /** @endcond */
  180. /**
  181. * Render target specialization that allows you to render into window frame buffer(s).
  182. *
  183. * @note Sim thread only. Retrieve core implementation from getCore() for core thread only functionality.
  184. */
  185. class BS_CORE_EXPORT RenderWindow : public RenderTarget
  186. {
  187. public:
  188. virtual ~RenderWindow() { }
  189. /** @copydoc RenderTarget::destroy */
  190. virtual void destroy() override;
  191. /** Converts screen position into window local position. */
  192. virtual Vector2I screenToWindowPos(const Vector2I& screenPos) const = 0;
  193. /** Converts window local position to screen position. */
  194. virtual Vector2I windowToScreenPos(const Vector2I& windowPos) const = 0;
  195. /** Resize the window to specified width and height in pixels. */
  196. void resize(CoreAccessor& accessor, UINT32 width, UINT32 height);
  197. /** Move the window to specified screen coordinates. */
  198. void move(CoreAccessor& accessor, INT32 left, INT32 top);
  199. /** Hide the window. (Does not destroy it, just hides it). */
  200. void hide(CoreAccessor& accessor);
  201. /** Shows a previously hidden window. */
  202. void show(CoreAccessor& accessor);
  203. /** @copydoc RenderWindowCore::minimize */
  204. void minimize(CoreAccessor& accessor);
  205. /** @copydoc RenderWindowCore::maximize */
  206. void maximize(CoreAccessor& accessor);
  207. /** @copydoc RenderWindowCore::restore */
  208. void restore(CoreAccessor& accessor);
  209. /** @copydoc RenderWindowCore::setFullscreen(UINT32, UINT32, float, UINT32) */
  210. void setFullscreen(CoreAccessor& accessor, UINT32 width, UINT32 height, float refreshRate = 60.0f, UINT32 monitorIdx = 0);
  211. /** @copydoc RenderWindowCore::setFullscreen(const VideoMode&) */
  212. void setFullscreen(CoreAccessor& accessor, const VideoMode& mode);
  213. /** @copydoc RenderWindowCore::setWindowed */
  214. void setWindowed(CoreAccessor& accessor, UINT32 width, UINT32 height);
  215. /** Retrieves a core implementation of a render window usable only from the core thread. */
  216. SPtr<RenderWindowCore> getCore() const;
  217. /** Returns properties that describe the render window. */
  218. const RenderWindowProperties& getProperties() const;
  219. /**
  220. * Creates a new render window using the specified options. Optionally makes the created window a child of another
  221. * window.
  222. */
  223. static RenderWindowPtr create(RENDER_WINDOW_DESC& desc, RenderWindowPtr parentWindow = nullptr);
  224. protected:
  225. friend class RenderWindowManager;
  226. RenderWindow(const RENDER_WINDOW_DESC& desc, UINT32 windowId);
  227. /** Returns render window properties that may be edited. */
  228. RenderWindowProperties& getMutableProperties();
  229. /** @copydoc RenderTarget::createCore */
  230. SPtr<CoreObjectCore> createCore() const override;
  231. /** Updates window properties from the synced property data. */
  232. virtual void syncProperties() = 0;
  233. protected:
  234. RENDER_WINDOW_DESC mDesc;
  235. UINT32 mWindowId;
  236. };
  237. /** @} */
  238. }