From 8bd87c4d3d9e7494ac5eb749ff07f2d43902a176 Mon Sep 17 00:00:00 2001 From: Thomas Kolb Date: Mon, 16 Dec 2019 23:31:15 +0100 Subject: [PATCH] Implement static color via special animation type --- include/Animation/AllAnimations.h | 1 + include/Animation/FadeToColorAnimation.h | 30 ++++++++++++++++++++++++ src/Animation/FadeToColorAnimation.cpp | 19 +++++++++++++++ src/WebServer.cpp | 6 ++++- 4 files changed, 55 insertions(+), 1 deletion(-) create mode 100644 include/Animation/FadeToColorAnimation.h create mode 100644 src/Animation/FadeToColorAnimation.cpp diff --git a/include/Animation/AllAnimations.h b/include/Animation/AllAnimations.h index 6d67280..28416c8 100644 --- a/include/Animation/AllAnimations.h +++ b/include/Animation/AllAnimations.h @@ -4,3 +4,4 @@ #include "ConnectionEstablishedAnimation.h" #include "FireAnimation.h" #include "SnowfallAnimation.h" +#include "FadeToColorAnimation.h" diff --git a/include/Animation/FadeToColorAnimation.h b/include/Animation/FadeToColorAnimation.h new file mode 100644 index 0000000..6eb8fa1 --- /dev/null +++ b/include/Animation/FadeToColorAnimation.h @@ -0,0 +1,30 @@ +#pragma once + +#include + +#include "Animation.h" + +class FadeToColorAnimation : public Animation +{ + public: + FadeToColorAnimation(Fader *fader, const Fader::Color &color); + + void loop(uint64_t frame) override; + + void stop(void) override + { + m_fader->fade_color(Fader::Color{0, 0, 0, 0}); + m_stopping = true; + } + + void reset(void) override + { + m_stopping = false; + m_running = true; + } + + private: + Fader::Color m_color; + + bool m_stopping; +}; diff --git a/src/Animation/FadeToColorAnimation.cpp b/src/Animation/FadeToColorAnimation.cpp new file mode 100644 index 0000000..3d724b3 --- /dev/null +++ b/src/Animation/FadeToColorAnimation.cpp @@ -0,0 +1,19 @@ +#include "Animation/FadeToColorAnimation.h" + +FadeToColorAnimation::FadeToColorAnimation(Fader *fader, const Fader::Color &color) + : Animation(fader), m_color(color), m_stopping(false) +{} + +void FadeToColorAnimation::loop(uint64_t frame) +{ + if(frame == 0) { + m_fader->set_fadestep(1); + m_fader->fade_color(m_color); + } + + m_fader->update(); + + if(m_stopping) { + m_running = m_fader->something_changed(); + } +} diff --git a/src/WebServer.cpp b/src/WebServer.cpp index 68ffc21..1157886 100644 --- a/src/WebServer.cpp +++ b/src/WebServer.cpp @@ -8,6 +8,7 @@ #include "Config.h" #include "Fader.h" +#include "Animation/AllAnimations.h" #include "Animation/AnimationController.h" #include "coreids.h" @@ -124,7 +125,10 @@ void WebServer::handleColor(httpsserver::HTTPRequest *req, httpsserver::HTTPResp res->print(" w:"); res->println(w); - WebServer::instance().m_fader->fade_color({r,g,b,w}); + WebServer::instance().m_animController->changeAnimation( + std::unique_ptr( + new FadeToColorAnimation(WebServer::instance().m_fader, Fader::Color{r,g,b,w})), + false); } void WebServer::handleSetAnim(httpsserver::HTTPRequest *req, httpsserver::HTTPResponse *res)