BsMacOSPlatform.h 4.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116
  1. //********************************** Banshee Engine (www.banshee3d.com) **************************************************//
  2. //**************** Copyright (c) 2017 Marko Pintera ([email protected]). All rights reserved. **********************//
  3. #pragma once
  4. #include "Platform/BsPlatform.h"
  5. #include "RenderAPI/BsRenderWindow.h"
  6. // Don't include macOS frameworks when generating script bindings, as it can't find them
  7. #ifndef BS_SBGEN
  8. #include <Cocoa/Cocoa.h>
  9. #endif
  10. namespace bs
  11. {
  12. // Forward declare Cocoa types for SBGen purposes, since we didn't include Cocoa.h above
  13. #if BS_SBGEN
  14. class NSImage;
  15. class NSCursor;
  16. class NSScreen;
  17. class NSWindow;
  18. struct NSRect;
  19. struct NSPoint;
  20. #endif
  21. class CocoaWindow;
  22. /** @addtogroup Platform-Internal
  23. * @{
  24. */
  25. /** Contains various macOS specific platform functionality. */
  26. class BS_CORE_EXPORT MacOSPlatform : public Platform
  27. {
  28. public:
  29. /** Notifies the system that a new window was created. */
  30. static void registerWindow(CocoaWindow* window);
  31. /** Notifies the system that a window is about to be destroyed. */
  32. static void unregisterWindow(CocoaWindow* window);
  33. /**
  34. * Locks the access to the list of CocoaWindows ensuring no new windows can be created or destroyed. This must be
  35. * called any time CocoaWindow is being used outside of the main thread to ensure the window doesn't get destroyed
  36. * while being in use. Needs to be followed by unlockWindows().
  37. */
  38. static void lockWindows();
  39. /** Releases the lock acquires by lockWindows(). */
  40. static void unlockWindows();
  41. /**
  42. * Returns a window based on its ID. Returns null if window cannot be found. Expects the caller to lock windows
  43. * using lockWindows() in case this is called from non-main thread.
  44. */
  45. static CocoaWindow* getWindow(UINT32 windowId);
  46. /** Generates a Cocoa image from the provided pixel data. */
  47. static NSImage* createNSImage(const PixelData& data);
  48. /** Sends an event notifying the system that a key corresponding to an input command was pressed. */
  49. static void sendInputCommandEvent(InputCommandType inputCommand);
  50. /** Sends an event notifying the system that the user typed some text. */
  51. static void sendCharInputEvent(UINT32 character);
  52. /** Sends an event notifying the system that a pointer button was pressed. */
  53. static void sendPointerButtonPressedEvent(
  54. const Vector2I& pos,
  55. OSMouseButton button,
  56. const OSPointerButtonStates& buttonStates);
  57. /** Sends an event notifying the system that a pointer button was released. */
  58. static void sendPointerButtonReleasedEvent(
  59. const Vector2I& pos,
  60. OSMouseButton button,
  61. const OSPointerButtonStates& buttonStates);
  62. /** Sends an event notifying the system that the user clicked the left pointer button twice in quick succession. */
  63. static void sendPointerDoubleClickEvent(const Vector2I& pos, const OSPointerButtonStates& buttonStates);
  64. /** Sends an event notifying the system that the pointer moved. */
  65. static void sendPointerMovedEvent(const Vector2I& pos, const OSPointerButtonStates& buttonStates);
  66. /** Sends an event notifying the system the user has scrolled the mouse wheel. */
  67. static void sendMouseWheelScrollEvent(float delta);
  68. /** Notifies the system that some window-related event has occurred. */
  69. static void notifyWindowEvent(WindowEventType type, UINT32 windowId);
  70. /** Returns the currently assigned custom cursor. */
  71. static NSCursor* _getCurrentCursor();
  72. /**
  73. * Clips the cursor position to clip bounds, if clipping is enabled. Returns true if clipping occured, and updates
  74. * @p pos to the clipped position.
  75. */
  76. static bool _clipCursor(Vector2I& pos);
  77. /** Updates clip bounds that depend on window size. Should be called after window size changes. */
  78. static void _updateClipBounds(NSWindow* window);
  79. /** Moves the cursor to the specified position in screen coordinates. */
  80. static void _setCursorPosition(const Vector2I& position);
  81. };
  82. /** Converts an area in screen space with bottom left origin, to top left origin. */
  83. void flipY(NSScreen* screen, NSRect& rect);
  84. /** Converts a point in screen space with bottom left origin, to top left origin. */
  85. void flipY(NSScreen* screen, NSPoint &point);
  86. /** Converts a point in window space with bottom left origin, to top left origin. */
  87. void flipYWindow(NSWindow* window, NSPoint &point);
  88. /** @} */
  89. }