CmRenderWindow.h 6.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219
  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. *
  79. * @note Core thread.
  80. */
  81. virtual void setFullscreen(const VideoMode& mode) { }
  82. /**
  83. * @brief Switches the window to windowed mode.
  84. */
  85. virtual void setWindowed() { }
  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. }