BsWin32Window.h 4.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203
  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. virtual ~Win32RenderWindowProperties() { }
  14. /**
  15. * @brief Retrieves the window handle.
  16. */
  17. HWND getHWnd() const { return mHWnd; }
  18. private:
  19. friend class Win32WindowCore;
  20. friend class Win32Window;
  21. /**
  22. * @copydoc RenderTargetProperties::copyToBuffer
  23. */
  24. virtual void copyToBuffer(UINT8* buffer) const;
  25. /**
  26. * @copydoc RenderTargetProperties::copyFromBuffer
  27. */
  28. virtual void copyFromBuffer(UINT8* buffer);
  29. /**
  30. * @copydoc RenderTargetProperties::getSize
  31. */
  32. virtual UINT32 getSize() const;
  33. HWND mHWnd = 0;
  34. };
  35. /**
  36. * @brief Render window implementation for Windows.
  37. *
  38. * @note Core thread only.
  39. */
  40. class BS_RSGL_EXPORT Win32WindowCore : public RenderWindowCore
  41. {
  42. public:
  43. Win32WindowCore(Win32Window* parent, RenderWindowProperties* properties, const RENDER_WINDOW_DESC& desc, Win32GLSupport &glsupport);
  44. ~Win32WindowCore();
  45. /**
  46. * @copydoc RenderWindowCore::setFullscreen(UINT32, UINT32, float, UINT32)
  47. */
  48. void setFullscreen(UINT32 width, UINT32 height, float refreshRate = 60.0f, UINT32 monitorIdx = 0);
  49. /**
  50. * @copydoc RenderWindowCore::setFullscreen(const VideoMode&)
  51. */
  52. void setFullscreen(const VideoMode& mode);
  53. /**
  54. * @copydoc RenderWindowCore::setWindowed
  55. */
  56. void setWindowed(UINT32 width, UINT32 height);
  57. /**
  58. * @copydoc RenderWindowCore::setHidden
  59. */
  60. void setHidden(bool hidden);
  61. /**
  62. * @copydoc RenderWindowCore::move
  63. */
  64. void move(INT32 left, INT32 top);
  65. /**
  66. * @copydoc RenderWindowCore::resize
  67. */
  68. void resize(UINT32 width, UINT32 height);
  69. /**
  70. * @copydoc RenderWindowCore::copyContentsToMemory
  71. */
  72. void copyToMemory(PixelData &dst, FrameBuffer buffer);
  73. /**
  74. * @copydoc RenderWindowCore::swapBuffers
  75. */
  76. void swapBuffers();
  77. /**
  78. * @copydoc RenderWindowCore::getCustomAttribute
  79. */
  80. void getCustomAttribute(const String& name, void* pData) const;
  81. /**
  82. * @copydoc RenderWindowCore::setActive
  83. */
  84. virtual void setActive(bool state);
  85. /**
  86. * @copydoc RenderWindowCore::_windowMovedOrResized
  87. */
  88. void _windowMovedOrResized();
  89. /**
  90. * @brief Returns handle to device context associated with the window.
  91. */
  92. HDC _getHDC() const { return mHDC; }
  93. protected:
  94. friend class Win32GLSupport;
  95. /**
  96. * @copydoc CoreObjectCore::initialize
  97. */
  98. virtual void initialize();
  99. /**
  100. * @copydoc CoreObjectCore::destroy
  101. */
  102. virtual void destroy();
  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. protected:
  108. Win32GLSupport &mGLSupport;
  109. HDC mHDC;
  110. DWORD mWindowedStyle;
  111. DWORD mWindowedStyleEx;
  112. bool mIsExternal;
  113. bool mIsChild;
  114. char* mDeviceName;
  115. bool mIsExternalGLControl;
  116. int mDisplayFrequency;
  117. Win32Context *mContext;
  118. RENDER_WINDOW_DESC mDesc;
  119. };
  120. /**
  121. * @brief Render window implementation for Windows.
  122. *
  123. * @note Sim thread only.
  124. */
  125. class BS_RSGL_EXPORT Win32Window : public RenderWindow
  126. {
  127. public:
  128. ~Win32Window() { }
  129. /**
  130. * @copydoc RenderWindow::requiresTextureFlipping
  131. */
  132. bool requiresTextureFlipping() const { return false; }
  133. /**
  134. * @copydoc RenderWindow::screenToWindowPos
  135. */
  136. Vector2I screenToWindowPos(const Vector2I& screenPos) const;
  137. /**
  138. * @copydoc RenderWindow::windowToScreenPos
  139. */
  140. Vector2I windowToScreenPos(const Vector2I& windowPos) const;
  141. /**
  142. * @copydoc RenderWindow::getCustomAttribute
  143. */
  144. void getCustomAttribute(const String& name, void* pData) const;
  145. /**
  146. * @copydoc RenderWindow::getCore
  147. */
  148. Win32WindowCore* getCore() const;
  149. protected:
  150. friend class GLRenderWindowManager;
  151. friend class Win32GLSupport;
  152. friend class Win32WindowCore;
  153. Win32Window(Win32GLSupport& glsupport);
  154. /**
  155. * @copydoc RenderWindow::createProperties
  156. */
  157. virtual RenderTargetProperties* createProperties() const;
  158. /**
  159. * @copydoc RenderWindow::createCore
  160. */
  161. virtual CoreObjectCore* createCore() const;
  162. private:
  163. Win32GLSupport& mGLSupport;
  164. };
  165. }