pitrix/src/effect_animation.cpp

54 lines
1.3 KiB
C++

#include "effect_animation.h"
#include "functions.h"
AnimationEffect::AnimationEffect(const char* name, uint32_t bg, int x, int y) {
this->name = name;
this->xOffset = x;
this->yOffset = y;
this->animation = new Animation(name, window);
this->animation->setBgColor(bg);
this->animation->setOffsets(this->xOffset, this->yOffset);
_last_blink_at = millis();
}
AnimationEffect* AnimationEffect::setFgColor(uint32_t c) {
animation->setFgColor(c);
return this;
}
AnimationEffect* AnimationEffect::setBlinkFrequency(uint16_t ms) {
_blink_freq = ms;
return this;
}
AnimationEffect::~AnimationEffect() {
delete this->animation;
}
void AnimationEffect::loop(uint16_t ms) {
if (_blink_freq > 0) {
unsigned long mil = millis();
if (mil < _last_blink_at || _last_blink_at + _blink_freq <= mil) {
this->animation->invert();
_last_blink_at = mil;
}
}
this->animation->drawFrame();
this->animation->advance();
}
String AnimationEffect::get_name() {
String s = "animation/";
s += this->name;
return s;
}
AnimationEffect* AnimationEffect::Blinker(const char* name, uint16_t interval, uint32_t color, uint32_t background_color) {
AnimationEffect* anim = new AnimationEffect(name, background_color);
anim->setFgColor(color);
anim->setBlinkFrequency(interval);
return anim;
}