Loading...
Searching...
No Matches
Updatable.h
Go to the documentation of this file.
1// Copyright (c) 2025 Dave R. Smith.
2// Malena Framework — Licensed under PolyForm Noncommercial 1.0.0; commercial use requires a paid license. See LICENSE.
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
74 void onUpdate(std::function<void()> callback, bool overwrite = false);
75
86 void onUpdate(std::function<void(const std::optional<sf::Event>&)> callback, bool overwrite = false);
87
88 // ── Window events ─────────────────────────────────────────────────────
89
97 void onWindowResized(std::function<void()> callback, bool overwrite = false);
98
106 void onWindowResized(std::function<void(const std::optional<sf::Event>&)> callback, bool overwrite = false);
107
115 void onWindowFocusGained(std::function<void()> callback, bool overwrite = false);
116
124 void onWindowFocusGained(std::function<void(const std::optional<sf::Event>&)> callback, bool overwrite = false);
125
133 void onWindowFocusLost(std::function<void()> callback, bool overwrite = false);
134
142 void onWindowFocusLost(std::function<void(const std::optional<sf::Event>&)> callback, bool overwrite = false);
143 };
144
146 class MALENA_API UpdatableDispatcher : public FrameDispatcher
147 {
148 public:
149 bool filter(const std::optional<sf::Event>& event, Core* component) override { return true; }
150 void fire() override;
151 bool occurred() override { return true; }
152 };
154
155} // namespace ml
156
157ML_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:97
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 onWindowFocusLost(std::function< void(const std::optional< sf::Event > &)> callback, bool overwrite=false)
Register a callback invoked when the application window loses OS focus, receiving the raw SFML event.
void onUpdate(std::function< void()> callback, bool overwrite=false)
Register a no-argument callback invoked every frame.
void onWindowResized(std::function< void()> callback, bool overwrite=false)
Register a no-argument callback invoked when the application window is resized.
void onWindowFocusGained(std::function< void()> callback, bool overwrite=false)
Register a no-argument callback invoked when the application window gains OS focus.
void onWindowFocusLost(std::function< void()> callback, bool overwrite=false)
Register a no-argument callback invoked when the application window loses OS focus.
void onWindowResized(std::function< void(const std::optional< sf::Event > &)> callback, bool overwrite=false)
Register a callback invoked when the application window is resized, receiving the raw SFML event.
void onUpdate(std::function< void(const std::optional< sf::Event > &)> callback, bool overwrite=false)
Register a callback invoked every frame, receiving the SFML event.
void onWindowFocusGained(std::function< void(const std::optional< sf::Event > &)> callback, bool overwrite=false)
Register a callback invoked when the application window gains OS focus, receiving the raw SFML event.
#define MALENA_API
Definition Component.h:22