BsWin32Window.h 5.5 KB

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