mirror of
https://github.com/AyuGram/AyuGramDesktop.git
synced 2025-06-06 15:13:57 +02:00
Use spoiler animation for ExtendedMedia.
This commit is contained in:
parent
20b5138e00
commit
a919978a37
3 changed files with 22 additions and 17 deletions
|
@ -74,6 +74,7 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL
|
||||||
#include "ui/text/text_options.h"
|
#include "ui/text/text_options.h"
|
||||||
#include "ui/emoji_config.h"
|
#include "ui/emoji_config.h"
|
||||||
#include "ui/effects/animations.h"
|
#include "ui/effects/animations.h"
|
||||||
|
#include "ui/effects/spoiler_mess.h"
|
||||||
#include "ui/cached_round_corners.h"
|
#include "ui/cached_round_corners.h"
|
||||||
#include "storage/serialize_common.h"
|
#include "storage/serialize_common.h"
|
||||||
#include "storage/storage_domain.h"
|
#include "storage/storage_domain.h"
|
||||||
|
@ -255,6 +256,7 @@ void Application::run() {
|
||||||
Ui::InitTextOptions();
|
Ui::InitTextOptions();
|
||||||
Ui::StartCachedCorners();
|
Ui::StartCachedCorners();
|
||||||
Ui::Emoji::Init();
|
Ui::Emoji::Init();
|
||||||
|
Ui::PrepareDefaultSpoilerMess();
|
||||||
startEmojiImageLoader();
|
startEmojiImageLoader();
|
||||||
startSystemDarkModeViewer();
|
startSystemDarkModeViewer();
|
||||||
Media::Player::start(_audio.get());
|
Media::Player::start(_audio.get());
|
||||||
|
|
|
@ -84,11 +84,12 @@ void ExtendedPreview::ensureThumbnailRead() const {
|
||||||
}
|
}
|
||||||
|
|
||||||
bool ExtendedPreview::hasHeavyPart() const {
|
bool ExtendedPreview::hasHeavyPart() const {
|
||||||
return !_inlineThumbnail.isNull();
|
return _animation || !_inlineThumbnail.isNull();
|
||||||
}
|
}
|
||||||
|
|
||||||
void ExtendedPreview::unloadHeavyPart() {
|
void ExtendedPreview::unloadHeavyPart() {
|
||||||
_inlineThumbnail = _imageCache = QImage();
|
_inlineThumbnail = _imageCache = QImage();
|
||||||
|
_animation = nullptr;
|
||||||
_caption.unloadCustomEmoji();
|
_caption.unloadCustomEmoji();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -192,7 +193,7 @@ void ExtendedPreview::draw(Painter &p, const PaintContext &context) const {
|
||||||
| ((isRoundedInBubbleBottom() && _caption.isEmpty()) ? (RectPart::BottomLeft | RectPart::BottomRight) : RectPart::None));
|
| ((isRoundedInBubbleBottom() && _caption.isEmpty()) ? (RectPart::BottomLeft | RectPart::BottomRight) : RectPart::None));
|
||||||
validateImageCache(rthumb.size(), roundRadius, roundCorners);
|
validateImageCache(rthumb.size(), roundRadius, roundCorners);
|
||||||
p.drawImage(rthumb.topLeft(), _imageCache);
|
p.drawImage(rthumb.topLeft(), _imageCache);
|
||||||
fillSpoilerMess(p, rthumb, roundRadius, roundCorners);
|
fillSpoilerMess(p, context.now, rthumb, roundRadius, roundCorners);
|
||||||
if (context.selected()) {
|
if (context.selected()) {
|
||||||
Ui::FillComplexOverlayRect(p, st, rthumb, roundRadius, roundCorners);
|
Ui::FillComplexOverlayRect(p, st, rthumb, roundRadius, roundCorners);
|
||||||
}
|
}
|
||||||
|
@ -267,25 +268,21 @@ QImage ExtendedPreview::prepareImageCache(QSize outer) const {
|
||||||
|
|
||||||
void ExtendedPreview::fillSpoilerMess(
|
void ExtendedPreview::fillSpoilerMess(
|
||||||
QPainter &p,
|
QPainter &p,
|
||||||
|
crl::time now,
|
||||||
QRect rect,
|
QRect rect,
|
||||||
ImageRoundRadius radius,
|
ImageRoundRadius radius,
|
||||||
RectParts corners) const {
|
RectParts corners) const {
|
||||||
const auto size = style::ConvertScale(100);
|
if (!_animation) {
|
||||||
static const auto test = [&] {
|
_animation = std::make_unique<Ui::SpoilerAnimation>([=] {
|
||||||
const auto ratio = style::DevicePixelRatio();
|
_parent->customEmojiRepaint();
|
||||||
return Ui::GenerateSpoilerMess({
|
|
||||||
.particleFadeInDuration = 200,
|
|
||||||
.particleFadeOutDuration = 200,
|
|
||||||
.particleSizeMin = style::ConvertScaleExact(1.5) * ratio,
|
|
||||||
.particleSizeMax = style::ConvertScaleExact(2.) * ratio,
|
|
||||||
.particleSpritesCount = 5,
|
|
||||||
.particlesCount = 2000,
|
|
||||||
.canvasSize = size * ratio,
|
|
||||||
.framesCount = 60,
|
|
||||||
.frameDuration = 33,
|
|
||||||
});
|
});
|
||||||
}();
|
history()->owner().registerHeavyViewPart(_parent);
|
||||||
const auto frame = test.frame();
|
}
|
||||||
|
_parent->clearCustomEmojiRepaint();
|
||||||
|
const auto &spoiler = Ui::DefaultImageSpoiler();
|
||||||
|
const auto size = spoiler.canvasSize() / style::DevicePixelRatio();
|
||||||
|
const auto frame = spoiler.frame(
|
||||||
|
_animation->index(now, _parent->delegate()->elementIsGifPaused()));
|
||||||
const auto columns = (rect.width() + size - 1) / size;
|
const auto columns = (rect.width() + size - 1) / size;
|
||||||
const auto rows = (rect.height() + size - 1) / size;
|
const auto rows = (rect.height() + size - 1) / size;
|
||||||
p.setClipRect(rect);
|
p.setClipRect(rect);
|
||||||
|
|
|
@ -11,6 +11,10 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL
|
||||||
|
|
||||||
enum class ImageRoundRadius;
|
enum class ImageRoundRadius;
|
||||||
|
|
||||||
|
namespace Ui {
|
||||||
|
class SpoilerAnimation;
|
||||||
|
} // namespace Ui
|
||||||
|
|
||||||
namespace Data {
|
namespace Data {
|
||||||
struct Invoice;
|
struct Invoice;
|
||||||
} // namespace Data
|
} // namespace Data
|
||||||
|
@ -84,6 +88,7 @@ private:
|
||||||
|
|
||||||
void fillSpoilerMess(
|
void fillSpoilerMess(
|
||||||
QPainter &p,
|
QPainter &p,
|
||||||
|
crl::time now,
|
||||||
QRect rect,
|
QRect rect,
|
||||||
ImageRoundRadius radius,
|
ImageRoundRadius radius,
|
||||||
RectParts corners) const;
|
RectParts corners) const;
|
||||||
|
@ -91,6 +96,7 @@ private:
|
||||||
const not_null<Data::Invoice*> _invoice;
|
const not_null<Data::Invoice*> _invoice;
|
||||||
ClickHandlerPtr _link;
|
ClickHandlerPtr _link;
|
||||||
Ui::Text::String _caption;
|
Ui::Text::String _caption;
|
||||||
|
mutable std::unique_ptr<Ui::SpoilerAnimation> _animation;
|
||||||
mutable QImage _inlineThumbnail;
|
mutable QImage _inlineThumbnail;
|
||||||
mutable QImage _imageCache;
|
mutable QImage _imageCache;
|
||||||
mutable int _imageCacheRoundRadius : 4 = 0;
|
mutable int _imageCacheRoundRadius : 4 = 0;
|
||||||
|
|
Loading…
Add table
Reference in a new issue