diff --git a/ui/animated_icon.cpp b/ui/animated_icon.cpp index 189a562..64ef391 100644 --- a/ui/animated_icon.cpp +++ b/ui/animated_icon.cpp @@ -195,7 +195,8 @@ void AnimatedIcon::Impl::renderPreloadFrame() { } AnimatedIcon::AnimatedIcon(AnimatedIconDescriptor &&descriptor) -: _impl(std::make_shared(base::make_weak(this))) { +: _impl(std::make_shared(base::make_weak(this))) +, _colorized(descriptor.colorized) { crl::async([ impl = _impl, factory = std::move(descriptor.generator), @@ -221,11 +222,29 @@ int AnimatedIcon::framesCount() const { return _impl->framesCount(); } -QImage AnimatedIcon::frame() const { - return frame(QSize(), nullptr).image; +QImage AnimatedIcon::frame(const QColor &textColor) const { + return frame(textColor, QSize(), nullptr).image; +} + +QImage AnimatedIcon::notColorizedFrame() const { + return notColorizedFrame(QSize(), nullptr).image; } AnimatedIcon::ResizedFrame AnimatedIcon::frame( + const QColor &textColor, + QSize desiredSize, + Fn updateWithPerfect) const { + auto result = notColorizedFrame( + desiredSize, + std::move(updateWithPerfect)); + if (_colorized) { + auto &image = result.image; + style::colorizeImage(image, textColor, &image, {}, {}, true); + } + return result; +} + +AnimatedIcon::ResizedFrame AnimatedIcon::notColorizedFrame( QSize desiredSize, Fn updateWithPerfect) const { auto &frame = _impl->frame(); diff --git a/ui/animated_icon.h b/ui/animated_icon.h index 80755f9..edec7cd 100644 --- a/ui/animated_icon.h +++ b/ui/animated_icon.h @@ -22,6 +22,7 @@ class FrameGenerator; struct AnimatedIconDescriptor { FnMut()> generator; QSize sizeOverride; + bool colorized = false; }; class AnimatedIcon final : public base::has_weak_ptr { @@ -35,7 +36,8 @@ public: [[nodiscard]] bool valid() const; [[nodiscard]] int frameIndex() const; [[nodiscard]] int framesCount() const; - [[nodiscard]] QImage frame() const; + [[nodiscard]] QImage frame(const QColor &textColor) const; + [[nodiscard]] QImage notColorizedFrame() const; [[nodiscard]] int width() const; [[nodiscard]] int height() const; [[nodiscard]] QSize size() const; @@ -45,6 +47,10 @@ public: bool scaled = false; }; [[nodiscard]] ResizedFrame frame( + const QColor &textColor, + QSize desiredSize, + Fn updateWithPerfect) const; + [[nodiscard]] ResizedFrame notColorizedFrame( QSize desiredSize, Fn updateWithPerfect) const; @@ -81,6 +87,7 @@ private: mutable crl::time _animationCurrentStart = 0; mutable crl::time _animationNextStart = 0; mutable int _animationCurrentIndex = 0; + bool _colorized = false; };