BsMacOSPlatform.h 3.1 KB

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