diff --git a/Telegram/SourceFiles/boxes/star_gift_craft_animation.cpp b/Telegram/SourceFiles/boxes/star_gift_craft_animation.cpp index a4be242311..0dae0f43f5 100644 --- a/Telegram/SourceFiles/boxes/star_gift_craft_animation.cpp +++ b/Telegram/SourceFiles/boxes/star_gift_craft_animation.cpp @@ -940,7 +940,7 @@ void PaintFailureThumbnails( not_null shared, QSize canvasSize, float64 fadeProgress) { - if (fadeProgress <= 0.) { + if (fadeProgress <= 0. || shared->lostGifts.empty()) { return; } @@ -948,14 +948,18 @@ void PaintFailureThumbnails( const auto width = canvasSize.width(); const auto giftsCount = int(shared->lostGifts.size()); - const auto thumbSize = shared->lostGifts.front().thumbnail.size() - / style::DevicePixelRatio(); + const auto &firstCorner = shared->corners[ + shared->lostGifts.front().cornerIndex]; + if (!firstCorner.giftButton) { + p.setOpacity(1.); + return; + } + const auto thumbSize = firstCorner.giftButton->size(); + const auto &extend = st::defaultDropdownMenu.wrap.shadow.extend; const auto thumbSpacing = st::boxRowPadding.left() / 2; const auto totalThumbWidth = giftsCount * thumbSize.width() + (giftsCount - 1) * thumbSpacing; - const auto available = width - - st::boxRowPadding.left() - - st::boxRowPadding.right(); + const auto available = width - extend.left() - extend.right(); const auto skip = (totalThumbWidth > available) ? (available - giftsCount * thumbSize.width()) / (giftsCount - 1) : thumbSpacing; @@ -963,11 +967,42 @@ void PaintFailureThumbnails( + (giftsCount - 1) * skip; auto x = (width - full) / 2; const auto y = shared->forgeRect.bottom() + st::craftFailureThumbsTop; + const auto rubberOut = st::lineWidth; for (const auto &gift : shared->lostGifts) { - if (!gift.thumbnail.isNull()) { + if (gift.cornerIndex < 0) { + x += thumbSize.width() + skip; + continue; + } + const auto &corner = shared->corners[gift.cornerIndex]; + const auto giftFrame = corner.gift(0.); + if (!giftFrame.isNull()) { const auto targetRect = QRect(QPoint(x, y), thumbSize); - p.drawImage(targetRect, gift.thumbnail); + p.drawImage(targetRect, giftFrame); + + if (!gift.number.isEmpty()) { + if (gift.badgeCache.isNull()) { + const auto burnedBg = BurnedBadgeBg(); + gift.badgeCache = ValidateRotatedBadge(GiftBadge{ + .text = gift.number, + .bg1 = burnedBg, + .bg2 = burnedBg, + .fg = st::white->c, + .small = true, + }, QMargins()); + } + const auto inner = targetRect.marginsRemoved(extend); + p.save(); + p.setClipRect(inner.marginsAdded( + { rubberOut, rubberOut, rubberOut, rubberOut })); + const auto badgeW = gift.badgeCache.width() + / gift.badgeCache.devicePixelRatio(); + p.drawImage( + inner.x() + inner.width() + rubberOut - badgeW, + inner.y() - rubberOut, + gift.badgeCache); + p.restore(); + } } x += thumbSize.width() + skip; } diff --git a/Telegram/SourceFiles/boxes/star_gift_craft_animation.h b/Telegram/SourceFiles/boxes/star_gift_craft_animation.h index 1a2b81d6bd..0df9d6fed0 100644 --- a/Telegram/SourceFiles/boxes/star_gift_craft_animation.h +++ b/Telegram/SourceFiles/boxes/star_gift_craft_animation.h @@ -122,8 +122,9 @@ struct CraftState { QString giftName; int successPermille = 0; struct LostGift { - QImage thumbnail; + int cornerIndex = -1; QString number; + mutable QImage badgeCache; }; std::vector lostGifts; QImage lostRadial; diff --git a/Telegram/SourceFiles/boxes/star_gift_craft_box.cpp b/Telegram/SourceFiles/boxes/star_gift_craft_box.cpp index 1d66618736..6fca4eeb83 100644 --- a/Telegram/SourceFiles/boxes/star_gift_craft_box.cpp +++ b/Telegram/SourceFiles/boxes/star_gift_craft_box.cpp @@ -508,8 +508,7 @@ AbstractButton *MakeRemoveButton( corner.removeButton = GrabWidgetToImage(entry.remove); } if (lostIndex < craftState->lostGifts.size()) { - craftState->lostGifts[lostIndex].thumbnail - = GrabWidgetToImage(entry.button); + craftState->lostGifts[lostIndex].cornerIndex = i; ++lostIndex; } corner.giftButton.reset(entry.button);