1#include "fl/engine_events.h"
11EngineEvents::Listener::Listener() {
14EngineEvents::Listener::~Listener() {
15 #if FASTLED_HAS_ENGINE_EVENTS
17 const bool has_listener = ptr && ptr->_hasListener(
this);
24 ptr->_removeListener(
this);
30 #if FASTLED_HAS_ENGINE_EVENTS
38#if FASTLED_HAS_ENGINE_EVENTS
39void EngineEvents::_onPlatformPreLoop() {
40 for (
auto& item : mListeners) {
41 auto listener = item.listener;
42 listener->onPlatformPreLoop();
44 for (
auto& item : mListeners) {
45 auto listener = item.listener;
46 listener->onPlatformPreLoop2();
50bool EngineEvents::_hasListener(Listener* listener) {
51 auto predicate = [listener](
const Pair& pair) {
52 return pair.listener == listener;
54 return mListeners.find_if(predicate) != mListeners.end();
57void EngineEvents::_addListener(Listener* listener,
int priority) {
58 if (_hasListener(listener)) {
61 for (
auto it = mListeners.begin(); it != mListeners.end(); ++it) {
62 if (it->priority < priority) {
64 EngineEvents::Pair pair = EngineEvents::Pair(listener, priority);
65 mListeners.insert(it, pair);
69 EngineEvents::Pair pair = EngineEvents::Pair(listener, priority);
70 mListeners.push_back(pair);
73void EngineEvents::_removeListener(Listener* listener) {
74 auto predicate = [listener](
const Pair& pair) {
75 return pair.listener == listener;
77 auto it = mListeners.find_if(predicate);
78 if (it != mListeners.end()) {
83void EngineEvents::_onBeginFrame() {
85 ListenerList copy = mListeners;
86 for (
auto& item : copy) {
87 auto listener = item.listener;
88 listener->onBeginFrame();
92void EngineEvents::_onEndShowLeds() {
94 ListenerList copy = mListeners;
95 for (
auto& item : copy) {
96 auto listener = item.listener;
97 listener->onEndShowLeds();
101void EngineEvents::_onEndFrame() {
103 ListenerList copy = mListeners;
104 for (
auto& item : copy) {
105 auto listener = item.listener;
106 listener->onEndFrame();
110void EngineEvents::_onStripAdded(
CLEDController* strip, uint32_t num_leds) {
112 ListenerList copy = mListeners;
113 for (
auto& item : copy) {
114 auto listener = item.listener;
115 listener->onStripAdded(strip, num_leds);
122 ListenerList copy = mListeners;
123 for (
auto& item : copy) {
124 auto listener = item.listener;
125 listener->onCanvasUiSet(strip, screenmap);
Base definition for an LED controller.
Implements the FastLED namespace macros.
#define FASTLED_NAMESPACE_END
End of the FastLED namespace.
#define FASTLED_NAMESPACE_BEGIN
Start of the FastLED namespace.
Implements a simple red square effect for 2D LED grids.