#pragma once #include #include #include #include #include #include namespace dchat { class Gif; class ImagePreview { public: // set @texture to nullptr if you wish to end preview static void preview(sf::Texture *texture, const std::string &url = ""); // set gif to nullptr if you wish to end preview static void preview(Gif *gif, const std::string &url = ""); static void* getPreviewContentPtr(); static sf::Int32 getTimeSinceLastSeenMs(); static void processEvent(const sf::Event &event); static void draw(sf::RenderWindow &window); private: enum class ContentType { NONE, TEXTURE, GIF }; ImagePreview() : texture(nullptr), contentType(ContentType::NONE) {} ImagePreview(const ImagePreview&) = delete; ImagePreview& operator=(const ImagePreview&) = delete; static ImagePreview* getInstance(); sf::Vector2u calculateImageSize(sf::Vector2u windowSize) const; private: sf::Vector2f position; sf::Sprite sprite; sf::Vector2u size; sf::Clock lastSeenTimer; union { sf::Texture *texture; Gif *gif; }; ContentType contentType; }; }