ApplicationWindow.h 1.2 KB

1234567891011121314151617181920212223242526272829303132333435363738
  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 <functional>
  6. // Responsible for opening the main window
  7. class ApplicationWindow
  8. {
  9. public:
  10. /// Destructor
  11. virtual ~ApplicationWindow() = default;
  12. /// Initialize the window
  13. virtual void Initialize() = 0;
  14. /// Get window size
  15. int GetWindowWidth() { return mWindowWidth; }
  16. int GetWindowHeight() { return mWindowHeight; }
  17. /// Set callback when the window resizes
  18. using WindowResizeListener = std::function<void()>;
  19. void SetWindowResizeListener(const WindowResizeListener &inListener) { mWindowResizeListener = inListener; }
  20. /// Enter the main loop and keep rendering frames until the window is closed
  21. using RenderCallback = std::function<bool()>;
  22. virtual void MainLoop(RenderCallback inRenderCallback) = 0;
  23. /// Function that will trigger the callback
  24. void OnWindowResized(int inWidth, int inHeight) { mWindowWidth = inWidth; mWindowHeight = inHeight; mWindowResizeListener(); }
  25. protected:
  26. int mWindowWidth = 1920;
  27. int mWindowHeight = 1080;
  28. WindowResizeListener mWindowResizeListener;
  29. };