BsMacOSWindow.h 4.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158
  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. /** Returns the current area of the window, relative to the screen. */
  61. Rect2I getArea() const;
  62. /** Hides the window. */
  63. void hide();
  64. /** Shows (unhides) the window. */
  65. void show();
  66. /** Minimizes the window. */
  67. void minimize();
  68. /** Maximizes the window over the entire current screen. */
  69. void maximize();
  70. /** Restores the window to original position and size if it is minimized or maximized. */
  71. void restore();
  72. /** Change the size of the window. */
  73. void resize(UINT32 width, UINT32 height);
  74. /** Reposition the window. */
  75. void move(INT32 left, INT32 top);
  76. /** Switches from fullscreen to windowed mode. */
  77. void setWindowed();
  78. /** Switches from windowed to fullscreen mode. */
  79. void setFullscreen();
  80. /** Converts screen position into window local position. */
  81. Vector2I screenToWindowPos(const Vector2I& screenPos) const;
  82. /** Converts window local position to screen position. */
  83. Vector2I windowToScreenPos(const Vector2I& windowPos) const;
  84. /**
  85. * @name Internal
  86. * @{
  87. */
  88. /**
  89. * Destroys the window, cleaning up any resources and removing it from the display. No further methods should be
  90. * called on this object after it has been destroyed.
  91. */
  92. void _destroy();
  93. /**
  94. * Sets a portion of the window in which the user can click and drag in order to move the window. This is needed
  95. * when window has no title bar, yet you still want to allow the user to drag it by clicking on some specific area
  96. * (e.g. a title bar you manually render).
  97. *
  98. * @param[in] rects Areas of the window (relative to the window origin in top-left corner) in which the drag
  99. * operation in allowed.
  100. */
  101. void _setDragZones(const Vector<Rect2I>& rects);
  102. /** Attaches non-specific user data that can later be retrieved through _getUserData(). */
  103. void _setUserData(void* data);
  104. /** Returns user data attached to the object when _setUserData was called. */
  105. void* _getUserData() const;
  106. /**
  107. * Registers the window with the drag and drop manager and allows it to accept file drop operations. Each call
  108. * to this method must eventually be followed with _unregisterForDragAndDrop.
  109. */
  110. void _registerForDragAndDrop();
  111. /**
  112. * Unregisters the window from the drag and drop manager. This will need to be called multiple times if
  113. * _registerForDragAndDrop was called multiple times.
  114. */
  115. void _unregisterForDragAndDrop();
  116. /** Returns internal private data for use by friends. */
  117. Pimpl* _getPrivateData() const { return m; }
  118. /** @} */
  119. private:
  120. Pimpl* m;
  121. };
  122. /** @} */
  123. /** @} */
  124. }