From 27f248645c3085638c65ff8ab9712c2b4c36b6c4 Mon Sep 17 00:00:00 2001 From: John Preston Date: Fri, 19 Jul 2019 17:19:13 +0200 Subject: [PATCH] Use correct animated sticker thumbnails size. --- .../SourceFiles/boxes/sticker_set_box.cpp | 18 ++++++++--- .../chat_helpers/field_autocomplete.cpp | 32 +++++++++++++------ .../chat_helpers/field_autocomplete.h | 1 + .../chat_helpers/stickers_list_widget.cpp | 17 +++++++--- 4 files changed, 50 insertions(+), 18 deletions(-) diff --git a/Telegram/SourceFiles/boxes/sticker_set_box.cpp b/Telegram/SourceFiles/boxes/sticker_set_box.cpp index 27c47d69b3..44b44e1de9 100644 --- a/Telegram/SourceFiles/boxes/sticker_set_box.cpp +++ b/Telegram/SourceFiles/boxes/sticker_set_box.cpp @@ -620,11 +620,19 @@ void StickerSetBox::Inner::paintSticker( const_cast(this)->setupLottie(index); } - float64 coef = qMin((st::stickersSize.width() - st::buttonRadius * 2) / float64(document->dimensions.width()), (st::stickersSize.height() - st::buttonRadius * 2) / float64(document->dimensions.height())); - if (coef > 1) coef = 1; - int32 w = qRound(coef * document->dimensions.width()), h = qRound(coef * document->dimensions.height()); - if (w < 1) w = 1; - if (h < 1) h = 1; + auto w = 1; + auto h = 1; + if (element.animated && !document->dimensions.isEmpty()) { + const auto request = Lottie::FrameRequest{ boundingBoxSize() * cIntRetinaFactor() }; + const auto size = request.size(document->dimensions) / cIntRetinaFactor(); + w = std::max(size.width(), 1); + h = std::max(size.height(), 1); + } else { + auto coef = qMin((st::stickersSize.width() - st::buttonRadius * 2) / float64(document->dimensions.width()), (st::stickersSize.height() - st::buttonRadius * 2) / float64(document->dimensions.height())); + if (coef > 1) coef = 1; + w = std::max(qRound(coef * document->dimensions.width()), 1); + h = std::max(qRound(coef * document->dimensions.height()), 1); + } QPoint ppos = position + QPoint((st::stickersSize.width() - w) / 2, (st::stickersSize.height() - h) / 2); if (element.animated && element.animated->ready()) { const auto frame = element.animated->frame(); diff --git a/Telegram/SourceFiles/chat_helpers/field_autocomplete.cpp b/Telegram/SourceFiles/chat_helpers/field_autocomplete.cpp index a1478dd88b..45cfa0b84b 100644 --- a/Telegram/SourceFiles/chat_helpers/field_autocomplete.cpp +++ b/Telegram/SourceFiles/chat_helpers/field_autocomplete.cpp @@ -638,6 +638,22 @@ void FieldAutocompleteInner::paintEvent(QPaintEvent *e) { } document->checkStickerSmall(); + auto w = 1; + auto h = 1; + if (sticker.animated && !document->dimensions.isEmpty()) { + const auto request = Lottie::FrameRequest{ stickerBoundingBox() * cIntRetinaFactor() }; + const auto size = request.size(document->dimensions) / cIntRetinaFactor(); + w = std::max(size.width(), 1); + h = std::max(size.height(), 1); + } else { + const auto coef = std::max( + std::min( + (st::stickerPanSize.width() - st::buttonRadius * 2) / float64(document->dimensions.width()), + (st::stickerPanSize.height() - st::buttonRadius * 2) / float64(document->dimensions.height())), + 1.); + w = std::max(qRound(coef * document->dimensions.width()), 1); + h = std::max(qRound(coef * document->dimensions.height()), 1); + } if (sticker.animated && sticker.animated->ready()) { const auto frame = sticker.animated->frame(); sticker.animated->markFrameShown(); @@ -649,11 +665,6 @@ void FieldAutocompleteInner::paintEvent(QPaintEvent *e) { QRect(ppos, size), frame); } else if (const auto image = document->getStickerSmall()) { - float64 coef = qMin((st::stickerPanSize.width() - st::buttonRadius * 2) / float64(document->dimensions.width()), (st::stickerPanSize.height() - st::buttonRadius * 2) / float64(document->dimensions.height())); - if (coef > 1) coef = 1; - int32 w = qRound(coef * document->dimensions.width()), h = qRound(coef * document->dimensions.height()); - if (w < 1) w = 1; - if (h < 1) h = 1; QPoint ppos = pos + QPoint((st::stickerPanSize.width() - w) / 2, (st::stickerPanSize.height() - h) / 2); p.drawPixmapLeft(ppos, width(), image->pix(document->stickerSetOrigin(), w, h)); } @@ -978,10 +989,7 @@ void FieldAutocompleteInner::setupLottie(StickerSuggestion &suggestion) { suggestion.animated = Stickers::LottiePlayerFromDocument( document, Stickers::LottieSize::InlineResults, - QSize( - st::stickerPanSize.width() - st::buttonRadius * 2, - st::stickerPanSize.height() - st::buttonRadius * 2 - ) * cIntRetinaFactor(), + stickerBoundingBox() * cIntRetinaFactor(), Lottie::Quality::Default, getLottieRenderer()); @@ -991,6 +999,12 @@ void FieldAutocompleteInner::setupLottie(StickerSuggestion &suggestion) { }, _stickersLifetime); } +QSize FieldAutocompleteInner::stickerBoundingBox() const { + return QSize( + st::stickerPanSize.width() - st::buttonRadius * 2, + st::stickerPanSize.height() - st::buttonRadius * 2); +} + void FieldAutocompleteInner::repaintSticker( not_null document) { const auto i = ranges::find( diff --git a/Telegram/SourceFiles/chat_helpers/field_autocomplete.h b/Telegram/SourceFiles/chat_helpers/field_autocomplete.h index 071b628ae0..a9133c56f9 100644 --- a/Telegram/SourceFiles/chat_helpers/field_autocomplete.h +++ b/Telegram/SourceFiles/chat_helpers/field_autocomplete.h @@ -193,6 +193,7 @@ private: void showPreview(); void selectByMouse(QPoint global); + QSize stickerBoundingBox() const; void setupLottie(StickerSuggestion &suggestion); void repaintSticker(not_null document); std::shared_ptr getLottieRenderer(); diff --git a/Telegram/SourceFiles/chat_helpers/stickers_list_widget.cpp b/Telegram/SourceFiles/chat_helpers/stickers_list_widget.cpp index 3196311c68..18c2c906e1 100644 --- a/Telegram/SourceFiles/chat_helpers/stickers_list_widget.cpp +++ b/Telegram/SourceFiles/chat_helpers/stickers_list_widget.cpp @@ -1660,10 +1660,19 @@ void StickersListWidget::paintSticker(Painter &p, Set &set, int y, int section, document->checkStickerSmall(); - auto coef = qMin((_singleSize.width() - st::buttonRadius * 2) / float64(document->dimensions.width()), (_singleSize.height() - st::buttonRadius * 2) / float64(document->dimensions.height())); - if (coef > 1) coef = 1; - auto w = qMax(qRound(coef * document->dimensions.width()), 1); - auto h = qMax(qRound(coef * document->dimensions.height()), 1); + auto w = 1; + auto h = 1; + if (sticker.animated && !document->dimensions.isEmpty()) { + const auto request = Lottie::FrameRequest{ boundingBoxSize() * cIntRetinaFactor() }; + const auto size = request.size(document->dimensions) / cIntRetinaFactor(); + w = std::max(size.width(), 1); + h = std::max(size.height(), 1); + } else { + auto coef = qMin((_singleSize.width() - st::buttonRadius * 2) / float64(document->dimensions.width()), (_singleSize.height() - st::buttonRadius * 2) / float64(document->dimensions.height())); + if (coef > 1) coef = 1; + w = std::max(qRound(coef * document->dimensions.width()), 1); + h = std::max(qRound(coef * document->dimensions.height()), 1); + } auto ppos = pos + QPoint((_singleSize.width() - w) / 2, (_singleSize.height() - h) / 2); if (sticker.animated && sticker.animated->ready()) { auto request = Lottie::FrameRequest();