blob: f97ff2f8bbe530f3e7544e23dd435380fc0a6b65 (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
|
#pragma once
#include "StringView.hpp"
#include "Vec2.hpp"
#include "Color.hpp"
#include "Clock.hpp"
#include <boost/filesystem/path.hpp>
#include <stdexcept>
extern "C"
{
#include <libnsgif.h>
}
namespace dchat
{
class GifLoadException : public std::runtime_error
{
public:
GifLoadException(const std::string &errMsg) : std::runtime_error(errMsg) {}
};
class Gif
{
public:
// Throws GifLoadException on error
Gif(const boost::filesystem::path &filepath);
Gif(StringView fileContent);
virtual ~Gif();
Vec2u getSize() const;
void update();
static bool isDataGif(const StringView &data);
protected:
// Return false if texture creation failed
virtual bool createTexture(int width, int height) = 0;
virtual void setPosition(const Vec2f &position) = 0;
virtual Vec2f getPosition() const = 0;
virtual void setScale(const Vec2f &scale) = 0;
virtual void setColor(Color color) = 0;
// Size of texture data is same as the size that the texture was created with (also same size returned by @getSize function)
virtual void updateTexture(void *textureData) = 0;
private:
void init();
private:
gif_animation gif;
StringView fileContent;
unsigned int currentFrame;
double timeElapsedCs;
Clock frameTimer;
};
}
|