1#include "engine_events.h"
8EngineEvents::Listener::Listener() {
11EngineEvents::Listener::~Listener() {
12 #if FASTLED_HAS_ENGINE_EVENTS
14 const bool has_listener = ptr && ptr->_hasListener(
this);
21 ptr->_removeListener(
this);
27 #if FASTLED_HAS_ENGINE_EVENTS
35#if FASTLED_HAS_ENGINE_EVENTS
36void EngineEvents::_onPlatformPreLoop() {
37 for (
auto& item : mListeners) {
38 auto listener = item.listener;
39 listener->onPlatformPreLoop();
41 for (
auto& item : mListeners) {
42 auto listener = item.listener;
43 listener->onPlatformPreLoop2();
47bool EngineEvents::_hasListener(Listener* listener) {
48 auto predicate = [listener](
const Pair& pair) {
49 return pair.listener == listener;
51 return mListeners.find_if(predicate) != mListeners.end();
54void EngineEvents::_addListener(Listener* listener,
int priority) {
55 if (_hasListener(listener)) {
58 for (
auto it = mListeners.begin(); it != mListeners.end(); ++it) {
59 if (it->priority < priority) {
61 EngineEvents::Pair pair = EngineEvents::Pair(listener, priority);
62 mListeners.insert(it, pair);
66 EngineEvents::Pair pair = EngineEvents::Pair(listener, priority);
67 mListeners.push_back(pair);
70void EngineEvents::_removeListener(Listener* listener) {
71 auto predicate = [listener](
const Pair& pair) {
72 return pair.listener == listener;
74 auto it = mListeners.find_if(predicate);
75 if (it != mListeners.end()) {
80void EngineEvents::_onBeginFrame() {
82 ListenerList copy = mListeners;
83 for (
auto& item : copy) {
84 auto listener = item.listener;
85 listener->onBeginFrame();
89void EngineEvents::_onEndShowLeds() {
91 ListenerList copy = mListeners;
92 for (
auto& item : copy) {
93 auto listener = item.listener;
94 listener->onEndShowLeds();
98void EngineEvents::_onEndFrame() {
100 ListenerList copy = mListeners;
101 for (
auto& item : copy) {
102 auto listener = item.listener;
103 listener->onEndFrame();
107void EngineEvents::_onStripAdded(
CLEDController* strip, uint32_t num_leds) {
109 ListenerList copy = mListeners;
110 for (
auto& item : copy) {
111 auto listener = item.listener;
112 listener->onStripAdded(strip, num_leds);
119 ListenerList copy = mListeners;
120 for (
auto& item : copy) {
121 auto listener = item.listener;
122 listener->onCanvasUiSet(strip, screenmap);
Base definition for an LED controller.