BsWin32Window.h 3.9 KB

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