BsRenderWindow.h 7.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279
  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)
  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. NameValuePairList platformSpecific; /**< Platform-specific creation options. */
  46. };
  47. /**
  48. * @brief Contains various properties that describe a render window.
  49. */
  50. class BS_CORE_EXPORT RenderWindowProperties : public RenderTargetProperties
  51. {
  52. public:
  53. virtual ~RenderWindowProperties() { }
  54. /**
  55. * @brief Gets the horizontal origin of the window in pixels.
  56. */
  57. INT32 getLeft() const { return mLeft; }
  58. /**
  59. * @brief Gets the vertical origin of the window in pixels.
  60. */
  61. INT32 getTop() const { return mTop; }
  62. /**
  63. * @brief Indicates whether the window currently has keyboard focus.
  64. */
  65. bool hasFocus() const { return mHasFocus; }
  66. /**
  67. * @brief Returns true if window is running in fullscreen mode.
  68. */
  69. bool isFullScreen() const { return mIsFullScreen; }
  70. /**
  71. * @brief Returns true if the window is modal (blocks interaction with
  72. * any non-modal window until closed).
  73. */
  74. bool isModal() const { return mIsModal; }
  75. /**
  76. * @brief Returns true if the window is hidden.
  77. */
  78. bool isHidden() const { return mHidden; }
  79. protected:
  80. friend class RenderWindowCore;
  81. friend class RenderWindow;
  82. /**
  83. * @copydoc RenderTargetProperties::copyToBuffer
  84. */
  85. virtual void copyToBuffer(UINT8* buffer) const;
  86. /**
  87. * @copydoc RenderTargetProperties::copyFromBuffer
  88. */
  89. virtual void copyFromBuffer(UINT8* buffer);
  90. /**
  91. * @copydoc RenderTargetProperties::getSize
  92. */
  93. virtual UINT32 getSize() const;
  94. bool mIsFullScreen = false;
  95. INT32 mLeft = 0;
  96. INT32 mTop = 0;
  97. bool mHasFocus = false;
  98. bool mHidden = false;
  99. bool mIsModal = false;
  100. };
  101. /**
  102. * @brief Provides access to internal render window implementation usable only from the core thread.
  103. *
  104. * @note Core thread only.
  105. */
  106. class BS_CORE_EXPORT RenderWindowCore : public RenderTargetCore
  107. {
  108. public:
  109. RenderWindowCore(RenderWindow* parent, RenderWindowProperties* properties);
  110. virtual ~RenderWindowCore() { }
  111. /**
  112. * @brief Switches the window to fullscreen mode. Child windows cannot go into fullscreen mode.
  113. *
  114. * @param width Width of the window frame buffer in pixels.
  115. * @param height Height of the window frame buffer in pixels.
  116. * @param refreshRate Refresh rate of the window in Hertz.
  117. * @param monitorIdx Index of the monitor to go fullscreen on.
  118. *
  119. * @note Core thread.
  120. * If the exact provided mode isn't available, closest one is used instead.
  121. */
  122. virtual void setFullscreen(UINT32 width, UINT32 height, float refreshRate = 60.0f, UINT32 monitorIdx = 0) { }
  123. /**
  124. * @brief Switches the window to fullscreen mode. Child windows cannot go into fullscreen mode.
  125. *
  126. * @param videoMode Mode retrieved from VideoModeInfo in RenderSystem.
  127. *
  128. * @note Core thread.
  129. */
  130. virtual void setFullscreen(const VideoMode& mode) { }
  131. /**
  132. * @brief Switches the window to windowed mode.
  133. *
  134. * @param Window width in pixels.
  135. * @param Window height in pixels.
  136. *
  137. * @note Core thread.
  138. */
  139. virtual void setWindowed(UINT32 width, UINT32 height) { }
  140. /**
  141. * @brief Hide or show the window.
  142. *
  143. * @note Core thread.
  144. */
  145. virtual void setHidden(bool hidden);
  146. /**
  147. * @brief Change the size of the window.
  148. *
  149. * @note Core thread.
  150. */
  151. virtual void resize(UINT32 width, UINT32 height) = 0;
  152. /**
  153. * @brief Reposition the window.
  154. *
  155. * @note Core thread.
  156. */
  157. virtual void move(INT32 left, INT32 top) = 0;
  158. /**
  159. * @brief Returns properties that describe the render texture.
  160. */
  161. const RenderWindowProperties& getProperties() const { return *static_cast<RenderWindowProperties*>(mProperties); }
  162. /**
  163. * @copydoc RenderTargetCore::getNonCore
  164. */
  165. RenderWindow* getNonCore() const;
  166. protected:
  167. friend class RenderWindow;
  168. friend class RenderWindowManager;
  169. /**
  170. * @brief Called when window is moved or resized.
  171. *
  172. * @note Core thread.
  173. */
  174. virtual void _windowMovedOrResized();
  175. /**
  176. * @brief Called when window has received focus.
  177. *
  178. * @note Core thread.
  179. */
  180. virtual void _windowFocusReceived();
  181. /**
  182. * @brief Called when window has lost focus.
  183. *
  184. * @note Core thread.
  185. */
  186. virtual void _windowFocusLost();
  187. };
  188. /**
  189. * @brief Render target specialization that allows you to render into window
  190. * frame buffer(s).
  191. *
  192. * @note Sim thread only. Retrieve core implementation from getCore()
  193. * for core thread only functionality.
  194. */
  195. class BS_CORE_EXPORT RenderWindow : public RenderTarget
  196. {
  197. public:
  198. virtual ~RenderWindow() { }
  199. /**
  200. * @copydoc RenderTarget::initialize
  201. */
  202. virtual void initialize(const RENDER_WINDOW_DESC& desc);
  203. /**
  204. * @copydoc RenderTarget::destroy
  205. */
  206. virtual void destroy();
  207. /**
  208. * @brief Converts screen position into window local position.
  209. */
  210. virtual Vector2I screenToWindowPos(const Vector2I& screenPos) const = 0;
  211. /**
  212. * @brief Converts window local position to screen position.
  213. */
  214. virtual Vector2I windowToScreenPos(const Vector2I& windowPos) const = 0;
  215. /**
  216. * @brief Returns properties that describe the render window.
  217. */
  218. const RenderWindowProperties& getProperties() const;
  219. /**
  220. * @brief Retrieves a core implementation of a render window usable only from the
  221. * core thread.
  222. *
  223. * @note Core thread only.
  224. */
  225. SPtr<RenderWindowCore> getCore() const;
  226. /**
  227. * @brief Creates a new render window using the specified options. Optionally
  228. * makes the created window a child of another window.
  229. */
  230. static RenderWindowPtr create(RENDER_WINDOW_DESC& desc, RenderWindowPtr parentWindow = nullptr);
  231. protected:
  232. friend class RenderWindowManager;
  233. RenderWindow() { }
  234. protected:
  235. RENDER_WINDOW_DESC mDesc;
  236. };
  237. }