Better handling of Animations, their members and the destructor.

This commit is contained in:
2019-06-19 22:16:06 +02:00
parent cb4afa5043
commit 41af01ee0b
4 changed files with 46 additions and 28 deletions

View File

@ -41,7 +41,7 @@ protected:
unsigned long currentFrameSince;
uint8_t currentFrame = 0;
uint8_t* animation_data;
CRGB** _colors;
CRGB** _colors = NULL;
CRGB* fgColor = NULL;
CRGB* bgColor = new CRGB(0x000000);
int8_t xOffset = 0;
@ -51,22 +51,22 @@ protected:
Window* _window;
uint8_t _width;
uint8_t _height;
uint8_t _frame_count;
uint8_t _color_count;
uint16_t* _frame_times;
uint16_t* _frame_data_lengths;
uint8_t** _frame_data;
uint8_t _frame_count = 0;
uint8_t _color_count = 0;
uint16_t* _frame_times = NULL;
uint16_t* _frame_data_lengths = NULL;
uint8_t** _frame_data = NULL;
bool _data_valid = false;
virtual CRGB* getColor(uint8_t color_index);
void drawPixel(int index, CRGB* color);
uint16_t getFrameDelay(int frame);
bool _load_from_file(const char* c);
public:
Animation(const char* filename, Window* win);
void setFgColor(CRGB*);
void setBgColor(CRGB* bg_color);
void setFgColor(uint32_t c);
void setBgColor(uint32_t c);
bool invert();
void setOffsets(int8_t x, int8_t y);
void setStartFrame(uint8_t sf);

View File

@ -8,13 +8,13 @@
class AnimationEffect : public Effect {
private:
Animation *animation;
CRGB *bg_color;
uint16_t xOffset;
uint16_t yOffset;
public:
AnimationEffect(const char* name) : AnimationEffect(name, new CRGB(0x000000), 0, 0) {}
AnimationEffect(const char* name, CRGB* background_color) : AnimationEffect(name, background_color, 0, 0) {}
AnimationEffect(const char* name, CRGB* bg_color, int x, int y);
AnimationEffect(const char* name) : AnimationEffect(name, 0x000000, 0, 0) {}
AnimationEffect(const char* name, uint32_t bg_color) : AnimationEffect(name, bg_color, 0, 0) {}
AnimationEffect(const char* name, uint32_t bg_color, int x, int y);
~AnimationEffect();
AnimationEffect* setFgColor(uint32_t c);
void loop();
};