From c43699fb433374660cd8042f5c3574282526af98 Mon Sep 17 00:00:00 2001 From: John Preston Date: Thu, 6 Jan 2022 16:16:31 +0300 Subject: [PATCH] Prepare for better clipping. --- .../view/history_view_react_button.cpp | 48 +++++++++---------- .../history/view/history_view_react_button.h | 3 +- 2 files changed, 23 insertions(+), 28 deletions(-) diff --git a/Telegram/SourceFiles/history/view/history_view_react_button.cpp b/Telegram/SourceFiles/history/view/history_view_react_button.cpp index 3a8326e43..6d9626489 100644 --- a/Telegram/SourceFiles/history/view/history_view_react_button.cpp +++ b/Telegram/SourceFiles/history/view/history_view_react_button.cpp @@ -100,10 +100,6 @@ bool Button::isHidden() const { return (_state == State::Hidden) && !_opacityAnimation.animating(); } -bool Button::hasInitialView() const { - return (_geometry.height() == _collapsed.height()); -} - QRect Button::geometry() const { return _geometry; } @@ -377,7 +373,7 @@ void Manager::updateButton(ButtonParameters parameters) { return; } else if (_button) { _button->applyParameters(parameters); - if (_button->hasInitialView()) { + if (_button->geometry().height() == _outer.height()) { clearAppearAnimations(); } return; @@ -700,6 +696,7 @@ void Manager::paintButton( const auto geometry = button->geometry(); const auto position = geometry.topLeft(); const auto size = geometry.size(); + const auto expanded = (size.height() - _outer.height()); const auto shadow = context.st->shadowFg()->c; if (opacity != 1.) { p.setOpacity(opacity); @@ -710,20 +707,27 @@ void Manager::paintButton( scale, background, shadow); - paintLongImage(p, geometry, _cacheBg, source); - - const auto mainEmojiPosition = position + (button->expandUp() - ? QPoint(0, size.height() - _outer.height()) - : QPoint()); - if (onlyMainEmojiVisible(button)) { - const auto source = validateEmoji(frameIndex, scale); - p.drawImage(mainEmojiPosition, _cacheParts, source); + if (expanded) { + paintLongImage(p, geometry, _cacheBg, source); } else { + p.drawImage(position, _cacheBg, source); + } + + const auto current = (button == _button.get()); + const auto mainEmojiPosition = position + + (button->expandUp() ? QPoint(0, expanded) : QPoint()); + if (expanded || (current && !onlyMainEmojiVisible())) { p.save(); paintAllEmoji(p, button, scale, mainEmojiPosition); p.restore(); + if (current && expanded) { + _showingAll = true; + } + } else { + const auto source = validateEmoji(frameIndex, scale); + p.drawImage(mainEmojiPosition, _cacheParts, source); } - if (button == _button.get() && button->hasInitialView()) { + if (current && !expanded) { clearAppearAnimations(); } @@ -732,10 +736,8 @@ void Manager::paintButton( } } -bool Manager::onlyMainEmojiVisible(not_null button) const { - if (!button->hasInitialView()) { - return false; - } else if (button != _button.get() || _icons.empty()) { +bool Manager::onlyMainEmojiVisible() const { + if (_icons.empty()) { return true; } const auto &icon = _icons.front(); @@ -782,12 +784,9 @@ void Manager::paintLongImage( QRect geometry, const QImage &image, QRect source) { - if (geometry.height() == _outer.height()) { - p.drawImage(geometry.topLeft(), image, source); - return; - } const auto factor = style::DevicePixelRatio(); - const auto part = (source.height() / factor) / 2 - 1; + const auto sourceHeight = (source.height() / factor); + const auto part = (sourceHeight / 2) - 1; const auto fill = geometry.height() - 2 * part; const auto half = part * factor; const auto top = source.height() - half; @@ -817,9 +816,6 @@ void Manager::paintAllEmoji( float64 scale, QPoint mainEmojiPosition) { const auto current = (button == _button.get()); - if (current) { - _showingAll = true; - } const auto clip = buttonInner(button); const auto skip = st::reactionAppearStartSkip; diff --git a/Telegram/SourceFiles/history/view/history_view_react_button.h b/Telegram/SourceFiles/history/view/history_view_react_button.h index c7501da75..f89a0f0d8 100644 --- a/Telegram/SourceFiles/history/view/history_view_react_button.h +++ b/Telegram/SourceFiles/history/view/history_view_react_button.h @@ -75,7 +75,6 @@ public: [[nodiscard]] bool expandUp() const; [[nodiscard]] bool isHidden() const; - [[nodiscard]] bool hasInitialView() const; [[nodiscard]] QRect geometry() const; [[nodiscard]] int scroll() const; [[nodiscard]] float64 currentScale() const; @@ -207,7 +206,7 @@ private: const Data::Reaction &reaction) const; void updateCurrentButton() const; - [[nodiscard]] bool onlyMainEmojiVisible(not_null button) const; + [[nodiscard]] bool onlyMainEmojiVisible() const; [[nodiscard]] bool checkIconLoaded(ReactionDocument &entry) const; void loadIcons(); void checkIcons();