BsWin32Window.h 4.5 KB

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