BsWin32RenderWindow.h 5.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218
  1. #pragma once
  2. #include "BsWin32Prerequisites.h"
  3. #include "BsRenderWindow.h"
  4. namespace BansheeEngine
  5. {
  6. class Win32RenderWindow;
  7. /**
  8. * @brief Contains various properties that describe a render window.
  9. */
  10. class BS_RSGL_EXPORT Win32RenderWindowProperties : public RenderWindowProperties
  11. {
  12. public:
  13. Win32RenderWindowProperties(const RENDER_WINDOW_DESC& desc);
  14. virtual ~Win32RenderWindowProperties() { }
  15. private:
  16. friend class Win32RenderWindowCore;
  17. friend class Win32RenderWindow;
  18. };
  19. /**
  20. * @brief Render window implementation for Windows.
  21. *
  22. * @note Core thread only.
  23. */
  24. class BS_RSGL_EXPORT Win32RenderWindowCore : public RenderWindowCore
  25. {
  26. public:
  27. Win32RenderWindowCore(const RENDER_WINDOW_DESC& desc, UINT32 windowId, Win32GLSupport &glsupport);
  28. ~Win32RenderWindowCore();
  29. /**
  30. * @copydoc RenderWindowCore::setFullscreen(UINT32, UINT32, float, UINT32)
  31. */
  32. void setFullscreen(UINT32 width, UINT32 height, float refreshRate = 60.0f, UINT32 monitorIdx = 0) override;
  33. /**
  34. * @copydoc RenderWindowCore::setFullscreen(const VideoMode&)
  35. */
  36. void setFullscreen(const VideoMode& mode) override;
  37. /**
  38. * @copydoc RenderWindowCore::setWindowed
  39. */
  40. void setWindowed(UINT32 width, UINT32 height) override;
  41. /**
  42. * @copydoc RenderWindowCore::setHidden
  43. */
  44. void setHidden(bool hidden) override;
  45. /**
  46. * @copydoc RenderWindowCore::minimize
  47. */
  48. void minimize() override;
  49. /**
  50. * @copydoc RenderWindowCore::maximize
  51. */
  52. void maximize() override;
  53. /**
  54. * @copydoc RenderWindowCore::restore
  55. */
  56. void restore() override;
  57. /**
  58. * @copydoc RenderWindowCore::move
  59. */
  60. void move(INT32 left, INT32 top) override;
  61. /**
  62. * @copydoc RenderWindowCore::resize
  63. */
  64. void resize(UINT32 width, UINT32 height) override;
  65. /**
  66. * @copydoc RenderWindowCore::copyContentsToMemory
  67. */
  68. void copyToMemory(PixelData &dst, FrameBuffer buffer);
  69. /**
  70. * @copydoc RenderWindowCore::swapBuffers
  71. */
  72. void swapBuffers() override;
  73. /**
  74. * @copydoc RenderWindowCore::getCustomAttribute
  75. */
  76. void getCustomAttribute(const String& name, void* pData) const override;
  77. /**
  78. * @copydoc RenderWindowCore::setActive
  79. */
  80. virtual void setActive(bool state) override;
  81. /**
  82. * @copydoc RenderWindowCore::_windowMovedOrResized
  83. */
  84. void _windowMovedOrResized() override;
  85. /**
  86. * @brief Returns handle to device context associated with the window.
  87. */
  88. HDC _getHDC() const { return mHDC; }
  89. /**
  90. * @brief Returns internal window handle.
  91. */
  92. HWND _getHWnd() const { return mHWnd; }
  93. protected:
  94. friend class Win32GLSupport;
  95. /**
  96. * @copydoc CoreObjectCore::initialize
  97. */
  98. virtual void initialize() override;
  99. /**
  100. * @brief Calculates window size based on provided client area size and currently set window style.
  101. */
  102. void getAdjustedWindowSize(UINT32 clientWidth, UINT32 clientHeight, UINT32* winWidth, UINT32* winHeight);
  103. /**
  104. * @copydoc RenderWindowCore::getProperties
  105. */
  106. const RenderTargetProperties& getPropertiesInternal() const override { return mProperties; }
  107. /**
  108. * @copydoc RenderWindowCore::getSyncedProperties
  109. */
  110. RenderWindowProperties& getSyncedProperties() override { return mSyncedProperties; }
  111. /**
  112. * @copydoc RenderWindowCore::syncProperties
  113. */
  114. void syncProperties() override;
  115. protected:
  116. friend class Win32RenderWindow;
  117. Win32GLSupport &mGLSupport;
  118. HDC mHDC;
  119. DWORD mWindowedStyle;
  120. DWORD mWindowedStyleEx;
  121. bool mIsExternal;
  122. bool mIsChild;
  123. char* mDeviceName;
  124. bool mIsExternalGLControl;
  125. int mDisplayFrequency;
  126. bool mShowOnSwap;
  127. HWND mHWnd;
  128. SPtr<Win32Context> mContext;
  129. Win32RenderWindowProperties mProperties;
  130. Win32RenderWindowProperties mSyncedProperties;
  131. };
  132. /**
  133. * @brief Render window implementation for Windows.
  134. *
  135. * @note Sim thread only.
  136. */
  137. class BS_RSGL_EXPORT Win32RenderWindow : public RenderWindow
  138. {
  139. public:
  140. ~Win32RenderWindow() { }
  141. /**
  142. * @copydoc RenderWindow::screenToWindowPos
  143. */
  144. void getCustomAttribute(const String& name, void* pData) const override;
  145. /**
  146. * @copydoc RenderWindow::screenToWindowPos
  147. */
  148. Vector2I screenToWindowPos(const Vector2I& screenPos) const override;
  149. /**
  150. * @copydoc RenderWindow::windowToScreenPos
  151. */
  152. Vector2I windowToScreenPos(const Vector2I& windowPos) const override;
  153. /**
  154. * @copydoc RenderWindow::getCore
  155. */
  156. SPtr<Win32RenderWindowCore> getCore() const;
  157. protected:
  158. friend class GLRenderWindowManager;
  159. friend class Win32GLSupport;
  160. friend class Win32RenderWindowCore;
  161. Win32RenderWindow(const RENDER_WINDOW_DESC& desc, UINT32 windowId, Win32GLSupport& glsupport);
  162. /**
  163. * @copydoc RenderWindow::getProperties
  164. */
  165. const RenderTargetProperties& getPropertiesInternal() const override { return mProperties; }
  166. /**
  167. * @copydoc RenderWindow::syncProperties
  168. */
  169. void syncProperties() override;
  170. /**
  171. * @brief Retrieves internal window handle.
  172. */
  173. HWND getHWnd() const;
  174. private:
  175. Win32GLSupport& mGLSupport;
  176. Win32RenderWindowProperties mProperties;
  177. };
  178. }