BsWin32Window.h 4.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141
  1. #pragma once
  2. #include "BsCorePrerequisites.h"
  3. #include "BsVector2I.h"
  4. #include "windows.h"
  5. namespace BansheeEngine
  6. {
  7. /**
  8. * @brief Descriptor used for creating a platform specific native window.
  9. */
  10. struct BS_CORE_EXPORT WINDOW_DESC
  11. {
  12. WINDOW_DESC()
  13. : module(nullptr), monitor(nullptr), parent(nullptr), external(nullptr), width(0), height(0), fullscreen(false)
  14. , hidden(false), left(-1), top(-1), title(""), border(WindowBorder::Normal), outerDimensions(false)
  15. , enableDoubleClick(true), toolWindow(false), creationParams(nullptr), alphaBlending(false)
  16. { }
  17. HINSTANCE module; /**< Instance to the local module. */
  18. HMONITOR monitor; /**< Handle ot the monitor onto which to display the window. */
  19. HWND parent; /**< Optional handle to the parent window if this window is to be a child of an existing window. */
  20. HWND external; /**< Optional external window handle if the window was created externally. */
  21. void* creationParams; /**< Parameter that will be passed through the WM_CREATE message. */
  22. UINT32 width; /**< Width of the window in pixels. */
  23. UINT32 height; /**< Height of the window in pixels. */
  24. bool fullscreen; /**< Should the window be opened in fullscreen mode. */
  25. bool hidden; /**< Should the window be hidden initially. */
  26. INT32 left; /**< Window origin on X axis in pixels. -1 == screen center. Relative to provided monitor. */
  27. INT32 top; /**< Window origin on Y axis in pixels. -1 == screen center. Relative to provided monitor. */
  28. String title; /**< Title of the window. */
  29. WindowBorder border; /**< Type of border to create the window with. */
  30. bool outerDimensions; /**< Do our dimensions include space for things like title-bar and border. */
  31. bool enableDoubleClick; /**< Does window accept double-clicks. */
  32. bool toolWindow; /**< Tool windows have a different style than normal windows and can be created with no border or title bar. */
  33. PixelDataPtr background; /**< Optional background image to apply to the window. */
  34. bool alphaBlending; /**< If true the window will support transparency based on the alpha channel of the background image. */
  35. };
  36. /**
  37. * @brief Represents a Windows native window.
  38. */
  39. class BS_CORE_EXPORT Win32Window
  40. {
  41. public:
  42. Win32Window(const WINDOW_DESC& desc);
  43. ~Win32Window();
  44. /**
  45. * @brief Returns position of the left-most border of the window, relative to the screen.
  46. */
  47. INT32 getLeft() const;
  48. /**
  49. * @brief Returns position of the top-most border of the window, relative to the screen.
  50. */
  51. INT32 getTop() const;
  52. /**
  53. * @brief Returns width of the window in pixels.
  54. */
  55. UINT32 getWidth() const;
  56. /**
  57. * @brief Returns height of the window in pixels.
  58. */
  59. UINT32 getHeight() const;
  60. /**
  61. * @brief Returns the native window handle.
  62. */
  63. HWND getHWnd() const;
  64. /**
  65. * @brief Hide or show the window.
  66. */
  67. void setHidden(bool hidden);
  68. /**
  69. * @brief Restores or minimizes the window.
  70. */
  71. void setActive(bool state);
  72. /**
  73. * @brief Minimizes the window to the taskbar.
  74. */
  75. void minimize();
  76. /**
  77. * @brief Maximizes the window over the entire current screen.
  78. */
  79. void maximize();
  80. /**
  81. * @brief Restores the window to original position and size if it is
  82. * minimized or maximized.
  83. */
  84. void restore();
  85. /**
  86. * @brief Change the size of the window.
  87. */
  88. void resize(UINT32 width, UINT32 height);
  89. /**
  90. * @brief Reposition the window.
  91. */
  92. void move(INT32 left, INT32 top);
  93. /**
  94. * @brief Converts screen position into window local position.
  95. */
  96. Vector2I screenToWindowPos(const Vector2I& screenPos) const;
  97. /**
  98. * @brief Converts window local position to screen position.
  99. */
  100. Vector2I windowToScreenPos(const Vector2I& windowPos) const;
  101. /**
  102. * @brief Returns the window style flags used for creating it.
  103. */
  104. DWORD getStyle() const;
  105. /**
  106. * @brief Returns the extended window style flags used for creating it.
  107. */
  108. DWORD getStyleEx() const;
  109. /**
  110. * @brief Called when window is moved or resized externally.
  111. *
  112. * @note Internal method.
  113. */
  114. void _windowMovedOrResized();
  115. private:
  116. struct Pimpl;
  117. Pimpl* m;
  118. };
  119. }