From 2cfb3c6755c48bc007e3c8a024e35bb51e9ebcf0 Mon Sep 17 00:00:00 2001 From: John Preston Date: Mon, 3 Feb 2020 15:38:42 +0400 Subject: [PATCH] Display dark background for PiP controls. --- .../SourceFiles/media/view/media_view.style | 1 - .../SourceFiles/media/view/media_view_pip.cpp | 64 +++++++++++++++++-- .../SourceFiles/media/view/media_view_pip.h | 4 ++ Telegram/lib_ui | 2 +- 4 files changed, 62 insertions(+), 9 deletions(-) diff --git a/Telegram/SourceFiles/media/view/media_view.style b/Telegram/SourceFiles/media/view/media_view.style index 62335e980..e5e5d4c55 100644 --- a/Telegram/SourceFiles/media/view/media_view.style +++ b/Telegram/SourceFiles/media/view/media_view.style @@ -289,7 +289,6 @@ pipResizeArea: 10px; pipControlSkip: 6px; pipPlaybackWidth: 2px; pipPlaybackSkip: 4px; -pipPlayBottom: 16px; pipPlayIcon: icon {{ "player_pip_play", mediaviewPipControlsFg }}; pipPlayIconOver: icon {{ "player_pip_play", mediaviewPipControlsFgOver }}; pipPauseIcon: icon {{ "player_pip_pause", mediaviewPipControlsFg }}; diff --git a/Telegram/SourceFiles/media/view/media_view_pip.cpp b/Telegram/SourceFiles/media/view/media_view_pip.cpp index cbe30d1a1..cf12926d2 100644 --- a/Telegram/SourceFiles/media/view/media_view_pip.cpp +++ b/Telegram/SourceFiles/media/view/media_view_pip.cpp @@ -300,6 +300,10 @@ QRect PipPanel::inner() const { return rect().marginsRemoved(_padding); } +RectParts PipPanel::attached() const { + return _attached; +} + bool PipPanel::dragging() const { return _dragState.has_value(); } @@ -703,6 +707,7 @@ Pip::Pip( , _panel( _delegate->pipParentWidget(), [=](QPainter &p, const FrameRequest &request) { paint(p, request); }) +, _roundRect(ImageRoundRadius::Large, st::radialBg) , _closeAndContinue(std::move(closeAndContinue)) , _destroy(std::move(destroy)) { setupPanel(); @@ -862,10 +867,7 @@ void Pip::setupButtons() { { skip, skip, skip, skip }); _play.icon = QRect( rect.x() + (rect.width() - st::pipPlayIcon.width()) / 2, - (rect.y() - + rect.height() - - st::pipPlayBottom - - st::pipPlayIcon.height()), + rect.y() + (rect.height() - st::pipPlayIcon.height()) / 2, st::pipPlayIcon.width(), st::pipPlayIcon.height()); const auto playbackHeight = 2 * st::pipPlaybackSkip @@ -904,14 +906,14 @@ void Pip::setupStreaming() { void Pip::paint(QPainter &p, FrameRequest request) { const auto image = videoFrameForDirectPaint(request); + const auto inner = _panel.inner(); p.drawImage( - QRect{ - _panel.inner().topLeft(), - request.outer / style::DevicePixelRatio() }, + QRect{ inner.topLeft(), request.outer / style::DevicePixelRatio() }, image); if (_instance.player().ready()) { _instance.markFrameShown(); } + paintRadialLoadingContent(p, inner); paintControls(p); } @@ -923,6 +925,22 @@ void Pip::paintControls(QPainter &p) { } p.setOpacity(shown); + using Part = RectPart; + const auto sides = _panel.attached(); + const auto rounded = RectPart(0) + | ((sides & (Part::Top | Part::Left)) ? Part(0) : Part::TopLeft) + | ((sides & (Part::Top | Part::Right)) ? Part(0) : Part::TopRight) + | ((sides & (Part::Bottom | Part::Right)) + ? Part(0) + : Part::BottomRight) + | ((sides & (Part::Bottom | Part::Left)) + ? Part(0) + : Part::BottomLeft); + _roundRect.paintSomeRounded( + p, + _panel.inner(), + rounded | Part::NoTopBottom | Part::Top | Part::Bottom); + const auto outer = _panel.width(); const auto drawOne = [&]( const Button &button, @@ -1059,6 +1077,38 @@ QImage Pip::videoFrameForDirectPaint(const FrameRequest &request) const { return result; } +void Pip::paintRadialLoadingContent(QPainter &p, QRect outer) const { + if (!_instance.waitingShown()) { + return; + } + const auto inner = QRect( + outer.x() + (outer.width() - st::radialSize.width()) / 2, + outer.y() + (outer.height() - st::radialSize.height()) / 2, + st::radialSize.width(), + st::radialSize.height()); + const auto arc = inner.marginsRemoved(QMargins( + st::radialLine, + st::radialLine, + st::radialLine, + st::radialLine)); + p.setOpacity(_instance.waitingOpacity()); + p.setPen(Qt::NoPen); + p.setBrush(st::radialBg); + { + PainterHighQualityEnabler hq(p); + p.drawEllipse(inner); + } + p.setOpacity(1.); + Ui::InfiniteRadialAnimation::Draw( + p, + _instance.waitingState(), + arc.topLeft(), + arc.size(), + _panel.width(), + st::radialFg, + st::radialLine); +} + Pip::OverState Pip::computeState(QPoint position) const { if (!_panel.inner().contains(position)) { return OverState::None; diff --git a/Telegram/SourceFiles/media/view/media_view_pip.h b/Telegram/SourceFiles/media/view/media_view_pip.h index d59294f11..cfe896597 100644 --- a/Telegram/SourceFiles/media/view/media_view_pip.h +++ b/Telegram/SourceFiles/media/view/media_view_pip.h @@ -9,6 +9,7 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL #include "media/streaming/media_streaming_instance.h" #include "ui/effects/animations.h" +#include "ui/round_rect.h" #include "ui/rp_widget.h" #include @@ -54,6 +55,7 @@ public: [[nodiscard]] Position countPosition() const; void setPosition(Position position); [[nodiscard]] QRect inner() const; + [[nodiscard]] RectParts attached() const; [[nodiscard]] bool dragging() const; [[nodiscard]] rpl::producer<> saveGeometryRequests() const; @@ -158,6 +160,7 @@ private: void handleClose(); void paintControls(QPainter &p); + void paintRadialLoadingContent(QPainter &p, QRect inner) const; const not_null _delegate; Streaming::Instance _instance; @@ -173,6 +176,7 @@ private: Button _playback; Button _play; Ui::Animations::Simple _controlsShown; + Ui::RoundRect _roundRect; FnMut _closeAndContinue; FnMut _destroy; diff --git a/Telegram/lib_ui b/Telegram/lib_ui index 18ba60ec8..1888853b5 160000 --- a/Telegram/lib_ui +++ b/Telegram/lib_ui @@ -1 +1 @@ -Subproject commit 18ba60ec86f1494d994ce507bb3e43ebe1766c20 +Subproject commit 1888853b52291c32ce5bbca7212e67c262c76cee