From 7c8ada0e78fb660d226dbe824191cd387f331868 Mon Sep 17 00:00:00 2001 From: 23rd <23rd@vivaldi.net> Date: Tue, 31 Jan 2023 22:49:10 +0300 Subject: [PATCH] Slightly improved shadows for bubble wraps in userpic emoji builder. --- .../info/userpic/info_userpic_bubble_wrap.cpp | 67 +++++++++++++------ 1 file changed, 46 insertions(+), 21 deletions(-) diff --git a/Telegram/SourceFiles/info/userpic/info_userpic_bubble_wrap.cpp b/Telegram/SourceFiles/info/userpic/info_userpic_bubble_wrap.cpp index 282d080402..e04981b4b3 100644 --- a/Telegram/SourceFiles/info/userpic/info_userpic_bubble_wrap.cpp +++ b/Telegram/SourceFiles/info/userpic/info_userpic_bubble_wrap.cpp @@ -7,13 +7,39 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL */ #include "info/userpic/info_userpic_bubble_wrap.h" -#include "ui/chat/message_bubble.h" +#include "ui/painter.h" #include "ui/rect.h" #include "ui/wrap/padding_wrap.h" #include "ui/wrap/vertical_layout.h" +#include "styles/style_chat.h" #include "styles/style_info_userpic_builder.h" namespace Ui { +namespace { + +void PaintExcludeTopShadow(QPainter &p, int radius, const QRect &r) { + constexpr auto kHorizontalOffset = 1; + constexpr auto kVerticalOffset = 2; + const auto opacity = p.opacity(); + p.setOpacity(opacity * 0.2); + p.drawRoundedRect( + r + QMargins(kHorizontalOffset, -radius, kHorizontalOffset, 0), + radius, + radius); + p.setOpacity(opacity * 0.2); + p.drawRoundedRect( + r + QMargins(0, 0, 0, kVerticalOffset), + radius, + radius); + p.setOpacity(opacity * 0.4); + p.drawRoundedRect( + r + QMargins(0, 0, 0, kVerticalOffset / 2), + radius, + radius); + p.setOpacity(opacity); +} + +} // namespace QRect BubbleWrap::innerRect() const { return rect() - st::userpicBuilderEmojiBubblePadding; @@ -33,29 +59,28 @@ not_null AddBubbleWrap( container, object_ptr(container)))->entity(); bubble->resize(size); - const auto rounding = BubbleRounding{ - .topLeft = BubbleCornerRounding::Small, - .topRight = BubbleCornerRounding::Small, - .bottomLeft = BubbleCornerRounding::Small, - .bottomRight = BubbleCornerRounding::Small, - }; + + auto cached = QImage( + size * style::DevicePixelRatio(), + QImage::Format_ARGB32_Premultiplied); + cached.setDevicePixelRatio(style::DevicePixelRatio()); + cached.fill(Qt::transparent); + { + auto p = QPainter(&cached); + const auto innerRect = bubble->innerRect(); + auto hq = PainterHighQualityEnabler(p); + const auto radius = st::bubbleRadiusSmall; + p.setPen(Qt::NoPen); + p.setBrush(st::shadowFg); + PaintExcludeTopShadow(p, radius, innerRect); + p.setBrush(st::boxBg); + p.drawRoundedRect(innerRect, radius, radius); + } bubble->paintRequest( - ) | rpl::start_with_next([=] { + ) | rpl::start_with_next([bubble, cached = std::move(cached)] { auto p = QPainter(bubble); - const auto innerRect = bubble->innerRect(); - const auto args = SimpleBubble{ - .st = chatStyle(), - .geometry = innerRect, - .pattern = nullptr, - .patternViewport = innerRect, - .outerWidth = bubble->width(), - .selected = false, - .shadowed = true, - .outbg = false, - .rounding = rounding, - }; - PaintBubble(p, args); + p.drawImage(0, 0, cached); }, bubble->lifetime()); return bubble;