CmRenderWindow.h 7.0 KB

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