diff options
Diffstat (limited to 'include/ImagePreview.hpp')
-rw-r--r-- | include/ImagePreview.hpp | 52 |
1 files changed, 52 insertions, 0 deletions
diff --git a/include/ImagePreview.hpp b/include/ImagePreview.hpp new file mode 100644 index 0000000..1d20fe8 --- /dev/null +++ b/include/ImagePreview.hpp @@ -0,0 +1,52 @@ +#pragma once + +#include <SFML/Graphics/RenderWindow.hpp> +#include <SFML/Graphics/Sprite.hpp> +#include <SFML/Graphics/Texture.hpp> +#include <SFML/Window/Event.hpp> +#include <SFML/System/Clock.hpp> +#include <string> + +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::Sprite sprite; + sf::Vector2u size; + sf::Clock lastSeenTimer; + + union + { + sf::Texture *texture; + Gif *gif; + }; + ContentType contentType; + }; +} |