ES-DE/es-core/src/components/AnimatedImageComponent.h
Leon Styhre e4fdd1e20d Code cleanup and code documentation update.
As of this commit, the initial code cleanup and code documentation has been completed for the entire application.
2020-06-28 18:39:18 +02:00

52 lines
1 KiB
C++

//
// AnimatedImageComponent.h
//
// Creates animation from multiple images files.
//
#pragma once
#ifndef ES_CORE_COMPONENTS_ANIMATED_IMAGE_COMPONENT_H
#define ES_CORE_COMPONENTS_ANIMATED_IMAGE_COMPONENT_H
#include "GuiComponent.h"
class ImageComponent;
struct AnimationFrame {
const char* path;
int time;
};
struct AnimationDef {
AnimationFrame* frames;
size_t frameCount;
bool loop;
};
class AnimatedImageComponent : public GuiComponent
{
public:
AnimatedImageComponent(Window* window);
void load(const AnimationDef* def); // No reference to def is kept after loading is complete.
void reset(); // Set to frame 0.
void update(int deltaTime) override;
void render(const Transform4x4f& trans) override;
void onSizeChanged() override;
private:
typedef std::pair<std::unique_ptr<ImageComponent>, int> ImageFrame;
std::vector<ImageFrame> mFrames;
bool mLoop;
bool mEnabled;
int mFrameAccumulator;
int mCurrentFrame;
};
#endif // ES_CORE_COMPONENTS_ANIMATED_IMAGE_COMPONENT_H