BsWin32Window.h 5.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144
  1. //********************************** Banshee Engine (www.banshee3d.com) **************************************************//
  2. //**************** Copyright (c) 2016 Marko Pintera ([email protected]). All rights reserved. **********************//
  3. #pragma once
  4. #include "Prerequisites/BsPrerequisitesUtil.h"
  5. #include "Math/BsVector2I.h"
  6. #include "windows.h"
  7. namespace bs
  8. {
  9. /** @addtogroup Internal-Utility
  10. * @{
  11. */
  12. /** @addtogroup Platform-Utility-Internal
  13. * @{
  14. */
  15. /** Descriptor used for creating a platform specific native window. */
  16. struct BS_UTILITY_EXPORT WINDOW_DESC
  17. {
  18. WINDOW_DESC()
  19. : module(nullptr), monitor(nullptr), parent(nullptr), external(nullptr), creationParams(nullptr), width(0)
  20. , height(0), fullscreen(false), hidden(false), left(-1), top(-1), title(""), showTitleBar(true)
  21. , showBorder(true), allowResize(true), outerDimensions(false), enableDoubleClick(true)
  22. , toolWindow(false), backgroundPixels(nullptr), backgroundWidth(0), backgroundHeight(0)
  23. , alphaBlending(false), modal(false), wndProc(nullptr)
  24. { }
  25. HINSTANCE module; /**< Instance to the local module. */
  26. HMONITOR monitor; /**< Handle ot the monitor onto which to display the window. */
  27. HWND parent; /**< Optional handle to the parent window if this window is to be a child of an existing window. */
  28. HWND external; /**< Optional external window handle if the window was created externally. */
  29. void* creationParams; /**< Parameter that will be passed through the WM_CREATE message. */
  30. UINT32 width; /**< Width of the window in pixels. */
  31. UINT32 height; /**< Height of the window in pixels. */
  32. bool fullscreen; /**< Should the window be opened in fullscreen mode. */
  33. bool hidden; /**< Should the window be hidden initially. */
  34. INT32 left; /**< Window origin on X axis in pixels. -1 == screen center. Relative to provided monitor. */
  35. INT32 top; /**< Window origin on Y axis in pixels. -1 == screen center. Relative to provided monitor. */
  36. String title; /**< Title of the window. */
  37. bool showTitleBar; /**< Determines if the title-bar should be shown or not. */
  38. bool showBorder; /**< Determines if the window border should be shown or not. */
  39. bool allowResize; /**< Determines if the user can resize the window by dragging on the window edges. */
  40. bool outerDimensions; /**< Do our dimensions include space for things like title-bar and border. */
  41. bool enableDoubleClick; /**< Does window accept double-clicks. */
  42. bool toolWindow; /**< Tool windows have a different look than normal windows and have no task bar entry. */
  43. /**
  44. * Optional background image to apply to the window. This must be a buffer of size
  45. * backgroundWidth * backgroundHeight.
  46. */
  47. Color* backgroundPixels;
  48. UINT32 backgroundWidth; /** Width of the background image. Only relevant if backgroundPixels is not null. */
  49. UINT32 backgroundHeight; /** Width of the background image. Only relevant if backgroundPixels is not null. */
  50. /** If true the window will support transparency based on the alpha channel of the background image. */
  51. bool alphaBlending;
  52. bool modal; /**< When a modal window is open all other windows will be locked until modal window is closed. */
  53. WNDPROC wndProc; /**< Pointer to a function that handles windows message processing. */
  54. };
  55. /** Represents a Windows native window. */
  56. class BS_UTILITY_EXPORT Win32Window
  57. {
  58. public:
  59. Win32Window(const WINDOW_DESC& desc);
  60. ~Win32Window();
  61. /** Returns position of the left-most border of the window, relative to the screen. */
  62. INT32 getLeft() const;
  63. /** Returns position of the top-most border of the window, relative to the screen. */
  64. INT32 getTop() const;
  65. /** Returns width of the window in pixels. */
  66. UINT32 getWidth() const;
  67. /** Returns height of the window in pixels. */
  68. UINT32 getHeight() const;
  69. /** Returns the native window handle. */
  70. HWND getHWnd() const;
  71. /** Hide or show the window. */
  72. void setHidden(bool hidden);
  73. /** Restores or minimizes the window. */
  74. void setActive(bool state);
  75. /** Minimizes the window to the taskbar. */
  76. void minimize();
  77. /** Maximizes the window over the entire current screen. */
  78. void maximize();
  79. /** Restores the window to original position and size if it is minimized or maximized. */
  80. void restore();
  81. /** Change the size of the window. */
  82. void resize(UINT32 width, UINT32 height);
  83. /** Reposition the window. */
  84. void move(INT32 left, INT32 top);
  85. /** Converts screen position into window local position. */
  86. Vector2I screenToWindowPos(const Vector2I& screenPos) const;
  87. /** Converts window local position to screen position. */
  88. Vector2I windowToScreenPos(const Vector2I& windowPos) const;
  89. /** Returns the window style flags used for creating it. */
  90. DWORD getStyle() const;
  91. /** Returns the extended window style flags used for creating it. */
  92. DWORD getStyleEx() const;
  93. /** Called when window is moved or resized externally. */
  94. void _windowMovedOrResized();
  95. /**
  96. * Enables all open windows. Enabled windows can receive mouse and keyboard input. This includes even windows
  97. * disabled because there is a modal window on top of them.
  98. */
  99. void static _enableAllWindows();
  100. /**
  101. * Restores disabled state of all windows that were disabled due to modal windows being on top of them. Companion
  102. * method to _enableAllWindows() that can help restore original state after it is called.
  103. */
  104. void static _restoreModalWindows();
  105. private:
  106. friend class Win32WindowManager;
  107. struct Pimpl;
  108. Pimpl* m;
  109. static Vector<Win32Window*> sAllWindows;
  110. static Vector<Win32Window*> sModalWindowStack;
  111. static Mutex sWindowsMutex;
  112. };
  113. /** @} */
  114. /** @} */
  115. }