BsRenderWindow.h 6.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222
  1. //__________________________ Banshee Project - A modern game development toolkit _________________________________//
  2. //_____________________________________ www.banshee-project.com __________________________________________________//
  3. //________________________ Copyright (c) 2014 Marko Pintera. All rights reserved. ________________________________//
  4. #pragma once
  5. #include "BsCorePrerequisites.h"
  6. #include "BsRenderTarget.h"
  7. #include "BsVideoModeInfo.h"
  8. #include "BsVector2I.h"
  9. namespace BansheeEngine
  10. {
  11. /**
  12. * @brief Enum that defines possible window border styles.
  13. */
  14. enum class WindowBorder
  15. {
  16. Normal,
  17. None,
  18. Fixed
  19. };
  20. /**
  21. * @brief Structure that is used for initializing a render window.
  22. */
  23. struct BS_CORE_EXPORT RENDER_WINDOW_DESC
  24. {
  25. RENDER_WINDOW_DESC()
  26. : vsync(false), vsyncInterval(1), fullscreen(false), hidden(false), depthBuffer(true)
  27. , multisampleCount(0), multisampleHint(""), gamma(false), left(-1), top(-1)
  28. , title(""), border(WindowBorder::Normal), outerDimensions(false), enableDoubleClick(true)
  29. , toolWindow(false), modal(false)
  30. { }
  31. VideoMode videoMode; /**< A set of frame buffer options. */
  32. bool fullscreen; /**< Should the window be opened in fullscreen mode. */
  33. bool vsync; /**< Should the window wait for vertical sync before swapping buffers. */
  34. UINT32 vsyncInterval; /**< Determines how many vsync intervals occur per frame. FPS = refreshRate/interval. Usually 1 when vsync active. */
  35. bool hidden; /**< Should the window be hidden. */
  36. bool depthBuffer; /**< Should the window be created with a depth/stencil buffer. */
  37. UINT32 multisampleCount; /**< If higher than 1, texture containing multiple samples per pixel is created. */
  38. String multisampleHint; /**< Hint about what kind of multisampling to use. Render system specific. */
  39. bool gamma; /**< Should the written color pixels be gamma corrected before write. */
  40. INT32 left; /**< Window origin on X axis in pixels. -1 == screen center. Relative to monitor provided in videoMode. */
  41. INT32 top; /**< Window origin on Y axis in pixels. -1 == screen center. Relative to monitor provided in videoMode. */
  42. String title; /**< Title of the window. */
  43. WindowBorder border; /**< Type of border to create the window with. */
  44. bool outerDimensions; /**< Do our dimensions include space for things like title-bar and border. */
  45. bool enableDoubleClick; /**< Does window accept double-clicks. */
  46. bool toolWindow; /**< Tool windows have a different style than normal windows and can be created with no border or title bar. */
  47. bool modal; /**< When a modal window is open all other windows will be locked until modal window is closed. */
  48. NameValuePairList platformSpecific; /**< Platform-specific creation options. */
  49. };
  50. /**
  51. * @brief Render target specialization that allows you to render into window
  52. * frame buffer(s).
  53. *
  54. * @note Thread safe, except where noted otherwise.
  55. */
  56. class BS_CORE_EXPORT RenderWindow : public RenderTarget
  57. {
  58. public:
  59. virtual ~RenderWindow();
  60. /**
  61. * @brief Switches the window to fullscreen mode. Child windows cannot go into fullscreen mode.
  62. *
  63. * @param width Width of the window frame buffer in pixels.
  64. * @param height Height of the window frame buffer in pixels.
  65. * @param refreshRate Refresh rate of the window in Hertz.
  66. * @param monitorIdx Index of the monitor to go fullscreen on.
  67. *
  68. * @note Core thread.
  69. * If the exact provided mode isn't available, closest one is used instead.
  70. */
  71. virtual void setFullscreen(UINT32 width, UINT32 height, float refreshRate = 60.0f, UINT32 monitorIdx = 0) { }
  72. /**
  73. * @brief Switches the window to fullscreen mode. Child windows cannot go into fullscreen mode.
  74. *
  75. * @param videoMode Mode retrieved from VideoModeInfo in RenderSystem.
  76. *
  77. * @note Core thread.
  78. */
  79. virtual void setFullscreen(const VideoMode& mode) { }
  80. /**
  81. * @brief Switches the window to windowed mode.
  82. *
  83. * @param Window width in pixels.
  84. * @param Window height in pixels.
  85. *
  86. * @note Core thread.
  87. */
  88. virtual void setWindowed(UINT32 width, UINT32 height) { }
  89. /**
  90. * @brief Hide or show the window.
  91. *
  92. * @note Core thread.
  93. */
  94. virtual void setHidden(bool hidden);
  95. /**
  96. * @brief Change the size of the window.
  97. *
  98. * @note Core thread.
  99. */
  100. virtual void resize(UINT32 width, UINT32 height) = 0;
  101. /**
  102. * @brief Reposition the window.
  103. *
  104. * @note Core thread.
  105. */
  106. virtual void move(INT32 left, INT32 top) = 0;
  107. /**
  108. * @copydoc RenderTarget::isWindow.
  109. */
  110. bool isWindow() const { return true; }
  111. /**
  112. * @brief Indicates whether the window is visible (not minimized or obscured).
  113. */
  114. virtual bool isVisible() const { return true; }
  115. /**
  116. * @copydoc RenderTarget::isActive
  117. */
  118. virtual bool isActive() const { return mActive && isVisible(); }
  119. /**
  120. * @brief Indicates whether the window has been closed by the user.
  121. */
  122. virtual bool isClosed() const = 0;
  123. /**
  124. * @brief Returns true if window is running in fullscreen mode.
  125. */
  126. virtual bool isFullScreen() const;
  127. /**
  128. * @brief Returns true if the window is modal.
  129. */
  130. bool isModal() const { return mDesc.modal; }
  131. /**
  132. * @brief Gets the horizontal origin of the window in pixels.
  133. */
  134. INT32 getLeft() const { return mLeft; }
  135. /**
  136. * @brief Gets the vertical origin of the window in pixels.
  137. */
  138. INT32 getTop() const { return mTop; }
  139. /**
  140. * @brief Indicates whether the window currently has keyboard focus.
  141. */
  142. bool hasFocus() const { return mHasFocus; }
  143. /**
  144. * @brief Converts screen position into window local position.
  145. */
  146. virtual Vector2I screenToWindowPos(const Vector2I& screenPos) const = 0;
  147. /**
  148. * @brief Converts window local position to screen position.
  149. */
  150. virtual Vector2I windowToScreenPos(const Vector2I& windowPos) const = 0;
  151. /**
  152. * @copydoc RenderTarget::destroy
  153. */
  154. virtual void destroy();
  155. /**
  156. * @brief Creates a new render window using the specified options. Optionally
  157. * makes the created window a child of another window.
  158. */
  159. static RenderWindowPtr create(RENDER_WINDOW_DESC& desc, RenderWindowPtr parentWindow = nullptr);
  160. protected:
  161. friend class RenderWindowManager;
  162. RenderWindow(const RENDER_WINDOW_DESC& desc);
  163. /**
  164. * @brief Called when window is moved or resized.
  165. *
  166. * @note Core thread.
  167. */
  168. virtual void _windowMovedOrResized();
  169. /**
  170. * @brief Called when window has received focus.
  171. *
  172. * @note Core thread.
  173. */
  174. virtual void _windowFocusReceived();
  175. /**
  176. * @brief Called when window has lost focus.
  177. *
  178. * @note Core thread.
  179. */
  180. virtual void _windowFocusLost();
  181. protected:
  182. bool mIsFullScreen;
  183. INT32 mLeft;
  184. INT32 mTop;
  185. bool mHasFocus;
  186. bool mHidden;
  187. RENDER_WINDOW_DESC mDesc;
  188. };
  189. }