BsWin32Window.h 4.2 KB

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