BsMacOSWindow.h 4.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166
  1. //********************************** Banshee Engine (www.banshee3d.com) **************************************************//
  2. //**************** Copyright (c) 2017 Marko Pintera ([email protected]). All rights reserved. **********************//
  3. #pragma once
  4. #include "Prerequisites/BsPrerequisitesUtil.h"
  5. #include "Math/BsVector2I.h"
  6. #ifdef BS_COCOA_INTERNALS
  7. #import <Cocoa/Cocoa.h>
  8. #endif
  9. #ifdef BS_COCOA_INTERNALS
  10. @class BSWindowDelegate;
  11. @class BSWindowListener;
  12. @class BSView;
  13. #endif
  14. namespace bs
  15. {
  16. class CocoaDropTarget;
  17. /** @addtogroup Internal-Utility
  18. * @{
  19. */
  20. /** @addtogroup Platform-Utility-Internal
  21. * @{
  22. */
  23. /** Descriptor used for creating a platform specific native window. */
  24. struct WINDOW_DESC
  25. {
  26. String title;
  27. INT32 x = -1;
  28. INT32 y = -1;
  29. UINT32 width = 20;
  30. UINT32 height = 20;
  31. bool showDecorations = true;
  32. bool allowResize = true;
  33. bool modal = false;
  34. SPtr<PixelData> background;
  35. };
  36. /** Represents a Cocoa window. */
  37. class BS_UTILITY_EXPORT CocoaWindow
  38. {
  39. public:
  40. #ifdef BS_COCOA_INTERNALS
  41. struct Pimpl
  42. {
  43. NSWindow* window;
  44. BSView* view;
  45. BSWindowListener* responder;
  46. BSWindowDelegate* delegate;
  47. NSUInteger style = 0;
  48. NSInteger windowNumber = 0;
  49. bool isFullscreen = false;
  50. NSRect windowedRect;
  51. bool isModal = false;
  52. UINT32 numDropTargets = 0;
  53. void* userData = nullptr;
  54. };
  55. #else
  56. struct Pimpl;
  57. #endif
  58. CocoaWindow(const WINDOW_DESC& desc);
  59. ~CocoaWindow();
  60. /**
  61. * Returns the current area of the window, relative to the screen.
  62. *
  63. * @param[in] topLeftOrigin If true the coordinates will use a top-left origin coordinate system (engine native).
  64. * If false the coordinates will use a bottom-left origin (Cocoa native).
  65. */
  66. Rect2I getArea(bool topLeftOrigin = true) const;
  67. /** Hides the window. */
  68. void hide();
  69. /** Shows (unhides) the window. */
  70. void show();
  71. /** Minimizes the window. */
  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. /** Switches from fullscreen to windowed mode. */
  82. void setWindowed();
  83. /** Switches from windowed to fullscreen mode. */
  84. void setFullscreen();
  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. /**
  90. * @name Internal
  91. * @{
  92. */
  93. /**
  94. * Destroys the window, cleaning up any resources and removing it from the display. No further methods should be
  95. * called on this object after it has been destroyed.
  96. */
  97. void _destroy();
  98. /**
  99. * Sets a portion of the window in which the user can click and drag in order to move the window. This is needed
  100. * when window has no title bar, yet you still want to allow the user to drag it by clicking on some specific area
  101. * (e.g. a title bar you manually render).
  102. *
  103. * @param[in] rects Areas of the window (relative to the window origin in top-left corner) in which the drag
  104. * operation in allowed.
  105. */
  106. void _setDragZones(const Vector<Rect2I>& rects);
  107. /** Attaches non-specific user data that can later be retrieved through _getUserData(). */
  108. void _setUserData(void* data);
  109. /** Returns user data attached to the object when _setUserData was called. */
  110. void* _getUserData() const;
  111. /**
  112. * Registers the window with the drag and drop manager and allows it to accept file drop operations. Each call
  113. * to this method must eventually be followed with _unregisterForDragAndDrop.
  114. */
  115. void _registerForDragAndDrop();
  116. /**
  117. * Unregisters the window from the drag and drop manager. This will need to be called multiple times if
  118. * _registerForDragAndDrop was called multiple times.
  119. */
  120. void _unregisterForDragAndDrop();
  121. /** Returns the area of the screen that the window currently occupies, in Cocoa screen coordinates. */
  122. Rect2I _getScreenArea() const;
  123. /** Returns internal private data for use by friends. */
  124. Pimpl* _getPrivateData() const { return m; }
  125. /** @} */
  126. private:
  127. Pimpl* m;
  128. };
  129. /** @} */
  130. /** @} */
  131. }