2017-10-31 17:12:50 +00:00
|
|
|
#pragma once
|
|
|
|
#ifndef ES_CORE_COMPONENTS_ANIMATED_IMAGE_COMPONENT_H
|
|
|
|
#define ES_CORE_COMPONENTS_ANIMATED_IMAGE_COMPONENT_H
|
|
|
|
|
2014-06-20 01:30:09 +00:00
|
|
|
#include "GuiComponent.h"
|
2017-11-01 22:21:10 +00:00
|
|
|
|
|
|
|
class ImageComponent;
|
2014-04-19 00:00:49 +00:00
|
|
|
|
|
|
|
struct AnimationFrame
|
|
|
|
{
|
|
|
|
const char* path;
|
|
|
|
int time;
|
|
|
|
};
|
|
|
|
|
|
|
|
struct AnimationDef
|
|
|
|
{
|
|
|
|
AnimationFrame* frames;
|
|
|
|
size_t frameCount;
|
|
|
|
bool loop;
|
|
|
|
};
|
|
|
|
|
|
|
|
class AnimatedImageComponent : public GuiComponent
|
|
|
|
{
|
|
|
|
public:
|
2014-04-19 00:46:55 +00:00
|
|
|
AnimatedImageComponent(Window* window);
|
2014-04-19 00:00:49 +00:00
|
|
|
|
|
|
|
void load(const AnimationDef* def); // no reference to def is kept after loading is complete
|
|
|
|
|
2014-04-19 00:46:55 +00:00
|
|
|
void reset(); // set to frame 0
|
|
|
|
|
2014-04-19 00:00:49 +00:00
|
|
|
void update(int deltaTime) override;
|
2017-10-28 20:24:35 +00:00
|
|
|
void render(const Transform4x4f& trans) override;
|
2014-04-19 00:00:49 +00:00
|
|
|
|
|
|
|
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;
|
|
|
|
};
|
2017-10-31 17:12:50 +00:00
|
|
|
|
|
|
|
#endif // ES_CORE_COMPONENTS_ANIMATED_IMAGE_COMPONENT_H
|