BsWin32Window.h 5.5 KB

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