diff options
Diffstat (limited to 'include/Gif.hpp')
-rw-r--r-- | include/Gif.hpp | 47 |
1 files changed, 47 insertions, 0 deletions
diff --git a/include/Gif.hpp b/include/Gif.hpp new file mode 100644 index 0000000..1a69a52 --- /dev/null +++ b/include/Gif.hpp @@ -0,0 +1,47 @@ +#pragma once + +#include "StringView.hpp" +#include <SFML/Graphics/RenderWindow.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(); + + void setPosition(const sf::Vector2f &position); + void setSize(const sf::Vector2f &size); + void draw(sf::RenderWindow &window); + + 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; + }; +} |