From a6e96f9a28e428981e2eb49c30ef304fca7983b3 Mon Sep 17 00:00:00 2001 From: John Preston Date: Mon, 1 Apr 2019 21:44:54 +0400 Subject: [PATCH] Use new animations engine in all Basic-s. --- .../boxes/background_preview_box.cpp | 18 ++-- .../boxes/background_preview_box.h | 2 +- Telegram/SourceFiles/boxes/connection_box.cpp | 36 +++---- .../SourceFiles/boxes/local_storage_box.cpp | 9 +- Telegram/SourceFiles/boxes/stickers_box.cpp | 90 ++++++++-------- Telegram/SourceFiles/boxes/stickers_box.h | 7 +- .../chat_helpers/emoji_sets_manager.cpp | 8 +- .../chat_helpers/stickers_list_widget.cpp | 37 +++---- Telegram/SourceFiles/config.h | 1 - .../dialogs/dialogs_inner_widget.cpp | 88 ++++++++------- .../dialogs/dialogs_inner_widget.h | 5 +- .../SourceFiles/dialogs/dialogs_widget.cpp | 8 +- .../history/history_item_components.cpp | 37 ++++--- .../history/history_item_components.h | 11 +- .../SourceFiles/history/history_widget.cpp | 61 +++++++---- Telegram/SourceFiles/history/history_widget.h | 9 +- .../history/media/history_media_document.cpp | 43 ++++---- .../history/media/history_media_document.h | 2 +- .../history/media/history_media_file.cpp | 28 ++--- .../history/media/history_media_file.h | 17 +-- .../history/media/history_media_poll.cpp | 18 ++-- .../history/media/history_media_poll.h | 2 +- .../view/history_view_top_bar_widget.cpp | 9 +- .../view/history_view_top_bar_widget.h | 2 +- .../inline_bot_layout_internal.cpp | 102 +++++++++--------- .../inline_bots/inline_bot_layout_internal.h | 31 +++--- .../inline_bots/inline_bot_layout_item.cpp | 2 +- .../inline_bots/inline_bot_layout_item.h | 2 +- .../media/audio/media_audio_capture.cpp | 3 +- .../media/view/media_view_overlay_widget.cpp | 54 ++++------ .../media/view/media_view_overlay_widget.h | 4 +- .../SourceFiles/overview/overview_layout.cpp | 30 +++--- .../SourceFiles/overview/overview_layout.h | 15 ++- .../SourceFiles/settings/settings_chat.cpp | 19 ++-- .../ui/effects/radial_animation.cpp | 47 +++----- .../SourceFiles/ui/effects/radial_animation.h | 41 ++++--- Telegram/SourceFiles/ui/special_buttons.cpp | 6 +- Telegram/SourceFiles/ui/special_buttons.h | 2 +- .../window/notifications_manager_default.cpp | 43 ++++---- .../window/notifications_manager_default.h | 9 +- .../window/window_connecting_widget.cpp | 8 +- 41 files changed, 479 insertions(+), 487 deletions(-) diff --git a/Telegram/SourceFiles/boxes/background_preview_box.cpp b/Telegram/SourceFiles/boxes/background_preview_box.cpp index 9560f72a8..2b6a83336 100644 --- a/Telegram/SourceFiles/boxes/background_preview_box.cpp +++ b/Telegram/SourceFiles/boxes/background_preview_box.cpp @@ -400,7 +400,7 @@ BackgroundPreviewBox::BackgroundPreviewBox( lang(lng_background_text2), true)) , _paper(paper) -, _radial(animation(this, &BackgroundPreviewBox::step_radial)) { +, _radial([=](crl::time now) { return radialAnimationCallback(now); }) { subscribe(Auth().downloaderTaskFinished(), [=] { update(); }); } @@ -549,13 +549,8 @@ void BackgroundPreviewBox::paintImage(Painter &p, crl::time ms) { } void BackgroundPreviewBox::paintRadial(Painter &p, crl::time ms) { - bool radial = false; - float64 radialOpacity = 0; - if (_radial.animating()) { - _radial.step(ms); - radial = _radial.animating(); - radialOpacity = _radial.opacity(); - } + const auto radial = _radial.animating(); + const auto radialOpacity = radial ? _radial.opacity() : 0.; if (!radial) { return; } @@ -623,7 +618,7 @@ void BackgroundPreviewBox::paintDate(Painter &p) { p.drawText(bubbleLeft + st::msgServicePadding.left(), bubbleTop + st::msgServicePadding.top() + st::msgServiceFont->ascent, text); } -void BackgroundPreviewBox::step_radial(crl::time ms, bool timer) { +void BackgroundPreviewBox::radialAnimationCallback(crl::time now) { Expects(_paper.document() != nullptr); const auto document = _paper.document(); @@ -631,9 +626,8 @@ void BackgroundPreviewBox::step_radial(crl::time ms, bool timer) { const auto updated = _radial.update( document->progress(), !document->loading(), - ms); - if (timer - && (wasAnimating || _radial.animating()) + now); + if ((wasAnimating || _radial.animating()) && (!anim::Disabled() || updated)) { update(radialRect()); } diff --git a/Telegram/SourceFiles/boxes/background_preview_box.h b/Telegram/SourceFiles/boxes/background_preview_box.h index 0eedd7710..2924daa12 100644 --- a/Telegram/SourceFiles/boxes/background_preview_box.h +++ b/Telegram/SourceFiles/boxes/background_preview_box.h @@ -50,7 +50,7 @@ private: void apply(); void share(); - void step_radial(crl::time ms, bool timer); + void radialAnimationCallback(crl::time now); QRect radialRect() const; void checkLoadedDocument(); diff --git a/Telegram/SourceFiles/boxes/connection_box.cpp b/Telegram/SourceFiles/boxes/connection_box.cpp index beaedd535..3a36a627f 100644 --- a/Telegram/SourceFiles/boxes/connection_box.cpp +++ b/Telegram/SourceFiles/boxes/connection_box.cpp @@ -52,7 +52,7 @@ protected: private: void setupControls(View &&view); int countAvailableWidth() const; - void step_radial(crl::time ms, bool timer); + void radialAnimationCallback(); void paintCheck(Painter &p, crl::time ms); void showMenu(); @@ -209,7 +209,7 @@ void ProxyRow::updateFields(View &&view) { if (state == State::Connecting) { if (!_progress) { _progress = std::make_unique( - animation(this, &ProxyRow::step_radial), + [=] { radialAnimationCallback(); }, st::proxyCheckingAnimation); } _progress->start(); @@ -219,7 +219,7 @@ void ProxyRow::updateFields(View &&view) { if (state == State::Checking) { if (!_checking) { _checking = std::make_unique( - animation(this, &ProxyRow::step_radial), + [=] { radialAnimationCallback(); }, st::proxyCheckingAnimation); _checking->start(); } @@ -241,8 +241,8 @@ void ProxyRow::updateFields(View &&view) { update(); } -void ProxyRow::step_radial(crl::time ms, bool timer) { - if (timer && !anim::Disabled()) { +void ProxyRow::radialAnimationCallback() { + if (!anim::Disabled()) { update(); } } @@ -323,28 +323,22 @@ void ProxyRow::paintEvent(QPaintEvent *e) { auto statusLeft = left; if (_checking) { - _checking->step(ms); - if (_checking) { - _checking->draw( - p, - { - st::proxyCheckingPosition.x() + statusLeft, - st::proxyCheckingPosition.y() + top - }, - width()); - statusLeft += st::proxyCheckingPosition.x() - + st::proxyCheckingAnimation.size.width() - + st::proxyCheckingSkip; - } + _checking->draw( + p, + { + st::proxyCheckingPosition.x() + statusLeft, + st::proxyCheckingPosition.y() + top + }, + width()); + statusLeft += st::proxyCheckingPosition.x() + + st::proxyCheckingAnimation.size.width() + + st::proxyCheckingSkip; } p.drawTextLeft(statusLeft, top, width(), status); top += st::normalFont->height + st::proxyRowPadding.bottom(); } void ProxyRow::paintCheck(Painter &p, crl::time ms) { - if (_progress) { - _progress->step(ms); - } const auto loading = _progress ? _progress->computeState() : Ui::RadialState{ 0., 0, FullArcLength }; diff --git a/Telegram/SourceFiles/boxes/local_storage_box.cpp b/Telegram/SourceFiles/boxes/local_storage_box.cpp index e9f7fb86b..08b88a5cd 100644 --- a/Telegram/SourceFiles/boxes/local_storage_box.cpp +++ b/Telegram/SourceFiles/boxes/local_storage_box.cpp @@ -139,7 +139,7 @@ protected: private: QString titleText(const Database::TaggedSummary &data) const; QString sizeText(const Database::TaggedSummary &data) const; - void step_radial(crl::time ms, bool timer); + void radialAnimationCallback(); Fn _titleFactory; object_ptr _title; @@ -186,7 +186,7 @@ void LocalStorageBox::Row::toggleProgress(bool shown) { _clearing.destroy(); } else if (!_progress) { _progress = std::make_unique( - animation(this, &Row::step_radial), + [=] { radialAnimationCallback(); }, st::proxyCheckingAnimation); _progress->start(); _clearing = object_ptr( @@ -201,8 +201,8 @@ void LocalStorageBox::Row::toggleProgress(bool shown) { } } -void LocalStorageBox::Row::step_radial(crl::time ms, bool timer) { - if (timer && !anim::Disabled()) { +void LocalStorageBox::Row::radialAnimationCallback() { + if (!anim::Disabled()) { RpWidget::update(); } } @@ -247,7 +247,6 @@ void LocalStorageBox::Row::paintEvent(QPaintEvent *e) { const auto padding = st::localStorageRowPadding; const auto height = st::localStorageRowHeight; const auto bottom = height - padding.bottom() - _description->height(); - _progress->step(crl::now()); _progress->draw( p, { diff --git a/Telegram/SourceFiles/boxes/stickers_box.cpp b/Telegram/SourceFiles/boxes/stickers_box.cpp index f8853e4bd..8a1627a87 100644 --- a/Telegram/SourceFiles/boxes/stickers_box.cpp +++ b/Telegram/SourceFiles/boxes/stickers_box.cpp @@ -44,8 +44,8 @@ int stickerPacksCount(bool includeArchivedOfficial) { auto result = 0; auto &order = Auth().data().stickerSetsOrder(); auto &sets = Auth().data().stickerSets(); - for (auto i = 0, l = order.size(); i < l; ++i) { - auto it = sets.constFind(order.at(i)); + for (const auto setId : order) { + const auto it = sets.constFind(setId); if (it != sets.cend()) { if (!(it->flags & MTPDstickerSet::Flag::f_archived) || ((it->flags & MTPDstickerSet::Flag::f_official) && includeArchivedOfficial)) { ++result; @@ -653,7 +653,9 @@ StickersBox::Inner::Row::~Row() = default; StickersBox::Inner::Inner(QWidget *parent, StickersBox::Section section) : TWidget(parent) , _section(section) , _rowHeight(st::contactsPadding.top() + st::contactsPhotoSize + st::contactsPadding.bottom()) -, _a_shifting(animation(this, &Inner::step_shifting)) +, _shiftingAnimation([=](crl::time now) { + return shiftingAnimationCallback(now); +}) , _itemsTop(st::membersMarginTop) , _addText(lang(lng_stickers_featured_add).toUpper()) , _addWidth(st::stickersTrendingAdd.font->width(_addText)) @@ -665,7 +667,9 @@ StickersBox::Inner::Inner(QWidget *parent, StickersBox::Section section) : TWidg StickersBox::Inner::Inner(QWidget *parent, not_null megagroup) : TWidget(parent) , _section(StickersBox::Section::Installed) , _rowHeight(st::contactsPadding.top() + st::contactsPhotoSize + st::contactsPadding.bottom()) -, _a_shifting(animation(this, &Inner::step_shifting)) +, _shiftingAnimation([=](crl::time now) { + return shiftingAnimationCallback(now); +}) , _itemsTop(st::membersMarginTop) , _megagroupSet(megagroup) , _megagroupSetInput(_megagroupSet->mgInfo->stickerSet) @@ -710,10 +714,6 @@ void StickersBox::Inner::setInnerFocus() { void StickersBox::Inner::paintEvent(QPaintEvent *e) { Painter p(this); - if (_a_shifting.animating()) { - _a_shifting.step(); - } - auto clip = e->rect(); auto ms = crl::now(); p.fillRect(clip, st::boxBg); @@ -1071,7 +1071,7 @@ void StickersBox::Inner::onUpdateSelected() { auto local = mapFromGlobal(_mouse); if (_dragging >= 0) { auto shift = 0; - auto ms = crl::now(); + auto now = crl::now(); int firstSetIndex = 0; if (_rows.at(firstSetIndex)->isRecentSet()) { ++firstSetIndex; @@ -1081,27 +1081,27 @@ void StickersBox::Inner::onUpdateSelected() { for (int32 from = _dragging, to = _dragging + shift; from > to; --from) { qSwap(_rows[from], _rows[from - 1]); _rows[from]->yadd = anim::value(_rows[from]->yadd.current() - _rowHeight, 0); - _animStartTimes[from] = ms; + _shiftingStartTimes[from] = now; } } else if (_dragStart.y() < local.y() && _dragging + 1 < _rows.size()) { shift = floorclamp(local.y() - _dragStart.y() + (_rowHeight / 2), _rowHeight, 0, _rows.size() - _dragging - 1); for (int32 from = _dragging, to = _dragging + shift; from < to; ++from) { qSwap(_rows[from], _rows[from + 1]); _rows[from]->yadd = anim::value(_rows[from]->yadd.current() + _rowHeight, 0); - _animStartTimes[from] = ms; + _shiftingStartTimes[from] = now; } } if (shift) { _dragging += shift; _above = _dragging; _dragStart.setY(_dragStart.y() + shift * _rowHeight); - if (!_a_shifting.animating()) { - _a_shifting.start(); + if (!_shiftingAnimation.animating()) { + _shiftingAnimation.start(); } } _rows[_dragging]->yadd = anim::value(local.y() - _dragStart.y(), local.y() - _dragStart.y()); - _animStartTimes[_dragging] = 0; - _a_shifting.step(ms, true); + _shiftingStartTimes[_dragging] = 0; + shiftingAnimationCallback(now); auto countDraggingScrollDelta = [this, local] { if (local.y() < _visibleTop) { @@ -1181,10 +1181,10 @@ void StickersBox::Inner::mouseReleaseEvent(QMouseEvent *e) { } else if (_dragging >= 0) { QPoint local(mapFromGlobal(_mouse)); _rows[_dragging]->yadd.start(0.); - _aboveShadowFadeStart = _animStartTimes[_dragging] = crl::now(); + _aboveShadowFadeStart = _shiftingStartTimes[_dragging] = crl::now(); _aboveShadowFadeOpacity = anim::value(aboveShadowOpacity(), 0); - if (!_a_shifting.animating()) { - _a_shifting.start(); + if (!_shiftingAnimation.animating()) { + _shiftingAnimation.start(); } _dragging = _started = -1; @@ -1262,64 +1262,64 @@ void StickersBox::Inner::leaveToChildEvent(QEvent *e, QWidget *child) { onUpdateSelected(); } -void StickersBox::Inner::step_shifting(crl::time ms, bool timer) { +bool StickersBox::Inner::shiftingAnimationCallback(crl::time now) { if (anim::Disabled()) { - ms += st::stickersRowDuration; + now += st::stickersRowDuration; } auto animating = false; auto updateMin = -1; auto updateMax = 0; - for (auto i = 0, l = _animStartTimes.size(); i < l; ++i) { - auto start = _animStartTimes.at(i); + for (auto i = 0, count = int(_shiftingStartTimes.size()); i != count; ++i) { + const auto start = _shiftingStartTimes[i]; if (start) { - if (updateMin < 0) updateMin = i; + if (updateMin < 0) { + updateMin = i; + } updateMax = i; - if (start + st::stickersRowDuration > ms && ms >= start) { - _rows[i]->yadd.update(float64(ms - start) / st::stickersRowDuration, anim::sineInOut); + if (start + st::stickersRowDuration > now && now >= start) { + _rows[i]->yadd.update(float64(now - start) / st::stickersRowDuration, anim::sineInOut); animating = true; } else { _rows[i]->yadd.finish(); - _animStartTimes[i] = 0; + _shiftingStartTimes[i] = 0; } } } if (_aboveShadowFadeStart) { if (updateMin < 0 || updateMin > _above) updateMin = _above; if (updateMax < _above) updateMin = _above; - if (_aboveShadowFadeStart + st::stickersRowDuration > ms && ms > _aboveShadowFadeStart) { - _aboveShadowFadeOpacity.update(float64(ms - _aboveShadowFadeStart) / st::stickersRowDuration, anim::sineInOut); + if (_aboveShadowFadeStart + st::stickersRowDuration > now && now > _aboveShadowFadeStart) { + _aboveShadowFadeOpacity.update(float64(now - _aboveShadowFadeStart) / st::stickersRowDuration, anim::sineInOut); animating = true; } else { _aboveShadowFadeOpacity.finish(); _aboveShadowFadeStart = 0; } } - if (timer) { - if (_dragging >= 0) { - if (updateMin < 0 || updateMin > _dragging) { - updateMin = _dragging; - } - if (updateMax < _dragging) updateMax = _dragging; - } - if (updateMin == 1 && _rows[0]->isRecentSet()) { - updateMin = 0; // Repaint from the very top of the content. - } - if (updateMin >= 0) { - update(0, _itemsTop + _rowHeight * (updateMin - 1), width(), _rowHeight * (updateMax - updateMin + 3)); + if (_dragging >= 0) { + if (updateMin < 0 || updateMin > _dragging) { + updateMin = _dragging; } + if (updateMax < _dragging) updateMax = _dragging; + } + if (updateMin == 1 && _rows[0]->isRecentSet()) { + updateMin = 0; // Repaint from the very top of the content. + } + if (updateMin >= 0) { + update(0, _itemsTop + _rowHeight * (updateMin - 1), width(), _rowHeight * (updateMax - updateMin + 3)); } if (!animating) { _above = _dragging; - _a_shifting.stop(); } + return animating; } void StickersBox::Inner::clear() { _rows.clear(); - _animStartTimes.clear(); + _shiftingStartTimes.clear(); _aboveShadowFadeStart = 0; _aboveShadowFadeOpacity = anim::value(); - _a_shifting.stop(); + _shiftingAnimation.stop(); _above = _dragging = _started = -1; setSelected(SelectedRow()); setPressed(SelectedRow()); @@ -1476,7 +1476,7 @@ void StickersBox::Inner::rebuild() { return Auth().data().archivedStickerSetsOrder(); })(); _rows.reserve(order.size() + 1); - _animStartTimes.reserve(order.size() + 1); + _shiftingStartTimes.reserve(order.size() + 1); auto &sets = Auth().data().stickerSets(); if (_megagroupSet) { @@ -1625,7 +1625,7 @@ void StickersBox::Inner::rebuildAppendSet(const Stickers::Set &set, int maxNameW removed, pixw, pixh)); - _animStartTimes.push_back(0); + _shiftingStartTimes.push_back(0); } void StickersBox::Inner::fillSetCover(const Stickers::Set &set, ImagePtr *thumbnail, DocumentData **outSticker, int *outWidth, int *outHeight) const { diff --git a/Telegram/SourceFiles/boxes/stickers_box.h b/Telegram/SourceFiles/boxes/stickers_box.h index 25907a05c..a56a0d850 100644 --- a/Telegram/SourceFiles/boxes/stickers_box.h +++ b/Telegram/SourceFiles/boxes/stickers_box.h @@ -11,6 +11,7 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL #include "base/timer.h" #include "mtproto/sender.h" #include "chat_helpers/stickers.h" +#include "ui/effects/animations.h" #include "ui/widgets/input_fields.h" class ConfirmBox; @@ -270,7 +271,7 @@ private: QRect relativeButtonRect(bool removeButton) const; void ensureRipple(const style::RippleAnimation &st, QImage mask, bool removeButton); - void step_shifting(crl::time ms, bool timer); + bool shiftingAnimationCallback(crl::time now); void paintRow(Painter &p, Row *set, int index, crl::time ms); void paintFakeButton(Painter &p, Row *set, int index, crl::time ms); void clear(); @@ -297,10 +298,10 @@ private: int32 _rowHeight; std::vector> _rows; - QList _animStartTimes; + std::vector _shiftingStartTimes; crl::time _aboveShadowFadeStart = 0; anim::value _aboveShadowFadeOpacity; - BasicAnimation _a_shifting; + Ui::Animations::Basic _shiftingAnimation; Fn _installSetCallback; Fn _loadMoreCallback; diff --git a/Telegram/SourceFiles/chat_helpers/emoji_sets_manager.cpp b/Telegram/SourceFiles/chat_helpers/emoji_sets_manager.cpp index 76430b866..0aaf22ee7 100644 --- a/Telegram/SourceFiles/chat_helpers/emoji_sets_manager.cpp +++ b/Telegram/SourceFiles/chat_helpers/emoji_sets_manager.cpp @@ -124,7 +124,7 @@ private: void setupHandler(); void load(); - void step_radial(crl::time ms, bool timer); + void radialAnimationCallback(); int _id = 0; bool _switching = false; @@ -582,8 +582,8 @@ void Row::setupPreview(const Set &set) { } } -void Row::step_radial(crl::time ms, bool timer) { - if (timer && !anim::Disabled()) { +void Row::radialAnimationCallback() { + if (!anim::Disabled()) { update(); } } @@ -633,7 +633,7 @@ void Row::updateAnimation(crl::time ms) { : 0.; if (!_loading) { _loading = std::make_unique( - animation(this, &Row::step_radial)); + [=] { radialAnimationCallback(); }); _loading->start(progress); } else { _loading->update(progress, false, crl::now()); diff --git a/Telegram/SourceFiles/chat_helpers/stickers_list_widget.cpp b/Telegram/SourceFiles/chat_helpers/stickers_list_widget.cpp index cc8a1f915..ef7a08d85 100644 --- a/Telegram/SourceFiles/chat_helpers/stickers_list_widget.cpp +++ b/Telegram/SourceFiles/chat_helpers/stickers_list_widget.cpp @@ -11,6 +11,7 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL #include "data/data_session.h" #include "data/data_channel.h" #include "ui/widgets/buttons.h" +#include "ui/effects/animations.h" #include "ui/effects/ripple_animation.h" #include "ui/image/image.h" #include "boxes/stickers_box.h" @@ -105,7 +106,7 @@ private: template void enumerateVisibleIcons(Callback callback); - void step_icons(crl::time ms, bool timer); + bool iconsAnimationCallback(crl::time now); void setSelectedIcon( int newSelected, ValidateIconAnimations animations); @@ -134,7 +135,7 @@ private: int _iconSel = 0; OverState _iconDown = SpecialOver::None; bool _iconsDragging = false; - BasicAnimation _a_icons; + Ui::Animations::Basic _iconsAnimation; QPoint _iconsMousePos, _iconsMouseDown; int _iconsLeft = 0; int _iconsRight = 0; @@ -180,7 +181,9 @@ StickersListWidget::Set::~Set() = default; StickersListWidget::Footer::Footer(not_null parent) : InnerFooter(parent) , _pan(parent) -, _a_icons(animation(this, &Footer::step_icons)) { +, _iconsAnimation([=](crl::time now) { + return iconsAnimationCallback(now); +}) { setMouseTracking(true); _iconsLeft = _iconsRight = st::emojiCategorySkip + st::stickerIconWidth; @@ -323,11 +326,11 @@ void StickersListWidget::Footer::setSelectedIcon( _iconsMax); if (animations == ValidateIconAnimations::None) { _iconsX = anim::value(iconsXFinal, iconsXFinal); - _a_icons.stop(); + _iconsAnimation.stop(); } else { _iconsX.start(iconsXFinal); _iconsStartAnim = crl::now(); - _a_icons.start(); + _iconsAnimation.start(); } updateSelected(); update(); @@ -336,7 +339,7 @@ void StickersListWidget::Footer::setSelectedIcon( void StickersListWidget::Footer::processHideFinished() { _iconOver = _iconDown = SpecialOver::None; _iconsStartAnim = 0; - _a_icons.stop(); + _iconsAnimation.stop(); _iconsX.finish(); _iconSelX.finish(); _horizontal = false; @@ -469,7 +472,7 @@ void StickersListWidget::Footer::mouseMoveEvent(QMouseEvent *e) { if (newX != qRound(_iconsX.current())) { _iconsX = anim::value(newX, newX); _iconsStartAnim = 0; - _a_icons.stop(); + _iconsAnimation.stop(); update(); } } @@ -504,7 +507,7 @@ void StickersListWidget::Footer::finishDragging() { if (newX != qRound(_iconsX.current())) { _iconsX = anim::value(newX, newX); _iconsStartAnim = 0; - _a_icons.stop(); + _iconsAnimation.stop(); update(); } _iconsDragging = false; @@ -539,7 +542,7 @@ void StickersListWidget::Footer::scrollByWheelEvent( if (newX != qRound(_iconsX.current())) { _iconsX = anim::value(newX, newX); _iconsStartAnim = 0; - _a_icons.stop(); + _iconsAnimation.stop(); updateSelected(); update(); } @@ -601,7 +604,7 @@ void StickersListWidget::Footer::refreshIconsGeometry( _iconsX.finish(); _iconSelX.finish(); _iconsStartAnim = 0; - _a_icons.stop(); + _iconsAnimation.stop(); _iconsMax = std::max( _iconsLeft + int(_icons.size()) * st::stickerIconWidth + _iconsRight - width(), 0); @@ -673,13 +676,13 @@ void StickersListWidget::Footer::paintSetIcon( } } -void StickersListWidget::Footer::step_icons(crl::time ms, bool timer) { +bool StickersListWidget::Footer::iconsAnimationCallback(crl::time now) { if (anim::Disabled()) { - ms += st::stickerIconMove; + now += st::stickerIconMove; } if (_iconsStartAnim) { - auto dt = (ms - _iconsStartAnim) / float64(st::stickerIconMove); - if (dt >= 1) { + const auto dt = (now - _iconsStartAnim) / float64(st::stickerIconMove); + if (dt >= 1.) { _iconsStartAnim = 0; _iconsX.finish(); _iconSelX.finish(); @@ -689,11 +692,9 @@ void StickersListWidget::Footer::step_icons(crl::time ms, bool timer) { } } - if (timer) update(); + update(); - if (!_iconsStartAnim) { - _a_icons.stop(); - } + return (_iconsStartAnim != 0); } StickersListWidget::StickersListWidget(QWidget *parent, not_null controller) : Inner(parent, controller) diff --git a/Telegram/SourceFiles/config.h b/Telegram/SourceFiles/config.h index f59991274..b1ced0c13 100644 --- a/Telegram/SourceFiles/config.h +++ b/Telegram/SourceFiles/config.h @@ -46,7 +46,6 @@ enum { MediaOverviewStartPerPage = 5, AudioVoiceMsgMaxLength = 100 * 60, // 100 minutes - AudioVoiceMsgUpdateView = 100, // 100ms AudioVoiceMsgChannels = 2, // stereo StickerMaxSize = 2048, // 2048x2048 is a max image size for sticker diff --git a/Telegram/SourceFiles/dialogs/dialogs_inner_widget.cpp b/Telegram/SourceFiles/dialogs/dialogs_inner_widget.cpp index 82ec8ffb3..490bd1746 100644 --- a/Telegram/SourceFiles/dialogs/dialogs_inner_widget.cpp +++ b/Telegram/SourceFiles/dialogs/dialogs_inner_widget.cpp @@ -71,7 +71,9 @@ DialogsInner::DialogsInner(QWidget *parent, not_null contro , _dialogs(std::make_unique(Dialogs::SortMode::Date)) , _contactsNoDialogs(std::make_unique(Dialogs::SortMode::Name)) , _contacts(std::make_unique(Dialogs::SortMode::Name)) -, _a_pinnedShifting(animation(this, &DialogsInner::step_pinnedShifting)) +, _pinnedShiftAnimation([=](crl::time now) { + return pinnedShiftAnimationCallback(now); +}) , _addContactLnk(this, lang(lng_add_contact_button)) , _cancelSearchInChat(this, st::dialogsCancelSearchInPeer) , _cancelSearchFromUser(this, st::dialogsCancelSearchInPeer) { @@ -255,10 +257,6 @@ void DialogsInner::paintRegion(Painter &p, const QRegion ®ion, bool paintingO auto fullWidth = getFullWidth(); auto ms = crl::now(); if (_state == State::Default) { - if (_a_pinnedShifting.animating()) { - _a_pinnedShifting.step(ms, false); - } - auto rows = shownDialogs(); auto dialogsClip = r; if (_dialogsImportant) { @@ -855,7 +853,7 @@ void DialogsInner::mousePressEvent(QMouseEvent *e) { } else if (_pressed) { auto row = _pressed; row->addRipple(e->pos() - QPoint(0, dialogsOffset() + _pressed->pos() * st::dialogsRowHeight), QSize(getFullWidth(), st::dialogsRowHeight), [this, row] { - if (!_a_pinnedShifting.animating()) { + if (!_pinnedShiftAnimation.animating()) { row->entry()->updateChatListEntry(); } }); @@ -901,7 +899,7 @@ void DialogsInner::checkReorderPinnedStart(QPoint localPosition) { _pinnedOrder = Auth().data().pinnedDialogsOrder(); _pinnedRows[_draggingIndex].yadd = anim::value(0, localPosition.y() - _dragStart.y()); _pinnedRows[_draggingIndex].animStartTime = crl::now(); - _a_pinnedShifting.start(); + _pinnedShiftAnimation.start(); } } } @@ -959,7 +957,7 @@ void DialogsInner::finishReorderPinned() { } _draggingIndex = -1; - if (!_a_pinnedShifting.animating()) { + if (!_pinnedShiftAnimation.animating()) { _pinnedRows.clear(); _aboveIndex = -1; } @@ -969,7 +967,7 @@ void DialogsInner::finishReorderPinned() { } void DialogsInner::stopReorderPinned() { - _a_pinnedShifting.stop(); + _pinnedShiftAnimation.stop(); finishReorderPinned(); } @@ -990,7 +988,7 @@ int DialogsInner::updateReorderIndexGetCount() { _draggingIndex = index; _aboveIndex = _draggingIndex; while (count > _pinnedRows.size()) { - _pinnedRows.push_back(PinnedRow()); + _pinnedRows.emplace_back(); } while (count < _pinnedRows.size()) { _pinnedRows.pop_back(); @@ -1007,7 +1005,7 @@ bool DialogsInner::updateReorderPinned(QPoint localPosition) { auto yaddWas = _pinnedRows[_draggingIndex].yadd.current(); auto shift = 0; - auto ms = crl::now(); + auto now = crl::now(); auto rowHeight = st::dialogsRowHeight; if (_dragStart.y() > localPosition.y() && _draggingIndex > 0) { shift = -floorclamp(_dragStart.y() - localPosition.y() + (rowHeight / 2), rowHeight, 0, _draggingIndex); @@ -1016,7 +1014,7 @@ bool DialogsInner::updateReorderPinned(QPoint localPosition) { shownDialogs()->movePinned(_dragging, -1); std::swap(_pinnedRows[from], _pinnedRows[from - 1]); _pinnedRows[from].yadd = anim::value(_pinnedRows[from].yadd.current() - rowHeight, 0); - _pinnedRows[from].animStartTime = ms; + _pinnedRows[from].animStartTime = now; } } else if (_dragStart.y() < localPosition.y() && _draggingIndex + 1 < pinnedCount) { shift = floorclamp(localPosition.y() - _dragStart.y() + (rowHeight / 2), rowHeight, 0, pinnedCount - _draggingIndex - 1); @@ -1025,15 +1023,15 @@ bool DialogsInner::updateReorderPinned(QPoint localPosition) { shownDialogs()->movePinned(_dragging, 1); std::swap(_pinnedRows[from], _pinnedRows[from + 1]); _pinnedRows[from].yadd = anim::value(_pinnedRows[from].yadd.current() + rowHeight, 0); - _pinnedRows[from].animStartTime = ms; + _pinnedRows[from].animStartTime = now; } } if (shift) { _draggingIndex += shift; _aboveIndex = _draggingIndex; _dragStart.setY(_dragStart.y() + shift * rowHeight); - if (!_a_pinnedShifting.animating()) { - _a_pinnedShifting.start(); + if (!_pinnedShiftAnimation.animating()) { + _pinnedShiftAnimation.start(); } } _aboveTopShift = qCeil(_pinnedRows[_aboveIndex].yadd.current()); @@ -1041,22 +1039,22 @@ bool DialogsInner::updateReorderPinned(QPoint localPosition) { if (!_pinnedRows[_draggingIndex].animStartTime) { _pinnedRows[_draggingIndex].yadd.finish(); } - _a_pinnedShifting.step(ms, true); + pinnedShiftAnimationCallback(now); - auto countDraggingScrollDelta = [this, localPosition] { + const auto delta = [&] { if (localPosition.y() < _visibleTop) { return localPosition.y() - _visibleTop; } return 0; - }; + }(); - emit draggingScrollDelta(countDraggingScrollDelta()); + emit draggingScrollDelta(delta); return true; } -void DialogsInner::step_pinnedShifting(crl::time ms, bool timer) { +bool DialogsInner::pinnedShiftAnimationCallback(crl::time now) { if (anim::Disabled()) { - ms += st::stickersRowDuration; + now += st::stickersRowDuration; } auto wasAnimating = false; @@ -1069,8 +1067,8 @@ void DialogsInner::step_pinnedShifting(crl::time ms, bool timer) { wasAnimating = true; if (updateMin < 0) updateMin = i; updateMax = i; - if (start + st::stickersRowDuration > ms && ms >= start) { - _pinnedRows[i].yadd.update(float64(ms - start) / st::stickersRowDuration, anim::sineInOut); + if (start + st::stickersRowDuration > now && now >= start) { + _pinnedRows[i].yadd.update(float64(now - start) / st::stickersRowDuration, anim::sineInOut); animating = true; } else { _pinnedRows[i].yadd.finish(); @@ -1078,33 +1076,31 @@ void DialogsInner::step_pinnedShifting(crl::time ms, bool timer) { } } } - if (timer || (wasAnimating && !animating)) { - updateReorderIndexGetCount(); - if (_draggingIndex >= 0) { - if (updateMin < 0 || updateMin > _draggingIndex) { - updateMin = _draggingIndex; - } - if (updateMax < _draggingIndex) updateMax = _draggingIndex; + updateReorderIndexGetCount(); + if (_draggingIndex >= 0) { + if (updateMin < 0 || updateMin > _draggingIndex) { + updateMin = _draggingIndex; } - if (updateMin >= 0) { - auto top = pinnedOffset(); - auto updateFrom = top + st::dialogsRowHeight * (updateMin - 1); - auto updateHeight = st::dialogsRowHeight * (updateMax - updateMin + 3); - if (base::in_range(_aboveIndex, 0, _pinnedRows.size())) { - // Always include currently dragged chat in its current and old positions. - auto aboveRowBottom = top + (_aboveIndex + 1) * st::dialogsRowHeight; - auto aboveTopShift = qCeil(_pinnedRows[_aboveIndex].yadd.current()); - accumulate_max(updateHeight, (aboveRowBottom - updateFrom) + _aboveTopShift); - accumulate_max(updateHeight, (aboveRowBottom - updateFrom) + aboveTopShift); - _aboveTopShift = aboveTopShift; - } - update(0, updateFrom, getFullWidth(), updateHeight); + if (updateMax < _draggingIndex) updateMax = _draggingIndex; + } + if (updateMin >= 0) { + auto top = pinnedOffset(); + auto updateFrom = top + st::dialogsRowHeight * (updateMin - 1); + auto updateHeight = st::dialogsRowHeight * (updateMax - updateMin + 3); + if (base::in_range(_aboveIndex, 0, _pinnedRows.size())) { + // Always include currently dragged chat in its current and old positions. + auto aboveRowBottom = top + (_aboveIndex + 1) * st::dialogsRowHeight; + auto aboveTopShift = qCeil(_pinnedRows[_aboveIndex].yadd.current()); + accumulate_max(updateHeight, (aboveRowBottom - updateFrom) + _aboveTopShift); + accumulate_max(updateHeight, (aboveRowBottom - updateFrom) + aboveTopShift); + _aboveTopShift = aboveTopShift; } + update(0, updateFrom, getFullWidth(), updateHeight); } if (!animating) { _aboveIndex = _draggingIndex; - _a_pinnedShifting.stop(); } + return animating; } void DialogsInner::mouseReleaseEvent(QMouseEvent *e) { @@ -1120,8 +1116,8 @@ void DialogsInner::mousePressReleased( if (_draggingIndex >= 0) { _pinnedRows[_draggingIndex].yadd.start(0.); _pinnedRows[_draggingIndex].animStartTime = crl::now(); - if (!_a_pinnedShifting.animating()) { - _a_pinnedShifting.start(); + if (!_pinnedShiftAnimation.animating()) { + _pinnedShiftAnimation.start(); } } finishReorderPinned(); diff --git a/Telegram/SourceFiles/dialogs/dialogs_inner_widget.h b/Telegram/SourceFiles/dialogs/dialogs_inner_widget.h index 149b2dbe1..2c6371844 100644 --- a/Telegram/SourceFiles/dialogs/dialogs_inner_widget.h +++ b/Telegram/SourceFiles/dialogs/dialogs_inner_widget.h @@ -10,6 +10,7 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL #include "dialogs/dialogs_widget.h" #include "dialogs/dialogs_key.h" #include "data/data_messages.h" +#include "ui/effects/animations.h" #include "base/flags.h" namespace Dialogs { @@ -283,7 +284,7 @@ private: void stopReorderPinned(); int countPinnedIndex(Dialogs::Row *ofRow); void savePinnedOrder(); - void step_pinnedShifting(crl::time ms, bool timer); + bool pinnedShiftAnimationCallback(crl::time now); void handleChatMigration(not_null chat); not_null _controller; @@ -313,7 +314,7 @@ private: crl::time animStartTime = 0; }; std::vector _pinnedRows; - BasicAnimation _a_pinnedShifting; + Ui::Animations::Basic _pinnedShiftAnimation; std::deque _pinnedOrder; // Remember the last currently dragged row top shift for updating area. diff --git a/Telegram/SourceFiles/dialogs/dialogs_widget.cpp b/Telegram/SourceFiles/dialogs/dialogs_widget.cpp index 161a4eb3b..e12b0426b 100644 --- a/Telegram/SourceFiles/dialogs/dialogs_widget.cpp +++ b/Telegram/SourceFiles/dialogs/dialogs_widget.cpp @@ -66,7 +66,7 @@ protected: void onStateChanged(State was, StateChangeSource source) override; private: - void step_radial(crl::time ms, bool timer); + void radialAnimationCallback(); QString _text; const style::FlatButton &_st; @@ -95,8 +95,8 @@ void DialogsWidget::BottomButton::setText(const QString &text) { update(); } -void DialogsWidget::BottomButton::step_radial(crl::time ms, bool timer) { - if (timer && !anim::Disabled() && width() < st::columnMinimalWidthLeft) { +void DialogsWidget::BottomButton::radialAnimationCallback() { + if (!anim::Disabled() && width() < st::columnMinimalWidthLeft) { update(); } } @@ -106,7 +106,7 @@ void DialogsWidget::BottomButton::onStateChanged(State was, StateChangeSource so if ((was & StateFlag::Disabled) != (state() & StateFlag::Disabled)) { _loading = isDisabled() ? std::make_unique( - animation(this, &BottomButton::step_radial), + [=] { radialAnimationCallback(); }, st::dialogsLoadMoreLoading) : nullptr; if (_loading) { diff --git a/Telegram/SourceFiles/history/history_item_components.cpp b/Telegram/SourceFiles/history/history_item_components.cpp index 4356ce00d..d4eaa1a3d 100644 --- a/Telegram/SourceFiles/history/history_item_components.cpp +++ b/Telegram/SourceFiles/history/history_item_components.cpp @@ -396,7 +396,9 @@ ReplyKeyboard::ReplyKeyboard( not_null item, std::unique_ptr