diff --git a/Telegram/SourceFiles/history/view/history_view_message.cpp b/Telegram/SourceFiles/history/view/history_view_message.cpp index c34a900ac..81de7a801 100644 --- a/Telegram/SourceFiles/history/view/history_view_message.cpp +++ b/Telegram/SourceFiles/history/view/history_view_message.cpp @@ -1448,20 +1448,20 @@ void Message::toggleCommentsButtonRipple(bool pressed) { if (!_comments->ripple) { createCommentsRipple(); } - _comments->ripple->add(_comments->lastPoint); + _comments->ripple->add(_comments->lastPoint + + QPoint(_comments->rippleShift, 0)); } else if (_comments->ripple) { _comments->ripple->lastStop(); } } -void Message::createCommentsRipple() { +BottomRippleMask Message::bottomRippleMask(int buttonHeight) const { using namespace Ui; using namespace Images; using Radius = CachedCornerRadius; using Corner = BubbleCornerRounding; const auto g = countGeometry(); - const auto linkWidth = g.width(); - const auto linkHeight = st::historyCommentsButtonHeight; + const auto buttonWidth = g.width(); const auto &large = CachedCornersMasks(Radius::BubbleLarge); const auto &small = CachedCornersMasks(Radius::BubbleSmall); const auto rounding = countBubbleRounding(); @@ -1493,8 +1493,8 @@ void Message::createCommentsRipple() { const auto height = image->height() / ratio; p.drawImage( QRect( - shift + (right ? (linkWidth - width) : 0), - linkHeight - height, + shift + (right ? (buttonWidth - width) : 0), + buttonHeight - height, width, height), *image); @@ -1503,26 +1503,34 @@ void Message::createCommentsRipple() { corner(kBottomLeft, false); corner(kBottomRight, true); if (icon) { - const auto left = shift ? 0 : linkWidth; + const auto left = shift ? 0 : buttonWidth; p.fillRect( - QRect{ left, 0, added, linkHeight }, + QRect{ left, 0, added, buttonHeight }, Qt::transparent); icon->paint( p, left, - linkHeight - icon->height(), - linkWidth + shift, + buttonHeight - icon->height(), + buttonWidth + shift, Qt::white); } }; - _comments->ripple = std::make_unique( - st::defaultRippleAnimation, + return { RippleAnimation::MaskByDrawer( - QSize(linkWidth + added, linkHeight), + QSize(buttonWidth + added, buttonHeight), true, drawer), + shift, + }; +} + +void Message::createCommentsRipple() { + auto mask = bottomRippleMask(st::historyCommentsButtonHeight); + _comments->ripple = std::make_unique( + st::defaultRippleAnimation, + std::move(mask.image), [=] { repaint(); }); - _comments->rippleShift = shift; + _comments->rippleShift = mask.shift; } bool Message::hasHeavyPart() const { diff --git a/Telegram/SourceFiles/history/view/history_view_message.h b/Telegram/SourceFiles/history/view/history_view_message.h index c79e74afd..f76390c56 100644 --- a/Telegram/SourceFiles/history/view/history_view_message.h +++ b/Telegram/SourceFiles/history/view/history_view_message.h @@ -50,6 +50,11 @@ struct PsaTooltipState : public RuntimeComponent { mutable bool buttonVisible = true; }; +struct BottomRippleMask { + QImage image; + int shift = 0; +}; + class Message final : public Element { public: Message( @@ -148,6 +153,7 @@ public: std::unique_ptr> override; QRect innerGeometry() const override; + [[nodiscard]] BottomRippleMask bottomRippleMask(int buttonHeight) const; protected: void refreshDataIdHook() override; diff --git a/Telegram/SourceFiles/history/view/media/history_view_poll.cpp b/Telegram/SourceFiles/history/view/media/history_view_poll.cpp index a940b79b7..184705564 100644 --- a/Telegram/SourceFiles/history/view/media/history_view_poll.cpp +++ b/Telegram/SourceFiles/history/view/media/history_view_poll.cpp @@ -10,7 +10,7 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL #include "lang/lang_keys.h" #include "history/history.h" #include "history/history_item.h" -#include "history/view/history_view_element.h" +#include "history/view/history_view_message.h" #include "history/view/history_view_cursor_state.h" #include "calls/calls_instance.h" #include "ui/chat/message_bubble.h" @@ -1568,30 +1568,20 @@ void Poll::toggleLinkRipple(bool pressed) { const auto linkWidth = width(); const auto linkHeight = bottomButtonHeight(); if (!_linkRipple) { - const auto drawMask = [&](QPainter &p) { - // #TODO rounding - const auto radius = st::bubbleRadiusSmall; - p.drawRoundedRect( - 0, - 0, - linkWidth, - linkHeight, - radius, - radius); - p.fillRect(0, 0, linkWidth, radius * 2, Qt::white); - }; auto mask = isRoundedInBubbleBottom() - ? Ui::RippleAnimation::MaskByDrawer( - QSize(linkWidth, linkHeight), - false, - drawMask) - : Ui::RippleAnimation::RectMask({ linkWidth, linkHeight }); + ? static_cast(_parent.get())->bottomRippleMask( + bottomButtonHeight()) + : BottomRippleMask{ + Ui::RippleAnimation::RectMask({ linkWidth, linkHeight }), + }; _linkRipple = std::make_unique( st::defaultRippleAnimation, - std::move(mask), + std::move(mask.image), [=] { repaint(); }); + _linkRippleShift = mask.shift; } - _linkRipple->add(_lastLinkPoint - QPoint(0, height() - linkHeight)); + _linkRipple->add(_lastLinkPoint + + QPoint(_linkRippleShift, linkHeight - height())); } else if (_linkRipple) { _linkRipple->lastStop(); } diff --git a/Telegram/SourceFiles/history/view/media/history_view_poll.h b/Telegram/SourceFiles/history/view/media/history_view_poll.h index 68eab16f2..08a79d1f2 100644 --- a/Telegram/SourceFiles/history/view/media/history_view_poll.h +++ b/Telegram/SourceFiles/history/view/media/history_view_poll.h @@ -23,6 +23,8 @@ class FireworksAnimation; namespace HistoryView { +class Message; + class Poll : public Media, public base::has_weak_ptr { public: Poll( @@ -213,6 +215,7 @@ private: ClickHandlerPtr _sendVotesLink; mutable ClickHandlerPtr _showSolutionLink; mutable std::unique_ptr _linkRipple; + mutable int _linkRippleShift = 0; mutable std::unique_ptr _answersAnimation; mutable std::unique_ptr _sendingAnimation;