2020-09-21 17:17:34 +00:00
|
|
|
// SPDX-License-Identifier: MIT
|
2020-06-28 16:39:18 +00:00
|
|
|
//
|
2020-09-21 17:17:34 +00:00
|
|
|
// EmulationStation Desktop Edition
|
2020-06-28 16:39:18 +00:00
|
|
|
// AnimatedImageComponent.h
|
|
|
|
//
|
|
|
|
// Creates animation from multiple images files.
|
|
|
|
//
|
|
|
|
|
2017-10-31 17:12:50 +00:00
|
|
|
#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
|
|
|
|
2020-06-28 16:39:18 +00:00
|
|
|
struct AnimationFrame {
|
2020-12-16 22:59:00 +00:00
|
|
|
std::string path;
|
2020-06-28 16:39:18 +00:00
|
|
|
int time;
|
2014-04-19 00:00:49 +00:00
|
|
|
};
|
|
|
|
|
2020-06-28 16:39:18 +00:00
|
|
|
struct AnimationDef {
|
|
|
|
AnimationFrame* frames;
|
|
|
|
size_t frameCount;
|
|
|
|
bool loop;
|
2014-04-19 00:00:49 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
class AnimatedImageComponent : public GuiComponent
|
|
|
|
{
|
|
|
|
public:
|
2020-06-28 16:39:18 +00:00
|
|
|
AnimatedImageComponent(Window* window);
|
2019-08-25 15:23:02 +00:00
|
|
|
|
2020-06-28 16:39:18 +00:00
|
|
|
void load(const AnimationDef* def); // No reference to def is kept after loading is complete.
|
2014-04-19 00:00:49 +00:00
|
|
|
|
2020-06-28 16:39:18 +00:00
|
|
|
void reset(); // Set to frame 0.
|
2014-04-19 00:46:55 +00:00
|
|
|
|
2020-06-28 16:39:18 +00:00
|
|
|
void update(int deltaTime) override;
|
2021-08-15 17:30:31 +00:00
|
|
|
void render(const glm::mat4& trans) override;
|
2014-04-19 00:00:49 +00:00
|
|
|
|
2020-06-28 16:39:18 +00:00
|
|
|
void onSizeChanged() override;
|
2014-04-19 00:00:49 +00:00
|
|
|
|
|
|
|
private:
|
2020-06-28 16:39:18 +00:00
|
|
|
typedef std::pair<std::unique_ptr<ImageComponent>, int> ImageFrame;
|
2014-04-19 00:00:49 +00:00
|
|
|
|
2020-06-28 16:39:18 +00:00
|
|
|
std::vector<ImageFrame> mFrames;
|
2014-04-19 00:00:49 +00:00
|
|
|
|
2020-06-28 16:39:18 +00:00
|
|
|
bool mLoop;
|
|
|
|
bool mEnabled;
|
|
|
|
int mFrameAccumulator;
|
|
|
|
int mCurrentFrame;
|
2014-04-19 00:00:49 +00:00
|
|
|
};
|
2017-10-31 17:12:50 +00:00
|
|
|
|
|
|
|
#endif // ES_CORE_COMPONENTS_ANIMATED_IMAGE_COMPONENT_H
|