BsWin32Window.h 4.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184
  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. * @brief Calculates window size based on provided client area size and currently set window style.
  89. */
  90. void getAdjustedWindowSize(UINT32 clientWidth, UINT32 clientHeight, UINT32* winWidth, UINT32* winHeight);
  91. /**
  92. * @copydoc RenderWindowCore::getProperties
  93. */
  94. const RenderTargetProperties& getPropertiesInternal() const { return mProperties; }
  95. protected:
  96. Win32GLSupport &mGLSupport;
  97. HDC mHDC;
  98. DWORD mWindowedStyle;
  99. DWORD mWindowedStyleEx;
  100. bool mIsExternal;
  101. bool mIsChild;
  102. char* mDeviceName;
  103. bool mIsExternalGLControl;
  104. int mDisplayFrequency;
  105. HWND mHWnd;
  106. SPtr<Win32Context> mContext;
  107. Win32RenderWindowProperties mProperties;
  108. };
  109. /**
  110. * @brief Render window implementation for Windows.
  111. *
  112. * @note Sim thread only.
  113. */
  114. class BS_RSGL_EXPORT Win32Window : public RenderWindow
  115. {
  116. public:
  117. ~Win32Window() { }
  118. /**
  119. * @copydoc RenderWindow::screenToWindowPos
  120. */
  121. void getCustomAttribute(const String& name, void* pData) const;
  122. /**
  123. * @copydoc RenderWindow::screenToWindowPos
  124. */
  125. Vector2I screenToWindowPos(const Vector2I& screenPos) const;
  126. /**
  127. * @copydoc RenderWindow::windowToScreenPos
  128. */
  129. Vector2I windowToScreenPos(const Vector2I& windowPos) const;
  130. /**
  131. * @copydoc RenderWindow::getCore
  132. */
  133. SPtr<Win32WindowCore> getCore() const;
  134. protected:
  135. friend class GLRenderWindowManager;
  136. friend class Win32GLSupport;
  137. friend class Win32WindowCore;
  138. Win32Window(const RENDER_WINDOW_DESC& desc, Win32GLSupport& glsupport);
  139. /**
  140. * @copydoc RenderWindowCore::getProperties
  141. */
  142. const RenderTargetProperties& getPropertiesInternal() const { return mProperties; }
  143. /**
  144. * @brief Retrieves internal window handle.
  145. */
  146. HWND getHWnd() const;
  147. private:
  148. Win32GLSupport& mGLSupport;
  149. Win32RenderWindowProperties mProperties;
  150. };
  151. }