2
0

ApplicationWindowMacOS.h 1.4 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647
  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 MTKView;
  8. @class CAMetalLayer;
  9. #else
  10. typedef void MTKView;
  11. typedef void CAMetalLayer;
  12. #endif
  13. // Responsible for opening the main window
  14. class ApplicationWindowMacOS : public ApplicationWindow
  15. {
  16. public:
  17. /// Destructor
  18. virtual ~ApplicationWindowMacOS() override;
  19. /// Initialize the window
  20. virtual void Initialize(const char *inTitle) override;
  21. /// Access to the metal objects
  22. MTKView * GetMetalView() const { return mMetalView; }
  23. CAMetalLayer * GetMetalLayer() const;
  24. /// Enter the main loop and keep rendering frames until the window is closed
  25. virtual void MainLoop(RenderCallback inRenderCallback) override;
  26. /// Call the render callback
  27. bool RenderCallback() { return mRenderCallback && mRenderCallback(); }
  28. /// Subscribe to mouse move callbacks that supply window coordinates
  29. using MouseMovedCallback = function<void(int, int)>;
  30. void SetMouseMovedCallback(MouseMovedCallback inCallback) { mMouseMovedCallback = inCallback; }
  31. void OnMouseMoved(int inX, int inY) { mMouseMovedCallback(inX, inY); }
  32. protected:
  33. MTKView * mMetalView = nullptr;
  34. ApplicationWindow::RenderCallback mRenderCallback;
  35. MouseMovedCallback mMouseMovedCallback;
  36. };