2014-04-19 00:00:49 +00:00
|
|
|
#include "../GuiComponent.h"
|
2014-04-20 19:23:49 +00:00
|
|
|
#include "ImageComponent.h"
|
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;
|
|
|
|
void render(const Eigen::Affine3f& 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;
|
|
|
|
};
|