blob: ebcb5d4360ecb30acf874affe8061f9d0e873051 (
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 <SFML/Graphics/RenderTarget.hpp>
#include <SFML/Graphics/Texture.hpp>
#include <SFML/Graphics/Sprite.hpp>
#include <SFML/System/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);
~Gif();
sf::Vector2u getSize() const;
void setPosition(const sf::Vector2f &position);
sf::Vector2f getPosition() const;
void setScale(const sf::Vector2f &scale);
void setColor(sf::Color color);
void draw(sf::RenderTarget &target, const sf::RenderStates &renderStates = sf::RenderStates::Default);
static bool isDataGif(const StringView &data);
private:
void init();
private:
gif_animation gif;
StringView fileContent;
unsigned int currentFrame;
sf::Sprite sprite;
sf::Texture texture;
double timeElapsedCs;
sf::Clock frameTimer;
};
}
|