diff --git a/Telegram/SourceFiles/chat_helpers/stickers_lottie.cpp b/Telegram/SourceFiles/chat_helpers/stickers_lottie.cpp index 8f93889339..b4f16f34be 100644 --- a/Telegram/SourceFiles/chat_helpers/stickers_lottie.cpp +++ b/Telegram/SourceFiles/chat_helpers/stickers_lottie.cpp @@ -235,7 +235,8 @@ bool PaintStickerThumbnailPath( QPainter &p, not_null media, QRect target, - QLinearGradient *gradient) { + QLinearGradient *gradient, + bool mirrorHorizontal) { const auto &path = media->thumbnailPath(); const auto dimensions = media->owner()->dimensions; if (path.isEmpty() || dimensions.isEmpty() || target.isEmpty()) { @@ -254,6 +255,12 @@ bool PaintStickerThumbnailPath( 0); p.setBrush(*gradient); } + if (mirrorHorizontal) { + const auto c = QPointF(target.width() / 2., target.height() / 2.); + p.translate(c); + p.scale(-1., 1.); + p.translate(-c); + } p.scale( target.width() / float64(dimensions.width()), target.height() / float64(dimensions.height())); @@ -266,14 +273,25 @@ bool PaintStickerThumbnailPath( QPainter &p, not_null media, QRect target, - not_null gradient) { + not_null gradient, + bool mirrorHorizontal) { return gradient->paint([&](const Ui::PathShiftGradient::Background &bg) { if (const auto color = std::get_if(&bg)) { p.setBrush(*color); - return PaintStickerThumbnailPath(p, media, target); + return PaintStickerThumbnailPath( + p, + media, + target, + nullptr, + mirrorHorizontal); } const auto gradient = v::get(bg); - return PaintStickerThumbnailPath(p, media, target, gradient); + return PaintStickerThumbnailPath( + p, + media, + target, + gradient, + mirrorHorizontal); }); } diff --git a/Telegram/SourceFiles/chat_helpers/stickers_lottie.h b/Telegram/SourceFiles/chat_helpers/stickers_lottie.h index 0e95a806ac..1f66515c62 100644 --- a/Telegram/SourceFiles/chat_helpers/stickers_lottie.h +++ b/Telegram/SourceFiles/chat_helpers/stickers_lottie.h @@ -105,13 +105,15 @@ bool PaintStickerThumbnailPath( QPainter &p, not_null media, QRect target, - QLinearGradient *gradient = nullptr); + QLinearGradient *gradient = nullptr, + bool mirrorHorizontal = false); bool PaintStickerThumbnailPath( QPainter &p, not_null media, QRect target, - not_null gradient); + not_null gradient, + bool mirrorHorizontal = false); [[nodiscard]] QSize ComputeStickerSize( not_null document, diff --git a/Telegram/SourceFiles/history/view/media/history_view_sticker.cpp b/Telegram/SourceFiles/history/view/media/history_view_sticker.cpp index ee0a3d3e16..a959c2c567 100644 --- a/Telegram/SourceFiles/history/view/media/history_view_sticker.cpp +++ b/Telegram/SourceFiles/history/view/media/history_view_sticker.cpp @@ -180,14 +180,7 @@ void Sticker::paintLottie( if (context.selected() && !_nextLastDiceFrame) { request.colored = context.st->msgStickerOverlay()->c; } - const auto premium = _data->isPremiumSticker(); - if (premium) { - const auto rightAligned = _parent->hasOutLayout() - && !_parent->delegate()->elementIsChatWide(); - if (!rightAligned) { - request.mirrorHorizontal = true; - } - } + request.mirrorHorizontal = mirrorHorizontal(); const auto frame = _lottie ? _lottie->frameInfo(request) : Lottie::Animation::FrameInfo(); @@ -249,11 +242,24 @@ bool Sticker::paintPixmap( if (pixmap.isNull()) { return false; } - p.drawPixmap( - QPoint( - r.x() + (r.width() - _size.width()) / 2, - r.y() + (r.height() - _size.height()) / 2), - pixmap); + const auto position = QPoint( + r.x() + (r.width() - _size.width()) / 2, + r.y() + (r.height() - _size.height()) / 2); + const auto size = pixmap.size() / pixmap.devicePixelRatio(); + const auto mirror = mirrorHorizontal(); + if (mirror) { + p.save(); + const auto middle = QPointF( + position.x() + size.width() / 2., + position.y() + size.height() / 2.); + p.translate(middle); + p.scale(-1., 1.); + p.translate(-middle); + } + p.drawPixmap(position, pixmap); + if (mirror) { + p.restore(); + } return true; } @@ -274,7 +280,8 @@ void Sticker::paintPath( p, _dataMedia.get(), r, - pathGradient); + pathGradient, + mirrorHorizontal()); } QPixmap Sticker::paintedPixmap(const PaintContext &context) const { @@ -301,6 +308,15 @@ QPixmap Sticker::paintedPixmap(const PaintContext &context) const { return QPixmap(); } +bool Sticker::mirrorHorizontal() const { + if (!_data->isPremiumSticker()) { + return false; + } + const auto rightAligned = _parent->hasOutLayout() + && !_parent->delegate()->elementIsChatWide(); + return !rightAligned; +} + ClickHandlerPtr Sticker::ShowSetHandler(not_null document) { return std::make_shared([=](ClickContext context) { const auto my = context.other.value(); diff --git a/Telegram/SourceFiles/history/view/media/history_view_sticker.h b/Telegram/SourceFiles/history/view/media/history_view_sticker.h index d952528414..da28cb4af0 100644 --- a/Telegram/SourceFiles/history/view/media/history_view_sticker.h +++ b/Telegram/SourceFiles/history/view/media/history_view_sticker.h @@ -83,6 +83,7 @@ private: bool paintPixmap(Painter &p, const PaintContext &context, const QRect &r); void paintPath(Painter &p, const PaintContext &context, const QRect &r); [[nodiscard]] QPixmap paintedPixmap(const PaintContext &context) const; + [[nodiscard]] bool mirrorHorizontal() const; void ensureDataMediaCreated() const; void dataMediaCreated() const;