#pragma once #include "common/Common.hpp" #include #include #include #include #include #include #include "common/NullablePtr.hpp" namespace chatterino { namespace { class Frame { public: explicit Frame(const QPixmap *nonOwning, int duration = 1); explicit Frame(std::unique_ptr owning, int duration = 1); const QPixmap *pixmap() const; int duration() const; private: const QPixmap *nonOwning_{nullptr}; std::unique_ptr owning_{}; int duration_{}; }; class Frames { public: Frames(); Frames(std::vector &&frames); ~Frames(); Frames(Frames &&other) = default; Frames &operator=(Frames &&other) = default; bool animated() const; void advance(); const QPixmap *current() const; const QPixmap *first() const; private: std::vector items_; int index_{0}; int timeOffset_{0}; }; } // namespace class Image; using ImagePtr = std::shared_ptr; class Image : public std::enable_shared_from_this, boost::noncopyable { public: static ImagePtr fromUrl(const Url &url, qreal scale = 1); static ImagePtr fromOwningPixmap(std::unique_ptr pixmap, qreal scale = 1); static ImagePtr fromNonOwningPixmap(QPixmap *pixmap, qreal scale = 1); static ImagePtr getEmpty(); const Url &url() const; const QPixmap *pixmap() const; qreal scale() const; bool empty() const; int width() const; int height() const; bool animated() const; bool operator==(const Image &image) const; bool operator!=(const Image &image) const; private: Image(); Image(const Url &url, qreal scale); Image(std::unique_ptr owning, qreal scale); Image(QPixmap *nonOwning, qreal scale); void load(); Url url_{}; qreal scale_{1}; bool empty_{false}; bool shouldLoad_{false}; Frames frames_{}; QObject object_{}; static std::atomic loadedEventQueued; }; } // namespace chatterino