Loading...
Searching...
No Matches
Updatable.h
Go to the documentation of this file.
1// Copyright (c) 2025 Dave R. Smith. All rights reserved.
2// Malena Framework — Proprietary Software. See LICENSE for terms.
3
4//
5// Updatable.h
6//
7
8#pragma once
13#include <functional>
14#include <optional>
15#include <SFML/Window/Event.hpp>
16
17namespace ml
18{
61 {
62 public:
63 // ── Per-frame ─────────────────────────────────────────────────────────
64
73 void onUpdate(std::function<void()> callback);
74
84 void onUpdate(std::function<void(const std::optional<sf::Event>&)> callback);
85
86 // ── Window events ─────────────────────────────────────────────────────
87
94 void onWindowResized(std::function<void()> callback);
95
102 void onWindowResized(std::function<void(const std::optional<sf::Event>&)> callback);
103
110 void onWindowFocusGained(std::function<void()> callback);
111
118 void onWindowFocusGained(std::function<void(const std::optional<sf::Event>&)> callback);
119
126 void onWindowFocusLost(std::function<void()> callback);
127
134 void onWindowFocusLost(std::function<void(const std::optional<sf::Event>&)> callback);
135 };
136
138 class MALENA_API UpdatableDispatcher : public FrameDispatcher
139 {
140 public:
141 bool filter(const std::optional<sf::Event>& event, Core* component) override { return true; }
142 void fire() override;
143 bool occurred() override { return true; }
144 };
146
147} // namespace ml
148
149ML_EXPORT(UpdatableDispatcher)
#define ML_EXPORT(ClassName)
Register a Malena type with the framework.
Definition Export.h:43
Virtual base class for all Malena framework objects.
Definition Core.h:69
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:61
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.
#define MALENA_API
Definition Component.h:22