BsWin32Window.h 4.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194
  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::move
  47. */
  48. void move(INT32 left, INT32 top);
  49. /**
  50. * @copydoc RenderWindowCore::resize
  51. */
  52. void resize(UINT32 width, UINT32 height);
  53. /**
  54. * @copydoc RenderWindowCore::copyContentsToMemory
  55. */
  56. void copyToMemory(PixelData &dst, FrameBuffer buffer);
  57. /**
  58. * @copydoc RenderWindowCore::swapBuffers
  59. */
  60. void swapBuffers();
  61. /**
  62. * @copydoc RenderWindowCore::getCustomAttribute
  63. */
  64. void getCustomAttribute(const String& name, void* pData) const;
  65. /**
  66. * @copydoc RenderWindowCore::setActive
  67. */
  68. virtual void setActive(bool state);
  69. /**
  70. * @copydoc RenderWindowCore::_windowMovedOrResized
  71. */
  72. void _windowMovedOrResized();
  73. /**
  74. * @brief Returns handle to device context associated with the window.
  75. */
  76. HDC _getHDC() const { return mHDC; }
  77. /**
  78. * @brief Returns internal window handle.
  79. */
  80. HWND _getHWnd() const { return mHWnd; }
  81. protected:
  82. friend class Win32GLSupport;
  83. /**
  84. * @copydoc CoreObjectCore::initialize
  85. */
  86. virtual void initialize();
  87. /**
  88. * @copydoc RenderWindowCore::getSyncData
  89. */
  90. UINT32 getSyncData(UINT8* buffer);
  91. /**
  92. * @brief Calculates window size based on provided client area size and currently set window style.
  93. */
  94. void getAdjustedWindowSize(UINT32 clientWidth, UINT32 clientHeight, UINT32* winWidth, UINT32* winHeight);
  95. /**
  96. * @copydoc RenderWindowCore::getProperties
  97. */
  98. const RenderTargetProperties& getPropertiesInternal() const { return mProperties; }
  99. protected:
  100. Win32GLSupport &mGLSupport;
  101. HDC mHDC;
  102. DWORD mWindowedStyle;
  103. DWORD mWindowedStyleEx;
  104. bool mIsExternal;
  105. bool mIsChild;
  106. char* mDeviceName;
  107. bool mIsExternalGLControl;
  108. int mDisplayFrequency;
  109. HWND mHWnd;
  110. SPtr<Win32Context> mContext;
  111. Win32RenderWindowProperties mProperties;
  112. };
  113. /**
  114. * @brief Render window implementation for Windows.
  115. *
  116. * @note Sim thread only.
  117. */
  118. class BS_RSGL_EXPORT Win32Window : public RenderWindow
  119. {
  120. public:
  121. ~Win32Window() { }
  122. /**
  123. * @copydoc RenderWindow::screenToWindowPos
  124. */
  125. void getCustomAttribute(const String& name, void* pData) const;
  126. /**
  127. * @copydoc RenderWindow::screenToWindowPos
  128. */
  129. Vector2I screenToWindowPos(const Vector2I& screenPos) const;
  130. /**
  131. * @copydoc RenderWindow::windowToScreenPos
  132. */
  133. Vector2I windowToScreenPos(const Vector2I& windowPos) const;
  134. /**
  135. * @copydoc RenderWindow::getCore
  136. */
  137. SPtr<Win32WindowCore> getCore() const;
  138. protected:
  139. friend class GLRenderWindowManager;
  140. friend class Win32GLSupport;
  141. friend class Win32WindowCore;
  142. Win32Window(const RENDER_WINDOW_DESC& desc, Win32GLSupport& glsupport);
  143. /**
  144. * @copydoc RenderWindow::getProperties
  145. */
  146. const RenderTargetProperties& getPropertiesInternal() const { return mProperties; }
  147. /**
  148. * @copydoc RenderWindow::setSyncData
  149. */
  150. void setSyncData(UINT8* buffer, UINT32 size);
  151. /**
  152. * @brief Retrieves internal window handle.
  153. */
  154. HWND getHWnd() const;
  155. private:
  156. Win32GLSupport& mGLSupport;
  157. Win32RenderWindowProperties mProperties;
  158. };
  159. }