Better handling of Animations, their members and the destructor.
This commit is contained in:
@ -143,7 +143,7 @@ bool Animation::_load_from_file(const char* filename) {
|
||||
}
|
||||
|
||||
file.close();
|
||||
|
||||
|
||||
LOGln("Animation * Loading completed successfully.");
|
||||
|
||||
return true;
|
||||
@ -160,12 +160,14 @@ Animation::Animation(const char* filename, Window* win) {
|
||||
}
|
||||
}
|
||||
|
||||
void Animation::setFgColor(CRGB* fg_color) {
|
||||
this->fgColor = fg_color;
|
||||
void Animation::setFgColor(uint32_t c) {
|
||||
if (this->fgColor) delete this->fgColor;
|
||||
this->fgColor = new CRGB(c);
|
||||
}
|
||||
|
||||
void Animation::setBgColor(CRGB* bg_color) {
|
||||
this->bgColor = bg_color;
|
||||
void Animation::setBgColor(uint32_t c) {
|
||||
if (this->bgColor) delete this->bgColor;
|
||||
this->bgColor = new CRGB(c);
|
||||
}
|
||||
|
||||
bool Animation::invert() {
|
||||
@ -205,15 +207,27 @@ void Animation::setSingleFrame(uint8_t frame) {
|
||||
|
||||
Animation::~Animation() {
|
||||
for (int i=0; i<_color_count; i++) delete _colors[i];
|
||||
delete [] _colors;
|
||||
if (fgColor) delete fgColor;
|
||||
delete bgColor;
|
||||
delete [] _frame_data_lengths;
|
||||
delete [] _frame_times;
|
||||
LOGln("Deleting _colors...");
|
||||
if (_colors) delete [] _colors;
|
||||
LOGln("Deleting fgColor...");
|
||||
|
||||
if (fgColor != NULL) delete fgColor;
|
||||
LOGln("Deleting bgColor...");
|
||||
|
||||
if (bgColor != NULL) delete bgColor;
|
||||
LOGln("Deleting _frame_data_lengths...");
|
||||
|
||||
if (_frame_data_lengths) delete [] _frame_data_lengths;
|
||||
LOGln("Deleting _frame_times...");
|
||||
|
||||
if (_frame_times) delete [] _frame_times;
|
||||
for (int i=0; i<_frame_count; i++) {
|
||||
delete [] _frame_data[i];
|
||||
}
|
||||
delete [] _frame_data;
|
||||
LOGln("Deleting _frame_data...");
|
||||
|
||||
if (_frame_data) delete [] _frame_data;
|
||||
LOGln("Deleteion done.");
|
||||
}
|
||||
|
||||
void Animation::draw() {
|
||||
@ -230,7 +244,7 @@ void Animation::drawFrame(uint8_t frame_index) {
|
||||
CRGB red(0xFF0000);
|
||||
CRGB black(0x000000);
|
||||
for (int x=0; x<_window->width; x++) for (int y=0; y<_window->height; y++) {
|
||||
_window->setPixel(x, y, (y*_window->width+x) % 2 ? &red : &black);
|
||||
_window->setPixel(x, y, (y*_window->width+x + y) % 2 ? &red : &black);
|
||||
}
|
||||
return;
|
||||
}
|
||||
|
@ -1,16 +1,20 @@
|
||||
#include "effect_animation.h"
|
||||
#include "functions.h"
|
||||
|
||||
AnimationEffect::AnimationEffect(const char* name, CRGB* bg, int x, int y) {
|
||||
this->bg_color = bg;
|
||||
AnimationEffect::AnimationEffect(const char* name, uint32_t bg, int x, int y) {
|
||||
this->xOffset = x;
|
||||
this->yOffset = y;
|
||||
|
||||
this->animation = new Animation(name, window);
|
||||
this->animation->setBgColor(this->bg_color);
|
||||
this->animation->setBgColor(bg);
|
||||
this->animation->setOffsets(this->xOffset, this->yOffset);
|
||||
}
|
||||
|
||||
AnimationEffect* AnimationEffect::setFgColor(uint32_t c) {
|
||||
animation->setFgColor(c);
|
||||
return this;
|
||||
}
|
||||
|
||||
AnimationEffect::~AnimationEffect() {
|
||||
delete this->animation;
|
||||
}
|
||||
|
Reference in New Issue
Block a user