Re-organized Animation code to move from multiple different constructors to one constructor and a handfull of setters for options.
This commit is contained in:
@ -33,11 +33,8 @@
|
||||
#include "Animation.h"
|
||||
#include "functions.h"
|
||||
|
||||
Animation::Animation(AnimationData *d, CRGB *bg_color, int8_t x, int8_t y) {
|
||||
Animation::Animation(AnimationData *d) {
|
||||
this->data = d;
|
||||
this->bgColor = bg_color;
|
||||
this->xOffset = x;
|
||||
this->yOffset = y;
|
||||
|
||||
this->endFrame = d->frame_count-1;
|
||||
this->colors = new CRGB[this->data->color_count];
|
||||
@ -50,6 +47,49 @@ Animation::Animation(AnimationData *d, CRGB *bg_color, int8_t x, int8_t y) {
|
||||
memcpy_P(this->animation_data, this->data->data, length);
|
||||
}
|
||||
|
||||
void Animation::setFgColor(CRGB* fg_color) {
|
||||
this->fgColor = fg_color;
|
||||
}
|
||||
|
||||
void Animation::setBgColor(CRGB* bg_color) {
|
||||
this->bgColor = bg_color;
|
||||
}
|
||||
|
||||
bool Animation::invert() {
|
||||
if (this->fgColor == NULL) return false;
|
||||
CRGB* temp = this->fgColor;
|
||||
this->fgColor = this->bgColor;
|
||||
this->bgColor = temp;
|
||||
return true;
|
||||
}
|
||||
|
||||
void Animation::setOffsets(int8_t x, int8_t y) {
|
||||
this->xOffset = x;
|
||||
this->yOffset = y;
|
||||
}
|
||||
|
||||
void Animation::setStartFrame(uint8_t sf) {
|
||||
if (sf <= this->endFrame && sf < this->data->frame_count ) this->startFrame = sf;
|
||||
}
|
||||
|
||||
void Animation::setEndFrame(uint8_t ef) {
|
||||
if (ef >= this->startFrame && ef < this->data->frame_count) this->endFrame = ef;
|
||||
}
|
||||
|
||||
void Animation::setFrameRange(uint8_t sf, uint8_t ef) {
|
||||
if (sf<=ef && ef < this->data->frame_count) {
|
||||
this->startFrame = sf;
|
||||
this->endFrame = ef;
|
||||
}
|
||||
}
|
||||
|
||||
void Animation::setSingleFrame(uint8_t frame) {
|
||||
if (frame < this->data->frame_count) {
|
||||
this->startFrame = frame;
|
||||
this->endFrame = frame;
|
||||
}
|
||||
}
|
||||
|
||||
Animation::~Animation() {
|
||||
delete this->colors;
|
||||
delete this->animation_data;
|
||||
@ -108,12 +148,6 @@ uint16_t Animation::getFrameDelay(int frame) {
|
||||
|
||||
CRGB* Animation::getColor(uint8_t index) {
|
||||
if (index==1) return this->bgColor;
|
||||
else if (this->fgColor) return this->fgColor;
|
||||
else return &this->colors[index - 2];
|
||||
}
|
||||
|
||||
AnimationSlice::AnimationSlice(AnimationData* d, uint8_t start, uint8_t end, CRGB* color, int8_t x, int8_t y) : Animation(d, color, x, y) {
|
||||
if (start <= end && end < d->frame_count) {
|
||||
this->startFrame = start;
|
||||
this->endFrame = end;
|
||||
}
|
||||
}
|
||||
|
@ -9,7 +9,9 @@ AnimationEffect::AnimationEffect(AnimationData* anim, CRGB* bg, int x, int y) {
|
||||
}
|
||||
|
||||
void AnimationEffect::start() {
|
||||
this->animation = new Animation(this->animation_data, this->bg_color, this->xOffset, this->yOffset);
|
||||
this->animation = new Animation(this->animation_data);
|
||||
this->animation->setBgColor(this->bg_color);
|
||||
this->animation->setOffsets(this->xOffset, this->yOffset);
|
||||
}
|
||||
|
||||
void AnimationEffect::stop() {
|
||||
|
Reference in New Issue
Block a user