Hide controls when mouse is out of video area.

This commit is contained in:
John Preston 2021-05-18 10:32:06 +04:00
parent e0e878cbb1
commit aaea367fba
12 changed files with 85 additions and 148 deletions

Binary file not shown.

Before

Width:  |  Height:  |  Size: 692 B

Binary file not shown.

Before

Width:  |  Height:  |  Size: 1.3 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 1.9 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 585 B

Binary file not shown.

Before

Width:  |  Height:  |  Size: 961 B

Binary file not shown.

Before

Width:  |  Height:  |  Size: 1.3 KiB

View file

@ -1190,7 +1190,6 @@ groupCallLargeVideoCrossLine: CrossLineAnimation(groupCallMemberColoredCrossLine
GroupCallLargeVideo {
shadowHeight: pixels;
enlargeAlign: align;
namePosition: point;
pinPosition: point;
iconPosition: point;
@ -1198,13 +1197,11 @@ GroupCallLargeVideo {
groupCallLargeVideoWide: GroupCallLargeVideo {
shadowHeight: 40px;
enlargeAlign: align(topright);
namePosition: point(15px, 8px);
pinPosition: point(18px, 18px);
iconPosition: point(10px, 5px);
}
groupCallLargeVideoNarrow: GroupCallLargeVideo(groupCallLargeVideoWide) {
enlargeAlign: align(center);
pinPosition: point(-1px, -1px);
}
//groupCallLargeVideoListItem: PeerListItem(groupCallMembersListItem) {
@ -1216,12 +1213,11 @@ groupCallLargeVideoNarrow: GroupCallLargeVideo(groupCallLargeVideoWide) {
//}
groupCallLargeVideoPin: CrossLineAnimation {
fg: groupCallVideoTextFg;
icon: icon {{ "calls/voice_pin", groupCallVideoTextFg }};
icon: icon {{ "calls/video_over_pin", groupCallVideoTextFg }};
startPosition: point(5px, 2px);
endPosition: point(20px, 17px);
stroke: 2px;
}
groupCallVideoEnlarge: icon {{ "calls/voice_enlarge", mediaviewPipControlsFgOver }};
groupCallVideoSmallSkip: 4px;
groupCallVideoLargeSkip: 6px;

View file

@ -34,10 +34,11 @@ LargeVideo::LargeVideo(
, _pinButton((_st.pinPosition.x() >= 0)
? std::make_unique<Ui::AbstractButton>(&_content)
: nullptr)
, _controlsShown(_st.enlargeAlign != style::al_center)
, _hasEnlarge(_st.enlargeAlign == style::al_center)
, _controlsShownRatio(_controlsShown.current() ? 1. : 0.) {
, _smallLayout(!_pinButton) {
_content.setVisible(visible);
if (_smallLayout) {
_content.setCursor(style::cur_pointer);
}
setup(std::move(track), std::move(pinned));
}
@ -62,15 +63,13 @@ void LargeVideo::setGeometry(int x, int y, int width, int height) {
}
}
void LargeVideo::setControlsShown(bool shown) {
if (_mouseInside == shown) {
void LargeVideo::setControlsShown(float64 shown) {
if (_controlsShownRatio == shown) {
return;
}
_mouseInside = shown;
if (!_toggleControlsScheduled) {
_toggleControlsScheduled = true;
crl::on_main(&_content, [=] { toggleControls(); });
}
_controlsShownRatio = shown;
_content.update();
updateControlsGeometry();
}
rpl::producer<bool> LargeVideo::pinToggled() const {
@ -79,10 +78,6 @@ rpl::producer<bool> LargeVideo::pinToggled() const {
: rpl::never<bool>() | rpl::type_erased();
}
rpl::producer<float64> LargeVideo::controlsShown() const {
return _controlsShownRatio.value();
}
QSize LargeVideo::trackSize() const {
return _trackSize.current();
}
@ -108,14 +103,7 @@ void LargeVideo::setup(
_content.events(
) | rpl::start_with_next([=](not_null<QEvent*> e) {
if (e->type() == QEvent::Enter) {
Ui::Integration::Instance().registerLeaveSubscription(&_content);
setControlsShown(true);
} else if (e->type() == QEvent::Leave) {
Ui::Integration::Instance().unregisterLeaveSubscription(
&_content);
setControlsShown(false);
} else if (e->type() == QEvent::MouseButtonPress
if (e->type() == QEvent::MouseButtonPress
&& static_cast<QMouseEvent*>(
e.get())->button() == Qt::LeftButton) {
_mouseDown = true;
@ -134,13 +122,6 @@ void LargeVideo::setup(
_content.shownValue(),
std::move(track)
) | rpl::map([=](bool shown, LargeVideoTrack track) {
if (!shown) {
_controlsAnimation.stop();
if (_hasEnlarge) {
_controlsShown = _mouseInside = false;
}
_controlsShownRatio = _controlsShown.current() ? 1. : 0.;
}
return shown ? track : LargeVideoTrack();
}) | rpl::distinct_until_changed(
) | rpl::start_with_next([=](LargeVideoTrack track) {
@ -170,39 +151,6 @@ void LargeVideo::setup(
setupControls(std::move(pinned));
}
void LargeVideo::toggleControlsHidingEnabled(bool enabled) {
if (_controlsHidingEnabled == enabled) {
return;
}
_controlsHidingEnabled = enabled;
toggleControls();
}
void LargeVideo::toggleControls() {
_toggleControlsScheduled = false;
const auto shown = _mouseInside
|| (!_hasEnlarge && !_controlsHidingEnabled);
if (_controlsShown.current() == shown) {
return;
}
_controlsShown = shown;
const auto callback = [=] {
_controlsShownRatio = _controlsAnimation.value(
_controlsShown.current() ? 1. : 0.);
_content.update();
updateControlsGeometry();
};
if (_content.isHidden()) {
updateControlsGeometry();
} else {
_controlsAnimation.start(
callback,
shown ? 0. : 1.,
shown ? 1. : 0.,
st::slideWrapDuration);
}
}
void LargeVideo::setupControls(rpl::producer<bool> pinned) {
std::move(pinned) | rpl::start_with_next([=](bool pinned) {
_pinned = pinned;
@ -287,9 +235,7 @@ void LargeVideo::paint(QRect clip) {
}
void LargeVideo::paintControls(Painter &p, QRect clip) {
const auto ratio = _controlsShownRatio.current();
const auto shown = _hasEnlarge ? 1. : ratio;
const auto enlarge = _hasEnlarge ? ratio : 0.;
const auto shown = _controlsShownRatio;
if (shown == 0.) {
return;
}
@ -309,7 +255,7 @@ void LargeVideo::paintControls(Painter &p, QRect clip) {
width,
_st.shadowHeight);
const auto shadowFill = shadowRect.intersected(clip);
if (shadowFill.isEmpty() && enlarge == 0. && !_pinButton) {
if (shadowFill.isEmpty() && _smallLayout) {
return;
}
const auto factor = style::DevicePixelRatio();
@ -321,16 +267,6 @@ void LargeVideo::paintControls(Painter &p, QRect clip) {
(shadowFill.y() - shadowRect.y()) * factor,
_shadow.width(),
shadowFill.height() * factor));
if (enlarge > 0.) {
auto color = st::radialBg->c;
color.setAlphaF(color.alphaF() * enlarge);
p.fillRect(clip, color);
p.setOpacity(enlarge);
st::groupCallVideoEnlarge.paintInCenter(p, _content.rect());
p.setOpacity(1.);
}
_track.row->lazyInitialize(st::groupCallMembersListItem);
// Mute.
@ -358,7 +294,7 @@ void LargeVideo::paintControls(Painter &p, QRect clip) {
_track.row->name().drawLeftElided(p, nameLeft, nameTop, hasWidth, width);
// Pin.
if (_st.pinPosition.x() >= 0) {
if (_pinButton) {
const auto &pin = st::groupCallLargeVideoPin.icon;
const auto pinLeft = (width - _st.pinPosition.x() - pin.width());
const auto pinShift = anim::interpolate(

View file

@ -65,11 +65,9 @@ public:
void raise();
void setVisible(bool visible);
void setGeometry(int x, int y, int width, int height);
void setControlsShown(bool shown);
void toggleControlsHidingEnabled(bool enabled);
void setControlsShown(float64 shown);
[[nodiscard]] rpl::producer<bool> pinToggled() const;
[[nodiscard]] rpl::producer<float64> controlsShown() const;
[[nodiscard]] rpl::producer<> clicks() const {
return _clicks.events();
}
@ -112,7 +110,6 @@ private:
void paint(QRect clip);
void paintControls(Painter &p, QRect clip);
void updateControlsGeometry();
void toggleControls();
Content _content;
const style::GroupCallLargeVideo &_st;
@ -120,16 +117,11 @@ private:
QImage _shadow;
Ui::CrossLineAnimation _pin;
std::unique_ptr<Ui::AbstractButton> _pinButton;
Ui::Animations::Simple _controlsAnimation;
rpl::variable<bool> _controlsShown = true;
rpl::event_stream<> _clicks;
const bool _hasEnlarge = true;
const bool _smallLayout = true;
bool _pinned = false;
bool _controlsHidingEnabled = false;
bool _mouseInside = false;
bool _mouseDown = false;
bool _toggleControlsScheduled = false;
rpl::variable<float64> _controlsShownRatio = 1.;
float64 _controlsShownRatio = 1.;
rpl::variable<QSize> _trackSize;
rpl::variable<VideoQuality> _requestedQuality;
rpl::lifetime _trackLifetime;

View file

@ -1865,8 +1865,9 @@ void Members::refreshTilesGeometry() {
QSize(width, heightMax),
Qt::KeepAspectRatio);
const auto height = std::max(scaled.height(), heightMin);
const auto skip = st::groupCallVideoSmallSkip;
sizes.front().first->setGeometry(0, 0, width, height);
_pinnedVideoWrap->resize(width, height);
_pinnedVideoWrap->resize(width, height + skip);
return;
}
const auto min = (st::groupCallWidth
@ -1900,7 +1901,7 @@ void Members::refreshTilesGeometry() {
}
}
}
_pinnedVideoWrap->resize(width, rows * (min + skip) - skip);
_pinnedVideoWrap->resize(width, rows * (min + skip));
}
void Members::setupPinnedVideo() {

View file

@ -1085,9 +1085,10 @@ void Panel::refreshTilesGeometry() {
if (_videoTiles.empty()
|| outer.isEmpty()
|| _mode == PanelMode::Default) {
trackControls(nullptr);
trackControls(false);
return;
}
trackControls(true);
struct Geometry {
QSize size;
QRect columns;
@ -1102,15 +1103,12 @@ void Panel::refreshTilesGeometry() {
? QSize()
: video->trackSize();
if (size.isEmpty()) {
video->toggleControlsHidingEnabled(false);
video->setGeometry(0, 0, outer.width(), 0);
} else {
sizes.emplace(video, Geometry{ size });
}
}
if (sizes.size() == 1) {
trackControls(sizes.front().first);
sizes.front().first->toggleControlsHidingEnabled(true);
sizes.front().first->setGeometry(0, 0, outer.width(), outer.height());
return;
}
@ -1191,7 +1189,6 @@ void Panel::refreshTilesGeometry() {
const auto &rect = (columnsBlack < rowsBlack)
? geometry.columns
: geometry.rows;
video->toggleControlsHidingEnabled(false);
video->setGeometry(rect.x(), rect.y(), rect.width(), rect.height());
}
}
@ -1199,6 +1196,7 @@ void Panel::refreshTilesGeometry() {
void Panel::setupPinnedVideo() {
using namespace rpl::mappers;
_pinnedVideoWrap = std::make_unique<Ui::RpWidget>(widget());
const auto raw = _pinnedVideoWrap.get();
const auto setupTile = [=](
const VideoEndpoint &endpoint,
@ -1206,7 +1204,7 @@ void Panel::setupPinnedVideo() {
const auto row = _members->lookupRow(track.peer);
Assert(row != nullptr);
auto video = std::make_unique<LargeVideo>(
_pinnedVideoWrap.get(),
raw,
st::groupCallLargeVideoWide,
(_mode == PanelMode::Wide),
rpl::single(LargeVideoTrack{ track.track.get(), row }),
@ -1227,12 +1225,6 @@ void Panel::setupPinnedVideo() {
refreshTilesGeometry();
}, video->lifetime());
video->lifetime().add([=, video = video.get()] {
if (_trackControlsTile == video) {
trackControls(nullptr);
}
});
return VideoTile{
.video = std::move(video),
.endpoint = endpoint,
@ -1245,7 +1237,7 @@ void Panel::setupPinnedVideo() {
) | rpl::start_with_next([=](const VideoEndpoint &endpoint) {
if (_call->activeVideoTracks().contains(endpoint)) {
// Add async (=> the participant row is definitely in Members).
crl::on_main(_pinnedVideoWrap.get(), [=] {
crl::on_main(raw, [=] {
const auto &tracks = _call->activeVideoTracks();
const auto i = tracks.find(endpoint);
if (i != end(tracks)) {
@ -1264,15 +1256,38 @@ void Panel::setupPinnedVideo() {
refreshTilesGeometry();
}
}
}, _pinnedVideoWrap->lifetime());
}, raw->lifetime());
_pinnedVideoWrap->sizeValue() | rpl::start_with_next([=] {
raw->sizeValue() | rpl::start_with_next([=] {
refreshTilesGeometry();
}, _pinnedVideoWrap->lifetime());
}, raw->lifetime());
raw->events(
) | rpl::start_with_next([=](not_null<QEvent*> e) {
if (e->type() == QEvent::Enter) {
Ui::Integration::Instance().registerLeaveSubscription(raw);
toggleWideControls(true);
} else if (e->type() == QEvent::Leave) {
Ui::Integration::Instance().unregisterLeaveSubscription(raw);
toggleWideControls(false);
}
}, raw->lifetime());
raiseControls();
}
void Panel::toggleWideControls(bool shown) {
if (_wideControlsShown == shown) {
return;
}
_wideControlsShown = shown;
_wideControlsAnimation.start(
[=] { updateButtonsGeometry(); },
shown ? 0. : 1.,
shown ? 1. : 0.,
st::slideWrapDuration);
}
void Panel::setupJoinAsChangedToasts() {
_call->rejoinEvents(
) | rpl::filter([](RejoinEvent event) {
@ -1780,9 +1795,12 @@ bool Panel::updateMode() {
_members->setMode(mode);
}
if (_pinnedVideoWrap) {
_wideControlsAnimation.stop();
_wideControlsShown = true;
_pinnedVideoWrap->setVisible(mode == PanelMode::Wide);
for (const auto &tile : _videoTiles) {
tile.video->setVisible(mode == PanelMode::Wide);
tile.video->setControlsShown(1.);
}
}
refreshControlsBackground();
@ -1817,16 +1835,17 @@ void Panel::refreshControlsBackground() {
raiseControls();
}
void Panel::trackControls(LargeVideo *video) {
if (_trackControlsTile == video) {
void Panel::trackControls(bool track) {
if (_trackControls == track) {
return;
}
_trackControlsTile = video;
if (!video) {
_trackControls = track;
if (!track) {
_trackControlsLifetime.destroy();
_trackControlsOverStateLifetime.destroy();
if (_pinnedVideoControlsShown != 1.) {
_pinnedVideoControlsShown = 1.;
toggleWideControls(true);
if (_wideControlsAnimation.animating()) {
_wideControlsAnimation.stop();
updateButtonsGeometry();
}
return;
@ -1834,39 +1853,24 @@ void Panel::trackControls(LargeVideo *video) {
const auto trackOne = [=](auto &&widget) {
if (widget) {
widget->events(
const auto raw = &*widget;
raw->events(
) | rpl::start_with_next([=](not_null<QEvent*> e) {
if (e->type() == QEvent::Enter) {
video->setControlsShown(true);
toggleWideControls(true);
} else if (e->type() == QEvent::Leave) {
video->setControlsShown(false);
toggleWideControls(false);
}
}, _trackControlsOverStateLifetime);
}
};
const auto trackOverState = [=] {
trackOne(_mute);
trackOne(_video);
trackOne(_screenShare);
trackOne(_settings);
trackOne(_callShare);
trackOne(_hangup);
trackOne(_controlsBackground);
};
video->controlsShown(
) | rpl::filter([=](float64 shown) {
return (_pinnedVideoControlsShown != shown);
}) | rpl::start_with_next([=](float64 shown) {
const auto hiding = (shown <= _pinnedVideoControlsShown);
_pinnedVideoControlsShown = shown;
if (hiding && _trackControlsLifetime) {
_trackControlsOverStateLifetime.destroy();
} else if (!hiding && !_trackControlsOverStateLifetime) {
trackOverState();
}
updateButtonsGeometry();
}, _trackControlsLifetime);
trackOne(_mute);
trackOne(_video);
trackOne(_screenShare);
trackOne(_settings);
trackOne(_callShare);
trackOne(_hangup);
trackOne(_controlsBackground);
}
void Panel::updateControlsGeometry() {
@ -1916,14 +1920,20 @@ void Panel::updateButtonsGeometry() {
};
if (_videoMode.current()) {
_mute->setStyle(st::callMuteButtonSmall);
toggle(_mode != PanelMode::Wide || _pinnedVideoControlsShown > 0.);
const auto shown = _wideControlsAnimation.value(
_wideControlsShown ? 1. : 0.);
toggle(_mode != PanelMode::Wide || shown > 0.);
for (const auto &tile : _videoTiles) {
tile.video->setControlsShown(shown);
}
const auto buttonsTop = widget()->height()
- (_mode == PanelMode::Wide
? anim::interpolate(
0,
st::groupCallButtonBottomSkipWide,
_pinnedVideoControlsShown)
shown)
: st::groupCallButtonBottomSkipSmall);
const auto addSkip = st::callMuteButtonSmall.active.outerRadius;
const auto muteSize = _mute->innerSize().width() + 2 * addSkip;

View file

@ -92,7 +92,7 @@ private:
bool handleClose();
void startScheduledNow();
void trackControls(LargeVideo *video);
void trackControls(bool track);
void raiseControls();
void enlargeVideo();
void minimizeVideo();
@ -105,6 +105,7 @@ private:
void showControls();
void refreshLeftButton();
void refreshTilesGeometry();
void toggleWideControls(bool shown);
void endCall();
@ -149,9 +150,7 @@ private:
object_ptr<Ui::AbstractButton> _joinAsToggle = { nullptr };
object_ptr<Members> _members = { nullptr };
std::unique_ptr<Ui::RpWidget> _pinnedVideoWrap;
float64 _pinnedVideoControlsShown = 1.;
std::vector<VideoTile> _videoTiles;
LargeVideo *_trackControlsTile = nullptr;
rpl::lifetime _trackControlsLifetime;
rpl::lifetime _trackControlsOverStateLifetime;
object_ptr<Ui::FlatLabel> _startsIn = { nullptr };
@ -163,6 +162,9 @@ private:
std::optional<QRect> _lastSmallGeometry;
std::optional<QRect> _lastLargeGeometry;
bool _lastLargeMaximized = false;
bool _wideControlsShown = false;
bool _trackControls = false;
Ui::Animations::Simple _wideControlsAnimation;
object_ptr<Ui::RpWidget> _controlsBackground = { nullptr };
object_ptr<Ui::CallButton> _settings = { nullptr };