BsRenderWindow.h 6.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219
  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 Render target specialization that allows you to render into window
  49. * frame buffer(s).
  50. *
  51. * @note Thread safe, except where noted otherwise.
  52. */
  53. class BS_CORE_EXPORT RenderWindow : public RenderTarget
  54. {
  55. public:
  56. virtual ~RenderWindow();
  57. /**
  58. * @brief Switches the window to fullscreen mode. Child windows cannot go into fullscreen mode.
  59. *
  60. * @param width Width of the window frame buffer in pixels.
  61. * @param height Height of the window frame buffer in pixels.
  62. * @param refreshRate Refresh rate of the window in Hertz.
  63. * @param monitorIdx Index of the monitor to go fullscreen on.
  64. *
  65. * @note Core thread.
  66. * If the exact provided mode isn't available, closest one is used instead.
  67. */
  68. virtual void setFullscreen(UINT32 width, UINT32 height, float refreshRate = 60.0f, UINT32 monitorIdx = 0) { }
  69. /**
  70. * @brief Switches the window to fullscreen mode. Child windows cannot go into fullscreen mode.
  71. *
  72. * @param videoMode Mode retrieved from VideoModeInfo in RenderSystem.
  73. *
  74. * @note Core thread.
  75. */
  76. virtual void setFullscreen(const VideoMode& mode) { }
  77. /**
  78. * @brief Switches the window to windowed mode.
  79. *
  80. * @param Window width in pixels.
  81. * @param Window height in pixels.
  82. *
  83. * @note Core thread.
  84. */
  85. virtual void setWindowed(UINT32 width, UINT32 height) { }
  86. /**
  87. * @brief Hide or show the window.
  88. *
  89. * @note Core thread.
  90. */
  91. virtual void setHidden(bool hidden);
  92. /**
  93. * @brief Change the size of the window.
  94. *
  95. * @note Core thread.
  96. */
  97. virtual void resize(UINT32 width, UINT32 height) = 0;
  98. /**
  99. * @brief Reposition the window.
  100. *
  101. * @note Core thread.
  102. */
  103. virtual void move(INT32 left, INT32 top) = 0;
  104. /**
  105. * @copydoc RenderTarget::isWindow.
  106. */
  107. bool isWindow() const { return true; }
  108. /**
  109. * @brief Indicates whether the window is visible (not minimized or obscured).
  110. */
  111. virtual bool isVisible() const { return true; }
  112. /**
  113. * @copydoc RenderTarget::isActive
  114. */
  115. virtual bool isActive() const { return mActive && isVisible(); }
  116. /**
  117. * @brief Indicates whether the window has been closed by the user.
  118. */
  119. virtual bool isClosed() const = 0;
  120. /**
  121. * @brief Returns true if window is running in fullscreen mode.
  122. */
  123. virtual bool isFullScreen() const;
  124. /**
  125. * @brief Returns true if the window is modal.
  126. */
  127. bool isModal() const { return mDesc.modal; }
  128. /**
  129. * @brief Gets the horizontal origin of the window in pixels.
  130. */
  131. INT32 getLeft() const { return mLeft; }
  132. /**
  133. * @brief Gets the vertical origin of the window in pixels.
  134. */
  135. INT32 getTop() const { return mTop; }
  136. /**
  137. * @brief Indicates whether the window currently has keyboard focus.
  138. */
  139. bool hasFocus() const { return mHasFocus; }
  140. /**
  141. * @brief Converts screen position into window local position.
  142. */
  143. virtual Vector2I screenToWindowPos(const Vector2I& screenPos) const = 0;
  144. /**
  145. * @brief Converts window local position to screen position.
  146. */
  147. virtual Vector2I windowToScreenPos(const Vector2I& windowPos) const = 0;
  148. /**
  149. * @copydoc RenderTarget::destroy
  150. */
  151. virtual void destroy();
  152. /**
  153. * @brief Creates a new render window using the specified options. Optionally
  154. * makes the created window a child of another window.
  155. */
  156. static RenderWindowPtr create(RENDER_WINDOW_DESC& desc, RenderWindowPtr parentWindow = nullptr);
  157. protected:
  158. friend class RenderWindowManager;
  159. RenderWindow(const RENDER_WINDOW_DESC& desc);
  160. /**
  161. * @brief Called when window is moved or resized.
  162. *
  163. * @note Core thread.
  164. */
  165. virtual void _windowMovedOrResized();
  166. /**
  167. * @brief Called when window has received focus.
  168. *
  169. * @note Core thread.
  170. */
  171. virtual void _windowFocusReceived();
  172. /**
  173. * @brief Called when window has lost focus.
  174. *
  175. * @note Core thread.
  176. */
  177. virtual void _windowFocusLost();
  178. protected:
  179. bool mIsFullScreen;
  180. INT32 mLeft;
  181. INT32 mTop;
  182. bool mHasFocus;
  183. bool mHidden;
  184. RENDER_WINDOW_DESC mDesc;
  185. };
  186. }