Loading...
Searching...
No Matches
Updatable.h
Go to the documentation of this file.
1//
2// Updatable.h
3//
4
5#pragma once
9#include <functional>
10#include <optional>
11#include <SFML/Window/Event.hpp>
12
13namespace ml
14{
56 class Updatable : public EventReceiver
57 {
58 public:
59 // ── Per-frame ─────────────────────────────────────────────────────────
60
69 void onUpdate(std::function<void()> callback);
70
80 void onUpdate(std::function<void(const std::optional<sf::Event>&)> callback);
81
82 // ── Window events ─────────────────────────────────────────────────────
83
90 void onWindowResized(std::function<void()> callback);
91
98 void onWindowResized(std::function<void(const std::optional<sf::Event>&)> callback);
99
106 void onWindowFocusGained(std::function<void()> callback);
107
114 void onWindowFocusGained(std::function<void(const std::optional<sf::Event>&)> callback);
115
122 void onWindowFocusLost(std::function<void()> callback);
123
130 void onWindowFocusLost(std::function<void(const std::optional<sf::Event>&)> callback);
131 };
132
134 class UpdatableDispatcher : public FrameDispatcher
135 {
136 public:
137 bool filter(const std::optional<sf::Event>& event, Core* component) override { return true; }
138 void fire() override;
139 bool occurred() override { return true; }
140 };
142
143} // namespace ml
144
145ML_EXPORT(UpdatableDispatcher)
#define ML_EXPORT(ClassName)
Register a Malena type with the framework.
Definition Export.h:38
Virtual base class for all Malena framework objects.
Definition Core.h:67
Base class for all event-receiving traits.
Base class for per-frame dispatchers in the Malena event system.
Trait that adds per-frame update and window lifecycle callbacks to any Core object.
Definition Updatable.h:57
void onUpdate(std::function< void(const std::optional< sf::Event > &)> callback)
Register a callback invoked every frame, receiving the SFML event.
void onWindowFocusGained(std::function< void(const std::optional< sf::Event > &)> callback)
Register a callback invoked when the application window gains OS focus, receiving the raw SFML event.
void onWindowFocusGained(std::function< void()> callback)
Register a no-argument callback invoked when the application window gains OS focus.
void onUpdate(std::function< void()> callback)
Register a no-argument callback invoked every frame.
void onWindowResized(std::function< void(const std::optional< sf::Event > &)> callback)
Register a callback invoked when the application window is resized, receiving the raw SFML event.
void onWindowFocusLost(std::function< void(const std::optional< sf::Event > &)> callback)
Register a callback invoked when the application window loses OS focus, receiving the raw SFML event.
void onWindowResized(std::function< void()> callback)
Register a no-argument callback invoked when the application window is resized.
void onWindowFocusLost(std::function< void()> callback)
Register a no-argument callback invoked when the application window loses OS focus.
Definition Component.h:18