Implement static color via special animation type
This commit is contained in:
parent
127b8d6dca
commit
8bd87c4d3d
|
@ -4,3 +4,4 @@
|
|||
#include "ConnectionEstablishedAnimation.h"
|
||||
#include "FireAnimation.h"
|
||||
#include "SnowfallAnimation.h"
|
||||
#include "FadeToColorAnimation.h"
|
||||
|
|
30
include/Animation/FadeToColorAnimation.h
Normal file
30
include/Animation/FadeToColorAnimation.h
Normal file
|
@ -0,0 +1,30 @@
|
|||
#pragma once
|
||||
|
||||
#include <random>
|
||||
|
||||
#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;
|
||||
};
|
19
src/Animation/FadeToColorAnimation.cpp
Normal file
19
src/Animation/FadeToColorAnimation.cpp
Normal file
|
@ -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();
|
||||
}
|
||||
}
|
|
@ -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<Animation>(
|
||||
new FadeToColorAnimation(WebServer::instance().m_fader, Fader::Color{r,g,b,w})),
|
||||
false);
|
||||
}
|
||||
|
||||
void WebServer::handleSetAnim(httpsserver::HTTPRequest *req, httpsserver::HTTPResponse *res)
|
||||
|
|
Loading…
Reference in a new issue