From a0e9e148b0cedbb56eb476685155f2b1eb39b360 Mon Sep 17 00:00:00 2001 From: John Preston Date: Wed, 10 May 2023 23:32:32 +0400 Subject: [PATCH] Apply rounding to stories. --- .../SourceFiles/media/view/media_view.style | 1 + .../media/view/media_view_overlay_opengl.cpp | 35 +++++++++++++------ .../media/view/media_view_overlay_opengl.h | 3 +- .../media/view/media_view_overlay_widget.cpp | 10 +++--- .../media/view/media_view_overlay_widget.h | 1 + 5 files changed, 34 insertions(+), 16 deletions(-) diff --git a/Telegram/SourceFiles/media/view/media_view.style b/Telegram/SourceFiles/media/view/media_view.style index 3f3c9f595..5e7a30bb8 100644 --- a/Telegram/SourceFiles/media/view/media_view.style +++ b/Telegram/SourceFiles/media/view/media_view.style @@ -406,6 +406,7 @@ pipVolumeIcon2Over: icon {{ "player/player_volume_on", mediaviewPipControlsFgOve speedSliderDividerSize: size(2px, 8px); storiesMaxSize: size(405px, 720px); +storiesRadius: 8px; storiesControlSize: 64px; storiesLeft: icon {{ "mediaview/stories_next-flip_horizontal", mediaviewControlFg }}; storiesRight: icon {{ "mediaview/stories_next", mediaviewControlFg }}; diff --git a/Telegram/SourceFiles/media/view/media_view_overlay_opengl.cpp b/Telegram/SourceFiles/media/view/media_view_overlay_opengl.cpp index 4756c6531..0ea2f2ee6 100644 --- a/Telegram/SourceFiles/media/view/media_view_overlay_opengl.cpp +++ b/Telegram/SourceFiles/media/view/media_view_overlay_opengl.cpp @@ -94,7 +94,7 @@ float roundedCorner() { } )", .body = R"( - result = vec4(roundedCorner()); + result *= roundedCorner(); )", }; } @@ -160,7 +160,8 @@ void OverlayWidget::RendererGL::init( _texturedVertexShader, FragmentShader({ FragmentSampleARGB32Texture(), - FragmentApplyControlsFade() + FragmentApplyControlsFade(), + FragmentRoundedCorners() })); _withTransparencyProgram.emplace(); @@ -179,7 +180,8 @@ void OverlayWidget::RendererGL::init( _texturedVertexShader, FragmentShader({ FragmentSampleYUV420Texture(), - FragmentApplyControlsFade() + FragmentApplyControlsFade(), + FragmentRoundedCorners() })); _nv12Program.emplace(); @@ -188,7 +190,8 @@ void OverlayWidget::RendererGL::init( _texturedVertexShader, FragmentShader({ FragmentSampleNV12Texture(), - FragmentApplyControlsFade() + FragmentApplyControlsFade(), + FragmentRoundedCorners() })); _fillProgram.emplace(); @@ -210,7 +213,10 @@ void OverlayWidget::RendererGL::init( LinkProgram( &*_roundedCornersProgram, VertexShader({ VertexViewportTransform() }), - FragmentShader({ FragmentRoundedCorners() })); + FragmentShader({ + { .body = "result = vec4(1.);" }, + FragmentRoundedCorners(), + })); const auto renderer = reinterpret_cast( f.glGetString(GL_RENDERER)); @@ -369,8 +375,8 @@ void OverlayWidget::RendererGL::paintTransformedVideoFrame( } program->setUniformValue("f_texture", GLint(nv12 ? 2 : 3)); - toggleBlending(false); - paintTransformedContent(program, geometry); + toggleBlending(geometry.roundRadius > 0.); + paintTransformedContent(program, geometry, false); } void OverlayWidget::RendererGL::paintTransformedStaticContent( @@ -440,13 +446,15 @@ void OverlayWidget::RendererGL::paintTransformedStaticContent( program->setUniformValue("s_texture", GLint(0)); program->setUniformValue("f_texture", GLint(1)); - toggleBlending(semiTransparent && !fillTransparentBackground); - paintTransformedContent(&*program, geometry); + toggleBlending((geometry.roundRadius > 0.) + || (semiTransparent && !fillTransparentBackground)); + paintTransformedContent(&*program, geometry, fillTransparentBackground); } void OverlayWidget::RendererGL::paintTransformedContent( not_null program, - ContentGeometry geometry) { + ContentGeometry geometry, + bool fillTransparentBackground) { const auto rect = transformRect(geometry.rect); const auto centerx = rect.x() + rect.width() / 2; const auto centery = rect.y() + rect.height() / 2; @@ -493,7 +501,12 @@ void OverlayWidget::RendererGL::paintTransformedContent( bottom.height() * _factor, geometry.controlsOpacity, 1.f - float(geometry.fade))); - + if (!fillTransparentBackground) { + program->setUniformValue("roundRect", Uniform(rect)); + program->setUniformValue( + "roundRadius", + GLfloat(geometry.roundRadius * _factor)); + } FillTexturedRectangle(*_f, &*program); } diff --git a/Telegram/SourceFiles/media/view/media_view_overlay_opengl.h b/Telegram/SourceFiles/media/view/media_view_overlay_opengl.h index a171752de..9cc233fba 100644 --- a/Telegram/SourceFiles/media/view/media_view_overlay_opengl.h +++ b/Telegram/SourceFiles/media/view/media_view_overlay_opengl.h @@ -51,7 +51,8 @@ private: bool fillTransparentBackground) override; void paintTransformedContent( not_null program, - ContentGeometry geometry); + ContentGeometry geometry, + bool fillTransparentBackground); void paintRadialLoading( QRect inner, bool radial, diff --git a/Telegram/SourceFiles/media/view/media_view_overlay_widget.cpp b/Telegram/SourceFiles/media/view/media_view_overlay_widget.cpp index 8c404e65d..76111c5e0 100644 --- a/Telegram/SourceFiles/media/view/media_view_overlay_widget.cpp +++ b/Telegram/SourceFiles/media/view/media_view_overlay_widget.cpp @@ -1493,6 +1493,7 @@ QRect OverlayWidget::finalContentRect() const { OverlayWidget::ContentGeometry OverlayWidget::contentGeometry() const { const auto fade = _stories ? _stories->contentFade() : 0.; + const auto radius = _stories ? float64(st::storiesRadius) : 0.; const auto controlsOpacity = _controlsOpacity.current(); const auto toRotation = qreal(finalContentRotation()); const auto toRectRotated = QRectF(finalContentRect()); @@ -1505,7 +1506,7 @@ OverlayWidget::ContentGeometry OverlayWidget::contentGeometry() const { toRectRotated.width()) : toRectRotated; if (!_geometryAnimation.animating()) { - return { toRect, toRotation, controlsOpacity, fade }; + return { toRect, toRotation, controlsOpacity, fade, radius }; } const auto fromRect = _oldGeometry.rect; const auto fromRotation = _oldGeometry.rotation; @@ -1528,7 +1529,7 @@ OverlayWidget::ContentGeometry OverlayWidget::contentGeometry() const { fromRect.width() + (toRect.width() - fromRect.width()) * progress, fromRect.height() + (toRect.height() - fromRect.height()) * progress ); - return { useRect, useRotation, controlsOpacity, fade }; + return { useRect, useRotation, controlsOpacity, fade, radius }; } void OverlayWidget::updateContentRect() { @@ -4164,17 +4165,18 @@ void OverlayWidget::paint(not_null renderer) { } paintRadialLoading(renderer); if (_stories) { + const auto radius = float64(st::storiesRadius); if (const auto left = _stories->siblingLeft()) { renderer->paintTransformedStaticContent( left.image, - { .rect = left.geometry }, + { .rect = left.geometry, .roundRadius = radius }, false, // semi-transparent false); // fill transparent background } if (const auto right = _stories->siblingRight()) { renderer->paintTransformedStaticContent( right.image, - { .rect = right.geometry }, + { .rect = right.geometry, .roundRadius = radius }, false, // semi-transparent false); // fill transparent background } diff --git a/Telegram/SourceFiles/media/view/media_view_overlay_widget.h b/Telegram/SourceFiles/media/view/media_view_overlay_widget.h index 61b240659..a95f5735d 100644 --- a/Telegram/SourceFiles/media/view/media_view_overlay_widget.h +++ b/Telegram/SourceFiles/media/view/media_view_overlay_widget.h @@ -166,6 +166,7 @@ private: qreal rotation = 0.; qreal controlsOpacity = 0.; qreal fade = 0.; + qreal roundRadius = 0.; }; struct StartStreaming { StartStreaming() : continueStreaming(false), startTime(0) {