From 01f28b4d526987843d5c21ef5261ec50b0e7134e Mon Sep 17 00:00:00 2001 From: John Preston Date: Thu, 11 Aug 2022 20:55:51 +0300 Subject: [PATCH] Use CustomEmoji instances for categories in the panel. --- .../chat_helpers/emoji_list_widget.cpp | 27 +++----------- .../chat_helpers/stickers_list_footer.cpp | 36 +++++++++++++++---- .../chat_helpers/stickers_list_footer.h | 3 ++ 3 files changed, 37 insertions(+), 29 deletions(-) diff --git a/Telegram/SourceFiles/chat_helpers/emoji_list_widget.cpp b/Telegram/SourceFiles/chat_helpers/emoji_list_widget.cpp index 45a653cce8..d269de4236 100644 --- a/Telegram/SourceFiles/chat_helpers/emoji_list_widget.cpp +++ b/Telegram/SourceFiles/chat_helpers/emoji_list_widget.cpp @@ -1474,31 +1474,12 @@ std::vector EmojiListWidget::fillIcons() { } else { result.emplace_back(AllEmojiSectionSetId()); } + const auto esize = Data::FrameSizeFromTag( + Data::CustomEmojiManager::SizeTag::Large + ) / style::DevicePixelRatio(); for (const auto &custom : _custom) { const auto set = custom.set; - const auto s = custom.thumbnailDocument; - const auto availw = st::stickerIconWidth - 2 * st::emojiIconPadding; - const auto availh = st::emojiFooterHeight - 2 * st::emojiIconPadding; - const auto size = set->hasThumbnail() - ? QSize( - set->thumbnailLocation().width(), - set->thumbnailLocation().height()) - : s->hasThumbnail() - ? QSize( - s->thumbnailLocation().width(), - s->thumbnailLocation().height()) - : QSize(); - auto thumbw = size.width(), thumbh = size.height(), pixw = 1, pixh = 1; - if (availw * thumbh > availh * thumbw) { - pixh = availh; - pixw = (pixh * thumbw) / thumbh; - } else { - pixw = availw; - pixh = thumbw ? ((pixw * thumbh) / thumbw) : 1; - } - if (pixw < 1) pixw = 1; - if (pixh < 1) pixh = 1; - result.emplace_back(set, s, pixw, pixh); + result.emplace_back(set, custom.thumbnailDocument, esize, esize); } return result; } diff --git a/Telegram/SourceFiles/chat_helpers/stickers_list_footer.cpp b/Telegram/SourceFiles/chat_helpers/stickers_list_footer.cpp index ae71d87208..6eb003129a 100644 --- a/Telegram/SourceFiles/chat_helpers/stickers_list_footer.cpp +++ b/Telegram/SourceFiles/chat_helpers/stickers_list_footer.cpp @@ -10,6 +10,7 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL #include "chat_helpers/stickers_lottie.h" #include "data/stickers/data_stickers_set.h" #include "data/stickers/data_stickers.h" +#include "data/stickers/data_custom_emoji.h" #include "data/data_file_origin.h" #include "data/data_channel.h" #include "data/data_session.h" @@ -88,11 +89,11 @@ StickerIcon::StickerIcon( DocumentData *sticker, int pixw, int pixh) - : setId(set->id) - , set(set) - , sticker(sticker) - , pixw(pixw) - , pixh(pixh) { +: setId(set->id) +, set(set) +, sticker(sticker) +, pixw(pixw) +, pixh(pixh) { } StickerIcon::StickerIcon(StickerIcon&&) = default; @@ -530,6 +531,7 @@ void StickersListFooter::setLoading(bool loading) { void StickersListFooter::paintEvent(QPaintEvent *e) { Painter p(this); + _repaintScheduled = false; if (_searchButtonVisible) { paintSearchIcon(p); } @@ -951,6 +953,7 @@ void StickersListFooter::refreshIcons( if (now.sticker == was.sticker) { now.webm = std::move(was.webm); now.lottie = std::move(was.lottie); + now.custom = std::move(was.custom); now.lifetime = std::move(was.lifetime); now.savedFrame = std::move(was.savedFrame); } @@ -1052,6 +1055,13 @@ void StickersListFooter::paintSearchIcon(Painter &p) const { width()); } +void StickersListFooter::customEmojiRepaint() { + if (!_repaintScheduled) { + _repaintScheduled = true; + update(); + } +} + void StickersListFooter::validateIconLottieAnimation( const StickerIcon &icon) { icon.ensureMediaCreated(); @@ -1104,6 +1114,18 @@ void StickersListFooter::validateIconWebmAnimation( void StickersListFooter::validateIconAnimation( const StickerIcon &icon) { + const auto emoji = icon.sticker; + if (emoji && emoji->sticker()->setType == Data::StickersType::Emoji) { + if (!icon.custom) { + const auto tag = Data::CustomEmojiManager::SizeTag::Large; + auto &manager = emoji->owner().customEmojiManager(); + icon.custom = manager.create( + emoji->id, + [=] { customEmojiRepaint(); }, + tag); + } + return; + } validateIconWebmAnimation(icon); validateIconLottieAnimation(icon); } @@ -1138,7 +1160,9 @@ void StickersListFooter::paintSetIcon( : nullptr; const auto x = info.adjustedLeft + (_singleWidth - icon.pixw) / 2; const auto y = _iconsTop + (st::emojiFooterHeight - icon.pixh) / 2; - if (icon.lottie && icon.lottie->ready()) { + if (icon.custom) { + icon.custom->paint(p, x, y, now, st::emojiIconFg->c, paused); + } else if (icon.lottie && icon.lottie->ready()) { const auto frame = icon.lottie->frame(); const auto size = frame.size() / cIntRetinaFactor(); if (icon.savedFrame.isNull()) { diff --git a/Telegram/SourceFiles/chat_helpers/stickers_list_footer.h b/Telegram/SourceFiles/chat_helpers/stickers_list_footer.h index 397d15601a..0a9b842f60 100644 --- a/Telegram/SourceFiles/chat_helpers/stickers_list_footer.h +++ b/Telegram/SourceFiles/chat_helpers/stickers_list_footer.h @@ -62,6 +62,7 @@ struct StickerIcon { uint64 setId = 0; Data::StickersSet *set = nullptr; mutable std::unique_ptr lottie; + mutable std::unique_ptr custom; mutable Media::Clip::ReaderPointer webm; mutable QImage savedFrame; DocumentData *sticker = nullptr; @@ -179,6 +180,7 @@ private: void validateIconLottieAnimation(const StickerIcon &icon); void validateIconWebmAnimation(const StickerIcon &icon); void validateIconAnimation(const StickerIcon &icon); + void customEmojiRepaint(); void refreshIconsGeometry( uint64 activeSetId, @@ -243,6 +245,7 @@ private: int _subiconsWidth = 0; bool _subiconsExpanded = false; bool _barSelection = false; + bool _repaintScheduled = false; bool _horizontal = false;