ApplicationWindowMacOS.h 1.2 KB

1234567891011121314151617181920212223242526272829303132333435363738394041
  1. // Jolt Physics Library (https://github.com/jrouwe/JoltPhysics)
  2. // SPDX-FileCopyrightText: 2024 Jorrit Rouwe
  3. // SPDX-License-Identifier: MIT
  4. #pragma once
  5. #include <Window/ApplicationWindow.h>
  6. #ifdef __OBJC__
  7. @class CAMetalLayer;
  8. #else
  9. typedef void CAMetalLayer;
  10. #endif
  11. // Responsible for opening the main window
  12. class ApplicationWindowMacOS : public ApplicationWindow
  13. {
  14. public:
  15. /// Initialize the window
  16. virtual void Initialize() override;
  17. /// Access to the metal layer
  18. CAMetalLayer * GetMetalLayer() const { return mMetalLayer; }
  19. /// Enter the main loop and keep rendering frames until the window is closed
  20. virtual void MainLoop(RenderCallback inRenderCallback) override;
  21. /// Call the render callback
  22. bool RenderCallback() { return mRenderCallback(); }
  23. /// Subscribe to mouse move callbacks that supply window coordinates
  24. using MouseMovedCallback = function<void(int, int)>;
  25. void SetMouseMovedCallback(MouseMovedCallback inCallback) { mMouseMovedCallback = inCallback; }
  26. void OnMouseMoved(int inX, int inY) { mMouseMovedCallback(inX, inY); }
  27. protected:
  28. CAMetalLayer * mMetalLayer = nullptr;
  29. ApplicationWindow::RenderCallback mRenderCallback;
  30. MouseMovedCallback mMouseMovedCallback;
  31. };