aboutsummaryrefslogtreecommitdiff
path: root/include/dchat/Gif.hpp
diff options
context:
space:
mode:
Diffstat (limited to 'include/dchat/Gif.hpp')
-rw-r--r--include/dchat/Gif.hpp52
1 files changed, 52 insertions, 0 deletions
diff --git a/include/dchat/Gif.hpp b/include/dchat/Gif.hpp
new file mode 100644
index 0000000..f97ff2f
--- /dev/null
+++ b/include/dchat/Gif.hpp
@@ -0,0 +1,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;
+ };
+}