diff --git a/CMakeLists.txt b/CMakeLists.txt index fd55c80..36a2548 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -47,6 +47,7 @@ PRIVATE ui/effects/cross_line.h ui/effects/fade_animation.cpp ui/effects/fade_animation.h + ui/effects/frame_generator.h ui/effects/gradient.cpp ui/effects/gradient.h ui/effects/numbers_animation.cpp diff --git a/ui/effects/frame_generator.h b/ui/effects/frame_generator.h new file mode 100644 index 0000000..0cc300e --- /dev/null +++ b/ui/effects/frame_generator.h @@ -0,0 +1,29 @@ +// This file is part of Desktop App Toolkit, +// a set of libraries for developing nice desktop applications. +// +// For license and copyright information please follow this link: +// https://github.com/desktop-app/legal/blob/master/LEGAL +// +#pragma once + +#include + +#include + +namespace Ui { + +class FrameGenerator { +public: + [[nodiscard]] virtual int count() = 0; + + struct Frame { + QImage image; + crl::time duration = 0; + }; + [[nodiscard]] virtual Frame renderNext( + QImage storage, + QSize size, + Qt::AspectRatioMode mode = Qt::IgnoreAspectRatio) = 0; +}; + +} // namespace Ui diff --git a/ui/painter.h b/ui/painter.h index 017e66e..d2b73d8 100644 --- a/ui/painter.h +++ b/ui/painter.h @@ -69,12 +69,19 @@ public: void restoreTextPalette() { _textPalette = nullptr; } - const style::TextPalette &textPalette() const { + [[nodiscard]] const style::TextPalette &textPalette() const { return _textPalette ? *_textPalette : st::defaultTextPalette; } + void setInactive(bool inactive) { + _inactive = inactive; + } + [[nodiscard]] bool inactive() const { + return _inactive; + } private: const style::TextPalette *_textPalette = nullptr; + bool _inactive = false; }; diff --git a/ui/text/text.cpp b/ui/text/text.cpp index 9ff22ab..45e33fc 100644 --- a/ui/text/text.cpp +++ b/ui/text/text.cpp @@ -1686,7 +1686,10 @@ private: x, y); } else if (const auto custom = static_cast(currentBlock)->_custom.get()) { - custom->paint(*_p, x, y, _textPalette->spoilerActiveBg->c); + if (!_now) { + _now = crl::now(); + } + custom->paint(*_p, x, y, _now, _textPalette->spoilerActiveBg->c, _p->inactive()); } } if (hasSpoiler) { @@ -1920,7 +1923,10 @@ private: if (!_background.startMs) { return 1.; } - const auto progress = float64(crl::now() - _background.startMs) + if (!_now) { + _now = crl::now(); + } + const auto progress = float64(_now - _background.startMs) / st::fadeWrapDuration; if ((progress > 1.) && _background.spoilerIndex) { const auto link = _t->_spoilers.at(_background.spoilerIndex - 1); @@ -2863,6 +2869,7 @@ private: TextSelection _selection = { 0, 0 }; bool _fullWidthSelection = true; const QChar *_str = nullptr; + crl::time _now = 0; int _indexOfElidedBlock = -1; // For spoilers. diff --git a/ui/text/text_block.h b/ui/text/text_block.h index 39ac2f9..4da5ec9 100644 --- a/ui/text/text_block.h +++ b/ui/text/text_block.h @@ -11,6 +11,8 @@ #include +#include + namespace Ui { namespace Text { @@ -168,7 +170,13 @@ class CustomEmoji { public: virtual ~CustomEmoji() = default; [[nodiscard]] virtual QString entityData() = 0; - virtual void paint(QPainter &p, int x, int y, const QColor &preview) = 0; + virtual void paint( + QPainter &p, + int x, + int y, + crl::time now, + const QColor &preview, + bool paused) = 0; virtual void unload() = 0; };