BsMacOSPlatform.h 3.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899
  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. // Don't include macOS frameworks when generating script bindings, as it can't find them
  6. #ifndef BS_SBGEN
  7. #include <Cocoa/Cocoa.h>
  8. #endif
  9. namespace bs
  10. {
  11. // Forward declare Cocoa types for SBGen purposes, since we didn't include Cocoa.h above
  12. #if BS_SBGEN
  13. class NSImage;
  14. class NSCursor;
  15. class NSScreen;
  16. class NSWindow;
  17. struct NSRect;
  18. struct NSPoint;
  19. #endif
  20. class CocoaWindow;
  21. /** @addtogroup Platform-Internal
  22. * @{
  23. */
  24. /** Contains various macOS specific platform functionality. */
  25. class BS_CORE_EXPORT MacOSPlatform : public Platform
  26. {
  27. public:
  28. /** Notifies the system that a new window was created. */
  29. static void registerWindow(CocoaWindow* window);
  30. /** Notifies the system that a window is about to be destroyed. */
  31. static void unregisterWindow(CocoaWindow* window);
  32. /** Generates a Cocoa image from the provided pixel data. */
  33. static NSImage* createNSImage(const PixelData& data);
  34. /** Sends an event notifying the system that a key corresponding to an input command was pressed. */
  35. static void sendInputCommandEvent(InputCommandType inputCommand);
  36. /** Sends an event notifying the system that the user typed some text. */
  37. static void sendCharInputEvent(UINT32 character);
  38. /** Sends an event notifying the system that a pointer button was pressed. */
  39. static void sendPointerButtonPressedEvent(
  40. const Vector2I& pos,
  41. OSMouseButton button,
  42. const OSPointerButtonStates& buttonStates);
  43. /** Sends an event notifying the system that a pointer button was released. */
  44. static void sendPointerButtonReleasedEvent(
  45. const Vector2I& pos,
  46. OSMouseButton button,
  47. const OSPointerButtonStates& buttonStates);
  48. /** Sends an event notifying the system that the user clicked the left pointer button twice in quick succession. */
  49. static void sendPointerDoubleClickEvent(const Vector2I& pos, const OSPointerButtonStates& buttonStates);
  50. /** Sends an event notifying the system that the pointer moved. */
  51. static void sendPointerMovedEvent(const Vector2I& pos, const OSPointerButtonStates& buttonStates);
  52. /** Sends an event notifying the system the user has scrolled the mouse wheel. */
  53. static void sendMouseWheelScrollEvent(float delta);
  54. /** Notifies the system that some window-related event has occurred. */
  55. static void notifyWindowEvent(WindowEventType type, UINT32 windowId);
  56. /** Returns the currently assigned custom cursor. */
  57. static NSCursor* _getCurrentCursor();
  58. /**
  59. * Clips the cursor position to clip bounds, if clipping is enabled. Returns true if clipping occured, and updates
  60. * @p pos to the clipped position.
  61. */
  62. static bool _clipCursor(Vector2I& pos);
  63. /** Updates clip bounds that depend on window size. Should be called after window size changes. */
  64. static void _updateClipBounds(NSWindow* window);
  65. /** Moves the cursor to the specified position in screen coordinates. */
  66. static void _setCursorPosition(const Vector2I& position);
  67. };
  68. /** Converts an area in screen space with bottom left origin, to top left origin. */
  69. void flipY(NSScreen* screen, NSRect& rect);
  70. /** Converts a point in screen space with bottom left origin, to top left origin. */
  71. void flipY(NSScreen* screen, NSPoint &point);
  72. /** Converts a point in window space with bottom left origin, to top left origin. */
  73. void flipYWindow(NSWindow* window, NSPoint &point);
  74. /** @} */
  75. }