BsWin32Window.h 4.0 KB

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