CmRenderWindow.h 6.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214
  1. #pragma once
  2. #include "CmPrerequisites.h"
  3. #include "CmRenderTarget.h"
  4. #include "CmVideoModeInfo.h"
  5. #include "CmVector2I.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 back buffer in pixels.
  61. * @param height Height of the window back buffer in pixels.
  62. * @param refreshRate Refresh rate of the window in Hertz. This is ignored in windowed mode.
  63. * @param monitorIdx Index of the monitor to go fullscreen on. This is ignored in windowed mode.
  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. virtual void setWindowed() { }
  81. /**
  82. * @brief Hide or show the window.
  83. *
  84. * @note Core thread.
  85. */
  86. virtual void setHidden(bool hidden);
  87. /**
  88. * @brief Change the size of the window.
  89. *
  90. * @note Core thread.
  91. */
  92. virtual void resize(UINT32 width, UINT32 height) = 0;
  93. /**
  94. * @brief Reposition the window.
  95. *
  96. * @note Core thread.
  97. */
  98. virtual void move(INT32 left, INT32 top) = 0;
  99. /**
  100. * @copydoc RenderTarget::isWindow.
  101. */
  102. bool isWindow() const { return true; }
  103. /**
  104. * @brief Indicates whether the window is visible (not minimized or obscured).
  105. */
  106. virtual bool isVisible() const { return true; }
  107. /**
  108. * @copydoc RenderTarget::isActive
  109. */
  110. virtual bool isActive() const { return mActive && isVisible(); }
  111. /**
  112. * @brief Indicates whether the window has been closed by the user.
  113. */
  114. virtual bool isClosed() const = 0;
  115. /**
  116. * @brief Returns true if window is running in fullscreen mode.
  117. */
  118. virtual bool isFullScreen() const;
  119. /**
  120. * @brief Returns true if the window is modal.
  121. */
  122. bool isModal() const { return mDesc.modal; }
  123. /**
  124. * @brief Gets the horizontal origin of the window in pixels.
  125. */
  126. INT32 getLeft() const { return mLeft; }
  127. /**
  128. * @brief Gets the vertical origin of the window in pixels.
  129. */
  130. INT32 getTop() const { return mTop; }
  131. /**
  132. * @brief Indicates whether the window currently has keyboard focus.
  133. */
  134. bool hasFocus() const { return mHasFocus; }
  135. /**
  136. * @brief Converts screen position into window local position.
  137. */
  138. virtual Vector2I screenToWindowPos(const Vector2I& screenPos) const = 0;
  139. /**
  140. * @brief Converts window local position to screen position.
  141. */
  142. virtual Vector2I windowToScreenPos(const Vector2I& windowPos) const = 0;
  143. /**
  144. * @copydoc RenderTarget::destroy
  145. */
  146. virtual void destroy();
  147. /**
  148. * @brief Creates a new render window using the specified options. Optionally
  149. * makes the created window a child of another window.
  150. */
  151. static RenderWindowPtr create(RENDER_WINDOW_DESC& desc, RenderWindowPtr parentWindow = nullptr);
  152. protected:
  153. friend class RenderWindowManager;
  154. RenderWindow(const RENDER_WINDOW_DESC& desc);
  155. /**
  156. * @brief Called when window is moved or resized.
  157. *
  158. * @note Core thread.
  159. */
  160. virtual void _windowMovedOrResized();
  161. /**
  162. * @brief Called when window has received focus.
  163. *
  164. * @note Core thread.
  165. */
  166. virtual void _windowFocusReceived();
  167. /**
  168. * @brief Called when window has lost focus.
  169. *
  170. * @note Core thread.
  171. */
  172. virtual void _windowFocusLost();
  173. protected:
  174. bool mIsFullScreen;
  175. INT32 mLeft;
  176. INT32 mTop;
  177. bool mHasFocus;
  178. bool mHidden;
  179. RENDER_WINDOW_DESC mDesc;
  180. };
  181. }