8#ifndef MALENA_APPMANAGER_H
9#define MALENA_APPMANAGER_H
16#include <SFML/Graphics.hpp>
126 Architecture _architecture;
129 bool _paused {
false };
132 sf::VideoMode _videoMode;
134 std::uint32_t _windowStyle;
135 unsigned int _framerateLimit { 60 };
137 std::function<void()> _preRenderHook;
138 std::function<void()> _postRenderHook;
139 std::function<bool()> _closeHandler;
140 std::function<void(
unsigned int,
unsigned int)> _resizeHandler;
143 inline static bool _isDrawing =
false;
144 inline static float _deltaTime = 0.f;
145 inline static AppManager* _instance =
nullptr;
146 inline static Core* _exclusiveOwner =
nullptr;
147 inline static std::vector<std::function<void()>> _deferredUnloads;
168 const std::string& title,
312 void onResize(std::function<
void(
unsigned int,
unsigned int)> handler);
335 static bool isDrawing() {
return _isDrawing; }
337 static bool isUnderExclusiveOwner(Core* component);
339 static void deferUnload(std::function<
void()> op)
341 _deferredUnloads.push_back(std::move(op));
351 static AppManager& get() {
return *_instance; }
355 void fireInputEvents(
const std::optional<sf::Event>& event);
356 void fireUpdateEvents();
358 void flushDeferredUnloads();
void setVSync(bool enabled)
Enable or disable vertical synchronisation.
static Core * exclusiveOwner()
The current exclusive-interaction owner, or nullptr.
void onPostRender(std::function< void()> hook)
Register a callback invoked after all components are drawn and before display().
Architecture
Architectural style hint passed at construction.
@ EDA
Event-Driven Architecture.
@ ECS
Entity-Component-System.
@ MVC
Model-View-Controller.
void run()
Enter the main loop and run until the window is closed.
void onPreRender(std::function< void()> hook)
Register a callback invoked after clear() and before drawing components.
void setIcon(const sf::Image &icon)
Set the window icon from an sf::Image.
static float getDeltaTime()
Return the elapsed time of the previous frame in seconds.
bool isPaused() const
Return true if the application is currently paused.
void resume()
Resume update events after a pause().
void setBackgroundColor(sf::Color color)
Set the colour used to clear the window at the start of each frame.
void pause()
Suspend per-frame update events.
static void clearExclusiveOwner()
Lift any active exclusive-owner restriction.
void onClose(std::function< bool()> handler)
Register a callback invoked when the OS close button is pressed.
void setFramerateLimit(unsigned int limit)
Cap the frame rate.
void setTitle(const std::string &title)
Change the window title at runtime.
Architecture getArchitecture() const
Return the architectural mode set at construction.
static void setExclusiveOwner(Core *owner)
Restrict click and hover dispatch to owner and its descendants. Any component outside that subtree si...
void setWindowPosition(int x, int y)
Move the window to a position on the desktop.
virtual ~AppManager()=default
void setWindowStyle(std::uint32_t style)
Recreate the window with new decoration-style flags.
AppManager(const sf::VideoMode &videoMode, const std::string &title, sf::RenderWindow &window=WindowManager::getWindow(), Architecture architecture=MVC, std::uint32_t windowStyle=sf::Style::Default)
Construct an AppManager and create the SFML window.
void onResize(std::function< void(unsigned int, unsigned int)> handler)
Register a callback invoked whenever the window is resized.
Virtual base class for all Malena framework objects.
Static, type-safe collection manager for Core-derived objects.
Trait that adds one-time initialization lifecycle hooks to any class.
sf::RenderWindow & getWindow()
Return the framework's shared sf::RenderWindow.