From 43af9fd87e639d65ea35fe6c16cad66decf015b4 Mon Sep 17 00:00:00 2001 From: John Preston Date: Fri, 9 Jun 2023 18:48:32 +0400 Subject: [PATCH] Fix controls fading in raster stories backend. --- .../media/view/media_view_overlay_opengl.cpp | 2 +- .../media/view/media_view_overlay_raster.cpp | 77 +++++++++++-------- .../media/view/media_view_overlay_raster.h | 5 +- 3 files changed, 48 insertions(+), 36 deletions(-) diff --git a/Telegram/SourceFiles/media/view/media_view_overlay_opengl.cpp b/Telegram/SourceFiles/media/view/media_view_overlay_opengl.cpp index a1bdce930..85211c74d 100644 --- a/Telegram/SourceFiles/media/view/media_view_overlay_opengl.cpp +++ b/Telegram/SourceFiles/media/view/media_view_overlay_opengl.cpp @@ -749,8 +749,8 @@ void OverlayWidget::RendererGL::invalidateControls() { } void OverlayWidget::RendererGL::validateControlsFade() { - const auto flip = !_owner->topShadowOnTheRight(); const auto forStories = (_owner->_stories != nullptr); + const auto flip = !forStories && !_owner->topShadowOnTheRight(); if (!_controlsFadeImage.image().isNull() && _shadowTopFlip == flip && _shadowsForStories == forStories) { diff --git a/Telegram/SourceFiles/media/view/media_view_overlay_raster.cpp b/Telegram/SourceFiles/media/view/media_view_overlay_raster.cpp index 13109e828..e7cc17d74 100644 --- a/Telegram/SourceFiles/media/view/media_view_overlay_raster.cpp +++ b/Telegram/SourceFiles/media/view/media_view_overlay_raster.cpp @@ -76,7 +76,7 @@ void OverlayWidget::RendererSW::paintTransformedVideoFrame( return; } paintTransformedImage(_owner->videoFrame(), rect, rotation); - paintControlsFade(rect, geometry.controlsOpacity, geometry.fade); + paintControlsFade(rect, geometry); } void OverlayWidget::RendererSW::paintTransformedStaticContent( @@ -97,56 +97,71 @@ void OverlayWidget::RendererSW::paintTransformedStaticContent( if (!image.isNull()) { paintTransformedImage(image, rect, rotation); } - paintControlsFade(rect, geometry.controlsOpacity, geometry.fade); + paintControlsFade(rect, geometry); } void OverlayWidget::RendererSW::paintControlsFade( - QRect geometry, - float64 opacity, - float64 fullFade) { - if (fullFade > 0.) { - _p->setOpacity(fullFade); - _p->fillRect(geometry, Qt::black); - opacity *= 1. - fullFade; + QRect content, + const ContentGeometry &geometry) { + auto opacity = geometry.controlsOpacity; + if (geometry.fade > 0.) { + _p->setOpacity(geometry.fade); + _p->fillRect(content, Qt::black); + opacity *= 1. - geometry.fade; } _p->setOpacity(opacity); - _p->setClipRect(geometry); + _p->setClipRect(content); const auto width = _owner->width(); - const auto flip = !_owner->topShadowOnTheRight(); const auto stories = (_owner->_stories != nullptr); - const auto &top = stories - ? st::storiesShadowTop - : st::mediaviewShadowTop; - const auto topShadow = stories - ? QRect(geometry.topLeft(), QSize(geometry.width(), top.height())) - : QRect( - QPoint(flip ? 0 : (width - top.width()), 0), - top.size()); - if (topShadow.intersected(geometry).intersects(_clipOuter)) { - if (flip) { - if (_topShadowCache.isNull() - || _topShadowColor != st::windowShadowFg->c) { - _topShadowColor = st::windowShadowFg->c; - _topShadowCache = top.instance( - _topShadowColor).mirrored(true, false); + if (!stories || geometry.topShadowShown) { + const auto flip = !stories && !_owner->topShadowOnTheRight(); + const auto &top = stories + ? st::storiesShadowTop + : st::mediaviewShadowTop; + const auto topShadow = stories + ? QRect( + content.topLeft(), + QSize(content.width(), top.height())) + : QRect( + QPoint(flip ? 0 : (width - top.width()), 0), + top.size()); + if (topShadow.intersected(content).intersects(_clipOuter)) { + if (stories) { + top.fill(*_p, topShadow); + } else if (flip) { + if (_topShadowCache.isNull() + || _topShadowColor != st::windowShadowFg->c) { + _topShadowColor = st::windowShadowFg->c; + _topShadowCache = top.instance( + _topShadowColor).mirrored(true, false); + } + _p->drawImage(0, 0, _topShadowCache); + } else { + top.paint(*_p, topShadow.topLeft(), width); } - _p->drawImage(0, 0, _topShadowCache); - } else { - top.paint(*_p, topShadow.topLeft(), width); } } const auto &bottom = stories ? st::storiesShadowBottom : st::mediaviewShadowBottom; + const auto bottomStart = _owner->height() - geometry.bottomShadowSkip; const auto bottomShadow = QRect( - QPoint(0, _owner->height() - bottom.height()), + QPoint(0, bottomStart - bottom.height()), QSize(width, bottom.height())); - if (bottomShadow.intersected(geometry).intersects(_clipOuter)) { + if (bottomShadow.intersected(content).intersects(_clipOuter)) { bottom.fill(*_p, bottomShadow); } _p->setClipping(false); _p->setOpacity(1.); + if (bottomStart < content.y() + content.height()) { + _p->fillRect( + content.x(), + bottomStart, + content.width(), + content.y() + content.height() - bottomStart, + QColor(0, 0, 0, 88)); + } } void OverlayWidget::RendererSW::paintTransformedImage( diff --git a/Telegram/SourceFiles/media/view/media_view_overlay_raster.h b/Telegram/SourceFiles/media/view/media_view_overlay_raster.h index 5c6a7880a..3d8abf4c4 100644 --- a/Telegram/SourceFiles/media/view/media_view_overlay_raster.h +++ b/Telegram/SourceFiles/media/view/media_view_overlay_raster.h @@ -33,10 +33,7 @@ private: const QImage &image, QRect rect, int rotation); - void paintControlsFade( - QRect geometry, - float64 opacity, - float64 fullFade); + void paintControlsFade(QRect content, const ContentGeometry &geometry); void paintRadialLoading( QRect inner, bool radial,