aboutsummaryrefslogtreecommitdiff
path: root/include/Gif.hpp
diff options
context:
space:
mode:
authordec05eba <dec05eba@protonmail.com>2018-04-22 05:58:44 +0200
committerdec05eba <dec05eba@protonmail.com>2018-04-22 05:59:18 +0200
commit1e0e68f9cda51c881b32a54d9eece71c1428f7ac (patch)
treeb8faa1d971c245e3fcf046aa1d2daa1fa601e0f9 /include/Gif.hpp
parent424b02609fa34175a4e2aadb95e68b3c9c8dc93c (diff)
Add video and gif support
Gif streams from url. Todo: Add play controls to video
Diffstat (limited to 'include/Gif.hpp')
-rw-r--r--include/Gif.hpp47
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;
+ };
+}