Allow AnimatedIcon to be colorized to textColor.
This commit is contained in:
parent
56945859e3
commit
efb7dc927a
2 changed files with 30 additions and 4 deletions
|
|
@ -195,7 +195,8 @@ void AnimatedIcon::Impl::renderPreloadFrame() {
|
|||
}
|
||||
|
||||
AnimatedIcon::AnimatedIcon(AnimatedIconDescriptor &&descriptor)
|
||||
: _impl(std::make_shared<Impl>(base::make_weak(this))) {
|
||||
: _impl(std::make_shared<Impl>(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<void()> 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<void()> updateWithPerfect) const {
|
||||
auto &frame = _impl->frame();
|
||||
|
|
|
|||
|
|
@ -22,6 +22,7 @@ class FrameGenerator;
|
|||
struct AnimatedIconDescriptor {
|
||||
FnMut<std::unique_ptr<FrameGenerator>()> 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<void()> updateWithPerfect) const;
|
||||
[[nodiscard]] ResizedFrame notColorizedFrame(
|
||||
QSize desiredSize,
|
||||
Fn<void()> updateWithPerfect) const;
|
||||
|
||||
|
|
@ -81,6 +87,7 @@ private:
|
|||
mutable crl::time _animationCurrentStart = 0;
|
||||
mutable crl::time _animationNextStart = 0;
|
||||
mutable int _animationCurrentIndex = 0;
|
||||
bool _colorized = false;
|
||||
|
||||
};
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue