diff --git a/Telegram/SourceFiles/boxes/background_preview_box.cpp b/Telegram/SourceFiles/boxes/background_preview_box.cpp index 2b6a83336..b7a1929de 100644 --- a/Telegram/SourceFiles/boxes/background_preview_box.cpp +++ b/Telegram/SourceFiles/boxes/background_preview_box.cpp @@ -39,8 +39,7 @@ public: Painter &p, int left, int top, - int outerWidth, - crl::time ms) override; + int outerWidth) override; QImage prepareRippleMask() const override; bool checkRippleStartPosition(QPoint position) const override; @@ -241,14 +240,13 @@ void ServiceCheck::paint( Painter &p, int left, int top, - int outerWidth, - crl::time ms) { + int outerWidth) { Frames().paintFrame( p, left + _st.margin.left(), top + _st.margin.top(), &_st, - currentAnimationValue(ms)); + currentAnimationValue()); } QImage ServiceCheck::prepareRippleMask() const { @@ -507,20 +505,20 @@ void BackgroundPreviewBox::paintEvent(QPaintEvent *e) { } if (!color || _paper.isPattern()) { if (!_scaled.isNull() || setScaledFromThumb()) { - paintImage(p, ms); - paintRadial(p, ms); + paintImage(p); + paintRadial(p); } else if (!color) { p.fillRect(e->rect(), st::boxBg); return; } else { // Progress of pattern loading. - paintRadial(p, ms); + paintRadial(p); } } paintTexts(p, ms); } -void BackgroundPreviewBox::paintImage(Painter &p, crl::time ms) { +void BackgroundPreviewBox::paintImage(Painter &p) { Expects(!_scaled.isNull()); const auto master = _paper.isPattern() @@ -536,7 +534,7 @@ void BackgroundPreviewBox::paintImage(Painter &p, crl::time ms) { height() * factor); const auto guard = gsl::finally([&] { p.setOpacity(1.); }); - const auto fade = _fadeIn.current(ms, 1.); + const auto fade = _fadeIn.value(1.); if (fade < 1. && !_fadeOutThumbnail.isNull()) { p.drawPixmap(rect(), _fadeOutThumbnail, from); } @@ -548,7 +546,7 @@ void BackgroundPreviewBox::paintImage(Painter &p, crl::time ms) { checkBlurAnimationStart(); } -void BackgroundPreviewBox::paintRadial(Painter &p, crl::time ms) { +void BackgroundPreviewBox::paintRadial(Painter &p) { const auto radial = _radial.animating(); const auto radialOpacity = radial ? _radial.opacity() : 0.; if (!radial) { diff --git a/Telegram/SourceFiles/boxes/background_preview_box.h b/Telegram/SourceFiles/boxes/background_preview_box.h index 2924daa12..a24d91f85 100644 --- a/Telegram/SourceFiles/boxes/background_preview_box.h +++ b/Telegram/SourceFiles/boxes/background_preview_box.h @@ -12,6 +12,7 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL #include "window/themes/window_theme.h" #include "history/admin_log/history_admin_log_item.h" #include "history/view/history_view_element.h" +#include "ui/effects/animations.h" #include "ui/effects/radial_animation.h" namespace Ui { @@ -58,8 +59,8 @@ private: void setScaledFromImage(QImage &&image, QImage &&blurred); void updateServiceBg(std::optional background); std::optional patternBackgroundColor() const; - void paintImage(Painter &p, crl::time ms); - void paintRadial(Painter &p, crl::time ms); + void paintImage(Painter &p); + void paintRadial(Painter &p); void paintTexts(Painter &p, crl::time ms); void paintDate(Painter &p); void createBlurCheckbox(); @@ -72,7 +73,7 @@ private: Data::WallPaper _paper; QImage _full; QPixmap _scaled, _blurred, _fadeOutThumbnail; - Animation _fadeIn; + Ui::Animations::Simple _fadeIn; Ui::RadialAnimation _radial; base::binary_guard _generating; std::optional _serviceBg; diff --git a/Telegram/SourceFiles/boxes/calendar_box.cpp b/Telegram/SourceFiles/boxes/calendar_box.cpp index 2e2b81fb3..bf725a82c 100644 --- a/Telegram/SourceFiles/boxes/calendar_box.cpp +++ b/Telegram/SourceFiles/boxes/calendar_box.cpp @@ -320,7 +320,7 @@ void CalendarBox::Inner::paintRows(Painter &p, QRect clip) { } return st::windowBgOver; }; - it->second->paint(p, innerLeft, innerTop, width(), ms, &(colorOverride()->c)); + it->second->paint(p, innerLeft, innerTop, width(), &(colorOverride()->c)); if (it->second->empty()) { _ripples.erase(it); } diff --git a/Telegram/SourceFiles/boxes/connection_box.cpp b/Telegram/SourceFiles/boxes/connection_box.cpp index 3a36a627f..1be879d51 100644 --- a/Telegram/SourceFiles/boxes/connection_box.cpp +++ b/Telegram/SourceFiles/boxes/connection_box.cpp @@ -20,6 +20,7 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL #include "ui/wrap/slide_wrap.h" #include "ui/wrap/vertical_layout.h" #include "ui/toast/toast.h" +#include "ui/effects/animations.h" #include "ui/effects/radial_animation.h" #include "ui/text_options.h" #include "styles/style_boxes.h" @@ -53,7 +54,7 @@ private: void setupControls(View &&view); int countAvailableWidth() const; void radialAnimationCallback(); - void paintCheck(Painter &p, crl::time ms); + void paintCheck(Painter &p); void showMenu(); View _view; @@ -67,8 +68,8 @@ private: base::unique_qptr _menu; bool _set = false; - Animation _toggled; - Animation _setAnimation; + Ui::Animations::Simple _toggled; + Ui::Animations::Simple _setAnimation; std::unique_ptr _progress; std::unique_ptr _checking; @@ -180,8 +181,8 @@ rpl::producer<> ProxyRow::shareClicks() const { void ProxyRow::setupControls(View &&view) { updateFields(std::move(view)); - _toggled.finish(); - _setAnimation.finish(); + _toggled.stop(); + _setAnimation.stop(); _menuToggle->addClickHandler([=] { showMenu(); }); } @@ -268,9 +269,8 @@ int ProxyRow::resizeGetHeight(int newWidth) { void ProxyRow::paintEvent(QPaintEvent *e) { Painter p(this); - const auto ms = crl::now(); if (!_view.deleted) { - paintRipple(p, 0, 0, ms); + paintRipple(p, 0, 0); } const auto left = _skipLeft; @@ -281,7 +281,7 @@ void ProxyRow::paintEvent(QPaintEvent *e) { p.setOpacity(st::stickersRowDisabledOpacity); } - paintCheck(p, ms); + paintCheck(p); p.setPen(st::proxyRowTitleFg); p.setFont(st::semiboldFont); @@ -338,14 +338,14 @@ void ProxyRow::paintEvent(QPaintEvent *e) { top += st::normalFont->height + st::proxyRowPadding.bottom(); } -void ProxyRow::paintCheck(Painter &p, crl::time ms) { +void ProxyRow::paintCheck(Painter &p) { const auto loading = _progress ? _progress->computeState() : Ui::RadialState{ 0., 0, FullArcLength }; - const auto toggled = _toggled.current(ms, _view.selected ? 1. : 0.) + const auto toggled = _toggled.value(_view.selected ? 1. : 0.) * (1. - loading.shown); const auto _st = &st::defaultRadio; - const auto set = _setAnimation.current(ms, _set ? 1. : 0.); + const auto set = _setAnimation.value(_set ? 1. : 0.); PainterHighQualityEnabler hq(p); diff --git a/Telegram/SourceFiles/boxes/edit_color_box.cpp b/Telegram/SourceFiles/boxes/edit_color_box.cpp index fc84dff09..549c3c3f5 100644 --- a/Telegram/SourceFiles/boxes/edit_color_box.cpp +++ b/Telegram/SourceFiles/boxes/edit_color_box.cpp @@ -442,7 +442,7 @@ public: protected: void correctValue(const QString &was, int wasCursor, QString &now, int &nowCursor) override; - void paintAdditionalPlaceholder(Painter &p, crl::time ms) override; + void paintAdditionalPlaceholder(Painter &p) override; void wheelEvent(QWheelEvent *e) override; void keyPressEvent(QKeyEvent *e) override; @@ -501,7 +501,7 @@ void EditColorBox::Field::correctValue(const QString &was, int wasCursor, QStrin } } -void EditColorBox::Field::paintAdditionalPlaceholder(Painter &p, crl::time ms) { +void EditColorBox::Field::paintAdditionalPlaceholder(Painter &p) { p.setFont(_st.font); p.setPen(_st.placeholderFg); auto inner = QRect(_st.textMargins.right(), _st.textMargins.top(), width() - 2 * _st.textMargins.right(), height() - _st.textMargins.top() - _st.textMargins.bottom()); @@ -565,7 +565,7 @@ public: protected: void correctValue(const QString &was, int wasCursor, QString &now, int &nowCursor) override; - void paintAdditionalPlaceholder(Painter &p, crl::time ms) override; + void paintAdditionalPlaceholder(Painter &p) override; }; @@ -606,7 +606,7 @@ void EditColorBox::ResultField::correctValue(const QString &was, int wasCursor, } } -void EditColorBox::ResultField::paintAdditionalPlaceholder(Painter &p, crl::time ms) { +void EditColorBox::ResultField::paintAdditionalPlaceholder(Painter &p) { p.setFont(_st.font); p.setPen(_st.placeholderFg); p.drawText(QRect(_st.textMargins.right(), _st.textMargins.top(), width(), height() - _st.textMargins.top() - _st.textMargins.bottom()), "#", style::al_topleft); diff --git a/Telegram/SourceFiles/boxes/language_box.cpp b/Telegram/SourceFiles/boxes/language_box.cpp index 07e9b8dc2..53df92553 100644 --- a/Telegram/SourceFiles/boxes/language_box.cpp +++ b/Telegram/SourceFiles/boxes/language_box.cpp @@ -772,7 +772,6 @@ int Rows::countAvailableWidth() const { void Rows::paintEvent(QPaintEvent *e) { Painter p(this); - const auto ms = crl::now(); const auto clip = e->rect(); const auto checkLeft = st::passportRowPadding.left(); @@ -801,14 +800,14 @@ void Rows::paintEvent(QPaintEvent *e) { } if (row.ripple) { - row.ripple->paint(p, 0, 0, width(), ms); + row.ripple->paint(p, 0, 0, width()); if (row.ripple->empty()) { row.ripple.reset(); } } const auto checkTop = (row.height - st::defaultRadio.diameter) / 2; - row.check->paint(p, checkLeft, checkTop, width(), ms); + row.check->paint(p, checkLeft, checkTop, width()); auto top = st::passportRowPadding.top(); @@ -829,7 +828,7 @@ void Rows::paintEvent(QPaintEvent *e) { p.drawEllipse(menu); } if (row.menuToggleRipple) { - row.menuToggleRipple->paint(p, menu.x(), menu.y(), width(), ms); + row.menuToggleRipple->paint(p, menu.x(), menu.y(), width()); if (row.menuToggleRipple->empty()) { row.menuToggleRipple.reset(); } diff --git a/Telegram/SourceFiles/boxes/peer_list_box.cpp b/Telegram/SourceFiles/boxes/peer_list_box.cpp index 61ee41bf1..ba729bfbb 100644 --- a/Telegram/SourceFiles/boxes/peer_list_box.cpp +++ b/Telegram/SourceFiles/boxes/peer_list_box.cpp @@ -457,9 +457,9 @@ void PeerListRow::stopLastRipple() { } } -void PeerListRow::paintRipple(Painter &p, crl::time ms, int x, int y, int outerWidth) { +void PeerListRow::paintRipple(Painter &p, int x, int y, int outerWidth) { if (_ripple) { - _ripple->paint(p, x, y, outerWidth, ms); + _ripple->paint(p, x, y, outerWidth); if (_ripple->empty()) { _ripple.reset(); } @@ -469,14 +469,13 @@ void PeerListRow::paintRipple(Painter &p, crl::time ms, int x, int y, int outerW void PeerListRow::paintUserpic( Painter &p, const style::PeerListItem &st, - crl::time ms, int x, int y, int outerWidth) { if (_disabledState == State::DisabledChecked) { paintDisabledCheckUserpic(p, st, x, y, outerWidth); } else if (_checkbox) { - _checkbox->paint(p, ms, x, y, outerWidth); + _checkbox->paint(p, x, y, outerWidth); } else if (_isSavedMessagesChat) { Ui::EmptyUserpic::PaintSavedMessages(p, x, y, outerWidth, st.photoSize); } else { @@ -1099,11 +1098,10 @@ crl::time PeerListContent::paintRow(Painter &p, crl::time ms, RowIndex index) { ? _st.item.button.textBgOver : _st.item.button.textBg; p.fillRect(0, 0, width(), _rowHeight, bg); - row->paintRipple(p, ms, 0, 0, width()); + row->paintRipple(p, 0, 0, width()); row->paintUserpic( p, _st.item, - ms, _st.item.photoPosition.x(), _st.item.photoPosition.y(), width()); @@ -1143,7 +1141,6 @@ crl::time PeerListContent::paintRow(Painter &p, crl::time ms, RowIndex index) { auto actionTop = actionMargins.top(); row->paintAction( p, - ms, actionLeft, actionTop, width(), diff --git a/Telegram/SourceFiles/boxes/peer_list_box.h b/Telegram/SourceFiles/boxes/peer_list_box.h index becf3f520..67ef59e69 100644 --- a/Telegram/SourceFiles/boxes/peer_list_box.h +++ b/Telegram/SourceFiles/boxes/peer_list_box.h @@ -92,7 +92,6 @@ public: } virtual void paintAction( Painter &p, - crl::time ms, int x, int y, int outerWidth, @@ -158,11 +157,10 @@ public: QPoint point, UpdateCallback updateCallback); void stopLastRipple(); - void paintRipple(Painter &p, crl::time ms, int x, int y, int outerWidth); + void paintRipple(Painter &p, int x, int y, int outerWidth); void paintUserpic( Painter &p, const style::PeerListItem &st, - crl::time ms, int x, int y, int outerWidth); diff --git a/Telegram/SourceFiles/boxes/peer_list_controllers.cpp b/Telegram/SourceFiles/boxes/peer_list_controllers.cpp index 92c6fed07..2b6649ed3 100644 --- a/Telegram/SourceFiles/boxes/peer_list_controllers.cpp +++ b/Telegram/SourceFiles/boxes/peer_list_controllers.cpp @@ -122,7 +122,6 @@ QMargins PeerListRowWithLink::actionMargins() const { void PeerListRowWithLink::paintAction( Painter &p, - crl::time ms, int x, int y, int outerWidth, diff --git a/Telegram/SourceFiles/boxes/peer_list_controllers.h b/Telegram/SourceFiles/boxes/peer_list_controllers.h index 929ebbb99..974a35602 100644 --- a/Telegram/SourceFiles/boxes/peer_list_controllers.h +++ b/Telegram/SourceFiles/boxes/peer_list_controllers.h @@ -42,7 +42,6 @@ private: QMargins actionMargins() const override; void paintAction( Painter &p, - crl::time ms, int x, int y, int outerWidth, diff --git a/Telegram/SourceFiles/boxes/send_files_box.cpp b/Telegram/SourceFiles/boxes/send_files_box.cpp index e3a46b119..e517fe24e 100644 --- a/Telegram/SourceFiles/boxes/send_files_box.cpp +++ b/Telegram/SourceFiles/boxes/send_files_box.cpp @@ -18,6 +18,7 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL #include "core/file_utilities.h" #include "core/mime_type.h" #include "core/event_filter.h" +#include "ui/effects/animations.h" #include "ui/widgets/checkbox.h" #include "ui/widgets/buttons.h" #include "ui/widgets/input_fields.h" @@ -122,8 +123,7 @@ public: int left, int top, float64 shrinkProgress, - float64 moveProgress, - crl::time ms); + float64 moveProgress); void paintPhoto(Painter &p, int left, int top, int outerWidth); void paintFile(Painter &p, int left, int top, int outerWidth); @@ -157,7 +157,7 @@ private: int _statusWidth = 0; bool _isVideo = false; float64 _suggestedMove = 0.; - Animation _suggestedMoveAnimation; + Ui::Animations::Simple _suggestedMoveAnimation; int _lastShrinkValue = 0; }; @@ -290,10 +290,8 @@ void AlbumThumb::paintInAlbum( int left, int top, float64 shrinkProgress, - float64 moveProgress, - crl::time ms) { + float64 moveProgress) { const auto shrink = anim::interpolate(0, _shrinkSize, shrinkProgress); - _suggestedMoveAnimation.step(ms); _lastShrinkValue = shrink; const auto geometry = countCurrentGeometry(moveProgress); const auto x = left + geometry.x(); @@ -540,7 +538,7 @@ void AlbumThumb::suggestMove(float64 delta, Fn callback) { QRect AlbumThumb::countRealGeometry() const { const auto addLeft = int(std::round( - _suggestedMoveAnimation.current(_suggestedMove) * _lastShrinkValue)); + _suggestedMoveAnimation.value(_suggestedMove) * _lastShrinkValue)); const auto current = _layout.geometry; const auto realTopLeft = current.topLeft() + _albumPosition @@ -562,7 +560,7 @@ QRect AlbumThumb::countCurrentGeometry(float64 progress) const { } void AlbumThumb::finishAnimations() { - _suggestedMoveAnimation.finish(); + _suggestedMoveAnimation.stop(); } SingleMediaPreview *SingleMediaPreview::Create( @@ -961,9 +959,9 @@ private: AlbumThumb *_paintedAbove = nullptr; QPoint _draggedStartPosition; - mutable Animation _thumbsHeightAnimation; - mutable Animation _shrinkAnimation; - mutable Animation _finishDragAnimation; + mutable Ui::Animations::Simple _thumbsHeightAnimation; + mutable Ui::Animations::Simple _shrinkAnimation; + mutable Ui::Animations::Simple _finishDragAnimation; }; @@ -1087,9 +1085,9 @@ int SendFilesBox::AlbumPreview::orderIndex( } void SendFilesBox::AlbumPreview::cancelDrag() { - _thumbsHeightAnimation.finish(); - _finishDragAnimation.finish(); - _shrinkAnimation.finish(); + _thumbsHeightAnimation.stop(); + _finishDragAnimation.stop(); + _shrinkAnimation.stop(); if (_draggedThumb) { _draggedThumb->moveInAlbum({ 0, 0 }); _draggedThumb = nullptr; @@ -1164,7 +1162,7 @@ void SendFilesBox::AlbumPreview::updateSize() { const auto newHeight = [&] { switch (_sendWay) { case SendFilesWay::Album: - return int(std::round(_thumbsHeightAnimation.current( + return int(std::round(_thumbsHeightAnimation.value( _thumbsHeight))); case SendFilesWay::Photos: return _photosHeight; case SendFilesWay::Files: return _filesHeight; @@ -1187,20 +1185,17 @@ void SendFilesBox::AlbumPreview::paintEvent(QPaintEvent *e) { } void SendFilesBox::AlbumPreview::paintAlbum(Painter &p) const { - const auto ms = crl::now(); - const auto shrink = _shrinkAnimation.current( - ms, - _draggedThumb ? 1. : 0.); - const auto moveProgress = _finishDragAnimation.current(ms, 1.); + const auto shrink = _shrinkAnimation.value(_draggedThumb ? 1. : 0.); + const auto moveProgress = _finishDragAnimation.value(1.); const auto left = contentLeft(); const auto top = contentTop(); for (const auto &thumb : _thumbs) { if (thumb.get() != _paintedAbove) { - thumb->paintInAlbum(p, left, top, shrink, moveProgress, ms); + thumb->paintInAlbum(p, left, top, shrink, moveProgress); } } if (_paintedAbove) { - _paintedAbove->paintInAlbum(p, left, top, shrink, moveProgress, ms); + _paintedAbove->paintInAlbum(p, left, top, shrink, moveProgress); } } diff --git a/Telegram/SourceFiles/boxes/share_box.cpp b/Telegram/SourceFiles/boxes/share_box.cpp index 43c43d080..bc46a8f02 100644 --- a/Telegram/SourceFiles/boxes/share_box.cpp +++ b/Telegram/SourceFiles/boxes/share_box.cpp @@ -85,7 +85,7 @@ private: PeerData *peer; Ui::RoundImageCheckbox checkbox; Text name; - Animation nameActive; + Ui::Animations::Simple nameActive; }; void notifyPeerUpdated(const Notify::PeerUpdate &update); @@ -93,7 +93,7 @@ private: int displayedChatsCount() const; - void paintChat(Painter &p, crl::time ms, not_null chat, int index); + void paintChat(Painter &p, not_null chat, int index); void updateChat(not_null peer); void updateChatName(not_null chat, not_null peer); void repaintChat(not_null peer); @@ -732,7 +732,6 @@ void ShareBox::Inner::setActive(int active) { void ShareBox::Inner::paintChat( Painter &p, - crl::time ms, not_null chat, int index) { auto x = _rowsLeft + qFloor((index % _columnCount) * _rowWidthReal); @@ -741,9 +740,9 @@ void ShareBox::Inner::paintChat( auto outerWidth = width(); auto photoLeft = (_rowWidth - (st::sharePhotoCheckbox.imageRadius * 2)) / 2; auto photoTop = st::sharePhotoTop; - chat->checkbox.paint(p, ms, x + photoLeft, y + photoTop, outerWidth); + chat->checkbox.paint(p, x + photoLeft, y + photoTop, outerWidth); - auto nameActive = chat->nameActive.current(ms, (index == _active) ? 1. : 0.); + auto nameActive = chat->nameActive.value((index == _active) ? 1. : 0.); p.setPen(anim::pen(st::shareNameFg, st::shareNameActiveFg, nameActive)); auto nameWidth = (_rowWidth - st::shareColumnSkip); @@ -761,7 +760,6 @@ ShareBox::Inner::Chat::Chat(PeerData *peer, Fn updateCallback) void ShareBox::Inner::paintEvent(QPaintEvent *e) { Painter p(this); - auto ms = crl::now(); auto r = e->rect(); p.setClipRect(r); p.fillRect(r, st::boxBg); @@ -777,7 +775,7 @@ void ShareBox::Inner::paintEvent(QPaintEvent *e) { if (indexFrom >= indexTo) { break; } - paintChat(p, ms, getChat(*i), indexFrom); + paintChat(p, getChat(*i), indexFrom); ++indexFrom; } } else { @@ -806,7 +804,7 @@ void ShareBox::Inner::paintEvent(QPaintEvent *e) { if (indexFrom >= _filtered.size()) { break; } - paintChat(p, ms, getChat(_filtered[indexFrom]), indexFrom); + paintChat(p, getChat(_filtered[indexFrom]), indexFrom); ++indexFrom; } indexFrom -= filteredSize; @@ -820,7 +818,6 @@ void ShareBox::Inner::paintEvent(QPaintEvent *e) { } paintChat( p, - ms, d_byUsernameFiltered[indexFrom].get(), filteredSize + indexFrom); ++indexFrom; diff --git a/Telegram/SourceFiles/boxes/share_box.h b/Telegram/SourceFiles/boxes/share_box.h index 5b53d7ea6..34e512ed3 100644 --- a/Telegram/SourceFiles/boxes/share_box.h +++ b/Telegram/SourceFiles/boxes/share_box.h @@ -10,6 +10,7 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL #include "boxes/abstract_box.h" #include "base/observer.h" #include "base/timer.h" +#include "ui/effects/animations.h" #include "ui/effects/round_checkbox.h" namespace Dialogs { @@ -99,6 +100,6 @@ private: using PeopleQueries = QMap; PeopleQueries _peopleQueries; - Animation _scrollAnimation; + Ui::Animations::Simple _scrollAnimation; }; diff --git a/Telegram/SourceFiles/boxes/sticker_set_box.cpp b/Telegram/SourceFiles/boxes/sticker_set_box.cpp index 94c26b79b..05046a483 100644 --- a/Telegram/SourceFiles/boxes/sticker_set_box.cpp +++ b/Telegram/SourceFiles/boxes/sticker_set_box.cpp @@ -73,7 +73,7 @@ private: void showPreview(); - std::vector _packOvers; + std::vector _packOvers; Stickers::Pack _pack; Stickers::ByEmojiMap _emoji; bool _loaded = false; @@ -460,7 +460,6 @@ void StickerSetBox::Inner::paintEvent(QPaintEvent *e) { if (_pack.isEmpty()) return; - auto ms = crl::now(); int32 rows = _pack.size() / kStickersPanelPerRow + ((_pack.size() % kStickersPanelPerRow) ? 1 : 0); int32 from = qFloor(e->rect().top() / st::stickersSize.height()), to = qFloor(e->rect().bottom() / st::stickersSize.height()) + 1; @@ -473,7 +472,7 @@ void StickerSetBox::Inner::paintEvent(QPaintEvent *e) { DocumentData *doc = _pack.at(index); QPoint pos(st::stickersPadding.left() + j * st::stickersSize.width(), st::stickersPadding.top() + i * st::stickersSize.height()); - if (auto over = _packOvers[index].current(ms, (index == _selected) ? 1. : 0.)) { + if (auto over = _packOvers[index].value((index == _selected) ? 1. : 0.)) { p.setOpacity(over); QPoint tl(pos); if (rtl()) tl.setX(width() - tl.x() - st::stickersSize.width()); diff --git a/Telegram/SourceFiles/boxes/stickers_box.cpp b/Telegram/SourceFiles/boxes/stickers_box.cpp index 8a1627a87..594bac46c 100644 --- a/Telegram/SourceFiles/boxes/stickers_box.cpp +++ b/Telegram/SourceFiles/boxes/stickers_box.cpp @@ -384,7 +384,7 @@ void StickersBox::paintEvent(QPaintEvent *e) { Painter p(this); if (_slideAnimation) { - _slideAnimation->paintFrame(p, 0, getTopSkip(), width(), crl::now()); + _slideAnimation->paintFrame(p, 0, getTopSkip(), width()); if (!_slideAnimation->animating()) { _slideAnimation.reset(); setInnerVisible(true); @@ -715,14 +715,13 @@ void StickersBox::Inner::paintEvent(QPaintEvent *e) { Painter p(this); auto clip = e->rect(); - auto ms = crl::now(); p.fillRect(clip, st::boxBg); p.setClipRect(clip); if (_megagroupSelectedSet) { auto setTop = _megagroupDivider->y() - _rowHeight; p.translate(0, setTop); - paintRow(p, _megagroupSelectedSet.get(), -1, ms); + paintRow(p, _megagroupSelectedSet.get(), -1); p.translate(0, -setTop); } @@ -740,13 +739,13 @@ void StickersBox::Inner::paintEvent(QPaintEvent *e) { p.translate(0, from * _rowHeight); for (int32 i = from; i < to; ++i) { if (i != _above) { - paintRow(p, _rows[i].get(), i, ms); + paintRow(p, _rows[i].get(), i); } p.translate(0, _rowHeight); } if (from <= _above && _above < to) { p.translate(0, (_above - to) * _rowHeight); - paintRow(p, _rows[_above].get(), _above, ms); + paintRow(p, _rows[_above].get(), _above); } } } @@ -790,7 +789,7 @@ QRect StickersBox::Inner::relativeButtonRect(bool removeButton) const { return QRect(buttonx, buttony, buttonw, buttonh); } -void StickersBox::Inner::paintRow(Painter &p, Row *set, int index, crl::time ms) { +void StickersBox::Inner::paintRow(Painter &p, Row *set, int index) { auto xadd = 0, yadd = qRound(set->yadd.current()); if (xadd || yadd) p.translate(xadd, yadd); @@ -804,7 +803,7 @@ void StickersBox::Inner::paintRow(Painter &p, Row *set, int index, crl::time ms) if (index >= 0 && index == selectedIndex) { p.fillRect(0, 0, width(), _rowHeight, st::contactsBgOver); if (set->ripple) { - set->ripple->paint(p, 0, 0, width(), ms); + set->ripple->paint(p, 0, 0, width()); } } } @@ -827,13 +826,13 @@ void StickersBox::Inner::paintRow(Painter &p, Row *set, int index, crl::time ms) App::roundRect(p, row, st::boxBg, BoxCorners); p.setOpacity(1. - current); - paintFakeButton(p, set, index, ms); + paintFakeButton(p, set, index); p.setOpacity(1.); } else if (!_megagroupSet) { - paintFakeButton(p, set, index, ms); + paintFakeButton(p, set, index); } } else if (!_megagroupSet) { - paintFakeButton(p, set, index, ms); + paintFakeButton(p, set, index); } if (set->removed && _section == Section::Installed) { @@ -893,7 +892,7 @@ void StickersBox::Inner::paintRow(Painter &p, Row *set, int index, crl::time ms) if (xadd || yadd) p.translate(-xadd, -yadd); } -void StickersBox::Inner::paintFakeButton(Painter &p, Row *set, int index, crl::time ms) { +void StickersBox::Inner::paintFakeButton(Painter &p, Row *set, int index) { auto removeButton = (_section == Section::Installed && !set->removed); auto rect = relativeButtonRect(removeButton); if (_section != Section::Installed && set->installed && !set->archived && !set->removed) { @@ -906,7 +905,7 @@ void StickersBox::Inner::paintFakeButton(Painter &p, Row *set, int index, crl::t if (removeButton) { // Trash icon button when not disabled in Installed. if (set->ripple) { - set->ripple->paint(p, rect.x(), rect.y(), width(), ms); + set->ripple->paint(p, rect.x(), rect.y(), width()); if (set->ripple->empty()) { set->ripple.reset(); } @@ -915,7 +914,7 @@ void StickersBox::Inner::paintFakeButton(Painter &p, Row *set, int index, crl::t auto position = st::stickersRemove.iconPosition; if (position.x() < 0) position.setX((rect.width() - icon.width()) / 2); if (position.y() < 0) position.setY((rect.height() - icon.height()) / 2); - icon.paint(p, rect.topLeft() + position, ms); + icon.paint(p, rect.topLeft() + position, width()); } else { // Round button ADD when not installed from Trending or Archived. // Or round button UNDO after disabled from Installed. @@ -925,7 +924,7 @@ void StickersBox::Inner::paintFakeButton(Painter &p, Row *set, int index, crl::t auto &textBg = selected ? st.textBgOver : st.textBg; App::roundRect(p, myrtlrect(rect), textBg, ImageRoundRadius::Small); if (set->ripple) { - set->ripple->paint(p, rect.x(), rect.y(), width(), ms); + set->ripple->paint(p, rect.x(), rect.y(), width()); if (set->ripple->empty()) { set->ripple.reset(); } diff --git a/Telegram/SourceFiles/boxes/stickers_box.h b/Telegram/SourceFiles/boxes/stickers_box.h index a56a0d850..dd049d614 100644 --- a/Telegram/SourceFiles/boxes/stickers_box.h +++ b/Telegram/SourceFiles/boxes/stickers_box.h @@ -272,8 +272,8 @@ private: void ensureRipple(const style::RippleAnimation &st, QImage mask, bool removeButton); 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 paintRow(Painter &p, Row *set, int index); + void paintFakeButton(Painter &p, Row *set, int index); void clear(); void setActionSel(int32 actionSel); float64 aboveShadowOpacity() const; diff --git a/Telegram/SourceFiles/calls/calls_box_controller.cpp b/Telegram/SourceFiles/calls/calls_box_controller.cpp index 6af707e78..f4acda1bb 100644 --- a/Telegram/SourceFiles/calls/calls_box_controller.cpp +++ b/Telegram/SourceFiles/calls/calls_box_controller.cpp @@ -97,7 +97,6 @@ public: } void paintAction( Painter &p, - crl::time ms, int x, int y, int outerWidth, @@ -143,7 +142,6 @@ void BoxController::Row::paintStatusText(Painter &p, const style::PeerListItem & void BoxController::Row::paintAction( Painter &p, - crl::time ms, int x, int y, int outerWidth, @@ -151,7 +149,7 @@ void BoxController::Row::paintAction( bool actionSelected) { auto size = actionSize(); if (_actionRipple) { - _actionRipple->paint(p, x + st::callReDial.rippleAreaPosition.x(), y + st::callReDial.rippleAreaPosition.y(), outerWidth, ms); + _actionRipple->paint(p, x + st::callReDial.rippleAreaPosition.x(), y + st::callReDial.rippleAreaPosition.y(), outerWidth); if (_actionRipple->empty()) { _actionRipple.reset(); } diff --git a/Telegram/SourceFiles/calls/calls_panel.cpp b/Telegram/SourceFiles/calls/calls_panel.cpp index 95a372785..90a937a40 100644 --- a/Telegram/SourceFiles/calls/calls_panel.cpp +++ b/Telegram/SourceFiles/calls/calls_panel.cpp @@ -66,7 +66,7 @@ private: QImage _iconMixedMask, _iconFrom, _iconTo, _iconMixed; float64 _outerValue = 0.; - Animation _outerAnimation; + Ui::Animations::Simple _outerAnimation; }; @@ -186,12 +186,11 @@ void Panel::Button::setProgress(float64 progress) { void Panel::Button::paintEvent(QPaintEvent *e) { Painter p(this); - auto ms = crl::now(); auto bgPosition = myrtlpoint(_stFrom->button.rippleAreaPosition); auto paintFrom = (_progress == 0.) || !_stTo; auto paintTo = !paintFrom && (_progress == 1.); - auto outerValue = _outerAnimation.current(ms, _outerValue); + auto outerValue = _outerAnimation.value(_outerValue); if (outerValue > 0.) { auto outerRadius = paintFrom ? _stFrom->outerRadius : paintTo ? _stTo->outerRadius : (_stFrom->outerRadius * (1. - _progress) + _stTo->outerRadius * _progress); auto outerPixels = outerValue * outerRadius; @@ -228,7 +227,7 @@ void Panel::Button::paintEvent(QPaintEvent *e) { } else { rippleColorInterpolated = anim::color(_stFrom->button.ripple.color, _stTo->button.ripple.color, _progress); } - paintRipple(p, _stFrom->button.rippleAreaPosition.x(), _stFrom->button.rippleAreaPosition.y(), ms, rippleColorOverride); + paintRipple(p, _stFrom->button.rippleAreaPosition.x(), _stFrom->button.rippleAreaPosition.y(), rippleColorOverride); auto positionFrom = iconPosition(_stFrom); if (paintFrom) { @@ -681,7 +680,7 @@ void Panel::updateHangupGeometry() { auto bothWidth = singleWidth + st::callControlsSkip + st::callCancel.button.width; auto rightFrom = (width() - bothWidth) / 2; auto rightTo = (width() - singleWidth) / 2; - auto hangupProgress = _hangupShownProgress.current(_hangupShown ? 1. : 0.); + auto hangupProgress = _hangupShownProgress.value(_hangupShown ? 1. : 0.); auto hangupRight = anim::interpolate(rightFrom, rightTo, hangupProgress); auto controlsTop = _contentTop + st::callControlsTop; _answerHangupRedial->moveToRight(hangupRight, controlsTop); @@ -695,7 +694,7 @@ void Panel::updateStatusGeometry() { void Panel::paintEvent(QPaintEvent *e) { Painter p(this); if (!_animationCache.isNull()) { - auto opacity = _opacityAnimation.current(crl::now(), _call ? 1. : 0.); + auto opacity = _opacityAnimation.value(_call ? 1. : 0.); if (!_opacityAnimation.animating()) { finishAnimating(); if (!_call || isHidden()) return; diff --git a/Telegram/SourceFiles/calls/calls_panel.h b/Telegram/SourceFiles/calls/calls_panel.h index 2d1d979b6..c7ba8feee 100644 --- a/Telegram/SourceFiles/calls/calls_panel.h +++ b/Telegram/SourceFiles/calls/calls_panel.h @@ -11,6 +11,7 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL #include "base/timer.h" #include "calls/calls_call.h" #include "ui/widgets/tooltip.h" +#include "ui/effects/animations.h" #include "ui/rp_widget.h" namespace Ui { @@ -126,7 +127,7 @@ private: object_ptr> _decline; object_ptr> _cancel; bool _hangupShown = false; - Animation _hangupShownProgress; + Ui::Animations::Simple _hangupShownProgress; object_ptr _mute; object_ptr _name; object_ptr _status; @@ -142,7 +143,7 @@ private: PhotoId _userPhotoId = 0; bool _userPhotoFull = false; - Animation _opacityAnimation; + Ui::Animations::Simple _opacityAnimation; QPixmap _animationCache; QPixmap _bottomCache; QPixmap _cache; diff --git a/Telegram/SourceFiles/chat_helpers/bot_keyboard.cpp b/Telegram/SourceFiles/chat_helpers/bot_keyboard.cpp index 79280a855..7011ac901 100644 --- a/Telegram/SourceFiles/chat_helpers/bot_keyboard.cpp +++ b/Telegram/SourceFiles/chat_helpers/bot_keyboard.cpp @@ -110,7 +110,7 @@ void BotKeyboard::paintEvent(QPaintEvent *e) { if (_impl) { int x = rtl() ? st::botKbScroll.width : _st->margin; p.translate(x, st::botKbScroll.deltat); - _impl->paint(p, width(), clip.translated(-x, -st::botKbScroll.deltat), crl::now()); + _impl->paint(p, width(), clip.translated(-x, -st::botKbScroll.deltat)); } } diff --git a/Telegram/SourceFiles/chat_helpers/emoji_list_widget.cpp b/Telegram/SourceFiles/chat_helpers/emoji_list_widget.cpp index 9fd745de4..8db6c83fb 100644 --- a/Telegram/SourceFiles/chat_helpers/emoji_list_widget.cpp +++ b/Telegram/SourceFiles/chat_helpers/emoji_list_widget.cpp @@ -7,6 +7,7 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL */ #include "chat_helpers/emoji_list_widget.h" +#include "ui/effects/animations.h" #include "ui/widgets/buttons.h" #include "ui/widgets/shadow.h" #include "ui/emoji_config.h" @@ -62,7 +63,7 @@ private: bool _hiding = false; QPixmap _cache; - Animation _a_opacity; + Ui::Animations::Simple _a_opacity; rpl::event_stream _chosen; rpl::event_stream<> _hidden; @@ -186,7 +187,7 @@ void EmojiColorPicker::updateSize() { void EmojiColorPicker::paintEvent(QPaintEvent *e) { Painter p(this); - auto opacity = _a_opacity.current(crl::now(), _hiding ? 0. : 1.); + auto opacity = _a_opacity.value(_hiding ? 0. : 1.); if (opacity < 1.) { if (opacity > 0.) { p.setOpacity(opacity); @@ -272,7 +273,7 @@ void EmojiColorPicker::animationCallback() { void EmojiColorPicker::hideFast() { clearSelection(); - _a_opacity.finish(); + _a_opacity.stop(); _cache = QPixmap(); hide(); _hidden.fire({}); diff --git a/Telegram/SourceFiles/chat_helpers/emoji_sets_manager.cpp b/Telegram/SourceFiles/chat_helpers/emoji_sets_manager.cpp index 0aaf22ee7..181c84c10 100644 --- a/Telegram/SourceFiles/chat_helpers/emoji_sets_manager.cpp +++ b/Telegram/SourceFiles/chat_helpers/emoji_sets_manager.cpp @@ -12,6 +12,7 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL #include "ui/wrap/fade_wrap.h" #include "ui/widgets/buttons.h" #include "ui/widgets/labels.h" +#include "ui/effects/animations.h" #include "ui/effects/radial_animation.h" #include "ui/emoji_config.h" #include "lang/lang_keys.h" @@ -119,8 +120,8 @@ private: void setupPreview(const Set &set); void setupAnimation(); void paintPreview(Painter &p) const; - void paintRadio(Painter &p, crl::time ms); - void updateAnimation(crl::time ms); + void paintRadio(Painter &p, crl::time now); + void updateAnimation(crl::time now); void setupHandler(); void load(); @@ -131,8 +132,8 @@ private: rpl::variable _state; Ui::FlatLabel *_status = nullptr; std::array _preview; - Animation _toggled; - Animation _active; + Ui::Animations::Simple _toggled; + Ui::Animations::Simple _active; std::unique_ptr _loading; }; @@ -355,11 +356,9 @@ void Row::paintEvent(QPaintEvent *e) { const auto bg = over ? st::windowBgOver : st::windowBg; p.fillRect(rect(), bg); - const auto ms = crl::now(); - paintRipple(p, 0, 0, ms); - + paintRipple(p, 0, 0); paintPreview(p); - paintRadio(p, ms); + paintRadio(p, crl::now()); } void Row::paintPreview(Painter &p) const { @@ -377,16 +376,16 @@ void Row::paintPreview(Painter &p) const { } } -void Row::paintRadio(Painter &p, crl::time ms) { - updateAnimation(ms); +void Row::paintRadio(Painter &p, crl::time now) { + updateAnimation(now); const auto loading = _loading ? _loading->computeState() : Ui::RadialState{ 0., 0, FullArcLength }; const auto isToggledSet = _state.current().is(); const auto isActiveSet = isToggledSet || _state.current().is(); - const auto toggled = _toggled.current(ms, isToggledSet ? 1. : 0.); - const auto active = _active.current(ms, isActiveSet ? 1. : 0.); + const auto toggled = _toggled.value(isToggledSet ? 1. : 0.); + const auto active = _active.value(isActiveSet ? 1. : 0.); const auto _st = &st::defaultRadio; PainterHighQualityEnabler hq(p); @@ -466,7 +465,7 @@ void Row::onStateChanged(State was, StateChangeSource source) { void Row::updateStatusColorOverride() { const auto isToggledSet = _state.current().is(); - const auto toggled = _toggled.current(isToggledSet ? 1. : 0.); + const auto toggled = _toggled.value(isToggledSet ? 1. : 0.); const auto over = showOver(); if (toggled == 0. && !over) { _status->setTextColorOverride(std::nullopt); @@ -620,12 +619,12 @@ void Row::setupAnimation() { st::defaultRadio.duration); }, lifetime()); - _toggled.finish(); - _active.finish(); + _toggled.stop(); + _active.stop(); updateStatusColorOverride(); } -void Row::updateAnimation(crl::time ms) { +void Row::updateAnimation(crl::time now) { const auto state = _state.current(); if (const auto loading = base::get_if(&state)) { const auto progress = (loading->size > 0) @@ -636,10 +635,10 @@ void Row::updateAnimation(crl::time ms) { [=] { radialAnimationCallback(); }); _loading->start(progress); } else { - _loading->update(progress, false, crl::now()); + _loading->update(progress, false, now); } } else if (_loading) { - _loading->update(state.is() ? 0. : 1., true, crl::now()); + _loading->update(state.is() ? 0. : 1., true, now); } else { _loading = nullptr; } diff --git a/Telegram/SourceFiles/chat_helpers/field_autocomplete.cpp b/Telegram/SourceFiles/chat_helpers/field_autocomplete.cpp index 4f44b1919..4187513fe 100644 --- a/Telegram/SourceFiles/chat_helpers/field_autocomplete.cpp +++ b/Telegram/SourceFiles/chat_helpers/field_autocomplete.cpp @@ -47,7 +47,7 @@ FieldAutocomplete::FieldAutocomplete(QWidget *parent) : TWidget(parent) void FieldAutocomplete::paintEvent(QPaintEvent *e) { Painter p(this); - auto opacity = _a_opacity.current(crl::now(), _hiding ? 0. : 1.); + auto opacity = _a_opacity.value(_hiding ? 0. : 1.); if (opacity < 1.) { if (opacity > 0.) { p.setOpacity(opacity); @@ -234,15 +234,15 @@ void FieldAutocomplete::updateFiltered(bool resetScroll) { bool listAllSuggestions = _filter.isEmpty(); auto &recent(cRecentWriteHashtags()); hrows.reserve(recent.size()); - for (auto i = recent.cbegin(), e = recent.cend(); i != e; ++i) { + for (const auto &[tag, ratio] : recent) { if (!listAllSuggestions - && (i->first.size() == _filter.size() - || !TextUtilities::RemoveAccents(i->first).startsWith( + && (tag.size() == _filter.size() + || !TextUtilities::RemoveAccents(tag).startsWith( _filter, Qt::CaseInsensitive))) { continue; } - hrows.push_back(i->first); + hrows.push_back(tag); } } else if (_type == Type::BotCommands) { bool listAllSuggestions = _filter.isEmpty(); @@ -290,8 +290,7 @@ void FieldAutocomplete::updateFiltered(bool resetScroll) { brows.reserve(cnt); int32 botStatus = _chat ? _chat->botStatus : ((_channel && _channel->isMegagroup()) ? _channel->mgInfo->botStatus : -1); if (_chat) { - for (auto i = _chat->lastAuthors.cbegin(), e = _chat->lastAuthors.cend(); i != e; ++i) { - auto user = *i; + for (const auto &user : _chat->lastAuthors) { if (!user->botInfo) continue; if (!bots.contains(user)) continue; if (!user->botInfo->inited) { @@ -396,7 +395,7 @@ void FieldAutocomplete::recount(bool resetScroll) { } void FieldAutocomplete::hideFast() { - _a_opacity.finish(); + _a_opacity.stop(); hideFinish(); } diff --git a/Telegram/SourceFiles/chat_helpers/field_autocomplete.h b/Telegram/SourceFiles/chat_helpers/field_autocomplete.h index a993ef213..36af635cb 100644 --- a/Telegram/SourceFiles/chat_helpers/field_autocomplete.h +++ b/Telegram/SourceFiles/chat_helpers/field_autocomplete.h @@ -7,6 +7,7 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL */ #pragma once +#include "ui/effects/animations.h" #include "ui/twidget.h" #include "base/timer.h" #include "chat_helpers/stickers.h" @@ -123,7 +124,7 @@ private: int32 _width, _height; bool _hiding = false; - Animation _a_opacity; + Ui::Animations::Simple _a_opacity; friend class internal::FieldAutocompleteInner; diff --git a/Telegram/SourceFiles/chat_helpers/stickers_list_widget.cpp b/Telegram/SourceFiles/chat_helpers/stickers_list_widget.cpp index ef7a08d85..51f6de13a 100644 --- a/Telegram/SourceFiles/chat_helpers/stickers_list_widget.cpp +++ b/Telegram/SourceFiles/chat_helpers/stickers_list_widget.cpp @@ -1170,7 +1170,6 @@ void StickersListWidget::paintStickers(Painter &p, QRect clip) { toColumn = _columnCount - toColumn; } - auto ms = crl::now(); auto &sets = shownSets(); auto selectedSticker = base::get_if(&_selected); auto selectedButton = base::get_if(_pressed ? &_pressed : &_selected); @@ -1199,7 +1198,7 @@ void StickersListWidget::paintStickers(Painter &p, QRect clip) { App::roundRect(p, myrtlrect(add), textBg, ImageRoundRadius::Small); if (set.ripple) { - set.ripple->paint(p, add.x(), add.y(), width(), ms); + set.ripple->paint(p, add.x(), add.y(), width()); if (set.ripple->empty()) { set.ripple.reset(); } @@ -1266,7 +1265,7 @@ void StickersListWidget::paintStickers(Painter &p, QRect clip) { auto remove = removeButtonRect(info.section); auto selected = selectedButton ? (selectedButton->section == info.section) : false; if (set.ripple) { - set.ripple->paint(p, remove.x() + st::stickerPanRemoveSet.rippleAreaPosition.x(), remove.y() + st::stickerPanRemoveSet.rippleAreaPosition.y(), width(), ms); + set.ripple->paint(p, remove.x() + st::stickerPanRemoveSet.rippleAreaPosition.x(), remove.y() + st::stickerPanRemoveSet.rippleAreaPosition.y(), width()); if (set.ripple->empty()) { set.ripple.reset(); } @@ -1286,7 +1285,7 @@ void StickersListWidget::paintStickers(Painter &p, QRect clip) { if (clip.top() + clip.height() > info.rowsTop) { if (set.id == Stickers::MegagroupSetId && set.pack.empty()) { auto buttonSelected = (base::get_if(&_selected) != nullptr); - paintMegagroupEmptySet(p, info.rowsTop, buttonSelected, ms); + paintMegagroupEmptySet(p, info.rowsTop, buttonSelected); } else { auto special = (set.flags & MTPDstickerSet::Flag::f_official) != 0; auto fromRow = floorclamp(clip.y() - info.rowsTop, _singleSize.height(), 0, info.rowsCount); @@ -1328,7 +1327,7 @@ int StickersListWidget::megagroupSetInfoLeft() const { return st::emojiPanHeaderLeft - st::buttonRadius; } -void StickersListWidget::paintMegagroupEmptySet(Painter &p, int y, bool buttonSelected, crl::time ms) { +void StickersListWidget::paintMegagroupEmptySet(Painter &p, int y, bool buttonSelected) { auto infoLeft = megagroupSetInfoLeft(); _megagroupSetAbout.drawLeft(p, infoLeft, y, width() - infoLeft, width()); @@ -1339,7 +1338,7 @@ void StickersListWidget::paintMegagroupEmptySet(Painter &p, int y, bool buttonSe auto button = _megagroupSetButtonRect.translated(0, y); App::roundRect(p, myrtlrect(button), textBg, ImageRoundRadius::Small); if (_megagroupSetButtonRipple) { - _megagroupSetButtonRipple->paint(p, button.x(), button.y(), width(), ms); + _megagroupSetButtonRipple->paint(p, button.x(), button.y(), width()); if (_megagroupSetButtonRipple->empty()) { _megagroupSetButtonRipple.reset(); } diff --git a/Telegram/SourceFiles/chat_helpers/stickers_list_widget.h b/Telegram/SourceFiles/chat_helpers/stickers_list_widget.h index 3251cf80c..43665092e 100644 --- a/Telegram/SourceFiles/chat_helpers/stickers_list_widget.h +++ b/Telegram/SourceFiles/chat_helpers/stickers_list_widget.h @@ -201,7 +201,7 @@ private: void paintFeaturedStickers(Painter &p, QRect clip); void paintStickers(Painter &p, QRect clip); - void paintMegagroupEmptySet(Painter &p, int y, bool buttonSelected, crl::time ms); + void paintMegagroupEmptySet(Painter &p, int y, bool buttonSelected); void paintSticker(Painter &p, Set &set, int y, int index, bool selected, bool deleteSelected); void paintEmptySearchResults(Painter &p); diff --git a/Telegram/SourceFiles/chat_helpers/tabbed_panel.cpp b/Telegram/SourceFiles/chat_helpers/tabbed_panel.cpp index d1856829a..ac3ff8b2a 100644 --- a/Telegram/SourceFiles/chat_helpers/tabbed_panel.cpp +++ b/Telegram/SourceFiles/chat_helpers/tabbed_panel.cpp @@ -155,12 +155,10 @@ void TabbedPanel::windowActiveChanged() { void TabbedPanel::paintEvent(QPaintEvent *e) { Painter p(this); - auto ms = crl::now(); - // This call can finish _a_show animation and destroy _showAnimation. - auto opacityAnimating = _a_opacity.animating(ms); + auto opacityAnimating = _a_opacity.animating(); - auto showAnimating = _a_show.animating(ms); + auto showAnimating = _a_show.animating(); if (_showAnimation && !showAnimating) { _showAnimation.reset(); if (!opacityAnimating && !isDestroying()) { @@ -171,11 +169,11 @@ void TabbedPanel::paintEvent(QPaintEvent *e) { if (showAnimating) { Assert(_showAnimation != nullptr); - if (auto opacity = _a_opacity.current(_hiding ? 0. : 1.)) { - _showAnimation->paintFrame(p, 0, 0, width(), _a_show.current(1.), opacity); + if (auto opacity = _a_opacity.value(_hiding ? 0. : 1.)) { + _showAnimation->paintFrame(p, 0, 0, width(), _a_show.value(1.), opacity); } } else if (opacityAnimating) { - p.setOpacity(_a_opacity.current(_hiding ? 0. : 1.)); + p.setOpacity(_a_opacity.value(_hiding ? 0. : 1.)); p.drawPixmap(0, 0, _cache); } else if (_hiding || isHidden()) { hideFinished(); @@ -208,8 +206,7 @@ void TabbedPanel::leaveEventHook(QEvent *e) { if (preventAutoHide()) { return; } - auto ms = crl::now(); - if (_a_show.animating(ms) || _a_opacity.animating(ms)) { + if (_a_show.animating() || _a_opacity.animating()) { hideAnimated(); } else { _hideTimer.callOnce(kHideTimeoutMs); @@ -226,8 +223,7 @@ void TabbedPanel::otherLeave() { return; } - auto ms = crl::now(); - if (_a_opacity.animating(ms)) { + if (_a_opacity.animating()) { hideByTimerOrLeave(); } else { _hideTimer.callOnce(0); @@ -239,7 +235,7 @@ void TabbedPanel::hideFast() { _hideTimer.cancel(); _hiding = false; - _a_opacity.finish(); + _a_opacity.stop(); hideFinished(); } @@ -363,7 +359,7 @@ QPointer TabbedPanel::getSelector() const { void TabbedPanel::hideFinished() { hide(); - _a_show.finish(); + _a_show.stop(); _showAnimation.reset(); _cache = QPixmap(); _hiding = false; diff --git a/Telegram/SourceFiles/chat_helpers/tabbed_panel.h b/Telegram/SourceFiles/chat_helpers/tabbed_panel.h index b398c8229..e63d94564 100644 --- a/Telegram/SourceFiles/chat_helpers/tabbed_panel.h +++ b/Telegram/SourceFiles/chat_helpers/tabbed_panel.h @@ -7,6 +7,7 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL */ #pragma once +#include "ui/effects/animations.h" #include "ui/rp_widget.h" #include "base/timer.h" @@ -99,12 +100,12 @@ private: int _maxContentHeight = 0; std::unique_ptr _showAnimation; - Animation _a_show; + Ui::Animations::Simple _a_show; bool _hiding = false; bool _hideAfterSlide = false; QPixmap _cache; - Animation _a_opacity; + Ui::Animations::Simple _a_opacity; base::Timer _hideTimer; }; diff --git a/Telegram/SourceFiles/chat_helpers/tabbed_selector.cpp b/Telegram/SourceFiles/chat_helpers/tabbed_selector.cpp index 843c6feba..f4e0f362c 100644 --- a/Telegram/SourceFiles/chat_helpers/tabbed_selector.cpp +++ b/Telegram/SourceFiles/chat_helpers/tabbed_selector.cpp @@ -494,11 +494,9 @@ void TabbedSelector::updateRestrictedLabelGeometry() { void TabbedSelector::paintEvent(QPaintEvent *e) { Painter p(this); - auto ms = crl::now(); - auto switching = (_slideAnimation != nullptr); if (switching) { - paintSlideFrame(p, ms); + paintSlideFrame(p); if (!_a_slide.animating()) { _slideAnimation.reset(); afterShown(); @@ -509,7 +507,7 @@ void TabbedSelector::paintEvent(QPaintEvent *e) { } } -void TabbedSelector::paintSlideFrame(Painter &p, crl::time ms) { +void TabbedSelector::paintSlideFrame(Painter &p) { if (_roundRadius > 0) { if (full()) { auto topPart = QRect(0, 0, width(), _tabsSlider->height() + _roundRadius); @@ -521,7 +519,7 @@ void TabbedSelector::paintSlideFrame(Painter &p, crl::time ms) { } else if (full()) { p.fillRect(0, 0, width(), _tabsSlider->height(), st::emojiPanBg); } - auto slideDt = _a_slide.current(ms, 1.); + auto slideDt = _a_slide.value(1.); _slideAnimation->paintFrame(p, slideDt, 1.); } @@ -621,7 +619,7 @@ void TabbedSelector::hideFinished() { } tab.widget()->panelHideFinished(); } - _a_slide.finish(); + _a_slide.stop(); _slideAnimation.reset(); } @@ -631,7 +629,7 @@ void TabbedSelector::showStarted() { } currentTab()->widget()->refreshRecent(); currentTab()->widget()->preloadImages(); - _a_slide.finish(); + _a_slide.stop(); _slideAnimation.reset(); showAll(); } diff --git a/Telegram/SourceFiles/chat_helpers/tabbed_selector.h b/Telegram/SourceFiles/chat_helpers/tabbed_selector.h index 0cd5073a4..0d8aa3541 100644 --- a/Telegram/SourceFiles/chat_helpers/tabbed_selector.h +++ b/Telegram/SourceFiles/chat_helpers/tabbed_selector.h @@ -8,6 +8,7 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL #pragma once #include "ui/rp_widget.h" +#include "ui/effects/animations.h" #include "ui/effects/panel_animation.h" #include "mtproto/sender.h" #include "auth_session.h" @@ -149,7 +150,7 @@ private: SelectorTab type, not_null controller); - void paintSlideFrame(Painter &p, crl::time ms); + void paintSlideFrame(Painter &p); void paintContent(Painter &p); void checkRestrictedPeer(); @@ -191,7 +192,7 @@ private: class SlideAnimation; std::unique_ptr _slideAnimation; - Animation _a_slide; + Ui::Animations::Simple _a_slide; object_ptr _tabsSlider = { nullptr }; object_ptr _topShadow; diff --git a/Telegram/SourceFiles/dialogs/dialogs_inner_widget.cpp b/Telegram/SourceFiles/dialogs/dialogs_inner_widget.cpp index 490bd1746..9a92cd5d5 100644 --- a/Telegram/SourceFiles/dialogs/dialogs_inner_widget.cpp +++ b/Telegram/SourceFiles/dialogs/dialogs_inner_widget.cpp @@ -368,7 +368,7 @@ void DialogsInner::paintRegion(Painter &p, const QRegion ®ion, bool paintingO auto &result = _hashtagResults[from]; bool selected = (from == (isPressed() ? _hashtagPressed : _hashtagSelected)); p.fillRect(0, 0, fullWidth, st::mentionHeight, selected ? st::mentionBgOver : st::dialogsBg); - result->row.paintRipple(p, 0, 0, fullWidth, ms); + result->row.paintRipple(p, 0, 0, fullWidth); if (!paintingOther) { auto &tag = result->tag; if (selected) { @@ -456,14 +456,14 @@ void DialogsInner::paintRegion(Painter &p, const QRegion ®ion, bool paintingO const auto selected = (from == (isPressed() ? _peerSearchPressed : _peerSearchSelected)); - paintPeerSearchResult(p, result.get(), fullWidth, active, selected, paintingOther, ms); + paintPeerSearchResult(p, result.get(), fullWidth, active, selected, paintingOther); p.translate(0, st::dialogsRowHeight); } } } if (_searchInChat) { - paintSearchInChat(p, fullWidth, paintingOther, ms); + paintSearchInChat(p, fullWidth, paintingOther); p.translate(0, searchInChatSkip()); if (_waitingForSearch && _searchResults.empty()) { p.fillRect( @@ -549,12 +549,11 @@ void DialogsInner::paintPeerSearchResult( int fullWidth, bool active, bool selected, - bool onlyBackground, - crl::time ms) const { + bool onlyBackground) const { QRect fullRect(0, 0, fullWidth, st::dialogsRowHeight); p.fillRect(fullRect, active ? st::dialogsBgActive : (selected ? st::dialogsBgOver : st::dialogsBg)); if (!active) { - result->row.paintRipple(p, 0, 0, fullWidth, ms); + result->row.paintRipple(p, 0, 0, fullWidth); } if (onlyBackground) return; @@ -605,8 +604,7 @@ void DialogsInner::paintPeerSearchResult( void DialogsInner::paintSearchInChat( Painter &p, int fullWidth, - bool onlyBackground, - crl::time ms) const { + bool onlyBackground) const { auto height = searchInChatSkip(); auto top = st::searchedBarHeight; diff --git a/Telegram/SourceFiles/dialogs/dialogs_inner_widget.h b/Telegram/SourceFiles/dialogs/dialogs_inner_widget.h index 2c6371844..c2998853a 100644 --- a/Telegram/SourceFiles/dialogs/dialogs_inner_widget.h +++ b/Telegram/SourceFiles/dialogs/dialogs_inner_widget.h @@ -236,13 +236,11 @@ private: int fullWidth, bool active, bool selected, - bool onlyBackground, - crl::time ms) const; + bool onlyBackground) const; void paintSearchInChat( Painter &p, int fullWidth, - bool onlyBackground, - crl::time ms) const; + bool onlyBackground) const; void paintSearchInPeer( Painter &p, not_null peer, diff --git a/Telegram/SourceFiles/dialogs/dialogs_layout.cpp b/Telegram/SourceFiles/dialogs/dialogs_layout.cpp index 875268046..a2483688e 100644 --- a/Telegram/SourceFiles/dialogs/dialogs_layout.cpp +++ b/Telegram/SourceFiles/dialogs/dialogs_layout.cpp @@ -202,7 +202,7 @@ void paintRow( ? st::dialogsRippleBgActive : st::dialogsRippleBg; p.fillRect(fullRect, bg); - row->paintRipple(p, 0, 0, fullWidth, ms, &ripple->c); + row->paintRipple(p, 0, 0, fullWidth, &ripple->c); if (flags & Flag::OnlyBackground) { return; diff --git a/Telegram/SourceFiles/dialogs/dialogs_row.cpp b/Telegram/SourceFiles/dialogs/dialogs_row.cpp index 1edc781b6..02b166628 100644 --- a/Telegram/SourceFiles/dialogs/dialogs_row.cpp +++ b/Telegram/SourceFiles/dialogs/dialogs_row.cpp @@ -31,9 +31,9 @@ void RippleRow::stopLastRipple() { } } -void RippleRow::paintRipple(Painter &p, int x, int y, int outerWidth, crl::time ms, const QColor *colorOverride) const { +void RippleRow::paintRipple(Painter &p, int x, int y, int outerWidth, const QColor *colorOverride) const { if (_ripple) { - _ripple->paint(p, x, y, outerWidth, ms, colorOverride); + _ripple->paint(p, x, y, outerWidth, colorOverride); if (_ripple->empty()) { _ripple.reset(); } diff --git a/Telegram/SourceFiles/dialogs/dialogs_row.h b/Telegram/SourceFiles/dialogs/dialogs_row.h index 0e7ae08e8..9876e7cde 100644 --- a/Telegram/SourceFiles/dialogs/dialogs_row.h +++ b/Telegram/SourceFiles/dialogs/dialogs_row.h @@ -30,7 +30,7 @@ public: void addRipple(QPoint origin, QSize size, Fn updateCallback); void stopLastRipple(); - void paintRipple(Painter &p, int x, int y, int outerWidth, crl::time ms, const QColor *colorOverride = nullptr) const; + void paintRipple(Painter &p, int x, int y, int outerWidth, const QColor *colorOverride = nullptr) const; private: mutable std::unique_ptr _ripple; diff --git a/Telegram/SourceFiles/dialogs/dialogs_widget.cpp b/Telegram/SourceFiles/dialogs/dialogs_widget.cpp index e12b0426b..a545eb648 100644 --- a/Telegram/SourceFiles/dialogs/dialogs_widget.cpp +++ b/Telegram/SourceFiles/dialogs/dialogs_widget.cpp @@ -125,7 +125,7 @@ void DialogsWidget::BottomButton::paintEvent(QPaintEvent *e) { p.fillRect(r, over ? _st.overBgColor : _st.bgColor); if (!isDisabled()) { - paintRipple(p, 0, 0, crl::now()); + paintRipple(p, 0, 0); } p.setFont(over ? _st.overFont : _st.font); @@ -333,7 +333,7 @@ void DialogsWidget::dialogsToUp() { return; } if (_filter->getLastText().trimmed().isEmpty() && !_searchInChat) { - _scrollToAnimation.finish(); + _scrollToAnimation.stop(); auto scrollTop = _scroll->scrollTop(); const auto scrollTo = 0; const auto maxAnimatedDelta = _scroll->height(); @@ -342,8 +342,8 @@ void DialogsWidget::dialogsToUp() { _scroll->scrollToY(scrollTop); } - const auto scroll = [&] { - _scroll->scrollToY(qRound(_scrollToAnimation.current())); + const auto scroll = [=] { + _scroll->scrollToY(qRound(_scrollToAnimation.value(scrollTo))); }; _scrollToAnimation.start( @@ -394,7 +394,7 @@ void DialogsWidget::showFast() { void DialogsWidget::showAnimated(Window::SlideDirection direction, const Window::SectionSlideParams ¶ms) { _showDirection = direction; - _a_show.finish(); + _a_show.stop(); _cacheUnder = params.oldContentCache; show(); @@ -1448,7 +1448,7 @@ void DialogsWidget::paintEvent(QPaintEvent *e) { if (r != rect()) { p.setClipRect(r); } - auto progress = _a_show.current(crl::now(), 1.); + auto progress = _a_show.value(1.); if (_a_show.animating()) { auto retina = cIntRetinaFactor(); auto fromLeft = (_showDirection == Window::SlideDirection::FromLeft); diff --git a/Telegram/SourceFiles/dialogs/dialogs_widget.h b/Telegram/SourceFiles/dialogs/dialogs_widget.h index faad0637c..71a6607cb 100644 --- a/Telegram/SourceFiles/dialogs/dialogs_widget.h +++ b/Telegram/SourceFiles/dialogs/dialogs_widget.h @@ -8,6 +8,7 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL #pragma once #include "window/section_widget.h" +#include "ui/effects/animations.h" #include "ui/widgets/scroll_area.h" #include "dialogs/dialogs_key.h" @@ -199,8 +200,8 @@ private: object_ptr _loadMoreChats = { nullptr }; std::unique_ptr _connecting; - Animation _scrollToAnimation; - Animation _a_show; + Ui::Animations::Simple _scrollToAnimation; + Ui::Animations::Simple _a_show; Window::SlideDirection _showDirection; QPixmap _cacheUnder, _cacheOver; diff --git a/Telegram/SourceFiles/export/view/export_view_progress.cpp b/Telegram/SourceFiles/export/view/export_view_progress.cpp index 45dad9330..517bed064 100644 --- a/Telegram/SourceFiles/export/view/export_view_progress.cpp +++ b/Telegram/SourceFiles/export/view/export_view_progress.cpp @@ -7,6 +7,7 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL */ #include "export/view/export_view_progress.h" +#include "ui/effects/animations.h" #include "ui/widgets/labels.h" #include "ui/widgets/buttons.h" #include "ui/wrap/fade_wrap.h" @@ -35,10 +36,10 @@ private: base::unique_qptr> info; float64 value = 0.; - Animation progress; + Ui::Animations::Simple progress; bool hiding = true; - Animation opacity; + Ui::Animations::Simple opacity; }; void fillCurrentInstance(); @@ -77,7 +78,7 @@ void ProgressWidget::Row::updateData(Content::Row &&data) { _current.info->entity()->setText(_data.info); setInstanceProgress(_current, _data.progress); if (nowId != wasId) { - _current.progress.finish(); + _current.progress.stop(); } } updateControlsGeometry(width()); @@ -105,7 +106,7 @@ void ProgressWidget::Row::fillCurrentInstance() { setInstanceProgress(_current, _data.progress); toggleInstance(_current, true); if (_data.id == "main") { - _current.opacity.finish(); + _current.opacity.stop(); _current.label->finishAnimating(); _current.info->finishAnimating(); } @@ -131,7 +132,7 @@ void ProgressWidget::Row::setInstanceProgress( st::exportProgressDuration, anim::sineInOut); } else if (_current.value > progress) { - _current.progress.finish(); + _current.progress.stop(); } _current.value = progress; } @@ -194,7 +195,7 @@ void ProgressWidget::Row::paintEvent(QPaintEvent *e) { } void ProgressWidget::Row::paintInstance(Painter &p, const Instance &data) { - const auto opacity = data.opacity.current(data.hiding ? 0. : 1.); + const auto opacity = data.opacity.value(data.hiding ? 0. : 1.); if (!opacity) { return; @@ -203,7 +204,7 @@ void ProgressWidget::Row::paintInstance(Painter &p, const Instance &data) { const auto thickness = st::exportProgressWidth; const auto top = height() - thickness; - const auto till = qRound(data.progress.current(data.value) * width()); + const auto till = qRound(data.progress.value(data.value) * width()); if (till > 0) { p.fillRect(0, top, till, thickness, st::exportProgressFg); } diff --git a/Telegram/SourceFiles/history/admin_log/history_admin_log_filter.cpp b/Telegram/SourceFiles/history/admin_log/history_admin_log_filter.cpp index e195f5db7..c1e6fc22b 100644 --- a/Telegram/SourceFiles/history/admin_log/history_admin_log_filter.cpp +++ b/Telegram/SourceFiles/history/admin_log/history_admin_log_filter.cpp @@ -99,10 +99,9 @@ void UserCheckbox::setChecked(bool checked, NotifyAboutChange notify) { void UserCheckbox::paintEvent(QPaintEvent *e) { Painter p(this); - auto ms = crl::now(); - auto active = _check->currentAnimationValue(ms); + auto active = _check->currentAnimationValue(); auto color = anim::color(_st.rippleBg, _st.rippleBgActive, active); - paintRipple(p, _st.rippleAreaPosition.x(), _st.rippleAreaPosition.y() + (_checkRect.y() - st::defaultBoxCheckbox.margin.top()), ms, &color); + paintRipple(p, _st.rippleAreaPosition.x(), _st.rippleAreaPosition.y() + (_checkRect.y() - st::defaultBoxCheckbox.margin.top()), &color); auto realCheckRect = myrtlrect(_checkRect); if (realCheckRect.intersects(e->rect())) { diff --git a/Telegram/SourceFiles/history/admin_log/history_admin_log_inner.cpp b/Telegram/SourceFiles/history/admin_log/history_admin_log_inner.cpp index 0cdc426b8..bf67d0b86 100644 --- a/Telegram/SourceFiles/history/admin_log/history_admin_log_inner.cpp +++ b/Telegram/SourceFiles/history/admin_log/history_admin_log_inner.cpp @@ -801,7 +801,7 @@ void InnerWidget::paintEvent(QPaintEvent *e) { }); auto dateHeight = st::msgServicePadding.bottom() + st::msgServiceFont->height + st::msgServicePadding.top(); - auto scrollDateOpacity = _scrollDateOpacity.current(ms, _scrollDateShown ? 1. : 0.); + auto scrollDateOpacity = _scrollDateOpacity.value(_scrollDateShown ? 1. : 0.); enumerateDates([&](not_null view, int itemtop, int dateTop) { // stop the enumeration if the date is above the painted rect if (dateTop + dateHeight <= clip.top()) { diff --git a/Telegram/SourceFiles/history/admin_log/history_admin_log_inner.h b/Telegram/SourceFiles/history/admin_log/history_admin_log_inner.h index 7532806c3..71df03e22 100644 --- a/Telegram/SourceFiles/history/admin_log/history_admin_log_inner.h +++ b/Telegram/SourceFiles/history/admin_log/history_admin_log_inner.h @@ -10,8 +10,9 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL #include "history/view/history_view_element.h" #include "history/admin_log/history_admin_log_item.h" #include "history/admin_log/history_admin_log_section.h" -#include "ui/widgets/tooltip.h" #include "ui/rp_widget.h" +#include "ui/effects/animations.h" +#include "ui/widgets/tooltip.h" #include "mtproto/sender.h" #include "base/timer.h" @@ -219,7 +220,7 @@ private: int _visibleTopFromItem = 0; bool _scrollDateShown = false; - Animation _scrollDateOpacity; + Ui::Animations::Simple _scrollDateOpacity; SingleQueuedInvokation _scrollDateCheck; base::Timer _scrollDateHideTimer; Element *_scrollDateLastItem = nullptr; diff --git a/Telegram/SourceFiles/history/admin_log/history_admin_log_section.cpp b/Telegram/SourceFiles/history/admin_log/history_admin_log_section.cpp index c7b5497a8..f6f1d1e1d 100644 --- a/Telegram/SourceFiles/history/admin_log/history_admin_log_section.cpp +++ b/Telegram/SourceFiles/history/admin_log/history_admin_log_section.cpp @@ -11,6 +11,7 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL #include "history/admin_log/history_admin_log_filter.h" #include "profile/profile_back_button.h" #include "core/shortcuts.h" +#include "ui/effects/animations.h" #include "ui/widgets/scroll_area.h" #include "ui/widgets/shadow.h" #include "ui/widgets/buttons.h" @@ -77,7 +78,7 @@ private: object_ptr _cancel; object_ptr _filter; - Animation _searchShownAnimation; + Ui::Animations::Simple _searchShownAnimation; bool _searchShown = false; bool _animatingMode = false; base::Timer _searchTimer; @@ -194,7 +195,7 @@ int FixedBar::resizeGetHeight(int newWidth) { auto searchShownLeft = st::topBarArrowPadding.left(); auto searchHiddenLeft = filterLeft - _search->width(); - auto searchShown = _searchShownAnimation.current(_searchShown ? 1. : 0.); + auto searchShown = _searchShownAnimation.value(_searchShown ? 1. : 0.); auto searchCurrentLeft = anim::interpolate(searchHiddenLeft, searchShownLeft, searchShown); _search->moveToLeft(searchCurrentLeft, 0); _backButton->resizeToWidth(searchCurrentLeft); diff --git a/Telegram/SourceFiles/history/feed/history_feed_section.cpp b/Telegram/SourceFiles/history/feed/history_feed_section.cpp index 6f158c9a4..76ec2c0ba 100644 --- a/Telegram/SourceFiles/history/feed/history_feed_section.cpp +++ b/Telegram/SourceFiles/history/feed/history_feed_section.cpp @@ -230,7 +230,7 @@ void Widget::updateScrollDownPosition() { auto top = anim::interpolate( 0, _scrollDown->height() + st::historyToDownPosition.y(), - _scrollDownShown.current(_scrollDownIsShown ? 1. : 0.)); + _scrollDownShown.value(_scrollDownIsShown ? 1. : 0.)); _scrollDown->moveToRight( st::historyToDownPosition.x(), _scroll->height() - top); @@ -241,7 +241,7 @@ void Widget::updateScrollDownPosition() { } void Widget::scrollDownAnimationFinish() { - _scrollDownShown.finish(); + _scrollDownShown.stop(); updateScrollDownPosition(); } @@ -536,9 +536,6 @@ void Widget::paintEvent(QPaintEvent *e) { // updateListSize(); //} - const auto ms = crl::now(); - _scrollDownShown.step(ms); - SectionWidget::PaintBackground(this, e->rect()); if (_emptyTextView) { diff --git a/Telegram/SourceFiles/history/feed/history_feed_section.h b/Telegram/SourceFiles/history/feed/history_feed_section.h index cb0be4845..9a0de09d2 100644 --- a/Telegram/SourceFiles/history/feed/history_feed_section.h +++ b/Telegram/SourceFiles/history/feed/history_feed_section.h @@ -7,6 +7,7 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL */ #pragma once +#include "ui/effects/animations.h" #include "history/view/history_view_list_widget.h" #include "window/section_widget.h" #include "window/section_memento.h" @@ -138,7 +139,7 @@ private: std::optional _nextAnimatedScrollPosition; int _nextAnimatedScrollDelta = 0; - Animation _scrollDownShown; + Ui::Animations::Simple _scrollDownShown; bool _scrollDownIsShown = false; object_ptr _scrollDown; std::shared_ptr _dateLink; diff --git a/Telegram/SourceFiles/history/history_drag_area.cpp b/Telegram/SourceFiles/history/history_drag_area.cpp index eae73270b..9235a485c 100644 --- a/Telegram/SourceFiles/history/history_drag_area.cpp +++ b/Telegram/SourceFiles/history/history_drag_area.cpp @@ -69,8 +69,7 @@ void DragArea::setText(const QString &text, const QString &subtext) { void DragArea::paintEvent(QPaintEvent *e) { Painter p(this); - auto ms = crl::now(); - auto opacity = _a_opacity.current(ms, _hiding ? 0. : 1.); + auto opacity = _a_opacity.value(_hiding ? 0. : 1.); if (!_a_opacity.animating() && _hiding) { return; } @@ -85,7 +84,7 @@ void DragArea::paintEvent(QPaintEvent *e) { Ui::Shadow::paint(p, inner, width(), st::boxRoundShadow); App::roundRect(p, inner, st::boxBg, BoxCorners); - p.setPen(anim::pen(st::dragColor, st::dragDropColor, _a_in.current(ms, _in ? 1. : 0.))); + p.setPen(anim::pen(st::dragColor, st::dragDropColor, _a_in.value(_in ? 1. : 0.))); p.setFont(st::dragFont); p.drawText(QRect(0, (height() - st::dragHeight) / 2, width(), st::dragFont->height), _text, QTextOption(style::al_top)); @@ -121,7 +120,7 @@ void DragArea::otherLeave() { } void DragArea::hideFast() { - _a_opacity.finish(); + _a_opacity.stop(); hide(); } @@ -142,7 +141,7 @@ void DragArea::hideStart() { void DragArea::hideFinish() { hide(); _in = false; - _a_in.finish(); + _a_in.stop(); } void DragArea::showStart() { diff --git a/Telegram/SourceFiles/history/history_drag_area.h b/Telegram/SourceFiles/history/history_drag_area.h index a17e3d4f4..b5c16ff29 100644 --- a/Telegram/SourceFiles/history/history_drag_area.h +++ b/Telegram/SourceFiles/history/history_drag_area.h @@ -8,6 +8,7 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL #pragma once #include "ui/twidget.h" +#include "ui/effects/animations.h" class DragArea : public TWidget { Q_OBJECT @@ -59,8 +60,8 @@ private: QPixmap _cache; Fn _droppedCallback; - Animation _a_opacity; - Animation _a_in; + Ui::Animations::Simple _a_opacity; + Ui::Animations::Simple _a_in; QString _text, _subtext; diff --git a/Telegram/SourceFiles/history/history_inner_widget.cpp b/Telegram/SourceFiles/history/history_inner_widget.cpp index d7498ab5e..46e99728a 100644 --- a/Telegram/SourceFiles/history/history_inner_widget.cpp +++ b/Telegram/SourceFiles/history/history_inner_widget.cpp @@ -718,7 +718,7 @@ void HistoryInner::paintEvent(QPaintEvent *e) { //int showFloatingBefore = height() - 2 * (_visibleAreaBottom - _visibleAreaTop) - dateHeight; - auto scrollDateOpacity = _scrollDateOpacity.current(ms, _scrollDateShown ? 1. : 0.); + auto scrollDateOpacity = _scrollDateOpacity.value(_scrollDateShown ? 1. : 0.); enumerateDates([&](not_null view, int itemtop, int dateTop) { // stop the enumeration if the date is above the painted rect if (dateTop + dateHeight <= clip.top()) { @@ -2471,7 +2471,7 @@ void HistoryInner::mouseActionUpdate() { } auto dateHeight = st::msgServicePadding.bottom() + st::msgServiceFont->height + st::msgServicePadding.top(); - auto scrollDateOpacity = _scrollDateOpacity.current(_scrollDateShown ? 1. : 0.); + auto scrollDateOpacity = _scrollDateOpacity.value(_scrollDateShown ? 1. : 0.); enumerateDates([&](not_null view, int itemtop, int dateTop) { // stop enumeration if the date is above our point if (dateTop + dateHeight <= point.y()) { diff --git a/Telegram/SourceFiles/history/history_inner_widget.h b/Telegram/SourceFiles/history/history_inner_widget.h index 869b3e601..acf29904a 100644 --- a/Telegram/SourceFiles/history/history_inner_widget.h +++ b/Telegram/SourceFiles/history/history_inner_widget.h @@ -9,6 +9,7 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL #include "base/timer.h" #include "ui/rp_widget.h" +#include "ui/effects/animations.h" #include "ui/widgets/tooltip.h" #include "ui/widgets/scroll_area.h" #include "history/view/history_view_top_bar_widget.h" @@ -362,7 +363,7 @@ private: int _visibleAreaBottom = 0; bool _scrollDateShown = false; - Animation _scrollDateOpacity; + Ui::Animations::Simple _scrollDateOpacity; SingleQueuedInvokation _scrollDateCheck; base::Timer _scrollDateHideTimer; Element *_scrollDateLastItem = nullptr; diff --git a/Telegram/SourceFiles/history/history_item_components.cpp b/Telegram/SourceFiles/history/history_item_components.cpp index d4eaa1a3d..748e5af9c 100644 --- a/Telegram/SourceFiles/history/history_item_components.cpp +++ b/Telegram/SourceFiles/history/history_item_components.cpp @@ -541,21 +541,21 @@ int ReplyKeyboard::naturalHeight() const { return (_rows.size() - 1) * _st->buttonSkip() + _rows.size() * _st->buttonHeight(); } -void ReplyKeyboard::paint(Painter &p, int outerWidth, const QRect &clip, crl::time ms) const { +void ReplyKeyboard::paint(Painter &p, int outerWidth, const QRect &clip) const { Assert(_st != nullptr); Assert(_width > 0); _st->startPaint(p); - for_const (auto &row, _rows) { - for_const (auto &button, row) { - QRect rect(button.rect); + for (const auto &row : _rows) { + for (const auto &button : row) { + const auto rect = button.rect; if (rect.y() >= clip.y() + clip.height()) return; if (rect.y() + rect.height() < clip.y()) continue; // just ignore the buttons that didn't layout well if (rect.x() + rect.width() > _width) break; - _st->paintButton(p, outerWidth, button, ms); + _st->paintButton(p, outerWidth, button); } } } @@ -694,12 +694,11 @@ int ReplyKeyboard::Style::buttonHeight() const { void ReplyKeyboard::Style::paintButton( Painter &p, int outerWidth, - const ReplyKeyboard::Button &button, - crl::time ms) const { + const ReplyKeyboard::Button &button) const { const QRect &rect = button.rect; paintButtonBg(p, rect, button.howMuchOver); if (button.ripple) { - button.ripple->paint(p, rect.x(), rect.y(), outerWidth, ms); + button.ripple->paint(p, rect.x(), rect.y(), outerWidth); if (button.ripple->empty()) { button.ripple.reset(); } diff --git a/Telegram/SourceFiles/history/history_item_components.h b/Telegram/SourceFiles/history/history_item_components.h index 67ea5b4d2..2d01d546b 100644 --- a/Telegram/SourceFiles/history/history_item_components.h +++ b/Telegram/SourceFiles/history/history_item_components.h @@ -278,7 +278,7 @@ public: private: const style::BotKeyboardButton *_st; - void paintButton(Painter &p, int outerWidth, const ReplyKeyboard::Button &button, crl::time ms) const; + void paintButton(Painter &p, int outerWidth, const ReplyKeyboard::Button &button) const; friend class ReplyKeyboard; }; @@ -297,7 +297,7 @@ public: int naturalWidth() const; int naturalHeight() const; - void paint(Painter &p, int outerWidth, const QRect &clip, crl::time ms) const; + void paint(Painter &p, int outerWidth, const QRect &clip) const; ClickHandlerPtr getLink(QPoint point) const; void clickHandlerActiveChanged(const ClickHandlerPtr &p, bool active); diff --git a/Telegram/SourceFiles/history/history_widget.cpp b/Telegram/SourceFiles/history/history_widget.cpp index 5b3426c66..1026fb568 100644 --- a/Telegram/SourceFiles/history/history_widget.cpp +++ b/Telegram/SourceFiles/history/history_widget.cpp @@ -675,7 +675,7 @@ void HistoryWidget::animatedScrollToY(int scrollTo, HistoryItem *attachTo) { return; } - _scrollToAnimation.finish(); + _scrollToAnimation.stop(); auto maxAnimatedDelta = _scroll->height(); auto transition = anim::sineInOut; if (scrollTo > scrollTop + maxAnimatedDelta) { @@ -692,15 +692,25 @@ void HistoryWidget::animatedScrollToY(int scrollTo, HistoryItem *attachTo) { // jump to the bottom of history in some updateHistoryGeometry() call. synteticScrollToY(scrollTop); } - _scrollToAnimation.start([this, itemId = attachTo->fullId()] { scrollToAnimationCallback(itemId); }, scrollTop - itemTop, scrollTo - itemTop, st::slideDuration, anim::sineInOut); + const auto itemId = attachTo->fullId(); + const auto relativeFrom = scrollTop - itemTop; + const auto relativeTo = scrollTo - itemTop; + _scrollToAnimation.start( + [=] { scrollToAnimationCallback(itemId, relativeTo); }, + relativeFrom, + relativeTo, + st::slideDuration, + anim::sineInOut); } -void HistoryWidget::scrollToAnimationCallback(FullMsgId attachToId) { +void HistoryWidget::scrollToAnimationCallback( + FullMsgId attachToId, + int relativeTo) { auto itemTop = _list->itemTop(App::histItemById(attachToId)); if (itemTop < 0) { - _scrollToAnimation.finish(); + _scrollToAnimation.stop(); } else { - synteticScrollToY(qRound(_scrollToAnimation.current()) + itemTop); + synteticScrollToY(qRound(_scrollToAnimation.value(relativeTo)) + itemTop); } if (!_scrollToAnimation.animating()) { preloadHistoryByScroll(); @@ -1346,7 +1356,7 @@ void HistoryWidget::setupShortcuts() { void HistoryWidget::clearReplyReturns() { _replyReturns.clear(); - _replyReturn = 0; + _replyReturn = nullptr; } void HistoryWidget::pushReplyReturn(not_null item) { @@ -1575,7 +1585,7 @@ void HistoryWidget::showHistory( destroyUnreadBar(); destroyPinnedBar(); _membersDropdown.destroy(); - _scrollToAnimation.finish(); + _scrollToAnimation.stop(); _history = _migrated = nullptr; _list = nullptr; _peer = nullptr; @@ -2924,7 +2934,7 @@ void HistoryWidget::showAnimated( const Window::SectionSlideParams ¶ms) { _showDirection = direction; - _a_show.finish(); + _a_show.stop(); _cacheUnder = params.oldContentCache; show(); @@ -2940,7 +2950,7 @@ void HistoryWidget::showAnimated( if (_showDirection == Window::SlideDirection::FromLeft) { std::swap(_cacheUnder, _cacheOver); } - _a_show.start([this] { animationCallback(); }, 0., 1., st::slideDuration, Window::SlideAnimation::transition()); + _a_show.start([=] { animationCallback(); }, 0., 1., st::slideDuration, Window::SlideAnimation::transition()); if (_history) { _topBar->show(); _topBar->setAnimatingMode(true); @@ -2978,7 +2988,7 @@ void HistoryWidget::doneShow() { void HistoryWidget::finishAnimating() { if (!_a_show.animating()) return; - _a_show.finish(); + _a_show.stop(); _topShadow->setVisible(_peer != nullptr); _topBar->setVisible(_peer != nullptr); historyDownAnimationFinish(); @@ -2986,12 +2996,12 @@ void HistoryWidget::finishAnimating() { } void HistoryWidget::historyDownAnimationFinish() { - _historyDownShown.finish(); + _historyDownShown.stop(); updateHistoryDownPosition(); } void HistoryWidget::unreadMentionsAnimationFinish() { - _unreadMentionsShown.finish(); + _unreadMentionsShown.stop(); updateUnreadMentionsPosition(); } @@ -4655,7 +4665,7 @@ void HistoryWidget::itemRemoved(not_null item) { } if (_kbReplyTo && item == _kbReplyTo) { onKbToggle(); - _kbReplyTo = 0; + _kbReplyTo = nullptr; } auto found = ranges::find(_toForward, item); if (found != _toForward.end()) { @@ -4837,7 +4847,7 @@ void HistoryWidget::updateHistoryGeometry(bool initial, bool loadedDown, const S if (initial) { _historyInited = true; - _scrollToAnimation.finish(); + _scrollToAnimation.stop(); } auto newScrollTop = initial ? countInitialScrollTop() @@ -4938,7 +4948,9 @@ void HistoryWidget::updateBotKeyboard(History *h, bool force) { } else if (_replyToId && _replyEditMsg) { changed = _keyboard->updateMarkup(_replyEditMsg, force); } else { - HistoryItem *keyboardItem = _history->lastKeyboardId ? App::histItemById(_channel, _history->lastKeyboardId) : nullptr; + const auto keyboardItem = _history->lastKeyboardId + ? App::histItemById(_channel, _history->lastKeyboardId) + : nullptr; changed = _keyboard->updateMarkup(keyboardItem, force); } updateCmdStartShown(); @@ -4966,7 +4978,9 @@ void HistoryWidget::updateBotKeyboard(History *h, bool force) { int32 maxh = hasMarkup ? qMin(_keyboard->height(), st::historyComposeFieldMaxHeight - (st::historyComposeFieldMaxHeight / 2)) : 0; _field->setMaxHeight(st::historyComposeFieldMaxHeight - maxh); _kbShown = hasMarkup; - _kbReplyTo = (_peer->isChat() || _peer->isChannel() || _keyboard->forceReply()) ? App::histItemById(_keyboard->forMsgId()) : 0; + _kbReplyTo = (_peer->isChat() || _peer->isChannel() || _keyboard->forceReply()) + ? App::histItemById(_keyboard->forMsgId()) + : nullptr; if (_kbReplyTo && !_replyToId) { updateReplyToName(); updateReplyEditText(_kbReplyTo); @@ -4981,7 +4995,7 @@ void HistoryWidget::updateBotKeyboard(History *h, bool force) { } _field->setMaxHeight(st::historyComposeFieldMaxHeight); _kbShown = false; - _kbReplyTo = 0; + _kbReplyTo = nullptr; if (!readyToForward() && (!_previewData || _previewData->pendingTill < 0) && !_replyToId) { _fieldBarCancel->hide(); updateMouseTracking(); @@ -4997,7 +5011,7 @@ void HistoryWidget::updateBotKeyboard(History *h, bool force) { } _field->setMaxHeight(st::historyComposeFieldMaxHeight); _kbShown = false; - _kbReplyTo = 0; + _kbReplyTo = nullptr; if (!readyToForward() && (!_previewData || _previewData->pendingTill < 0) && !_replyToId && !_editMsgId) { _fieldBarCancel->hide(); updateMouseTracking(); @@ -5009,7 +5023,7 @@ void HistoryWidget::updateBotKeyboard(History *h, bool force) { void HistoryWidget::updateHistoryDownPosition() { // _historyDown is a child widget of _scroll, not me. - auto top = anim::interpolate(0, _historyDown->height() + st::historyToDownPosition.y(), _historyDownShown.current(_historyDownIsShown ? 1. : 0.)); + auto top = anim::interpolate(0, _historyDown->height() + st::historyToDownPosition.y(), _historyDownShown.value(_historyDownIsShown ? 1. : 0.)); _historyDown->moveToRight(st::historyToDownPosition.x(), _scroll->height() - top); auto shouldBeHidden = !_historyDownIsShown && !_historyDownShown.animating(); if (shouldBeHidden != _historyDown->isHidden()) { @@ -5052,14 +5066,14 @@ void HistoryWidget::updateHistoryDownVisibility() { auto historyDownIsShown = historyDownIsVisible(); if (_historyDownIsShown != historyDownIsShown) { _historyDownIsShown = historyDownIsShown; - _historyDownShown.start([this] { updateHistoryDownPosition(); }, _historyDownIsShown ? 0. : 1., _historyDownIsShown ? 1. : 0., st::historyToDownDuration); + _historyDownShown.start([=] { updateHistoryDownPosition(); }, _historyDownIsShown ? 0. : 1., _historyDownIsShown ? 1. : 0., st::historyToDownDuration); } } void HistoryWidget::updateUnreadMentionsPosition() { // _unreadMentions is a child widget of _scroll, not me. - auto right = anim::interpolate(-_unreadMentions->width(), st::historyToDownPosition.x(), _unreadMentionsShown.current(_unreadMentionsIsShown ? 1. : 0.)); - auto shift = anim::interpolate(0, _historyDown->height() + st::historyUnreadMentionsSkip, _historyDownShown.current(_historyDownIsShown ? 1. : 0.)); + auto right = anim::interpolate(-_unreadMentions->width(), st::historyToDownPosition.x(), _unreadMentionsShown.value(_unreadMentionsIsShown ? 1. : 0.)); + auto shift = anim::interpolate(0, _historyDown->height() + st::historyUnreadMentionsSkip, _historyDownShown.value(_historyDownIsShown ? 1. : 0.)); auto top = _scroll->height() - _unreadMentions->height() - st::historyToDownPosition.y() - shift; _unreadMentions->moveToRight(right, top); auto shouldBeHidden = !_unreadMentionsIsShown && !_unreadMentionsShown.animating(); @@ -5087,7 +5101,7 @@ void HistoryWidget::updateUnreadMentionsVisibility() { } if (_unreadMentionsIsShown != unreadMentionsIsShown) { _unreadMentionsIsShown = unreadMentionsIsShown; - _unreadMentionsShown.start([this] { updateUnreadMentionsPosition(); }, _unreadMentionsIsShown ? 0. : 1., _unreadMentionsIsShown ? 1. : 0., st::historyToDownDuration); + _unreadMentionsShown.start([=] { updateUnreadMentionsPosition(); }, _unreadMentionsIsShown ? 0. : 1., _unreadMentionsIsShown ? 1. : 0., st::historyToDownDuration); } } @@ -6534,8 +6548,8 @@ void HistoryWidget::drawPinnedBar(Painter &p) { } } -bool HistoryWidget::paintShowAnimationFrame(crl::time ms) { - auto progress = _a_show.current(ms, 1.); +bool HistoryWidget::paintShowAnimationFrame() { + auto progress = _a_show.value(1.); if (!_a_show.animating()) { return false; } @@ -6560,10 +6574,7 @@ bool HistoryWidget::paintShowAnimationFrame(crl::time ms) { } void HistoryWidget::paintEvent(QPaintEvent *e) { - auto ms = crl::now(); - _historyDownShown.step(ms); - _unreadMentionsShown.step(ms); - if (paintShowAnimationFrame(ms)) { + if (paintShowAnimationFrame()) { return; } if (Ui::skipPaintEvent(this, e)) { diff --git a/Telegram/SourceFiles/history/history_widget.h b/Telegram/SourceFiles/history/history_widget.h index 5b937c969..91cff8641 100644 --- a/Telegram/SourceFiles/history/history_widget.h +++ b/Telegram/SourceFiles/history/history_widget.h @@ -550,7 +550,7 @@ private: void drawRecording(Painter &p, float64 recordActive); void drawPinnedBar(Painter &p); void drawRestrictedWrite(Painter &p, const QString &error); - bool paintShowAnimationFrame(crl::time ms); + bool paintShowAnimationFrame(); void updateMouseTracking(); @@ -670,7 +670,7 @@ private: int countAutomaticScrollTop(); void preloadHistoryByScroll(); void checkReplyReturns(); - void scrollToAnimationCallback(FullMsgId attachToId); + void scrollToAnimationCallback(FullMsgId attachToId, int relativeTo); bool readyToForward() const; bool hasSilentToggle() const; @@ -707,13 +707,13 @@ private: crl::time _lastUserScrolled = 0; bool _synteticScrollEvent = false; - Animation _scrollToAnimation; + Ui::Animations::Simple _scrollToAnimation; - Animation _historyDownShown; + Ui::Animations::Simple _historyDownShown; bool _historyDownIsShown = false; object_ptr _historyDown; - Animation _unreadMentionsShown; + Ui::Animations::Simple _unreadMentionsShown; bool _unreadMentionsIsShown = false; object_ptr _unreadMentions; @@ -797,7 +797,7 @@ private: QString _confirmSource; - Animation _a_show; + Ui::Animations::Simple _a_show; Window::SlideDirection _showDirection; QPixmap _cacheUnder, _cacheOver; diff --git a/Telegram/SourceFiles/history/media/history_media_file.h b/Telegram/SourceFiles/history/media/history_media_file.h index f85d91367..02b349d96 100644 --- a/Telegram/SourceFiles/history/media/history_media_file.h +++ b/Telegram/SourceFiles/history/media/history_media_file.h @@ -8,6 +8,7 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL #pragma once #include "history/media/history_media.h" +#include "ui/effects/animations.h" #include "ui/effects/radial_animation.h" class HistoryFileMedia : public HistoryMedia { @@ -73,9 +74,9 @@ protected: && _animation->radial.animating() && radialAnimationCallback(now); } - bool isThumbAnimation(crl::time ms) const { + bool isThumbAnimation() const { if (_animation) { - if (_animation->a_thumbOver.animating(ms)) { + if (_animation->a_thumbOver.animating()) { return true; } checkAnimationFinished(); @@ -93,7 +94,7 @@ protected: : radial(std::forward(radialCallback)) { } - Animation a_thumbOver; + Ui::Animations::Simple a_thumbOver; Ui::RadialAnimation radial; }; mutable std::unique_ptr _animation; diff --git a/Telegram/SourceFiles/history/media/history_media_gif.cpp b/Telegram/SourceFiles/history/media/history_media_gif.cpp index fa0d88424..1c4cfc377 100644 --- a/Telegram/SourceFiles/history/media/history_media_gif.cpp +++ b/Telegram/SourceFiles/history/media/history_media_gif.cpp @@ -376,8 +376,8 @@ void HistoryGif::draw(Painter &p, const QRect &r, TextSelection selection, crl:: p.setPen(Qt::NoPen); if (selected) { p.setBrush(st::msgDateImgBgSelected); - } else if (isThumbAnimation(ms)) { - auto over = _animation->a_thumbOver.current(); + } else if (isThumbAnimation()) { + auto over = _animation->a_thumbOver.value(1.); p.setBrush(anim::brush(st::msgDateImgBg, st::msgDateImgBgOver, over)); } else { auto over = ClickHandler::showAsActive(_data->loading() ? _cancell : _savel); diff --git a/Telegram/SourceFiles/history/media/history_media_photo.cpp b/Telegram/SourceFiles/history/media/history_media_photo.cpp index 53d61df86..21da6be74 100644 --- a/Telegram/SourceFiles/history/media/history_media_photo.cpp +++ b/Telegram/SourceFiles/history/media/history_media_photo.cpp @@ -224,8 +224,8 @@ void HistoryPhoto::draw(Painter &p, const QRect &r, TextSelection selection, crl p.setPen(Qt::NoPen); if (selected) { p.setBrush(st::msgDateImgBgSelected); - } else if (isThumbAnimation(ms)) { - auto over = _animation->a_thumbOver.current(); + } else if (isThumbAnimation()) { + auto over = _animation->a_thumbOver.value(1.); p.setBrush(anim::brush(st::msgDateImgBg, st::msgDateImgBgOver, over)); } else { auto over = ClickHandler::showAsActive(_data->loading() ? _cancell : _savel); @@ -395,8 +395,8 @@ void HistoryPhoto::drawGrouped( p.setPen(Qt::NoPen); if (selected) { p.setBrush(st::msgDateImgBgSelected); - } else if (isThumbAnimation(ms)) { - auto over = _animation->a_thumbOver.current(); + } else if (isThumbAnimation()) { + auto over = _animation->a_thumbOver.value(1.); p.setBrush(anim::brush(st::msgDateImgBg, st::msgDateImgBgOver, over)); } else { auto over = ClickHandler::showAsActive(_data->loading() ? _cancell : _savel); diff --git a/Telegram/SourceFiles/history/media/history_media_poll.cpp b/Telegram/SourceFiles/history/media/history_media_poll.cpp index cc29d61b8..9af486f01 100644 --- a/Telegram/SourceFiles/history/media/history_media_poll.cpp +++ b/Telegram/SourceFiles/history/media/history_media_poll.cpp @@ -14,6 +14,7 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL #include "history/view/history_view_cursor_state.h" #include "calls/calls_instance.h" #include "ui/text_options.h" +#include "ui/effects/animations.h" #include "ui/effects/radial_animation.h" #include "ui/effects/ripple_animation.h" #include "data/data_media_types.h" @@ -138,7 +139,7 @@ struct HistoryPoll::AnswerAnimation { struct HistoryPoll::AnswersAnimation { std::vector data; - Animation progress; + Ui::Animations::Simple progress; }; struct HistoryPoll::SendingAnimation { @@ -512,7 +513,7 @@ void HistoryPoll::draw(Painter &p, const QRect &r, TextSelection selection, crl: tshift += st::msgDateFont->height + st::historyPollAnswersSkip; const auto progress = _answersAnimation - ? _answersAnimation->progress.current(ms, 1.) + ? _answersAnimation->progress.value(1.) : 1.; if (progress == 1.) { resetAnswersAnimation(); @@ -538,8 +539,7 @@ void HistoryPoll::draw(Painter &p, const QRect &r, TextSelection selection, crl: tshift, paintw, width(), - selection, - ms); + selection); tshift += height; } if (!_totalVotesLabel.isEmpty()) { @@ -577,8 +577,7 @@ int HistoryPoll::paintAnswer( int top, int width, int outerWidth, - TextSelection selection, - crl::time ms) const { + TextSelection selection) const { const auto height = countAnswerHeight(answer, width); const auto outbg = _parent->hasOutLayout(); const auto aleft = left + st::historyPollAnswerPadding.left(); @@ -588,7 +587,7 @@ int HistoryPoll::paintAnswer( if (answer.ripple) { p.setOpacity(st::historyPollRippleOpacity); - answer.ripple->paint(p, left - st::msgPadding.left(), top, outerWidth, ms); + answer.ripple->paint(p, left - st::msgPadding.left(), top, outerWidth); if (answer.ripple->empty()) { answer.ripple.reset(); } diff --git a/Telegram/SourceFiles/history/media/history_media_poll.h b/Telegram/SourceFiles/history/media/history_media_poll.h index 5e687fa07..0ec11ce27 100644 --- a/Telegram/SourceFiles/history/media/history_media_poll.h +++ b/Telegram/SourceFiles/history/media/history_media_poll.h @@ -79,8 +79,7 @@ private: int top, int width, int outerWidth, - TextSelection selection, - crl::time ms) const; + TextSelection selection) const; void paintRadio( Painter &p, const Answer &answer, diff --git a/Telegram/SourceFiles/history/media/history_media_video.cpp b/Telegram/SourceFiles/history/media/history_media_video.cpp index 0111b052d..7b6b93402 100644 --- a/Telegram/SourceFiles/history/media/history_media_video.cpp +++ b/Telegram/SourceFiles/history/media/history_media_video.cpp @@ -222,8 +222,8 @@ void HistoryVideo::draw(Painter &p, const QRect &r, TextSelection selection, crl p.setPen(Qt::NoPen); if (selected) { p.setBrush(st::msgDateImgBgSelected); - } else if (isThumbAnimation(ms)) { - auto over = _animation->a_thumbOver.current(); + } else if (isThumbAnimation()) { + auto over = _animation->a_thumbOver.value(1.); p.setBrush(anim::brush(st::msgDateImgBg, st::msgDateImgBgOver, over)); } else { bool over = ClickHandler::showAsActive((_data->loading() || _data->uploading()) ? _cancell : _savel); @@ -431,8 +431,8 @@ void HistoryVideo::drawGrouped( p.setPen(Qt::NoPen); if (selected) { p.setBrush(st::msgDateImgBgSelected); - } else if (isThumbAnimation(ms)) { - auto over = _animation->a_thumbOver.current(); + } else if (isThumbAnimation()) { + auto over = _animation->a_thumbOver.value(1.); p.setBrush(anim::brush(st::msgDateImgBg, st::msgDateImgBgOver, over)); } else { auto over = ClickHandler::showAsActive(_data->loading() ? _cancell : _savel); diff --git a/Telegram/SourceFiles/history/media/history_media_wall_paper.cpp b/Telegram/SourceFiles/history/media/history_media_wall_paper.cpp index f352a0a2b..c1c27e935 100644 --- a/Telegram/SourceFiles/history/media/history_media_wall_paper.cpp +++ b/Telegram/SourceFiles/history/media/history_media_wall_paper.cpp @@ -137,8 +137,8 @@ void HistoryWallPaper::draw(Painter &p, const QRect &r, TextSelection selection, p.setPen(Qt::NoPen); if (selected) { p.setBrush(st::msgDateImgBgSelected); - } else if (isThumbAnimation(ms)) { - auto over = _animation->a_thumbOver.current(); + } else if (isThumbAnimation()) { + auto over = _animation->a_thumbOver.value(1.); p.setBrush(anim::brush(st::msgDateImgBg, st::msgDateImgBgOver, over)); } else { auto over = ClickHandler::showAsActive(_data->loading() ? _cancell : _openl); diff --git a/Telegram/SourceFiles/history/view/history_view_list_widget.cpp b/Telegram/SourceFiles/history/view/history_view_list_widget.cpp index 9d647c2ce..abafab781 100644 --- a/Telegram/SourceFiles/history/view/history_view_list_widget.cpp +++ b/Telegram/SourceFiles/history/view/history_view_list_widget.cpp @@ -369,7 +369,7 @@ void ListWidget::animatedScrollTo( Data::MessagePosition attachPosition, int delta, AnimatedScroll type) { - _scrollToAnimation.finish(); + _scrollToAnimation.stop(); if (!delta || _items.empty()) { _delegate->listScrollTo(scrollTop); return; @@ -388,20 +388,23 @@ void ListWidget::animatedScrollTo( const auto relativeStart = initial - attachToTop; const auto relativeFinish = scrollTop - attachToTop; _scrollToAnimation.start( - [=] { scrollToAnimationCallback(attachToId); }, + [=] { scrollToAnimationCallback(attachToId, relativeFinish); }, relativeStart, relativeFinish, st::slideDuration, transition); } -void ListWidget::scrollToAnimationCallback(FullMsgId attachToId) { +void ListWidget::scrollToAnimationCallback( + FullMsgId attachToId, + int relativeTo) { const auto attachTo = App::histItemById(attachToId); const auto attachToView = viewForItem(attachTo); if (!attachToView) { - _scrollToAnimation.finish(); + _scrollToAnimation.stop(); } else { - const auto current = int(std::round(_scrollToAnimation.current())); + const auto current = int(std::round(_scrollToAnimation.value( + relativeTo))); _delegate->listScrollTo(itemTop(attachToView) + current); } } @@ -1326,7 +1329,7 @@ void ListWidget::paintEvent(QPaintEvent *e) { }); auto dateHeight = st::msgServicePadding.bottom() + st::msgServiceFont->height + st::msgServicePadding.top(); - auto scrollDateOpacity = _scrollDateOpacity.current(ms, _scrollDateShown ? 1. : 0.); + auto scrollDateOpacity = _scrollDateOpacity.value(_scrollDateShown ? 1. : 0.); enumerateDates([&](not_null view, int itemtop, int dateTop) { // stop the enumeration if the date is above the painted rect if (dateTop + dateHeight <= clip.top()) { @@ -1426,7 +1429,7 @@ TextWithEntities ListWidget::getSelectedText() const { part.text.reserve(size); part.text.append(item->author()->name).append(time); TextUtilities::Append(part, std::move(unwrapped)); - texts.push_back(std::make_pair(std::move(item), std::move(part))); + texts.emplace_back(std::move(item), std::move(part)); fullSize += size; }; const auto addItem = [&](not_null item) { @@ -2092,7 +2095,7 @@ void ListWidget::mouseActionUpdate() { const auto dateHeight = st::msgServicePadding.bottom() + st::msgServiceFont->height + st::msgServicePadding.top(); - const auto scrollDateOpacity = _scrollDateOpacity.current(_scrollDateShown ? 1. : 0.); + const auto scrollDateOpacity = _scrollDateOpacity.value(_scrollDateShown ? 1. : 0.); enumerateDates([&](not_null view, int itemtop, int dateTop) { // stop enumeration if the date is above our point if (dateTop + dateHeight <= point.y()) { diff --git a/Telegram/SourceFiles/history/view/history_view_list_widget.h b/Telegram/SourceFiles/history/view/history_view_list_widget.h index 4b8425bc7..642808034 100644 --- a/Telegram/SourceFiles/history/view/history_view_list_widget.h +++ b/Telegram/SourceFiles/history/view/history_view_list_widget.h @@ -7,8 +7,9 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL */ #pragma once -#include "ui/widgets/tooltip.h" #include "ui/rp_widget.h" +#include "ui/effects/animations.h" +#include "ui/widgets/tooltip.h" #include "mtproto/sender.h" #include "base/timer.h" #include "data/data_messages.h" @@ -381,7 +382,7 @@ private: not_null view) const; void checkUnreadBarCreation(); void applyUpdatedScrollState(); - void scrollToAnimationCallback(FullMsgId attachToId); + void scrollToAnimationCallback(FullMsgId attachToId, int relativeTo); void updateHighlightedMessage(); @@ -437,10 +438,10 @@ private: Element *_visibleTopItem = nullptr; int _visibleTopFromItem = 0; ScrollTopState _scrollTopState; - Animation _scrollToAnimation; + Ui::Animations::Simple _scrollToAnimation; bool _scrollDateShown = false; - Animation _scrollDateOpacity; + Ui::Animations::Simple _scrollDateOpacity; SingleQueuedInvokation _scrollDateCheck; base::Timer _scrollDateHideTimer; Element *_scrollDateLastItem = nullptr; diff --git a/Telegram/SourceFiles/history/view/history_view_message.cpp b/Telegram/SourceFiles/history/view/history_view_message.cpp index 4bfcba975..4e0d864ef 100644 --- a/Telegram/SourceFiles/history/view/history_view_message.cpp +++ b/Telegram/SourceFiles/history/view/history_view_message.cpp @@ -421,7 +421,7 @@ void Message::draw( g.setHeight(g.height() - keyboardHeight); auto keyboardPosition = QPoint(g.left(), g.top() + g.height() + st::msgBotKbButton.margin); p.translate(keyboardPosition); - keyboard->paint(p, g.width(), clip.translated(-keyboardPosition), ms); + keyboard->paint(p, g.width(), clip.translated(-keyboardPosition)); p.translate(-keyboardPosition); } diff --git a/Telegram/SourceFiles/history/view/history_view_top_bar_widget.cpp b/Telegram/SourceFiles/history/view/history_view_top_bar_widget.cpp index a786bfb1b..1390065a2 100644 --- a/Telegram/SourceFiles/history/view/history_view_top_bar_widget.cpp +++ b/Telegram/SourceFiles/history/view/history_view_top_bar_widget.cpp @@ -286,20 +286,17 @@ void TopBarWidget::paintEvent(QPaintEvent *e) { } Painter p(this); - auto ms = crl::now(); - _forward->stepNumbersAnimation(ms); - _delete->stepNumbersAnimation(ms); auto hasSelected = (_selectedCount > 0); - auto selectedButtonsTop = countSelectedButtonsTop(_selectedShown.current(crl::now(), hasSelected ? 1. : 0.)); + auto selectedButtonsTop = countSelectedButtonsTop(_selectedShown.value(hasSelected ? 1. : 0.)); p.fillRect(QRect(0, 0, width(), st::topBarHeight), st::topBarBg); if (selectedButtonsTop < 0) { p.translate(0, selectedButtonsTop + st::topBarHeight); - paintTopBar(p, ms); + paintTopBar(p); } } -void TopBarWidget::paintTopBar(Painter &p, crl::time ms) { +void TopBarWidget::paintTopBar(Painter &p) { if (!_activeChat) { return; } @@ -339,7 +336,7 @@ void TopBarWidget::paintTopBar(Painter &p, crl::time ms) { history->peer->dialogName().drawElided(p, nameleft, nametop, namewidth); p.setFont(st::dialogsTextFont); - if (paintConnectingState(p, nameleft, statustop, width(), ms)) { + if (paintConnectingState(p, nameleft, statustop, width())) { return; } else if (history->paintSendAction( p, @@ -348,7 +345,7 @@ void TopBarWidget::paintTopBar(Painter &p, crl::time ms) { namewidth, width(), st::historyStatusFgTyping, - ms)) { + crl::now())) { return; } else { paintStatus(p, nameleft, statustop, namewidth, width()); @@ -360,8 +357,7 @@ bool TopBarWidget::paintConnectingState( Painter &p, int left, int top, - int outerWidth, - crl::time ms) { + int outerWidth) { if (!_connecting) { return false; } @@ -485,7 +481,7 @@ int TopBarWidget::countSelectedButtonsTop(float64 selectedShown) { void TopBarWidget::updateControlsGeometry() { auto hasSelected = (_selectedCount > 0); - auto selectedButtonsTop = countSelectedButtonsTop(_selectedShown.current(hasSelected ? 1. : 0.)); + auto selectedButtonsTop = countSelectedButtonsTop(_selectedShown.value(hasSelected ? 1. : 0.)); auto otherButtonsTop = selectedButtonsTop + st::topBarHeight; auto buttonsLeft = st::topBarActionSkip + (Adaptive::OneColumn() ? 0 : st::lineWidth); auto buttonsWidth = _forward->contentWidth() + _delete->contentWidth() + _clear->width(); @@ -541,7 +537,7 @@ void TopBarWidget::updateControlsGeometry() { } void TopBarWidget::finishAnimating() { - _selectedShown.finish(); + _selectedShown.stop(); updateControlsVisibility(); } diff --git a/Telegram/SourceFiles/history/view/history_view_top_bar_widget.h b/Telegram/SourceFiles/history/view/history_view_top_bar_widget.h index b18e75287..ffc662ab5 100644 --- a/Telegram/SourceFiles/history/view/history_view_top_bar_widget.h +++ b/Telegram/SourceFiles/history/view/history_view_top_bar_widget.h @@ -8,6 +8,7 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL #pragma once #include "ui/rp_widget.h" +#include "ui/effects/animations.h" #include "base/timer.h" #include "dialogs/dialogs_key.h" @@ -86,19 +87,14 @@ private: int countSelectedButtonsTop(float64 selectedShown); void connectingAnimationCallback(); - void paintTopBar(Painter &p, crl::time ms); + void paintTopBar(Painter &p); void paintStatus( Painter &p, int left, int top, int availableWidth, int outerWidth); - bool paintConnectingState( - Painter &p, - int left, - int top, - int outerWidth, - crl::time ms); + bool paintConnectingState(Painter &p, int left, int top, int outerWidth); QRect getMembersShowAreaGeometry() const; void updateMembersShowArea(); void updateOnlineDisplay(); @@ -118,7 +114,7 @@ private: bool _canDelete = false; bool _canForward = false; - Animation _selectedShown; + Ui::Animations::Simple _selectedShown; object_ptr _clear; object_ptr _forward, _delete; diff --git a/Telegram/SourceFiles/info/feed/info_feed_channels.cpp b/Telegram/SourceFiles/info/feed/info_feed_channels.cpp index b99e38c17..ee1acb753 100644 --- a/Telegram/SourceFiles/info/feed/info_feed_channels.cpp +++ b/Telegram/SourceFiles/info/feed/info_feed_channels.cpp @@ -218,7 +218,7 @@ void Channels::updateHeaderControlsGeometry(int newWidth) { //auto searchShownLeft = st::infoIconPosition.x() // - st::infoMembersSearch.iconPosition.x(); //auto searchHiddenLeft = availableWidth - _search->width(); - //auto searchShown = _searchShownAnimation.current(_searchShown ? 1. : 0.); + //auto searchShown = _searchShownAnimation.value(_searchShown ? 1. : 0.); //auto searchCurrentLeft = anim::interpolate( // searchHiddenLeft, // searchShownLeft, diff --git a/Telegram/SourceFiles/info/feed/info_feed_channels_controllers.cpp b/Telegram/SourceFiles/info/feed/info_feed_channels_controllers.cpp index a05449e02..c4904c484 100644 --- a/Telegram/SourceFiles/info/feed/info_feed_channels_controllers.cpp +++ b/Telegram/SourceFiles/info/feed/info_feed_channels_controllers.cpp @@ -39,7 +39,6 @@ public: QMargins actionMargins() const override; void paintAction( Painter &p, - crl::time ms, int x, int y, int outerWidth, @@ -77,7 +76,6 @@ QMargins ChannelsController::Row::actionMargins() const { void ChannelsController::Row::paintAction( Painter &p, - crl::time ms, int x, int y, int outerWidth, diff --git a/Telegram/SourceFiles/info/info_top_bar.cpp b/Telegram/SourceFiles/info/info_top_bar.cpp index ff12b1b0c..4fb6bd6dd 100644 --- a/Telegram/SourceFiles/info/info_top_bar.cpp +++ b/Telegram/SourceFiles/info/info_top_bar.cpp @@ -356,8 +356,7 @@ void TopBar::updateSelectionControlsGeometry(int newWidth) { void TopBar::paintEvent(QPaintEvent *e) { Painter p(this); - auto ms = crl::now(); - auto highlight = _a_highlight.current(ms, _highlight ? 1. : 0.); + auto highlight = _a_highlight.value(_highlight ? 1. : 0.); if (_highlight && !_a_highlight.animating()) { _highlight = false; startHighlightAnimation(); diff --git a/Telegram/SourceFiles/info/info_top_bar.h b/Telegram/SourceFiles/info/info_top_bar.h index ff4d3b550..82396bcdf 100644 --- a/Telegram/SourceFiles/info/info_top_bar.h +++ b/Telegram/SourceFiles/info/info_top_bar.h @@ -9,6 +9,7 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL #include "ui/rp_widget.h" #include "ui/wrap/fade_wrap.h" +#include "ui/effects/animations.h" #include "ui/effects/numbers_animation.h" #include "info/info_wrap_widget.h" @@ -130,7 +131,7 @@ private: void registerToggleControlCallback(Widget *widget, IsVisible &&callback); const style::InfoTopBar &_st; - Animation _a_highlight; + Ui::Animations::Simple _a_highlight; bool _highlight = false; QPointer> _back; std::vector> _buttons; diff --git a/Telegram/SourceFiles/info/info_wrap_widget.h b/Telegram/SourceFiles/info/info_wrap_widget.h index eed9f91fc..c49d996dc 100644 --- a/Telegram/SourceFiles/info/info_wrap_widget.h +++ b/Telegram/SourceFiles/info/info_wrap_widget.h @@ -7,9 +7,8 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL */ #pragma once -#include -#include #include "window/section_widget.h" +#include "ui/effects/animations.h" namespace Storage { enum class SharedMediaType : signed char; @@ -209,7 +208,7 @@ private: //object_ptr _topTabs = { nullptr }; object_ptr _topBar = { nullptr }; object_ptr _topBarSurrogate = { nullptr }; - Animation _topBarOverrideAnimation; + Ui::Animations::Simple _topBarOverrideAnimation; bool _topBarOverrideShown = false; object_ptr _topShadow; diff --git a/Telegram/SourceFiles/info/profile/info_profile_button.cpp b/Telegram/SourceFiles/info/profile/info_profile_button.cpp index 2ba447db9..83c0fd269 100644 --- a/Telegram/SourceFiles/info/profile/info_profile_button.cpp +++ b/Telegram/SourceFiles/info/profile/info_profile_button.cpp @@ -77,11 +77,10 @@ void Button::setColorOverride(std::optional textColorOverride) { void Button::paintEvent(QPaintEvent *e) { Painter p(this); - auto ms = crl::now(); auto paintOver = (isOver() || isDown()) && !isDisabled(); p.fillRect(e->rect(), paintOver ? _st.textBgOver : _st.textBg); - paintRipple(p, 0, 0, ms); + paintRipple(p, 0, 0); auto outerw = width(); p.setFont(_st.font); @@ -99,7 +98,7 @@ void Button::paintEvent(QPaintEvent *e) { if (_toggle) { auto rect = toggleRect(); - _toggle->paint(p, rect.left(), rect.top(), outerw, ms); + _toggle->paint(p, rect.left(), rect.top(), outerw); } } diff --git a/Telegram/SourceFiles/info/profile/info_profile_cover.cpp b/Telegram/SourceFiles/info/profile/info_profile_cover.cpp index 5ea43bcea..795740adf 100644 --- a/Telegram/SourceFiles/info/profile/info_profile_cover.cpp +++ b/Telegram/SourceFiles/info/profile/info_profile_cover.cpp @@ -43,8 +43,7 @@ public: Painter &p, int left, int top, - int outerWidth, - crl::time ms) override; + int outerWidth) override; QImage prepareRippleMask() const override; bool checkRippleStartPosition(QPoint position) const override; @@ -71,8 +70,7 @@ void SectionToggle::paint( Painter &p, int left, int top, - int outerWidth, - crl::time ms) { + int outerWidth) { auto sqrt2 = sqrt(2.); auto vLeft = rtlpoint(left + _st.skip, 0, outerWidth).x() + 0.; auto vTop = top + _st.skip + 0.; @@ -89,7 +87,7 @@ void SectionToggle::paint( { vLeft + (vWidth / 2.), vTop + (vHeight * 3. / 4.) + vStroke }, } }; - auto toggled = currentAnimationValue(ms); + auto toggled = currentAnimationValue(); auto alpha = (toggled - 1.) * M_PI_2; auto cosalpha = cos(alpha); auto sinalpha = sin(alpha); diff --git a/Telegram/SourceFiles/info/profile/info_profile_members.cpp b/Telegram/SourceFiles/info/profile/info_profile_members.cpp index 731cd0d5b..8a333e845 100644 --- a/Telegram/SourceFiles/info/profile/info_profile_members.cpp +++ b/Telegram/SourceFiles/info/profile/info_profile_members.cpp @@ -270,7 +270,7 @@ void Members::updateHeaderControlsGeometry(int newWidth) { //auto searchShownLeft = st::infoIconPosition.x() // - st::infoMembersSearch.iconPosition.x(); //auto searchHiddenLeft = availableWidth - _search->width(); - //auto searchShown = _searchShownAnimation.current(_searchShown ? 1. : 0.); + //auto searchShown = _searchShownAnimation.value(_searchShown ? 1. : 0.); //auto searchCurrentLeft = anim::interpolate( // searchHiddenLeft, // searchShownLeft, diff --git a/Telegram/SourceFiles/info/profile/info_profile_members.h b/Telegram/SourceFiles/info/profile/info_profile_members.h index 12e618841..85cf56a1d 100644 --- a/Telegram/SourceFiles/info/profile/info_profile_members.h +++ b/Telegram/SourceFiles/info/profile/info_profile_members.h @@ -117,7 +117,7 @@ private: Ui::IconButton *_search = nullptr; //Ui::CrossButton *_cancelSearch = nullptr; - //Animation _searchShownAnimation; + //Ui::Animations::Simple _searchShownAnimation; //bool _searchShown = false; //base::Timer _searchTimer; diff --git a/Telegram/SourceFiles/info/profile/info_profile_members_controllers.cpp b/Telegram/SourceFiles/info/profile/info_profile_members_controllers.cpp index b9c73540d..d85092959 100644 --- a/Telegram/SourceFiles/info/profile/info_profile_members_controllers.cpp +++ b/Telegram/SourceFiles/info/profile/info_profile_members_controllers.cpp @@ -49,7 +49,6 @@ QSize MemberListRow::actionSize() const { void MemberListRow::paintAction( Painter &p, - crl::time ms, int x, int y, int outerWidth, diff --git a/Telegram/SourceFiles/info/profile/info_profile_members_controllers.h b/Telegram/SourceFiles/info/profile/info_profile_members_controllers.h index cecd4bc15..e5b5666ed 100644 --- a/Telegram/SourceFiles/info/profile/info_profile_members_controllers.h +++ b/Telegram/SourceFiles/info/profile/info_profile_members_controllers.h @@ -34,7 +34,6 @@ public: QSize actionSize() const override; void paintAction( Painter &p, - crl::time ms, int x, int y, int outerWidth, diff --git a/Telegram/SourceFiles/inline_bots/inline_bot_layout_internal.cpp b/Telegram/SourceFiles/inline_bots/inline_bot_layout_internal.cpp index 973772f68..d31a786fe 100644 --- a/Telegram/SourceFiles/inline_bots/inline_bot_layout_internal.cpp +++ b/Telegram/SourceFiles/inline_bots/inline_bot_layout_internal.cpp @@ -174,8 +174,8 @@ void Gif::paint(Painter &p, const QRect &clip, const PaintContext *context) cons if (radial || _gif.isBad() || (!_gif && !loaded && !loading)) { auto radialOpacity = (radial && loaded) ? _animation->radial.opacity() : 1.; - if (_animation && _animation->_a_over.animating(context->ms)) { - auto over = _animation->_a_over.current(); + if (_animation && _animation->_a_over.animating()) { + auto over = _animation->_a_over.value(1.); p.fillRect(r, anim::brush(st::msgDateImgBg, st::msgDateImgBgOver, over)); } else { auto over = (_state & StateFlag::Over); @@ -400,7 +400,7 @@ void Sticker::preload() const { void Sticker::paint(Painter &p, const QRect &clip, const PaintContext *context) const { bool loaded = getShownDocument()->loaded(); - auto over = _a_over.current(context->ms, _active ? 1. : 0.); + auto over = _a_over.value(_active ? 1. : 0.); if (over > 0) { p.setOpacity(over); App::roundRect(p, QRect(QPoint(0, 0), st::stickerPanSize), st::emojiPanHover, StickerHoverCorners); @@ -755,8 +755,8 @@ void File::paint(Painter &p, const QRect &clip, const PaintContext *context) con auto inner = rtlrect(0, st::inlineRowMargin, st::msgFileSize, st::msgFileSize, _width); p.setPen(Qt::NoPen); - if (isThumbAnimation(context->ms)) { - auto over = _animation->a_thumbOver.current(); + if (isThumbAnimation()) { + auto over = _animation->a_thumbOver.value(1.); p.setBrush(anim::brush(st::msgFileInBg, st::msgFileInBgOver, over)); } else { bool over = ClickHandler::showAsActive(_document->loading() ? _cancel : _open); diff --git a/Telegram/SourceFiles/inline_bots/inline_bot_layout_internal.h b/Telegram/SourceFiles/inline_bots/inline_bot_layout_internal.h index 7632f5e3e..74e1c5e58 100644 --- a/Telegram/SourceFiles/inline_bots/inline_bot_layout_internal.h +++ b/Telegram/SourceFiles/inline_bots/inline_bot_layout_internal.h @@ -9,6 +9,7 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL #include "base/flags.h" #include "inline_bots/inline_bot_layout_item.h" +#include "ui/effects/animations.h" #include "ui/effects/radial_animation.h" #include "ui/text/text.h" @@ -103,11 +104,11 @@ private: : radial(std::forward(callback)) { } bool over = false; - Animation _a_over; + Ui::Animations::Simple _a_over; Ui::RadialAnimation radial; }; mutable std::unique_ptr _animation; - mutable Animation _a_deleteOver; + mutable Ui::Animations::Simple _a_deleteOver; }; @@ -174,7 +175,7 @@ public: private: QSize getThumbSize() const; - mutable Animation _a_over; + mutable Ui::Animations::Simple _a_over; mutable bool _active = false; mutable QPixmap _thumb; @@ -261,9 +262,9 @@ private: && _animation->radial.animating() && radialAnimationCallback(now); } - bool isThumbAnimation(crl::time ms) const { + bool isThumbAnimation() const { if (_animation) { - if (_animation->a_thumbOver.animating(ms)) { + if (_animation->a_thumbOver.animating()) { return true; } checkAnimationFinished(); @@ -276,7 +277,7 @@ private: AnimationData(Callback &&radialCallback) : radial(std::forward(radialCallback)) { } - Animation a_thumbOver; + Ui::Animations::Simple a_thumbOver; Ui::RadialAnimation radial; }; mutable std::unique_ptr _animation; diff --git a/Telegram/SourceFiles/inline_bots/inline_results_widget.cpp b/Telegram/SourceFiles/inline_bots/inline_results_widget.cpp index 518e85cc5..4f8308be3 100644 --- a/Telegram/SourceFiles/inline_bots/inline_results_widget.cpp +++ b/Telegram/SourceFiles/inline_bots/inline_results_widget.cpp @@ -804,12 +804,9 @@ void Widget::onWndActiveChanged() { void Widget::paintEvent(QPaintEvent *e) { Painter p(this); - auto ms = crl::now(); + auto opacityAnimating = _a_opacity.animating(); - // This call can finish _a_show animation and destroy _showAnimation. - auto opacityAnimating = _a_opacity.animating(ms); - - auto showAnimating = _a_show.animating(ms); + auto showAnimating = _a_show.animating(); if (_showAnimation && !showAnimating) { _showAnimation.reset(); if (!opacityAnimating) { @@ -819,11 +816,11 @@ void Widget::paintEvent(QPaintEvent *e) { if (showAnimating) { Assert(_showAnimation != nullptr); - if (auto opacity = _a_opacity.current(_hiding ? 0. : 1.)) { - _showAnimation->paintFrame(p, 0, 0, width(), _a_show.current(1.), opacity); + if (auto opacity = _a_opacity.value(_hiding ? 0. : 1.)) { + _showAnimation->paintFrame(p, 0, 0, width(), _a_show.value(1.), opacity); } } else if (opacityAnimating) { - p.setOpacity(_a_opacity.current(_hiding ? 0. : 1.)); + p.setOpacity(_a_opacity.value(_hiding ? 0. : 1.)); p.drawPixmap(0, 0, _cache); } else if (_hiding || isHidden()) { hideFinished(); @@ -853,7 +850,7 @@ void Widget::hideFast() { if (isHidden()) return; _hiding = false; - _a_opacity.finish(); + _a_opacity.stop(); hideFinished(); } @@ -936,7 +933,7 @@ void Widget::hideFinished() { _controller->disableGifPauseReason(Window::GifPauseReason::InlineResults); _inner->hideFinish(true); - _a_show.finish(); + _a_show.stop(); _showAnimation.reset(); _cache = QPixmap(); _horizontal = false; diff --git a/Telegram/SourceFiles/inline_bots/inline_results_widget.h b/Telegram/SourceFiles/inline_bots/inline_results_widget.h index b50b6da77..6ce27573f 100644 --- a/Telegram/SourceFiles/inline_bots/inline_results_widget.h +++ b/Telegram/SourceFiles/inline_bots/inline_results_widget.h @@ -9,6 +9,7 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL #include "ui/twidget.h" #include "ui/abstract_button.h" +#include "ui/effects/animations.h" #include "ui/effects/panel_animation.h" #include "base/timer.h" #include "mtproto/sender.h" @@ -245,11 +246,11 @@ private: int _bottom = 0; std::unique_ptr _showAnimation; - Animation _a_show; + Ui::Animations::Simple _a_show; bool _hiding = false; QPixmap _cache; - Animation _a_opacity; + Ui::Animations::Simple _a_opacity; bool _inPanelGrab = false; object_ptr _scroll; diff --git a/Telegram/SourceFiles/intro/introwidget.cpp b/Telegram/SourceFiles/intro/introwidget.cpp index ba1e29e70..0f8352397 100644 --- a/Telegram/SourceFiles/intro/introwidget.cpp +++ b/Telegram/SourceFiles/intro/introwidget.cpp @@ -489,12 +489,12 @@ void Widget::showAnimated(const QPixmap &bgAnimCache, bool back) { (_showBack ? _cacheOver : _cacheUnder) = bgAnimCache; - _a_show.finish(); + _a_show.stop(); showControls(); (_showBack ? _cacheUnder : _cacheOver) = Ui::GrabWidget(this); hideControls(); - _a_show.start([this] { animationCallback(); }, 0., 1., st::slideDuration, Window::SlideAnimation::transition()); + _a_show.start([=] { animationCallback(); }, 0., 1., st::slideDuration, Window::SlideAnimation::transition()); show(); } @@ -513,16 +513,12 @@ void Widget::paintEvent(QPaintEvent *e) { bool trivial = (rect() == e->rect()); setMouseTracking(true); - if (_coverShownAnimation.animating()) { - _coverShownAnimation.step(crl::now()); - } - QPainter p(this); if (!trivial) { p.setClipRect(e->rect()); } p.fillRect(e->rect(), st::windowBg); - auto progress = _a_show.current(crl::now(), 1.); + auto progress = _a_show.value(1.); if (_a_show.animating()) { auto coordUnder = _showBack ? anim::interpolate(-st::slideShift, 0, progress) : anim::interpolate(0, -st::slideShift, progress); auto coordOver = _showBack ? anim::interpolate(0, width(), progress) : anim::interpolate(width(), 0, progress); @@ -559,7 +555,7 @@ void Widget::resizeEvent(QResizeEvent *e) { } void Widget::updateControlsGeometry() { - auto shown = _coverShownAnimation.current(1.); + auto shown = _coverShownAnimation.value(1.); auto controlsTopTo = getStep()->hasCover() ? st::introCoverHeight : 0; auto controlsTop = anim::interpolate(_controlsTopFrom, controlsTopTo, shown); @@ -701,7 +697,7 @@ void Widget::Step::refreshLang() { } void Widget::Step::showFinished() { - _a_show.finish(); + _a_show.stop(); _coverAnimation = CoverAnimation(); _slideAnimation.reset(); prepareCoverMask(); @@ -710,7 +706,7 @@ void Widget::Step::showFinished() { bool Widget::Step::paintAnimated(Painter &p, QRect clip) { if (_slideAnimation) { - _slideAnimation->paintFrame(p, (width() - st::introStepWidth) / 2, contentTop(), width(), crl::now()); + _slideAnimation->paintFrame(p, (width() - st::introStepWidth) / 2, contentTop(), width()); if (!_slideAnimation->animating()) { showFinished(); return false; @@ -718,7 +714,7 @@ bool Widget::Step::paintAnimated(Painter &p, QRect clip) { return true; } - auto dt = _a_show.current(crl::now(), 1.); + auto dt = _a_show.value(1.); if (!_a_show.animating()) { if (hasCover()) { paintCover(p, 0); diff --git a/Telegram/SourceFiles/intro/introwidget.h b/Telegram/SourceFiles/intro/introwidget.h index 36d75a30a..32a7cffae 100644 --- a/Telegram/SourceFiles/intro/introwidget.h +++ b/Telegram/SourceFiles/intro/introwidget.h @@ -9,6 +9,7 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL #include "mtproto/sender.h" #include "ui/rp_widget.h" +#include "ui/effects/animations.h" #include "window/window_lock_widgets.h" #include "core/core_cloud_password.h" @@ -219,7 +220,7 @@ public: Fn _errorTextFactory; object_ptr> _error = { nullptr }; - Animation _a_show; + Ui::Animations::Simple _a_show; CoverAnimation _coverAnimation; std::unique_ptr _slideAnimation; QPixmap _coverMask; @@ -260,7 +261,7 @@ private: void getNearestDC(); void showTerms(Fn callback); - Animation _a_show; + Ui::Animations::Simple _a_show; bool _showBack = false; QPixmap _cacheUnder, _cacheOver; @@ -268,7 +269,7 @@ private: Data _data; - Animation _coverShownAnimation; + Ui::Animations::Simple _coverShownAnimation; int _nextTopFrom = 0; int _controlsTopFrom = 0; diff --git a/Telegram/SourceFiles/mainwidget.cpp b/Telegram/SourceFiles/mainwidget.cpp index 702a11468..28d30c24c 100644 --- a/Telegram/SourceFiles/mainwidget.cpp +++ b/Telegram/SourceFiles/mainwidget.cpp @@ -1593,7 +1593,7 @@ void MainWidget::ui_showPeerHistory( } _controller->dialogsListFocused().set(false, true); - _a_dialogsWidth.finish(); + _a_dialogsWidth.stop(); using Way = SectionShow::Way; auto way = params.way; @@ -1922,7 +1922,7 @@ void MainWidget::showNewSection( QPixmap animCache; _controller->dialogsListFocused().set(false, true); - _a_dialogsWidth.finish(); + _a_dialogsWidth.stop(); auto mainSectionTop = getMainSectionTop(); auto newMainGeometry = QRect( @@ -2230,7 +2230,7 @@ void MainWidget::showAnimated(const QPixmap &bgAnimCache, bool back) { _showBack = back; (_showBack ? _cacheOver : _cacheUnder) = bgAnimCache; - _a_show.finish(); + _a_show.stop(); showAll(); (_showBack ? _cacheUnder : _cacheOver) = Ui::GrabWidget(this); @@ -2262,7 +2262,7 @@ void MainWidget::paintEvent(QPaintEvent *e) { } Painter p(this); - auto progress = _a_show.current(crl::now(), 1.); + auto progress = _a_show.value(1.); if (_a_show.animating()) { auto coordUnder = _showBack ? anim::interpolate(-st::slideShift, 0, progress) : anim::interpolate(0, -st::slideShift, progress); auto coordOver = _showBack ? anim::interpolate(0, width(), progress) : anim::interpolate(width(), 0, progress); @@ -2374,7 +2374,7 @@ void MainWidget::resizeEvent(QResizeEvent *e) { void MainWidget::updateControlsGeometry() { updateWindowAdaptiveLayout(); if (session().settings().dialogsWidthRatio() > 0) { - _a_dialogsWidth.finish(); + _a_dialogsWidth.stop(); } if (!_a_dialogsWidth.animating()) { _dialogs->stopWidthAnimation(); @@ -2401,7 +2401,7 @@ void MainWidget::updateControlsGeometry() { _thirdShadow.destroy(); } auto mainSectionTop = getMainSectionTop(); - auto dialogsWidth = qRound(_a_dialogsWidth.current(_dialogsWidth)); + auto dialogsWidth = qRound(_a_dialogsWidth.value(_dialogsWidth)); if (Adaptive::OneColumn()) { if (_callTopBar) { _callTopBar->resizeToWidth(dialogsWidth); diff --git a/Telegram/SourceFiles/mainwidget.h b/Telegram/SourceFiles/mainwidget.h index e5afee957..6d00a8cfb 100644 --- a/Telegram/SourceFiles/mainwidget.h +++ b/Telegram/SourceFiles/mainwidget.h @@ -10,6 +10,7 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL #include "base/timer.h" #include "base/weak_ptr.h" #include "ui/rp_widget.h" +#include "ui/effects/animations.h" #include "media/player/media_player_float.h" #include "data/data_pts_waiter.h" @@ -451,13 +452,13 @@ private: not_null _controller; bool _started = false; - Animation _a_show; + Ui::Animations::Simple _a_show; bool _showBack = false; QPixmap _cacheUnder, _cacheOver; int _dialogsWidth = 0; int _thirdColumnWidth = 0; - Animation _a_dialogsWidth; + Ui::Animations::Simple _a_dialogsWidth; object_ptr _sideShadow; object_ptr _thirdShadow = { nullptr }; diff --git a/Telegram/SourceFiles/media/player/media_player_button.cpp b/Telegram/SourceFiles/media/player/media_player_button.cpp index d202fd144..bcbc5f85b 100644 --- a/Telegram/SourceFiles/media/player/media_player_button.cpp +++ b/Telegram/SourceFiles/media/player/media_player_button.cpp @@ -21,7 +21,7 @@ void PlayButtonLayout::setState(State state) { if (_nextState == state) return; _nextState = state; - if (!_transformProgress.animating(crl::now())) { + if (!_transformProgress.animating()) { _oldState = _state; _state = _nextState; _transformBackward = false; @@ -37,16 +37,16 @@ void PlayButtonLayout::setState(State state) { } void PlayButtonLayout::finishTransform() { - _transformProgress.finish(); + _transformProgress.stop(); _transformBackward = false; if (_callback) _callback(); } void PlayButtonLayout::paint(Painter &p, const QBrush &brush) { - if (_transformProgress.animating(crl::now())) { + if (_transformProgress.animating()) { auto from = _oldState, to = _state; auto backward = _transformBackward; - auto progress = _transformProgress.current(1.); + auto progress = _transformProgress.value(1.); if (from == State::Cancel || (from == State::Pause && to == State::Play)) { qSwap(from, to); backward = !backward; diff --git a/Telegram/SourceFiles/media/player/media_player_button.h b/Telegram/SourceFiles/media/player/media_player_button.h index 6ad124e8c..aaabadf83 100644 --- a/Telegram/SourceFiles/media/player/media_player_button.h +++ b/Telegram/SourceFiles/media/player/media_player_button.h @@ -8,6 +8,7 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL #pragma once #include "ui/abstract_button.h" +#include "ui/effects/animations.h" #include "styles/style_media_player.h" namespace Media { @@ -40,7 +41,7 @@ private: State _state = State::Play; State _oldState = State::Play; State _nextState = State::Play; - Animation _transformProgress; + Ui::Animations::Simple _transformProgress; bool _transformBackward = false; Fn _callback; diff --git a/Telegram/SourceFiles/media/player/media_player_float.cpp b/Telegram/SourceFiles/media/player/media_player_float.cpp index dee65dd14..a2d5d861c 100644 --- a/Telegram/SourceFiles/media/player/media_player_float.cpp +++ b/Telegram/SourceFiles/media/player/media_player_float.cpp @@ -458,7 +458,7 @@ std::optional FloatController::filterWheelEvent( } void FloatController::updatePosition(not_null instance) { - auto visible = instance->visibleAnimation.current(instance->visible ? 1. : 0.); + auto visible = instance->visibleAnimation.value(instance->visible ? 1. : 0.); if (visible == 0. && !instance->visible) { instance->widget->hide(); if (instance->widget->detached()) { @@ -474,7 +474,7 @@ void FloatController::updatePosition(not_null instance) { instance->widget->show(); } - auto dragged = instance->draggedAnimation.current(1.); + auto dragged = instance->draggedAnimation.value(1.); auto position = QPoint(); if (instance->hiddenByDrag) { instance->widget->setOpacity(instance->widget->countOpacityByParent()); @@ -604,7 +604,7 @@ void FloatController::finishDrag(not_null instance, bool closed) { instance->column = Auth().settings().floatPlayerColumn(); instance->corner = Auth().settings().floatPlayerCorner(); - instance->draggedAnimation.finish(); + instance->draggedAnimation.stop(); instance->draggedAnimation.start( [=] { updatePosition(instance); }, 0., diff --git a/Telegram/SourceFiles/media/player/media_player_float.h b/Telegram/SourceFiles/media/player/media_player_float.h index d03a8c22f..28580d40f 100644 --- a/Telegram/SourceFiles/media/player/media_player_float.h +++ b/Telegram/SourceFiles/media/player/media_player_float.h @@ -8,6 +8,7 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL #pragma once #include "ui/rp_widget.h" +#include "ui/effects/animations.h" namespace Window { class Controller; @@ -200,11 +201,11 @@ private: bool hiddenByHistory = false; bool visible = false; RectPart animationSide; - Animation visibleAnimation; + Ui::Animations::Simple visibleAnimation; Window::Column column; RectPart corner; QPoint dragFrom; - Animation draggedAnimation; + Ui::Animations::Simple draggedAnimation; bool hiddenByDrag = false; object_ptr widget; }; diff --git a/Telegram/SourceFiles/media/player/media_player_panel.cpp b/Telegram/SourceFiles/media/player/media_player_panel.cpp index 38a4e6650..545b40ae5 100644 --- a/Telegram/SourceFiles/media/player/media_player_panel.cpp +++ b/Telegram/SourceFiles/media/player/media_player_panel.cpp @@ -138,9 +138,9 @@ void Panel::paintEvent(QPaintEvent *e) { Painter p(this); if (!_cache.isNull()) { - bool animating = _a_appearance.animating(crl::now()); + bool animating = _a_appearance.animating(); if (animating) { - p.setOpacity(_a_appearance.current(_hiding ? 0. : 1.)); + p.setOpacity(_a_appearance.value(_hiding ? 0. : 1.)); } else if (_hiding || isHidden()) { hideFinished(); return; @@ -168,7 +168,7 @@ void Panel::enterEventHook(QEvent *e) { if (_ignoringEnterEvents || contentTooSmall()) return; _hideTimer.cancel(); - if (_a_appearance.animating(crl::now())) { + if (_a_appearance.animating()) { startShow(); } else { _showTimer.callOnce(0); @@ -181,7 +181,7 @@ void Panel::leaveEventHook(QEvent *e) { return; } _showTimer.cancel(); - if (_a_appearance.animating(crl::now())) { + if (_a_appearance.animating()) { startHide(); } else { _hideTimer.callOnce(300); @@ -191,7 +191,7 @@ void Panel::leaveEventHook(QEvent *e) { void Panel::showFromOther() { _hideTimer.cancel(); - if (_a_appearance.animating(crl::now())) { + if (_a_appearance.animating()) { startShow(); } else { _showTimer.callOnce(300); @@ -200,7 +200,7 @@ void Panel::showFromOther() { void Panel::hideFromOther() { _showTimer.cancel(); - if (_a_appearance.animating(crl::now())) { + if (_a_appearance.animating()) { startHide(); } else { _hideTimer.callOnce(0); diff --git a/Telegram/SourceFiles/media/player/media_player_panel.h b/Telegram/SourceFiles/media/player/media_player_panel.h index 766b514de..060c9ac2f 100644 --- a/Telegram/SourceFiles/media/player/media_player_panel.h +++ b/Telegram/SourceFiles/media/player/media_player_panel.h @@ -9,6 +9,7 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL #include "base/timer.h" #include "ui/rp_widget.h" +#include "ui/effects/animations.h" #include "info/info_controller.h" namespace Window { @@ -90,7 +91,7 @@ private: bool _hiding = false; QPixmap _cache; - Animation _a_appearance; + Ui::Animations::Simple _a_appearance; bool _ignoringEnterEvents = false; diff --git a/Telegram/SourceFiles/media/player/media_player_volume_controller.cpp b/Telegram/SourceFiles/media/player/media_player_volume_controller.cpp index 5191ace15..daeaf85f6 100644 --- a/Telegram/SourceFiles/media/player/media_player_volume_controller.cpp +++ b/Telegram/SourceFiles/media/player/media_player_volume_controller.cpp @@ -117,9 +117,9 @@ void VolumeWidget::paintEvent(QPaintEvent *e) { Painter p(this); if (!_cache.isNull()) { - bool animating = _a_appearance.animating(crl::now()); + bool animating = _a_appearance.animating(); if (animating) { - p.setOpacity(_a_appearance.current(_hiding)); + p.setOpacity(_a_appearance.value(_hiding ? 0. : 1.)); } else if (_hiding || isHidden()) { hidingFinished(); return; @@ -142,7 +142,7 @@ void VolumeWidget::paintEvent(QPaintEvent *e) { void VolumeWidget::enterEventHook(QEvent *e) { _hideTimer.stop(); - if (_a_appearance.animating(crl::now())) { + if (_a_appearance.animating()) { onShowStart(); } else { _showTimer.start(0); @@ -152,7 +152,7 @@ void VolumeWidget::enterEventHook(QEvent *e) { void VolumeWidget::leaveEventHook(QEvent *e) { _showTimer.stop(); - if (_a_appearance.animating(crl::now())) { + if (_a_appearance.animating()) { onHideStart(); } else { _hideTimer.start(300); @@ -162,7 +162,7 @@ void VolumeWidget::leaveEventHook(QEvent *e) { void VolumeWidget::otherEnter() { _hideTimer.stop(); - if (_a_appearance.animating(crl::now())) { + if (_a_appearance.animating()) { onShowStart(); } else { _showTimer.start(0); @@ -171,7 +171,7 @@ void VolumeWidget::otherEnter() { void VolumeWidget::otherLeave() { _showTimer.stop(); - if (_a_appearance.animating(crl::now())) { + if (_a_appearance.animating()) { onHideStart(); } else { _hideTimer.start(0); @@ -196,14 +196,16 @@ void VolumeWidget::onHideStart() { } void VolumeWidget::startAnimation() { - auto from = _hiding ? 1. : 0.; - auto to = _hiding ? 0. : 1.; if (_cache.isNull()) { showChildren(); _cache = Ui::GrabWidget(this); } hideChildren(); - _a_appearance.start([this] { appearanceCallback(); }, from, to, st::defaultInnerDropdown.duration); + _a_appearance.start( + [=] { appearanceCallback(); }, + _hiding ? 1. : 0., + _hiding ? 0. : 1., + st::defaultInnerDropdown.duration); } void VolumeWidget::appearanceCallback() { diff --git a/Telegram/SourceFiles/media/player/media_player_volume_controller.h b/Telegram/SourceFiles/media/player/media_player_volume_controller.h index f5e54285a..7d5e761ae 100644 --- a/Telegram/SourceFiles/media/player/media_player_volume_controller.h +++ b/Telegram/SourceFiles/media/player/media_player_volume_controller.h @@ -7,6 +7,8 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL */ #pragma once +#include "ui/effects/animations.h" + namespace Ui { class IconButton; class MediaSlider; @@ -66,7 +68,7 @@ private: bool _hiding = false; QPixmap _cache; - Animation _a_appearance; + Ui::Animations::Simple _a_appearance; QTimer _hideTimer, _showTimer; diff --git a/Telegram/SourceFiles/media/player/media_player_widget.cpp b/Telegram/SourceFiles/media/player/media_player_widget.cpp index 4b067f806..1f635c5ad 100644 --- a/Telegram/SourceFiles/media/player/media_player_widget.cpp +++ b/Telegram/SourceFiles/media/player/media_player_widget.cpp @@ -62,7 +62,7 @@ Widget::PlayButton::PlayButton(QWidget *parent) : Ui::RippleButton(parent, st::m void Widget::PlayButton::paintEvent(QPaintEvent *e) { Painter p(this); - paintRipple(p, st::mediaPlayerButton.rippleAreaPosition.x(), st::mediaPlayerButton.rippleAreaPosition.y(), crl::now()); + paintRipple(p, st::mediaPlayerButton.rippleAreaPosition.x(), st::mediaPlayerButton.rippleAreaPosition.y()); p.translate(st::mediaPlayerButtonPosition.x(), st::mediaPlayerButtonPosition.y()); _layout.paint(p, st::mediaPlayerActiveFg); } diff --git a/Telegram/SourceFiles/media/view/media_view_group_thumbs.cpp b/Telegram/SourceFiles/media/view/media_view_group_thumbs.cpp index 7a76ddb78..2bace1d44 100644 --- a/Telegram/SourceFiles/media/view/media_view_group_thumbs.cpp +++ b/Telegram/SourceFiles/media/view/media_view_group_thumbs.cpp @@ -624,7 +624,7 @@ void GroupThumbs::clear() { } void GroupThumbs::startDelayedAnimation() { - _animation.finish(); + _animation.stop(); _waitingForAnimationStart = true; countUpdatedRect(); } @@ -661,15 +661,10 @@ void GroupThumbs::update() { _updateRequests.fire_copy(_updatedRect); } -void GroupThumbs::paint( - Painter &p, - int x, - int y, - int outerWidth, - crl::time ms) { +void GroupThumbs::paint(Painter &p, int x, int y, int outerWidth) { const auto progress = _waitingForAnimationStart ? 0. - : _animation.current(ms, 1.); + : _animation.value(1.); x += (_width / 2); y += st::mediaviewGroupPadding.top(); for (auto i = _cache.begin(); i != _cache.end();) { diff --git a/Telegram/SourceFiles/media/view/media_view_group_thumbs.h b/Telegram/SourceFiles/media/view/media_view_group_thumbs.h index 1aff8cb8f..dfd54da50 100644 --- a/Telegram/SourceFiles/media/view/media_view_group_thumbs.h +++ b/Telegram/SourceFiles/media/view/media_view_group_thumbs.h @@ -8,6 +8,7 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL #pragma once #include "history/history_item_components.h" +#include "ui/effects/animations.h" #include "base/weak_ptr.h" class SharedMediaWithLastSlice; @@ -57,7 +58,7 @@ public: bool hidden() const; void checkForAnimationStart(); - void paint(Painter &p, int x, int y, int outerWidth, crl::time ms); + void paint(Painter &p, int x, int y, int outerWidth); ClickHandlerPtr getState(QPoint point) const; rpl::producer updateRequests() const { @@ -112,7 +113,7 @@ private: Context _context; bool _waitingForAnimationStart = true; - Animation _animation; + Ui::Animations::Simple _animation; std::vector> _items; std::vector> _dying; base::flat_map> _cache; diff --git a/Telegram/SourceFiles/media/view/media_view_overlay_widget.cpp b/Telegram/SourceFiles/media/view/media_view_overlay_widget.cpp index 93737074e..c698200db 100644 --- a/Telegram/SourceFiles/media/view/media_view_overlay_widget.cpp +++ b/Telegram/SourceFiles/media/view/media_view_overlay_widget.cpp @@ -2652,8 +2652,7 @@ void OverlayWidget::paintEvent(QPaintEvent *e) { p, _groupThumbsLeft, _groupThumbsTop, - width(), - ms); + width()); if (_groupThumbs->hidden()) { _groupThumbs = nullptr; _groupThumbsRect = QRect(); diff --git a/Telegram/SourceFiles/overview/overview_layout.cpp b/Telegram/SourceFiles/overview/overview_layout.cpp index 87960e539..c40991c1c 100644 --- a/Telegram/SourceFiles/overview/overview_layout.cpp +++ b/Telegram/SourceFiles/overview/overview_layout.cpp @@ -72,7 +72,7 @@ public: , _check(st, _updateCallback) { } - void paint(Painter &p, crl::time ms, QPoint position, int outerWidth, bool selected, bool selecting); + void paint(Painter &p, QPoint position, int outerWidth, bool selected, bool selecting); void setActive(bool active); void setPressed(bool pressed); @@ -87,18 +87,18 @@ private: Fn _updateCallback; Ui::RoundCheckbox _check; - Animation _pression; + Ui::Animations::Simple _pression; bool _active = false; bool _pressed = false; }; -void Checkbox::paint(Painter &p, crl::time ms, QPoint position, int outerWidth, bool selected, bool selecting) { +void Checkbox::paint(Painter &p, QPoint position, int outerWidth, bool selected, bool selecting) { _check.setDisplayInactive(selecting); _check.setChecked(selected); - const auto pression = _pression.current(ms, (_active && _pressed) ? 1. : 0.); + const auto pression = _pression.value((_active && _pressed) ? 1. : 0.); const auto masterScale = 1. - (1. - st::overviewCheckPressedSize) * pression; - _check.paint(p, ms, position.x(), position.y(), outerWidth, masterScale); + _check.paint(p, position.x(), position.y(), outerWidth, masterScale); } void Checkbox::setActive(bool active) { @@ -167,7 +167,7 @@ void ItemBase::paintCheckbox( ensureCheckboxCreated(); } if (_check) { - _check->paint(p, context->ms, position, _width, selected, context->selecting); + _check->paint(p, position, _width, selected, context->selecting); } } @@ -491,7 +491,7 @@ void Video::paint(Painter &p, const QRect &clip, TextSelection selection, const p.setBrush(st::msgDateImgBgSelected); } else { auto over = ClickHandler::showAsActive((_data->loading() || _data->uploading()) ? _cancell : (loaded || _data->canBePlayed()) ? _openl : _savel); - p.setBrush(anim::brush(st::msgDateImgBg, st::msgDateImgBgOver, _a_iconOver.current(context->ms, over ? 1. : 0.))); + p.setBrush(anim::brush(st::msgDateImgBg, st::msgDateImgBgOver, _a_iconOver.value(over ? 1. : 0.))); } { @@ -670,10 +670,10 @@ void Voice::paint(Painter &p, const QRect &clip, TextSelection selection, const p.setBrush((thumbLoaded || blurred) ? st::msgDateImgBgSelected : st::msgFileInBgSelected); } else if (_data->hasThumbnail()) { auto over = ClickHandler::showAsActive(checkLink); - p.setBrush(anim::brush(st::msgDateImgBg, st::msgDateImgBgOver, _a_iconOver.current(context->ms, over ? 1. : 0.))); + p.setBrush(anim::brush(st::msgDateImgBg, st::msgDateImgBgOver, _a_iconOver.value(over ? 1. : 0.))); } else { auto over = ClickHandler::showAsActive(checkLink); - p.setBrush(anim::brush(st::msgFileInBg, st::msgFileInBgOver, _a_iconOver.current(context->ms, over ? 1. : 0.))); + p.setBrush(anim::brush(st::msgFileInBg, st::msgFileInBgOver, _a_iconOver.value(over ? 1. : 0.))); } { PainterHighQualityEnabler hq(p); @@ -948,7 +948,7 @@ void Document::paint(Painter &p, const QRect &clip, TextSelection selection, con p.setBrush(st::msgFileInBgSelected); } else { auto over = ClickHandler::showAsActive((!cornerDownload && (_data->loading() || _data->uploading())) ? _cancell : (loaded || _data->canBePlayed()) ? _openl : _savel); - p.setBrush(anim::brush(_st.songIconBg, _st.songOverBg, _a_iconOver.current(context->ms, over ? 1. : 0.))); + p.setBrush(anim::brush(_st.songIconBg, _st.songOverBg, _a_iconOver.value(over ? 1. : 0.))); } { @@ -1026,7 +1026,7 @@ void Document::paint(Painter &p, const QRect &clip, TextSelection selection, con p.setBrush(wthumb ? st::msgDateImgBgSelected : documentSelectedColor(_colorIndex)); } else { auto over = ClickHandler::showAsActive(_data->loading() ? _cancell : _savel); - p.setBrush(anim::brush(wthumb ? st::msgDateImgBg : documentDarkColor(_colorIndex), wthumb ? st::msgDateImgBgOver : documentOverColor(_colorIndex), _a_iconOver.current(context->ms, over ? 1. : 0.))); + p.setBrush(anim::brush(wthumb ? st::msgDateImgBg : documentDarkColor(_colorIndex), wthumb ? st::msgDateImgBgOver : documentOverColor(_colorIndex), _a_iconOver.value(over ? 1. : 0.))); } p.setOpacity(radialOpacity * p.opacity()); diff --git a/Telegram/SourceFiles/overview/overview_layout.h b/Telegram/SourceFiles/overview/overview_layout.h index cfaabedbf..95c807b59 100644 --- a/Telegram/SourceFiles/overview/overview_layout.h +++ b/Telegram/SourceFiles/overview/overview_layout.h @@ -9,6 +9,7 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL #include "layout.h" #include "core/click_handler_types.h" +#include "ui/effects/animations.h" #include "ui/effects/radial_animation.h" #include "styles/style_overview.h" @@ -148,7 +149,7 @@ protected: } mutable std::unique_ptr _radial; - Animation _a_iconOver; + Ui::Animations::Simple _a_iconOver; }; diff --git a/Telegram/SourceFiles/passport/passport_panel_details_row.cpp b/Telegram/SourceFiles/passport/passport_panel_details_row.cpp index 6006d1101..5405ce5b8 100644 --- a/Telegram/SourceFiles/passport/passport_panel_details_row.cpp +++ b/Telegram/SourceFiles/passport/passport_panel_details_row.cpp @@ -124,7 +124,7 @@ private: object_ptr _link; rpl::variable _value; bool _errorShown = false; - Animation _errorAnimation; + Ui::Animations::Simple _errorAnimation; }; @@ -197,14 +197,14 @@ private: rpl::variable _value; style::cursor _cursor = style::cur_default; - Animation _a_borderShown; + Ui::Animations::Simple _a_borderShown; int _borderAnimationStart = 0; - Animation _a_borderOpacity; + Ui::Animations::Simple _a_borderOpacity; bool _borderVisible = false; - Animation _a_error; + Ui::Animations::Simple _a_error; bool _error = false; - Animation _a_focused; + Ui::Animations::Simple _a_focused; bool _focused = false; }; @@ -248,7 +248,7 @@ private: rpl::variable _value; bool _errorShown = false; - Animation _errorAnimation; + Ui::Animations::Simple _errorAnimation; }; @@ -344,7 +344,7 @@ void CountryRow::showInnerError() { void CountryRow::finishInnerAnimating() { if (_errorAnimation.animating()) { - _errorAnimation.finish(); + _errorAnimation.stop(); errorAnimationCallback(); } } @@ -365,7 +365,7 @@ void CountryRow::toggleError(bool shown) { } void CountryRow::errorAnimationCallback() { - const auto error = _errorAnimation.current(_errorShown ? 1. : 0.); + const auto error = _errorAnimation.value(_errorShown ? 1. : 0.); if (error == 0.) { _link->setColorOverride(std::nullopt); } else { @@ -676,11 +676,10 @@ void DateRow::paintEvent(QPaintEvent *e) { if (_st.border) { p.fillRect(0, height - _st.border, width, _st.border, _st.borderFg); } - const auto ms = crl::now(); - auto errorDegree = _a_error.current(ms, _error ? 1. : 0.); - auto focusedDegree = _a_focused.current(ms, _focused ? 1. : 0.); - auto borderShownDegree = _a_borderShown.current(ms, 1.); - auto borderOpacity = _a_borderOpacity.current(ms, _borderVisible ? 1. : 0.); + auto errorDegree = _a_error.value(_error ? 1. : 0.); + auto focusedDegree = _a_focused.value(_focused ? 1. : 0.); + auto borderShownDegree = _a_borderShown.value(1.); + auto borderOpacity = _a_borderOpacity.value(_borderVisible ? 1. : 0.); if (_st.borderActive && (borderOpacity > 0.)) { auto borderStart = snap(_borderAnimationStart, 0, width); auto borderFrom = qRound(borderStart * (1. - borderShownDegree)); @@ -818,9 +817,9 @@ void DateRow::finishInnerAnimating() { _day->finishAnimating(); _month->finishAnimating(); _year->finishAnimating(); - _a_borderOpacity.finish(); - _a_borderShown.finish(); - _a_error.finish(); + _a_borderOpacity.stop(); + _a_borderShown.stop(); + _a_error.stop(); } void DateRow::startBorderAnimation() { @@ -914,7 +913,7 @@ void GenderRow::showInnerError() { void GenderRow::finishInnerAnimating() { if (_errorAnimation.animating()) { - _errorAnimation.finish(); + _errorAnimation.stop(); errorAnimationCallback(); } } @@ -935,7 +934,7 @@ void GenderRow::toggleError(bool shown) { } void GenderRow::errorAnimationCallback() { - const auto error = _errorAnimation.current(_errorShown ? 1. : 0.); + const auto error = _errorAnimation.value(_errorShown ? 1. : 0.); if (error == 0.) { _maleRadio->setUntoggledOverride(std::nullopt); _femaleRadio->setUntoggledOverride(std::nullopt); @@ -1107,7 +1106,7 @@ void PanelDetailsRow::finishAnimating() { _error->finishAnimating(); } if (_errorAnimation.animating()) { - _errorAnimation.finish(); + _errorAnimation.stop(); update(); } } @@ -1115,8 +1114,7 @@ void PanelDetailsRow::finishAnimating() { void PanelDetailsRow::paintEvent(QPaintEvent *e) { Painter p(this); - const auto ms = crl::now(); - const auto error = _errorAnimation.current(ms, _errorShown ? 1. : 0.); + const auto error = _errorAnimation.value(_errorShown ? 1. : 0.); p.setFont(st::semiboldFont); p.setPen(anim::pen( st::passportDetailsField.placeholderFg, diff --git a/Telegram/SourceFiles/passport/passport_panel_details_row.h b/Telegram/SourceFiles/passport/passport_panel_details_row.h index 73ed0cfbb..fc0204967 100644 --- a/Telegram/SourceFiles/passport/passport_panel_details_row.h +++ b/Telegram/SourceFiles/passport/passport_panel_details_row.h @@ -8,6 +8,7 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL #pragma once #include "ui/rp_widget.h" +#include "ui/effects/animations.h" #include "ui/wrap/padding_wrap.h" #include "ui/widgets/labels.h" #include "boxes/abstract_box.h" @@ -76,7 +77,7 @@ private: object_ptr> _error = { nullptr }; bool _errorShown = false; bool _errorHideSubscription = false; - Animation _errorAnimation; + Ui::Animations::Simple _errorAnimation; }; diff --git a/Telegram/SourceFiles/passport/passport_panel_edit_scans.cpp b/Telegram/SourceFiles/passport/passport_panel_edit_scans.cpp index 2628ce44d..e6b0afded 100644 --- a/Telegram/SourceFiles/passport/passport_panel_edit_scans.cpp +++ b/Telegram/SourceFiles/passport/passport_panel_edit_scans.cpp @@ -119,7 +119,7 @@ struct EditScans::SpecialScan { base::unique_qptr> row; QPointer upload; bool errorShown = false; - Animation errorAnimation; + Ui::Animations::Simple errorAnimation; rpl::variable rowCreated; }; @@ -231,7 +231,7 @@ void EditScans::List::toggleError(bool shown) { } void EditScans::List::errorAnimationCallback() { - const auto error = errorAnimation.current(errorShown ? 1. : 0.); + const auto error = errorAnimation.value(errorShown ? 1. : 0.); if (error == 0.) { upload->setColorOverride(std::nullopt); } else { @@ -972,7 +972,7 @@ void EditScans::toggleSpecialScanError(FileType type, bool shown) { void EditScans::specialScanErrorAnimationCallback(FileType type) { auto &scan = findSpecialScan(type); - const auto error = scan.errorAnimation.current( + const auto error = scan.errorAnimation.value( scan.errorShown ? 1. : 0.); if (error == 0.) { scan.upload->setColorOverride(std::nullopt); diff --git a/Telegram/SourceFiles/passport/passport_panel_edit_scans.h b/Telegram/SourceFiles/passport/passport_panel_edit_scans.h index 676ccef87..fc8fee23b 100644 --- a/Telegram/SourceFiles/passport/passport_panel_edit_scans.h +++ b/Telegram/SourceFiles/passport/passport_panel_edit_scans.h @@ -8,6 +8,7 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL #pragma once #include "ui/rp_widget.h" +#include "ui/effects/animations.h" class BoxContentDivider; @@ -102,7 +103,7 @@ private: QPointer upload; rpl::event_stream> uploadTexts; bool errorShown = false; - Animation errorAnimation; + Ui::Animations::Simple errorAnimation; }; List &list(FileType type); diff --git a/Telegram/SourceFiles/passport/passport_panel_form.cpp b/Telegram/SourceFiles/passport/passport_panel_form.cpp index db51a81dc..6d73697ac 100644 --- a/Telegram/SourceFiles/passport/passport_panel_form.cpp +++ b/Telegram/SourceFiles/passport/passport_panel_form.cpp @@ -12,6 +12,7 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL #include "boxes/abstract_box.h" #include "core/click_handler_types.h" #include "data/data_user.h" +#include "ui/effects/animations.h" #include "ui/widgets/shadow.h" #include "ui/widgets/buttons.h" #include "ui/widgets/scroll_area.h" @@ -52,7 +53,7 @@ private: int _descriptionHeight = 0; bool _ready = false; bool _error = false; - Animation _errorAnimation; + Ui::Animations::Simple _errorAnimation; }; @@ -85,7 +86,7 @@ void PanelForm::Row::updateContent( if (_error != error) { _error = error; if (animated == anim::type::instant) { - _errorAnimation.finish(); + _errorAnimation.stop(); } else { _errorAnimation.start( [=] { update(); }, @@ -127,14 +128,13 @@ int PanelForm::Row::countAvailableWidth() const { void PanelForm::Row::paintEvent(QPaintEvent *e) { Painter p(this); - const auto ms = crl::now(); - paintRipple(p, 0, 0, ms); + paintRipple(p, 0, 0); const auto left = st::passportRowPadding.left(); const auto availableWidth = countAvailableWidth(); auto top = st::passportRowPadding.top(); - const auto error = _errorAnimation.current(ms, _error ? 1. : 0.); + const auto error = _errorAnimation.value(_error ? 1. : 0.); p.setPen(st::passportRowTitleFg); _title.drawLeft(p, left, top, availableWidth, width()); diff --git a/Telegram/SourceFiles/profile/profile_block_peer_list.cpp b/Telegram/SourceFiles/profile/profile_block_peer_list.cpp index 5a5cfb0d7..4cffb8ded 100644 --- a/Telegram/SourceFiles/profile/profile_block_peer_list.cpp +++ b/Telegram/SourceFiles/profile/profile_block_peer_list.cpp @@ -50,7 +50,6 @@ void PeerListWidget::visibleTopBottomUpdated(int visibleTop, int visibleBottom) } void PeerListWidget::paintContents(Painter &p) { - auto ms = crl::now(); auto left = getListLeft(); auto top = getListTop(); auto memberRowWidth = rowWidth(); @@ -64,11 +63,11 @@ void PeerListWidget::paintContents(Painter &p) { if (_pressed >= 0 && !_pressedRemove) { selectedRemove = false; } - paintItem(p, left, y, _items[i], selected, selectedRemove, ms); + paintItem(p, left, y, _items[i], selected, selectedRemove); } } -void PeerListWidget::paintItem(Painter &p, int x, int y, Item *item, bool selected, bool selectedKick, crl::time ms) { +void PeerListWidget::paintItem(Painter &p, int x, int y, Item *item, bool selected, bool selectedKick) { if (_updateItemCallback) { _updateItemCallback(item); } @@ -78,7 +77,7 @@ void PeerListWidget::paintItem(Painter &p, int x, int y, Item *item, bool select paintOutlinedRect(p, x, y, memberRowWidth, _st.height); } if (auto &ripple = item->ripple) { - ripple->paint(p, x + _st.button.outlineWidth, y, width(), ms); + ripple->paint(p, x + _st.button.outlineWidth, y, width()); if (ripple->empty()) { ripple.reset(); } diff --git a/Telegram/SourceFiles/profile/profile_block_peer_list.h b/Telegram/SourceFiles/profile/profile_block_peer_list.h index eed0e5e61..d834780d3 100644 --- a/Telegram/SourceFiles/profile/profile_block_peer_list.h +++ b/Telegram/SourceFiles/profile/profile_block_peer_list.h @@ -119,7 +119,7 @@ private: void preloadPhotos(); int rowWidth() const; - void paintItem(Painter &p, int x, int y, Item *item, bool selected, bool selectedRemove, crl::time ms); + void paintItem(Painter &p, int x, int y, Item *item, bool selected, bool selectedRemove); const style::PeerListItem &_st; diff --git a/Telegram/SourceFiles/profile/profile_cover_drop_area.cpp b/Telegram/SourceFiles/profile/profile_cover_drop_area.cpp index 8d5111d2b..d1513eda8 100644 --- a/Telegram/SourceFiles/profile/profile_cover_drop_area.cpp +++ b/Telegram/SourceFiles/profile/profile_cover_drop_area.cpp @@ -33,8 +33,8 @@ void CoverDropArea::hideAnimated(HideFinishCallback &&callback) { void CoverDropArea::paintEvent(QPaintEvent *e) { Painter p(this); - if (_a_appearance.animating(crl::now())) { - p.setOpacity(_a_appearance.current()); + if (_a_appearance.animating()) { + p.setOpacity(_a_appearance.value(_hiding ? 0. : 1.)); p.drawPixmap(0, 0, _cache); return; } @@ -82,7 +82,7 @@ void CoverDropArea::setupAnimation() { } auto from = _hiding ? 1. : 0., to = _hiding ? 0. : 1.; _a_appearance.start( - [this] { update(); }, + [=] { update(); }, from, to, st::profileDropAreaDuration); diff --git a/Telegram/SourceFiles/profile/profile_cover_drop_area.h b/Telegram/SourceFiles/profile/profile_cover_drop_area.h index c6b0fef70..c757c510e 100644 --- a/Telegram/SourceFiles/profile/profile_cover_drop_area.h +++ b/Telegram/SourceFiles/profile/profile_cover_drop_area.h @@ -7,6 +7,8 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL */ #pragma once +#include "ui/effects/animations.h" + namespace Profile { class CoverDropArea : public TWidget { @@ -32,7 +34,7 @@ private: int _titleWidth, _subtitleWidth; QPixmap _cache; - Animation _a_appearance; + Ui::Animations::Simple _a_appearance; bool _hiding = false; HideFinishCallback _hideFinishCallback; diff --git a/Telegram/SourceFiles/settings/settings_chat.cpp b/Telegram/SourceFiles/settings/settings_chat.cpp index 20681f43c..fbac5a6e4 100644 --- a/Telegram/SourceFiles/settings/settings_chat.cpp +++ b/Telegram/SourceFiles/settings/settings_chat.cpp @@ -93,8 +93,7 @@ public: Painter &p, int left, int top, - int outerWidth, - crl::time ms) override; + int outerWidth) override; QImage prepareRippleMask() const override; bool checkRippleStartPosition(QPoint position) const override; @@ -319,8 +318,7 @@ void DefaultTheme::paint( Painter &p, int left, int top, - int outerWidth, - crl::time ms) { + int outerWidth) { const auto received = QRect( st::settingsThemeBubblePosition, st::settingsThemeBubbleSize); @@ -347,8 +345,7 @@ void DefaultTheme::paint( p, (outerWidth - radio.width()) / 2, getSize().height() - radio.height() - st::settingsThemeRadioBottom, - outerWidth, - crl::now()); + outerWidth); } QImage DefaultTheme::prepareRippleMask() const { @@ -799,7 +796,7 @@ void SetupDefaultThemes(not_null container) { return Type(-1); } const auto path = Window::Theme::Background()->themeAbsolutePath(); - for (const auto scheme : schemes) { + for (const auto &scheme : schemes) { if (path == scheme.path) { return scheme.type; } diff --git a/Telegram/SourceFiles/settings/settings_notifications.cpp b/Telegram/SourceFiles/settings/settings_notifications.cpp index 1613aee25..154cfa9c5 100644 --- a/Telegram/SourceFiles/settings/settings_notifications.cpp +++ b/Telegram/SourceFiles/settings/settings_notifications.cpp @@ -8,6 +8,7 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL #include "settings/settings_notifications.h" #include "settings/settings_common.h" +#include "ui/effects/animations.h" #include "ui/wrap/vertical_layout.h" #include "ui/wrap/slide_wrap.h" #include "ui/widgets/checkbox.h" @@ -74,7 +75,7 @@ private: QPixmap _notificationSampleSmall; QPixmap _notificationSampleLarge; ScreenCorner _chosenCorner; - std::vector _sampleOpacities; + std::vector _sampleOpacities; bool _isOverCorner = false; ScreenCorner _overCorner = ScreenCorner::TopLeft; @@ -106,7 +107,7 @@ private: NotificationsCount *_owner; QPixmap _cache; - Animation _opacity; + Ui::Animations::Simple _opacity; bool _hiding = false; bool _deleted = false; @@ -148,7 +149,7 @@ void NotificationsCount::paintEvent(QPaintEvent *e) { if (corner == static_cast(_chosenCorner)) { auto count = _oldCount; for (int i = 0; i != kMaxNotificationsCount; ++i) { - auto opacity = _sampleOpacities[i].current(crl::now(), (i < count) ? 1. : 0.); + auto opacity = _sampleOpacities[i].value((i < count) ? 1. : 0.); p.setOpacity(opacity); p.drawPixmapLeft(sampleLeft, sampleTop, width(), _notificationSampleSmall); sampleTop += (isTop ? 1 : -1) * (st::notificationSampleSize.height() + st::notificationsSampleMargin); @@ -463,7 +464,7 @@ void NotificationsCount::SampleWidget::startAnimation() { } void NotificationsCount::SampleWidget::animationCallback() { - setWindowOpacity(_opacity.current(_hiding ? 0. : 1.)); + setWindowOpacity(_opacity.value(_hiding ? 0. : 1.)); if (!_opacity.animating() && _hiding) { if (_owner) { _owner->removeSample(this); diff --git a/Telegram/SourceFiles/ui/animation.h b/Telegram/SourceFiles/ui/animation.h index 19f244ce3..24fe812cc 100644 --- a/Telegram/SourceFiles/ui/animation.h +++ b/Telegram/SourceFiles/ui/animation.h @@ -660,13 +660,6 @@ public: } } - template - void setUpdateCallback(Lambda &&updateCallback) { - if (_data) { - _data->updateCallback = std::forward(updateCallback); - } - } - private: struct Data { template diff --git a/Telegram/SourceFiles/ui/countryinput.cpp b/Telegram/SourceFiles/ui/countryinput.cpp index 0b18b36f8..c644bf9c2 100644 --- a/Telegram/SourceFiles/ui/countryinput.cpp +++ b/Telegram/SourceFiles/ui/countryinput.cpp @@ -345,7 +345,6 @@ void CountrySelectBox::Inner::paintEvent(QPaintEvent *e) { QRect r(e->rect()); p.setClipRect(r); - auto ms = crl::now(); int l = countriesNow->size(); if (l) { if (r.intersects(QRect(0, 0, width(), st::countriesSkip))) { @@ -359,7 +358,7 @@ void CountrySelectBox::Inner::paintEvent(QPaintEvent *e) { p.fillRect(0, y, width(), _rowHeight, selected ? st::countryRowBgOver : st::countryRowBg); if (_ripples.size() > i && _ripples[i]) { - _ripples[i]->paint(p, 0, y, width(), ms); + _ripples[i]->paint(p, 0, y, width()); if (_ripples[i]->empty()) { _ripples[i].reset(); } diff --git a/Telegram/SourceFiles/ui/effects/fade_animation.h b/Telegram/SourceFiles/ui/effects/fade_animation.h index 96afd5c47..bff9eb616 100644 --- a/Telegram/SourceFiles/ui/effects/fade_animation.h +++ b/Telegram/SourceFiles/ui/effects/fade_animation.h @@ -7,9 +7,9 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL */ #pragma once -#include "styles/style_widgets.h" #include "ui/rp_widget.h" #include "ui/effects/animations.h" +#include "styles/style_widgets.h" namespace Ui { diff --git a/Telegram/SourceFiles/ui/effects/numbers_animation.cpp b/Telegram/SourceFiles/ui/effects/numbers_animation.cpp index baa962389..0af4ba6ed 100644 --- a/Telegram/SourceFiles/ui/effects/numbers_animation.cpp +++ b/Telegram/SourceFiles/ui/effects/numbers_animation.cpp @@ -23,7 +23,7 @@ NumbersAnimation::NumbersAnimation( } void NumbersAnimation::setText(const QString &text, int value) { - if (_a_ready.animating(crl::now())) { + if (_a_ready.animating()) { _delayedText = text; _delayedValue = value; } else { @@ -89,20 +89,16 @@ int NumbersAnimation::countWidth() const { return anim::interpolate( _fromWidth, _toWidth, - anim::easeOutCirc(1., _a_ready.current(1.))); + anim::easeOutCirc(1., _a_ready.value(1.))); } int NumbersAnimation::maxWidth() const { return std::max(_fromWidth, _toWidth); } -void NumbersAnimation::stepAnimation(crl::time ms) { - _a_ready.step(ms); -} - void NumbersAnimation::finishAnimating() { auto width = countWidth(); - _a_ready.finish(); + _a_ready.stop(); if (_widthChangedCallback && countWidth() != width) { _widthChangedCallback(); } @@ -115,7 +111,7 @@ void NumbersAnimation::paint(Painter &p, int x, int y, int outerWidth) { auto digitsCount = _digits.size(); if (!digitsCount) return; - auto progress = anim::easeOutCirc(1., _a_ready.current(1.)); + auto progress = anim::easeOutCirc(1., _a_ready.value(1.)); auto width = anim::interpolate(_fromWidth, _toWidth, progress); QString singleChar('0'); @@ -204,7 +200,7 @@ void LabelWithNumbers::setValue(const StringWithNumbers &value) { } void LabelWithNumbers::finishAnimating() { - _beforeWidthAnimation.finish(); + _beforeWidthAnimation.stop(); _numbers.finishAnimating(); update(); } @@ -212,9 +208,7 @@ void LabelWithNumbers::finishAnimating() { void LabelWithNumbers::paintEvent(QPaintEvent *e) { Painter p(this); - const auto ms = crl::now(); - const auto beforeWidth = _beforeWidthAnimation.current(ms, _beforeWidth); - _numbers.stepAnimation(ms); + const auto beforeWidth = _beforeWidthAnimation.value(_beforeWidth); p.setFont(_st.style.font); p.setBrush(Qt::NoBrush); diff --git a/Telegram/SourceFiles/ui/effects/numbers_animation.h b/Telegram/SourceFiles/ui/effects/numbers_animation.h index 05b441269..b93efa5fb 100644 --- a/Telegram/SourceFiles/ui/effects/numbers_animation.h +++ b/Telegram/SourceFiles/ui/effects/numbers_animation.h @@ -8,6 +8,7 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL #pragma once #include "ui/rp_widget.h" +#include "ui/effects/animations.h" namespace style { struct FlatLabel; @@ -25,7 +26,6 @@ public: _widthChangedCallback = std::move(callback); } void setText(const QString &text, int value); - void stepAnimation(crl::time ms); void finishAnimating(); void paint(Painter &p, int x, int y, int outerWidth); @@ -51,7 +51,7 @@ private: int _fromWidth = 0; int _toWidth = 0; - Animation _a_ready; + Ui::Animations::Simple _a_ready; QString _delayedText; int _delayedValue = 0; @@ -99,7 +99,7 @@ private: NumbersAnimation _numbers; int _beforeWidth = 0; int _afterWidth = 0; - Animation _beforeWidthAnimation; + Ui::Animations::Simple _beforeWidthAnimation; }; diff --git a/Telegram/SourceFiles/ui/effects/ripple_animation.cpp b/Telegram/SourceFiles/ui/effects/ripple_animation.cpp index a8cf6ad2f..cb6e2d810 100644 --- a/Telegram/SourceFiles/ui/effects/ripple_animation.cpp +++ b/Telegram/SourceFiles/ui/effects/ripple_animation.cpp @@ -7,6 +7,8 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL */ #include "ui/effects/ripple_animation.h" +#include "ui/effects/animations.h" + namespace Ui { class RippleAnimation::Ripple { @@ -14,7 +16,7 @@ public: Ripple(const style::RippleAnimation &st, QPoint origin, int startRadius, const QPixmap &mask, Fn update); Ripple(const style::RippleAnimation &st, const QPixmap &mask, Fn update); - void paint(QPainter &p, const QPixmap &mask, crl::time ms, const QColor *colorOverride); + void paint(QPainter &p, const QPixmap &mask, const QColor *colorOverride); void stop(); void unstop(); @@ -33,8 +35,8 @@ private: int _radiusTo = 0; bool _hiding = false; - Animation _show; - Animation _hide; + Ui::Animations::Simple _show; + Ui::Animations::Simple _hide; QPixmap _cache; QImage _frame; @@ -73,14 +75,14 @@ RippleAnimation::Ripple::Ripple(const style::RippleAnimation &st, const QPixmap _hide.start(_update, 0., 1., _st.hideDuration); } -void RippleAnimation::Ripple::paint(QPainter &p, const QPixmap &mask, crl::time ms, const QColor *colorOverride) { - auto opacity = _hide.current(ms, _hiding ? 0. : 1.); +void RippleAnimation::Ripple::paint(QPainter &p, const QPixmap &mask, const QColor *colorOverride) { + auto opacity = _hide.value(_hiding ? 0. : 1.); if (opacity == 0.) { return; } if (_cache.isNull() || colorOverride != nullptr) { - auto radius = anim::interpolate(_radiusFrom, _radiusTo, _show.current(ms, 1.)); + auto radius = anim::interpolate(_radiusFrom, _radiusTo, _show.value(1.)); _frame.fill(Qt::transparent); { Painter p(&_frame); @@ -129,8 +131,8 @@ void RippleAnimation::Ripple::finish() { if (_update) { _update(); } - _show.finish(); - _hide.finish(); + _show.stop(); + _hide.stop(); } void RippleAnimation::Ripple::clearCache() { @@ -181,7 +183,7 @@ void RippleAnimation::forceRepaint() { } } -void RippleAnimation::paint(QPainter &p, int x, int y, int outerWidth, crl::time ms, const QColor *colorOverride) { +void RippleAnimation::paint(QPainter &p, int x, int y, int outerWidth, const QColor *colorOverride) { if (_ripples.empty()) { return; } @@ -189,7 +191,7 @@ void RippleAnimation::paint(QPainter &p, int x, int y, int outerWidth, crl::time if (rtl()) x = outerWidth - x - (_mask.width() / cIntRetinaFactor()); p.translate(x, y); for (const auto &ripple : _ripples) { - ripple->paint(p, _mask, ms, colorOverride); + ripple->paint(p, _mask, colorOverride); } p.translate(-x, -y); clearFinished(); diff --git a/Telegram/SourceFiles/ui/effects/ripple_animation.h b/Telegram/SourceFiles/ui/effects/ripple_animation.h index 237ccdbcf..5734efecf 100644 --- a/Telegram/SourceFiles/ui/effects/ripple_animation.h +++ b/Telegram/SourceFiles/ui/effects/ripple_animation.h @@ -23,7 +23,7 @@ public: void lastFinish(); void forceRepaint(); - void paint(QPainter &p, int x, int y, int outerWidth, crl::time ms, const QColor *colorOverride = nullptr); + void paint(QPainter &p, int x, int y, int outerWidth, const QColor *colorOverride = nullptr); bool empty() const { return _ripples.empty(); diff --git a/Telegram/SourceFiles/ui/effects/round_checkbox.cpp b/Telegram/SourceFiles/ui/effects/round_checkbox.cpp index 0d8f36410..1f7db3689 100644 --- a/Telegram/SourceFiles/ui/effects/round_checkbox.cpp +++ b/Telegram/SourceFiles/ui/effects/round_checkbox.cpp @@ -283,7 +283,7 @@ RoundCheckbox::RoundCheckbox(const style::RoundCheckbox &st, Fn updateCa , _updateCallback(updateCallback) { } -void RoundCheckbox::paint(Painter &p, crl::time ms, int x, int y, int outerWidth, float64 masterScale) { +void RoundCheckbox::paint(Painter &p, int x, int y, int outerWidth, float64 masterScale) { if (!_checkedProgress.animating() && !_checked && !_displayInactive) { return; } @@ -298,7 +298,7 @@ void RoundCheckbox::paint(Painter &p, crl::time ms, int x, int y, int outerWidth p.drawPixmap(inactiveTo, _inactiveCacheBg, cacheFrom); } - const auto progress = _checkedProgress.current(ms, _checked ? 1. : 0.); + const auto progress = _checkedProgress.value(_checked ? 1. : 0.); if (progress > 0.) { auto frame = FrameCaches()->frame(&_st, _displayInactive, progress); p.drawPixmap(inactiveTo, frame, cacheFrom); @@ -312,7 +312,7 @@ void RoundCheckbox::paint(Painter &p, crl::time ms, int x, int y, int outerWidth void RoundCheckbox::setChecked(bool newChecked, SetStyle speed) { if (_checked == newChecked) { if (speed != SetStyle::Animated) { - _checkedProgress.finish(); + _checkedProgress.stop(); } return; } @@ -325,7 +325,7 @@ void RoundCheckbox::setChecked(bool newChecked, SetStyle speed) { _st.duration, anim::linear); } else { - _checkedProgress.finish(); + _checkedProgress.stop(); } } @@ -385,10 +385,8 @@ RoundImageCheckbox::RoundImageCheckbox(const style::RoundImageCheckbox &st, Fn updateCallback); - void paint(Painter &p, crl::time ms, int x, int y, int outerWidth, float64 masterScale = 1.); + void paint(Painter &p, int x, int y, int outerWidth, float64 masterScale = 1.); void setDisplayInactive(bool displayInactive); bool checked() const { @@ -36,7 +37,7 @@ private: Fn _updateCallback; bool _checked = false; - Animation _checkedProgress; + Ui::Animations::Simple _checkedProgress; bool _displayInactive = false; QPixmap _inactiveCacheBg, _inactiveCacheFg; @@ -48,7 +49,7 @@ public: using PaintRoundImage = Fn; RoundImageCheckbox(const style::RoundImageCheckbox &st, Fn updateCallback, PaintRoundImage &&paintRoundImage); - void paint(Painter &p, crl::time ms, int x, int y, int outerWidth); + void paint(Painter &p, int x, int y, int outerWidth); float64 checkedAnimationRatio() const; bool checked() const { @@ -69,7 +70,7 @@ private: PaintRoundImage _paintRoundImage; QPixmap _wideCache; - Animation _selection; + Ui::Animations::Simple _selection; RoundCheckbox _check; diff --git a/Telegram/SourceFiles/ui/effects/slide_animation.cpp b/Telegram/SourceFiles/ui/effects/slide_animation.cpp index d4366c499..1dd099d75 100644 --- a/Telegram/SourceFiles/ui/effects/slide_animation.cpp +++ b/Telegram/SourceFiles/ui/effects/slide_animation.cpp @@ -18,8 +18,8 @@ void SlideAnimation::setSnapshots(QPixmap leftSnapshot, QPixmap rightSnapshot) { _rightSnapshot.setDevicePixelRatio(cRetinaFactor()); } -void SlideAnimation::paintFrame(Painter &p, int x, int y, int outerWidth, crl::time ms) { - auto dt = _animation.current(ms, 1.); +void SlideAnimation::paintFrame(Painter &p, int x, int y, int outerWidth) { + auto dt = _animation.value(1.); if (!animating()) return; auto easeOut = anim::easeOutCirc(1., dt); diff --git a/Telegram/SourceFiles/ui/effects/slide_animation.h b/Telegram/SourceFiles/ui/effects/slide_animation.h index c257a1efd..055434fca 100644 --- a/Telegram/SourceFiles/ui/effects/slide_animation.h +++ b/Telegram/SourceFiles/ui/effects/slide_animation.h @@ -7,6 +7,8 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL */ #pragma once +#include "ui/effects/animations.h" + namespace Ui { class SlideAnimation { @@ -20,14 +22,14 @@ public: template void start(bool slideLeft, Lambda &&updateCallback, float64 duration); - void paintFrame(Painter &p, int x, int y, int outerWidth, crl::time ms); + void paintFrame(Painter &p, int x, int y, int outerWidth); bool animating() const { return _animation.animating(); } private: - Animation _animation; + Ui::Animations::Simple _animation; QPixmap _leftSnapshot; QPixmap _rightSnapshot; bool _slideLeft = false; diff --git a/Telegram/SourceFiles/ui/special_buttons.cpp b/Telegram/SourceFiles/ui/special_buttons.cpp index 14c85ccf6..a8e6c81ad 100644 --- a/Telegram/SourceFiles/ui/special_buttons.cpp +++ b/Telegram/SourceFiles/ui/special_buttons.cpp @@ -151,11 +151,10 @@ QPoint HistoryDownButton::prepareRippleStartPosition() const { void HistoryDownButton::paintEvent(QPaintEvent *e) { Painter p(this); - const auto ms = crl::now(); const auto over = isOver(); const auto down = isDown(); ((over || down) ? _st.iconBelowOver : _st.iconBelow).paint(p, _st.iconPosition, width()); - paintRipple(p, _st.rippleAreaPosition.x(), _st.rippleAreaPosition.y(), ms); + paintRipple(p, _st.rippleAreaPosition.x(), _st.rippleAreaPosition.y()); ((over || down) ? _st.iconAboveOver : _st.iconAbove).paint(p, _st.iconPosition, width()); if (_unreadCount > 0) { auto unreadString = QString::number(_unreadCount); @@ -189,10 +188,8 @@ EmojiButton::EmojiButton(QWidget *parent, const style::IconButton &st) void EmojiButton::paintEvent(QPaintEvent *e) { Painter p(this); - auto ms = crl::now(); - p.fillRect(e->rect(), st::historyComposeAreaBg); - paintRipple(p, _st.rippleAreaPosition.x(), _st.rippleAreaPosition.y(), ms, _rippleOverride ? &(*_rippleOverride)->c : nullptr); + paintRipple(p, _st.rippleAreaPosition.x(), _st.rippleAreaPosition.y(), _rippleOverride ? &(*_rippleOverride)->c : nullptr); const auto over = isOver(); const auto loadingState = _loading @@ -297,14 +294,14 @@ void SendButton::setType(Type type) { if (_type != type) { _contentFrom = grabContent(); _type = type; - _a_typeChanged.finish(); + _a_typeChanged.stop(); _contentTo = grabContent(); _a_typeChanged.start([this] { update(); }, 0., 1., st::historyRecordVoiceDuration); update(); } if (_type != Type::Record) { _recordActive = false; - _a_recordActive.finish(); + _a_recordActive.stop(); } } @@ -317,8 +314,8 @@ void SendButton::setRecordActive(bool recordActive) { } void SendButton::finishAnimating() { - _a_typeChanged.finish(); - _a_recordActive.finish(); + _a_typeChanged.stop(); + _a_recordActive.stop(); update(); } @@ -334,9 +331,8 @@ void SendButton::mouseMoveEvent(QMouseEvent *e) { void SendButton::paintEvent(QPaintEvent *e) { Painter p(this); - auto ms = crl::now(); auto over = (isDown() || isOver()); - auto changed = _a_typeChanged.current(ms, 1.); + auto changed = _a_typeChanged.value(1.); if (changed < 1.) { PainterHighQualityEnabler hq(p); p.setOpacity(1. - changed); @@ -351,7 +347,7 @@ void SendButton::paintEvent(QPaintEvent *e) { } else if (_type == Type::Record) { auto recordActive = recordActiveRatio(); auto rippleColor = anim::color(st::historyAttachEmoji.ripple.color, st::historyRecordVoiceRippleBgActive, recordActive); - paintRipple(p, (width() - st::historyAttachEmoji.rippleAreaSize) / 2, st::historyAttachEmoji.rippleAreaPosition.y(), ms, &rippleColor); + paintRipple(p, (width() - st::historyAttachEmoji.rippleAreaSize) / 2, st::historyAttachEmoji.rippleAreaPosition.y(), &rippleColor); auto fastIcon = [&] { if (recordActive == 1.) { @@ -371,7 +367,7 @@ void SendButton::paintEvent(QPaintEvent *e) { auto &saveIcon = over ? st::historyEditSaveIconOver : st::historyEditSaveIcon; saveIcon.paint(p, st::historySendIconPosition, width()); } else if (_type == Type::Cancel) { - paintRipple(p, (width() - st::historyAttachEmoji.rippleAreaSize) / 2, st::historyAttachEmoji.rippleAreaPosition.y(), ms); + paintRipple(p, (width() - st::historyAttachEmoji.rippleAreaSize) / 2, st::historyAttachEmoji.rippleAreaPosition.y()); auto &cancelIcon = over ? st::historyReplyCancelIconOver : st::historyReplyCancelIcon; cancelIcon.paintInCenter(p, rect()); @@ -579,7 +575,6 @@ void UserpicButton::paintEvent(QPaintEvent *e) { auto photoLeft = photoPosition.x(); auto photoTop = photoPosition.y(); - auto ms = crl::now(); if (showSavedMessages()) { Ui::EmptyUserpic::PaintSavedMessages( p, @@ -588,9 +583,9 @@ void UserpicButton::paintEvent(QPaintEvent *e) { width(), _st.photoSize); } else { - if (_a_appearance.animating(ms)) { + if (_a_appearance.animating()) { p.drawPixmapLeft(photoPosition, width(), _oldUserpic); - p.setOpacity(_a_appearance.current()); + p.setOpacity(_a_appearance.value(1.)); } p.drawPixmapLeft(photoPosition, width(), _userpic); } @@ -613,7 +608,6 @@ void UserpicButton::paintEvent(QPaintEvent *e) { p, photoLeft, photoTop, - ms, _userpicHasImage ? &st::shadowFg->c : &_st.changeButton.ripple.color->c); @@ -631,8 +625,7 @@ void UserpicButton::paintEvent(QPaintEvent *e) { width()); } } else if (_changeOverlayEnabled) { - auto current = _changeOverlayShown.current( - ms, + auto current = _changeOverlayShown.value( (isOver() || isDown()) ? 1. : 0.); auto barHeight = anim::interpolate( 0, @@ -788,7 +781,7 @@ void UserpicButton::startNewPhotoShowing() { } void UserpicButton::startAnimation() { - _a_appearance.finish(); + _a_appearance.stop(); _a_appearance.start([this] { update(); }, 0, 1, _st.duration); } @@ -804,7 +797,7 @@ void UserpicButton::switchChangePhotoOverlay(bool enabled) { updateCursorInChangeOverlay( mapFromGlobal(QCursor::pos())); } else { - _changeOverlayShown.finish(); + _changeOverlayShown.stop(); update(); } } diff --git a/Telegram/SourceFiles/ui/special_buttons.h b/Telegram/SourceFiles/ui/special_buttons.h index 49feddd69..6fdeaa64a 100644 --- a/Telegram/SourceFiles/ui/special_buttons.h +++ b/Telegram/SourceFiles/ui/special_buttons.h @@ -9,6 +9,7 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL #include "ui/widgets/buttons.h" #include "ui/widgets/tooltip.h" +#include "ui/effects/animations.h" #include "styles/style_window.h" #include "styles/style_widgets.h" @@ -108,7 +109,7 @@ public: } float64 recordActiveRatio() { - return _a_recordActive.current(crl::now(), _recordActive ? 1. : 0.); + return _a_recordActive.value(_recordActive ? 1. : 0.); } protected: @@ -127,8 +128,8 @@ private: bool _recordActive = false; QPixmap _contentFrom, _contentTo; - Animation _a_typeChanged; - Animation _a_recordActive; + Ui::Animations::Simple _a_typeChanged; + Ui::Animations::Simple _a_recordActive; bool _recording = false; Fn _recordStartCallback; @@ -214,14 +215,14 @@ private: bool _userpicHasImage = false; bool _userpicCustom = false; InMemoryKey _userpicUniqueKey; - Animation _a_appearance; + Ui::Animations::Simple _a_appearance; QImage _result; bool _showSavedMessagesOnSelf = false; bool _canOpenPhoto = false; bool _cursorInChangeOverlay = false; bool _changeOverlayEnabled = false; - Animation _changeOverlayShown; + Ui::Animations::Simple _changeOverlayShown; }; diff --git a/Telegram/SourceFiles/ui/toast/toast.cpp b/Telegram/SourceFiles/ui/toast/toast.cpp index 9acb564e4..aea5ac7fb 100644 --- a/Telegram/SourceFiles/ui/toast/toast.cpp +++ b/Telegram/SourceFiles/ui/toast/toast.cpp @@ -40,7 +40,7 @@ void Show(const QString &text) { } void Instance::opacityAnimationCallback() { - _widget->setShownLevel(_a_opacity.current(_hiding ? 0. : 1.)); + _widget->setShownLevel(_a_opacity.value(_hiding ? 0. : 1.)); _widget->update(); if (!_a_opacity.animating()) { if (_hiding) { diff --git a/Telegram/SourceFiles/ui/toast/toast.h b/Telegram/SourceFiles/ui/toast/toast.h index 16ec1f117..0d485aab0 100644 --- a/Telegram/SourceFiles/ui/toast/toast.h +++ b/Telegram/SourceFiles/ui/toast/toast.h @@ -7,6 +7,8 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL */ #pragma once +#include "ui/effects/animations.h" + namespace Ui { namespace Toast { @@ -43,7 +45,7 @@ private: void opacityAnimationCallback(); bool _hiding = false; - Animation _a_opacity; + Ui::Animations::Simple _a_opacity; const crl::time _hideAtMs; diff --git a/Telegram/SourceFiles/ui/widgets/buttons.cpp b/Telegram/SourceFiles/ui/widgets/buttons.cpp index d029f86e0..15b190a20 100644 --- a/Telegram/SourceFiles/ui/widgets/buttons.cpp +++ b/Telegram/SourceFiles/ui/widgets/buttons.cpp @@ -117,9 +117,9 @@ void RippleButton::setForceRippled( update(); } -void RippleButton::paintRipple(QPainter &p, int x, int y, crl::time ms, const QColor *colorOverride) { +void RippleButton::paintRipple(QPainter &p, int x, int y, const QColor *colorOverride) { if (_ripple) { - _ripple->paint(p, x, y, width(), ms, colorOverride); + _ripple->paint(p, x, y, width(), colorOverride); if (_ripple->empty()) { _ripple.reset(); } @@ -207,7 +207,7 @@ void FlatButton::paintEvent(QPaintEvent *e) { QRect r(0, height() - _st.height, width(), _st.height); p.fillRect(r, isOver() ? _st.overBgColor : _st.bgColor); - paintRipple(p, 0, 0, crl::now()); + paintRipple(p, 0, 0); p.setFont(isOver() ? _st.overFont : _st.font); p.setRenderHint(QPainter::TextAntialiasing); @@ -257,12 +257,6 @@ void RoundButton::setWidthChangedCallback(Fn callback) { _numbers->setWidthChangedCallback(std::move(callback)); } -void RoundButton::stepNumbersAnimation(crl::time ms) { - if (_numbers) { - _numbers->stepAnimation(ms); - } -} - void RoundButton::finishNumbersAnimation() { if (_numbers) { _numbers->finishAnimating(); @@ -357,8 +351,7 @@ void RoundButton::paintEvent(QPaintEvent *e) { drawRect(_st.textBgOver); } - auto ms = crl::now(); - paintRipple(p, rounded.x(), rounded.y(), ms); + paintRipple(p, rounded.x(), rounded.y()); p.setFont(_st.font); const auto textTop = _st.padding.top() + _st.textTop; @@ -428,12 +421,10 @@ void IconButton::setRippleColorOverride(const style::color *colorOverride) { void IconButton::paintEvent(QPaintEvent *e) { Painter p(this); - auto ms = crl::now(); - - paintRipple(p, _st.rippleAreaPosition.x(), _st.rippleAreaPosition.y(), ms, _rippleColorOverride ? &(*_rippleColorOverride)->c : nullptr); + paintRipple(p, _st.rippleAreaPosition.x(), _st.rippleAreaPosition.y(), _rippleColorOverride ? &(*_rippleColorOverride)->c : nullptr); auto down = isDown(); - auto overIconOpacity = (down || forceRippled()) ? 1. : _a_over.current(crl::now(), isOver() ? 1. : 0.); + auto overIconOpacity = (down || forceRippled()) ? 1. : _a_over.value(isOver() ? 1. : 0.); auto overIcon = [this] { if (_iconOverrideOver) { return _iconOverrideOver; @@ -532,7 +523,7 @@ void LeftOutlineButton::paintEvent(QPaintEvent *e) { auto down = isDown(); if (width() > _st.outlineWidth) { p.fillRect(rtlrect(_st.outlineWidth, 0, width() - _st.outlineWidth, height(), width()), (over || down) ? _st.textBgOver : _st.textBg); - paintRipple(p, 0, 0, crl::now()); + paintRipple(p, 0, 0); p.fillRect(rtlrect(0, 0, _st.outlineWidth, height(), width()), (over || down) ? _st.outlineFgOver : _st.outlineFg); } p.setFont(_st.font); @@ -585,15 +576,15 @@ void CrossButton::animationCallback() { void CrossButton::paintEvent(QPaintEvent *e) { Painter p(this); - auto now = crl::now(); auto over = isOver(); auto shown = _showAnimation.value(_shown ? 1. : 0.); p.setOpacity(shown); - paintRipple(p, _st.crossPosition.x(), _st.crossPosition.y(), now); + paintRipple(p, _st.crossPosition.x(), _st.crossPosition.y()); auto loading = 0.; if (_loadingAnimation.animating()) { + const auto now = crl::now(); if (stopLoadingAnimation(now)) { _loadingAnimation.stop(); } else if (anim::Disabled()) { diff --git a/Telegram/SourceFiles/ui/widgets/buttons.h b/Telegram/SourceFiles/ui/widgets/buttons.h index 3b6e4f3eb..40b61cf7f 100644 --- a/Telegram/SourceFiles/ui/widgets/buttons.h +++ b/Telegram/SourceFiles/ui/widgets/buttons.h @@ -60,7 +60,7 @@ public: ~RippleButton(); protected: - void paintRipple(QPainter &p, int x, int y, crl::time ms, const QColor *colorOverride = nullptr); + void paintRipple(QPainter &p, int x, int y, const QColor *colorOverride = nullptr); void onStateChanged(State was, StateChangeSource source) override; @@ -116,7 +116,6 @@ public: setNumbersText(QString::number(numbers), numbers); } void setWidthChangedCallback(Fn callback); - void stepNumbersAnimation(crl::time ms); void finishNumbersAnimation(); int contentWidth() const; @@ -182,7 +181,7 @@ private: const style::icon *_iconOverrideOver = nullptr; const style::color *_rippleColorOverride = nullptr; - Animation _a_over; + Ui::Animations::Simple _a_over; }; diff --git a/Telegram/SourceFiles/ui/widgets/checkbox.cpp b/Telegram/SourceFiles/ui/widgets/checkbox.cpp index 7bba60881..00472e73a 100644 --- a/Telegram/SourceFiles/ui/widgets/checkbox.cpp +++ b/Telegram/SourceFiles/ui/widgets/checkbox.cpp @@ -38,7 +38,7 @@ void AbstractCheckView::setChecked(bool checked, anim::type animated) { } } else if (changed) { _toggleAnimation.start( - _updateCallback, + [=] { if (_updateCallback) _updateCallback(); }, _checked ? 0. : 1., _checked ? 1. : 0., _duration); @@ -51,9 +51,6 @@ void AbstractCheckView::setChecked(bool checked, anim::type animated) { void AbstractCheckView::setUpdateCallback(Fn updateCallback) { _updateCallback = std::move(updateCallback); - if (_toggleAnimation.animating()) { - _toggleAnimation.setUpdateCallback(_updateCallback); - } } void AbstractCheckView::update() { @@ -63,11 +60,11 @@ void AbstractCheckView::update() { } void AbstractCheckView::finishAnimating() { - _toggleAnimation.finish(); + _toggleAnimation.stop(); } -float64 AbstractCheckView::currentAnimationValue(crl::time ms) { - return ms ? _toggleAnimation.current(ms, _checked ? 1. : 0.) : _toggleAnimation.current(_checked ? 1. : 0.); +float64 AbstractCheckView::currentAnimationValue() { + return _toggleAnimation.value(_checked ? 1. : 0.); } bool AbstractCheckView::animating() const { @@ -90,12 +87,12 @@ void ToggleView::setStyle(const style::Toggle &st) { _st = &st; } -void ToggleView::paint(Painter &p, int left, int top, int outerWidth, crl::time ms) { +void ToggleView::paint(Painter &p, int left, int top, int outerWidth) { left += _st->border; top += _st->border; PainterHighQualityEnabler hq(p); - auto toggled = currentAnimationValue(ms); + auto toggled = currentAnimationValue(); auto fullWidth = _st->diameter + _st->width; auto innerDiameter = _st->diameter - 2 * _st->shift; auto innerRadius = float64(innerDiameter) / 2.; @@ -241,8 +238,8 @@ void CheckView::setStyle(const style::Check &st) { _st = &st; } -void CheckView::paint(Painter &p, int left, int top, int outerWidth, crl::time ms) { - auto toggled = currentAnimationValue(ms); +void CheckView::paint(Painter &p, int left, int top, int outerWidth) { + auto toggled = currentAnimationValue(); auto pen = _untoggledOverride ? anim::pen(*_untoggledOverride, _st->toggledFg, toggled) : anim::pen(_st->untoggledFg, _st->toggledFg, toggled); @@ -299,10 +296,10 @@ void RadioView::setStyle(const style::Radio &st) { _st = &st; } -void RadioView::paint(Painter &p, int left, int top, int outerWidth, crl::time ms) { +void RadioView::paint(Painter &p, int left, int top, int outerWidth) { PainterHighQualityEnabler hq(p); - auto toggled = currentAnimationValue(ms); + auto toggled = currentAnimationValue(); auto pen = _toggledOverride ? (_untoggledOverride ? anim::pen(*_untoggledOverride, *_toggledOverride, toggled) @@ -488,7 +485,7 @@ void Checkbox::paintEvent(QPaintEvent *e) { auto check = checkRect(); auto ms = crl::now(); - auto active = _check->currentAnimationValue(ms); + auto active = _check->currentAnimationValue(); if (isDisabled()) { p.setOpacity(_st.disabledOpacity); } else { @@ -497,7 +494,6 @@ void Checkbox::paintEvent(QPaintEvent *e) { p, check.x() + _st.rippleAreaPosition.x(), check.y() + _st.rippleAreaPosition.y(), - ms, &color); } diff --git a/Telegram/SourceFiles/ui/widgets/checkbox.h b/Telegram/SourceFiles/ui/widgets/checkbox.h index d06c65a1e..117e661d2 100644 --- a/Telegram/SourceFiles/ui/widgets/checkbox.h +++ b/Telegram/SourceFiles/ui/widgets/checkbox.h @@ -8,8 +8,8 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL #pragma once #include "ui/widgets/buttons.h" +#include "ui/effects/animations.h" #include "styles/style_widgets.h" -#include namespace Ui { @@ -24,7 +24,7 @@ public: return _checked; } void update(); - float64 currentAnimationValue(crl::time ms); + float64 currentAnimationValue(); bool animating() const; auto checkedChanges() const { @@ -36,17 +36,10 @@ public: virtual QSize getSize() const = 0; - // Zero instead of ms value means that animation was already updated for this time. - // It can be passed to currentAnimationValue() safely. - virtual void paint(Painter &p, int left, int top, int outerWidth, crl::time ms) = 0; + virtual void paint(Painter &p, int left, int top, int outerWidth) = 0; virtual QImage prepareRippleMask() const = 0; virtual bool checkRippleStartPosition(QPoint position) const = 0; - void paint(Painter &p, int left, int top, int outerWidth) { - // Pass zero in ms if the animation was already updated for this time. - paint(p, left, top, outerWidth, 0); - } - virtual ~AbstractCheckView() = default; private: @@ -56,7 +49,7 @@ private: int _duration = 0; bool _checked = false; Fn _updateCallback; - Animation _toggleAnimation; + Ui::Animations::Simple _toggleAnimation; rpl::event_stream _checks; @@ -72,7 +65,7 @@ public: void setStyle(const style::Check &st); QSize getSize() const override; - void paint(Painter &p, int left, int top, int outerWidth, crl::time ms) override; + void paint(Painter &p, int left, int top, int outerWidth) override; QImage prepareRippleMask() const override; bool checkRippleStartPosition(QPoint position) const override; @@ -100,7 +93,7 @@ public: void setUntoggledOverride(std::optional untoggledOverride); QSize getSize() const override; - void paint(Painter &p, int left, int top, int outerWidth, crl::time ms) override; + void paint(Painter &p, int left, int top, int outerWidth) override; QImage prepareRippleMask() const override; bool checkRippleStartPosition(QPoint position) const override; @@ -123,7 +116,7 @@ public: void setStyle(const style::Toggle &st); QSize getSize() const override; - void paint(Painter &p, int left, int top, int outerWidth, crl::time ms) override; + void paint(Painter &p, int left, int top, int outerWidth) override; QImage prepareRippleMask() const override; bool checkRippleStartPosition(QPoint position) const override; void setLocked(bool locked); diff --git a/Telegram/SourceFiles/ui/widgets/discrete_sliders.cpp b/Telegram/SourceFiles/ui/widgets/discrete_sliders.cpp index aa2cd5e03..f8c4f3bb5 100644 --- a/Telegram/SourceFiles/ui/widgets/discrete_sliders.cpp +++ b/Telegram/SourceFiles/ui/widgets/discrete_sliders.cpp @@ -45,7 +45,7 @@ void DiscreteSlider::setActiveSectionFast(int index) { } void DiscreteSlider::finishAnimating() { - _a_left.finish(); + _a_left.stop(); update(); } @@ -62,7 +62,7 @@ void DiscreteSlider::setSections(const QStringList &labels) { Assert(!labels.isEmpty()); _sections.clear(); - for_const (auto &label, labels) { + for (const auto &label : labels) { _sections.push_back(Section(label, getLabelFont())); } stopAnimation(); @@ -75,9 +75,9 @@ void DiscreteSlider::setSections(const QStringList &labels) { resizeToWidth(width()); } -int DiscreteSlider::getCurrentActiveLeft(crl::time ms) { +int DiscreteSlider::getCurrentActiveLeft() { const auto left = _sections.empty() ? 0 : _sections[_selected].left; - return _a_left.current(ms, left); + return _a_left.value(left); } template @@ -273,15 +273,14 @@ void SettingsSlider::paintEvent(QPaintEvent *e) { Painter p(this); auto clip = e->rect(); - auto ms = crl::now(); - auto activeLeft = getCurrentActiveLeft(ms); + auto activeLeft = getCurrentActiveLeft(); p.setFont(_st.labelFont); - enumerateSections([this, &p, activeLeft, ms, clip](Section §ion) { + enumerateSections([&](Section §ion) { auto active = 1. - snap(qAbs(activeLeft - section.left) / float64(section.width), 0., 1.); if (section.ripple) { auto color = anim::color(_st.rippleBg, _st.rippleBgActive, active); - section.ripple->paint(p, section.left, 0, width(), ms, &color); + section.ripple->paint(p, section.left, 0, width(), &color); if (section.ripple->empty()) { section.ripple.reset(); } diff --git a/Telegram/SourceFiles/ui/widgets/discrete_sliders.h b/Telegram/SourceFiles/ui/widgets/discrete_sliders.h index 878c5ee4c..a09c550b0 100644 --- a/Telegram/SourceFiles/ui/widgets/discrete_sliders.h +++ b/Telegram/SourceFiles/ui/widgets/discrete_sliders.h @@ -7,8 +7,8 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL */ #pragma once -#include #include "ui/rp_widget.h" +#include "ui/effects/animations.h" #include "styles/style_widgets.h" namespace Ui { @@ -49,7 +49,7 @@ protected: std::unique_ptr ripple; }; - int getCurrentActiveLeft(crl::time ms); + int getCurrentActiveLeft(); int getSectionsCount() const { return _sections.size(); @@ -65,7 +65,7 @@ protected: } void stopAnimation() { - _a_left.finish(); + _a_left.stop(); } void setSelectOnPress(bool selectOnPress); @@ -86,7 +86,7 @@ private: int _pressed = -1; int _selected = 0; - Animation _a_left; + Ui::Animations::Simple _a_left; int _timerId = -1; crl::time _callbackAfterMs = 0; diff --git a/Telegram/SourceFiles/ui/widgets/inner_dropdown.cpp b/Telegram/SourceFiles/ui/widgets/inner_dropdown.cpp index b252eb225..deb9a427e 100644 --- a/Telegram/SourceFiles/ui/widgets/inner_dropdown.cpp +++ b/Telegram/SourceFiles/ui/widgets/inner_dropdown.cpp @@ -96,16 +96,15 @@ void InnerDropdown::onScroll() { void InnerDropdown::paintEvent(QPaintEvent *e) { Painter p(this); - const auto ms = crl::now(); - if (_a_show.animating(ms)) { - if (auto opacity = _a_opacity.current(ms, _hiding ? 0. : 1.)) { + if (_a_show.animating()) { + if (auto opacity = _a_opacity.value(_hiding ? 0. : 1.)) { // _a_opacity.current(ms)->opacityAnimationCallback()->_showAnimation.reset() if (_showAnimation) { - _showAnimation->paintFrame(p, 0, 0, width(), _a_show.current(1.), opacity); + _showAnimation->paintFrame(p, 0, 0, width(), _a_show.value(1.), opacity); } } - } else if (_a_opacity.animating(ms)) { - p.setOpacity(_a_opacity.current(0.)); + } else if (_a_opacity.animating()) { + p.setOpacity(_a_opacity.value(0.)); p.drawPixmap(0, 0, _cache); } else if (_hiding || isHidden()) { hideFinished(); @@ -130,8 +129,7 @@ void InnerDropdown::enterEventHook(QEvent *e) { void InnerDropdown::leaveEventHook(QEvent *e) { if (_autoHiding) { - const auto ms = crl::now(); - if (_a_show.animating(ms) || _a_opacity.animating(ms)) { + if (_a_show.animating() || _a_opacity.animating()) { hideAnimated(); } else { _hideTimer.start(300); @@ -148,8 +146,7 @@ void InnerDropdown::otherEnter() { void InnerDropdown::otherLeave() { if (_autoHiding) { - const auto ms = crl::now(); - if (_a_show.animating(ms) || _a_opacity.animating(ms)) { + if (_a_show.animating() || _a_opacity.animating()) { hideAnimated(); } else { _hideTimer.start(0); @@ -184,7 +181,7 @@ void InnerDropdown::hideAnimated(HideOption option) { void InnerDropdown::finishAnimating() { if (_a_show.animating()) { - _a_show.finish(); + _a_show.stop(); showAnimationCallback(); } if (_showAnimation) { @@ -192,7 +189,7 @@ void InnerDropdown::finishAnimating() { showChildren(); } if (_a_opacity.animating()) { - _a_opacity.finish(); + _a_opacity.stop(); opacityAnimationCallback(); } } @@ -217,7 +214,7 @@ void InnerDropdown::hideFast() { } void InnerDropdown::hideFinished() { - _a_show.finish(); + _a_show.stop(); _showAnimation.reset(); _cache = QPixmap(); _ignoreShowEvents = false; diff --git a/Telegram/SourceFiles/ui/widgets/inner_dropdown.h b/Telegram/SourceFiles/ui/widgets/inner_dropdown.h index 1575f344e..49cd886d4 100644 --- a/Telegram/SourceFiles/ui/widgets/inner_dropdown.h +++ b/Telegram/SourceFiles/ui/widgets/inner_dropdown.h @@ -8,6 +8,7 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL #pragma once #include "styles/style_widgets.h" +#include "ui/effects/animations.h" #include "ui/effects/panel_animation.h" namespace Ui { @@ -106,12 +107,12 @@ private: PanelAnimation::Origin _origin = PanelAnimation::Origin::TopLeft; std::unique_ptr _showAnimation; - Animation _a_show; + Ui::Animations::Simple _a_show; bool _autoHiding = true; bool _hiding = false; QPixmap _cache; - Animation _a_opacity; + Ui::Animations::Simple _a_opacity; QTimer _hideTimer; bool _ignoreShowEvents = false; diff --git a/Telegram/SourceFiles/ui/widgets/input_fields.cpp b/Telegram/SourceFiles/ui/widgets/input_fields.cpp index 9eecc41bf..2e8674858 100644 --- a/Telegram/SourceFiles/ui/widgets/input_fields.cpp +++ b/Telegram/SourceFiles/ui/widgets/input_fields.cpp @@ -1557,7 +1557,6 @@ void InputField::handleTouchEvent(QTouchEvent *e) { void InputField::paintEvent(QPaintEvent *e) { Painter p(this); - auto ms = crl::now(); auto r = rect().intersected(e->rect()); if (_st.textBg->c.alphaF() > 0.) { p.fillRect(r, _st.textBg); @@ -1565,10 +1564,10 @@ void InputField::paintEvent(QPaintEvent *e) { if (_st.border) { p.fillRect(0, height() - _st.border, width(), _st.border, _st.borderFg); } - auto errorDegree = _a_error.current(ms, _error ? 1. : 0.); - auto focusedDegree = _a_focused.current(ms, _focused ? 1. : 0.); - auto borderShownDegree = _a_borderShown.current(ms, 1.); - auto borderOpacity = _a_borderOpacity.current(ms, _borderVisible ? 1. : 0.); + auto errorDegree = _a_error.value(_error ? 1. : 0.); + auto focusedDegree = _a_focused.value(_focused ? 1. : 0.); + auto borderShownDegree = _a_borderShown.value(1.); + auto borderOpacity = _a_borderOpacity.value(_borderVisible ? 1. : 0.); if (_st.borderActive && (borderOpacity > 0.)) { auto borderStart = snap(_borderAnimationStart, 0, width()); auto borderFrom = qRound(borderStart * (1. - borderShownDegree)); @@ -1582,7 +1581,7 @@ void InputField::paintEvent(QPaintEvent *e) { } if (_st.placeholderScale > 0. && !_placeholderPath.isEmpty()) { - auto placeholderShiftDegree = _a_placeholderShifted.current(ms, _placeholderShifted ? 1. : 0.); + auto placeholderShiftDegree = _a_placeholderShifted.value(_placeholderShifted ? 1. : 0.); p.save(); p.setClipRect(r); @@ -1605,7 +1604,7 @@ void InputField::paintEvent(QPaintEvent *e) { p.restore(); } else if (!_placeholder.isEmpty()) { - auto placeholderHiddenDegree = _a_placeholderShifted.current(ms, _placeholderShifted ? 1. : 0.); + auto placeholderHiddenDegree = _a_placeholderShifted.value(_placeholderShifted ? 1. : 0.); if (placeholderHiddenDegree < 1.) { p.setOpacity(1. - placeholderHiddenDegree); p.save(); @@ -2273,11 +2272,11 @@ void InputField::selectAll() { } void InputField::finishAnimating() { - _a_focused.finish(); - _a_error.finish(); - _a_placeholderShifted.finish(); - _a_borderShown.finish(); - _a_borderOpacity.finish(); + _a_focused.stop(); + _a_error.stop(); + _a_placeholderShifted.stop(); + _a_borderShown.stop(); + _a_borderOpacity.stop(); update(); } @@ -3603,16 +3602,15 @@ QRect MaskedInputField::getTextRect() const { void MaskedInputField::paintEvent(QPaintEvent *e) { Painter p(this); - auto ms = crl::now(); auto r = rect().intersected(e->rect()); p.fillRect(r, _st.textBg); if (_st.border) { p.fillRect(0, height() - _st.border, width(), _st.border, _st.borderFg->b); } - auto errorDegree = _a_error.current(ms, _error ? 1. : 0.); - auto focusedDegree = _a_focused.current(ms, _focused ? 1. : 0.); - auto borderShownDegree = _a_borderShown.current(ms, 1.); - auto borderOpacity = _a_borderOpacity.current(ms, _borderVisible ? 1. : 0.); + auto errorDegree = _a_error.value(_error ? 1. : 0.); + auto focusedDegree = _a_focused.value(_focused ? 1. : 0.); + auto borderShownDegree = _a_borderShown.value(1.); + auto borderOpacity = _a_borderOpacity.value(_borderVisible ? 1. : 0.); if (_st.borderActive && (borderOpacity > 0.)) { auto borderStart = snap(_borderAnimationStart, 0, width()); auto borderFrom = qRound(borderStart * (1. - borderShownDegree)); @@ -3627,7 +3625,7 @@ void MaskedInputField::paintEvent(QPaintEvent *e) { p.setClipRect(r); if (_st.placeholderScale > 0. && !_placeholderPath.isEmpty()) { - auto placeholderShiftDegree = _a_placeholderShifted.current(ms, _placeholderShifted ? 1. : 0.); + auto placeholderShiftDegree = _a_placeholderShifted.value(_placeholderShifted ? 1. : 0.); p.save(); p.setClipRect(r); @@ -3650,7 +3648,7 @@ void MaskedInputField::paintEvent(QPaintEvent *e) { p.restore(); } else if (!_placeholder.isEmpty()) { - auto placeholderHiddenDegree = _a_placeholderShifted.current(ms, _placeholderShifted ? 1. : 0.); + auto placeholderHiddenDegree = _a_placeholderShifted.value(_placeholderShifted ? 1. : 0.); if (placeholderHiddenDegree < 1.) { p.setOpacity(1. - placeholderHiddenDegree); p.save(); @@ -3671,7 +3669,7 @@ void MaskedInputField::paintEvent(QPaintEvent *e) { } } - paintAdditionalPlaceholder(p, ms); + paintAdditionalPlaceholder(p); QLineEdit::paintEvent(e); } @@ -3685,9 +3683,9 @@ void MaskedInputField::startBorderAnimation() { } else { _a_borderShown.start([this] { update(); }, 0., 1., _st.duration); } - } else if (qFuzzyCompare(_a_borderShown.current(1.), 0.)) { - _a_borderShown.finish(); - _a_borderOpacity.finish(); + } else if (qFuzzyCompare(_a_borderShown.value(1.), 0.)) { + _a_borderShown.stop(); + _a_borderOpacity.stop(); } else { _a_borderOpacity.start([this] { update(); }, 1., 0., _st.duration); } @@ -3786,11 +3784,11 @@ void MaskedInputField::setDisplayFocused(bool focused) { } void MaskedInputField::finishAnimating() { - _a_focused.finish(); - _a_error.finish(); - _a_placeholderShifted.finish(); - _a_borderShown.finish(); - _a_borderOpacity.finish(); + _a_focused.stop(); + _a_error.stop(); + _a_placeholderShifted.stop(); + _a_borderShown.stop(); + _a_borderOpacity.stop(); update(); } @@ -3811,7 +3809,7 @@ QRect MaskedInputField::placeholderRect() const { return rect().marginsRemoved(_textMargins + _st.placeholderMargins); } -void MaskedInputField::placeholderAdditionalPrepare(Painter &p, crl::time ms) { +void MaskedInputField::placeholderAdditionalPrepare(Painter &p) { p.setFont(_st.font); p.setPen(_st.placeholderFg); } @@ -3940,7 +3938,7 @@ void CountryCodeInput::correctValue( PhonePartInput::PhonePartInput(QWidget *parent, const style::InputField &st) : MaskedInputField(parent, st/*, lang(lng_phone_ph)*/) { } -void PhonePartInput::paintAdditionalPlaceholder(Painter &p, crl::time ms) { +void PhonePartInput::paintAdditionalPlaceholder(Painter &p) { if (!_pattern.isEmpty()) { auto t = getDisplayedText(); auto ph = _additionalPlaceholder.mid(t.size()); @@ -3950,7 +3948,7 @@ void PhonePartInput::paintAdditionalPlaceholder(Painter &p, crl::time ms) { int tw = phFont()->width(t); if (tw < phRect.width()) { phRect.setLeft(phRect.left() + tw); - placeholderAdditionalPrepare(p, ms); + placeholderAdditionalPrepare(p); p.drawText(phRect, ph, style::al_topleft); } } @@ -4051,9 +4049,9 @@ void PhonePartInput::onChooseCode(const QString &code) { _additionalPlaceholder = QString(); if (!_pattern.isEmpty()) { _additionalPlaceholder.reserve(20); - for (int i = 0, l = _pattern.size(); i < l; ++i) { + for (const auto part : _pattern) { _additionalPlaceholder.append(' '); - _additionalPlaceholder.append(QString(_pattern.at(i), QChar(0x2212))); + _additionalPlaceholder.append(QString(part, QChar(0x2212))); } } setPlaceholderHidden(!_additionalPlaceholder.isEmpty()); @@ -4141,7 +4139,7 @@ void UsernameInput::setLinkPlaceholder(const QString &placeholder) { } } -void UsernameInput::paintAdditionalPlaceholder(Painter &p, crl::time ms) { +void UsernameInput::paintAdditionalPlaceholder(Painter &p) { if (!_linkPlaceholder.isEmpty()) { p.setFont(_st.font); p.setPen(_st.placeholderFg); @@ -4205,7 +4203,7 @@ void PhoneInput::clearText() { correctValue(QString(), 0, phone, pos); } -void PhoneInput::paintAdditionalPlaceholder(Painter &p, crl::time ms) { +void PhoneInput::paintAdditionalPlaceholder(Painter &p) { if (!_pattern.isEmpty()) { auto t = getDisplayedText(); auto ph = _additionalPlaceholder.mid(t.size()); @@ -4215,7 +4213,7 @@ void PhoneInput::paintAdditionalPlaceholder(Painter &p, crl::time ms) { int tw = phFont()->width(t); if (tw < phRect.width()) { phRect.setLeft(phRect.left() + tw); - placeholderAdditionalPrepare(p, ms); + placeholderAdditionalPrepare(p); p.drawText(phRect, ph, style::al_topleft); } } diff --git a/Telegram/SourceFiles/ui/widgets/input_fields.h b/Telegram/SourceFiles/ui/widgets/input_fields.h index e1327995b..e8c04fe4e 100644 --- a/Telegram/SourceFiles/ui/widgets/input_fields.h +++ b/Telegram/SourceFiles/ui/widgets/input_fields.h @@ -461,17 +461,17 @@ private: QString _placeholder; Fn _placeholderFactory; int _placeholderAfterSymbols = 0; - Animation _a_placeholderShifted; + Ui::Animations::Simple _a_placeholderShifted; bool _placeholderShifted = false; QPainterPath _placeholderPath; - Animation _a_borderShown; + Ui::Animations::Simple _a_borderShown; int _borderAnimationStart = 0; - Animation _a_borderOpacity; + Ui::Animations::Simple _a_borderOpacity; bool _borderVisible = false; - Animation _a_focused; - Animation _a_error; + Ui::Animations::Simple _a_focused; + Ui::Animations::Simple _a_error; bool _focused = false; bool _error = false; @@ -580,14 +580,14 @@ protected: } void setCorrectedText(QString &now, int &nowCursor, const QString &newText, int newPos); - virtual void paintAdditionalPlaceholder(Painter &p, crl::time ms) { + virtual void paintAdditionalPlaceholder(Painter &p) { } style::font phFont() { return _st.font; } - void placeholderAdditionalPrepare(Painter &p, crl::time ms); + void placeholderAdditionalPrepare(Painter &p); QRect placeholderRect() const; void setTextMargins(const QMargins &mrg); @@ -614,17 +614,17 @@ private: QString _placeholder; Fn _placeholderFactory; - Animation _a_placeholderShifted; + Ui::Animations::Simple _a_placeholderShifted; bool _placeholderShifted = false; QPainterPath _placeholderPath; - Animation _a_borderShown; + Ui::Animations::Simple _a_borderShown; int _borderAnimationStart = 0; - Animation _a_borderOpacity; + Ui::Animations::Simple _a_borderOpacity; bool _borderVisible = false; - Animation _a_focused; - Animation _a_error; + Ui::Animations::Simple _a_focused; + Ui::Animations::Simple _a_error; bool _focused = false; bool _error = false; @@ -685,7 +685,7 @@ protected: int wasCursor, QString &now, int &nowCursor) override; - void paintAdditionalPlaceholder(Painter &p, crl::time ms) override; + void paintAdditionalPlaceholder(Painter &p) override; private: QVector _pattern; @@ -737,7 +737,7 @@ protected: int wasCursor, QString &now, int &nowCursor) override; - void paintAdditionalPlaceholder(Painter &p, crl::time ms) override; + void paintAdditionalPlaceholder(Painter &p) override; private: QString _linkPlaceholder; @@ -758,7 +758,7 @@ protected: int wasCursor, QString &now, int &nowCursor) override; - void paintAdditionalPlaceholder(Painter &p, crl::time ms) override; + void paintAdditionalPlaceholder(Painter &p) override; private: QVector _pattern; diff --git a/Telegram/SourceFiles/ui/widgets/menu.cpp b/Telegram/SourceFiles/ui/widgets/menu.cpp index b4712e7a4..24c232099 100644 --- a/Telegram/SourceFiles/ui/widgets/menu.cpp +++ b/Telegram/SourceFiles/ui/widgets/menu.cpp @@ -178,7 +178,6 @@ void Menu::actionChanged() { void Menu::paintEvent(QPaintEvent *e) { Painter p(this); - auto ms = crl::now(); auto clip = e->rect(); auto topskip = QRect(0, 0, width(), _st.skip); @@ -205,7 +204,7 @@ void Menu::paintEvent(QPaintEvent *e) { auto selected = ((i == _selected || i == _pressed) && enabled); p.fillRect(0, 0, width(), actionHeight, selected ? _st.itemBgOver : _st.itemBg); if (data.ripple) { - data.ripple->paint(p, 0, 0, width(), ms); + data.ripple->paint(p, 0, 0, width()); if (data.ripple->empty()) { data.ripple.reset(); } @@ -233,7 +232,7 @@ void Menu::paintEvent(QPaintEvent *e) { p.drawTextRight(_st.itemPadding.right(), _st.itemPadding.top(), width(), data.shortcut); } else if (data.toggle) { auto toggleSize = data.toggle->getSize(); - data.toggle->paint(p, width() - _st.itemPadding.right() - toggleSize.width() + _st.itemToggleShift, (_itemHeight - toggleSize.height()) / 2, width(), ms); + data.toggle->paint(p, width() - _st.itemPadding.right() - toggleSize.width() + _st.itemToggleShift, (_itemHeight - toggleSize.height()) / 2, width()); } } } diff --git a/Telegram/SourceFiles/ui/widgets/multi_select.cpp b/Telegram/SourceFiles/ui/widgets/multi_select.cpp index f7540c1eb..2950bb99a 100644 --- a/Telegram/SourceFiles/ui/widgets/multi_select.cpp +++ b/Telegram/SourceFiles/ui/widgets/multi_select.cpp @@ -36,8 +36,8 @@ void MultiSelect::Item::setText(const QString &text) { accumulate_min(_width, _st.maxWidth); } -void MultiSelect::Item::paint(Painter &p, int outerWidth, crl::time ms) { - if (!_cache.isNull() && !_visibility.animating(ms)) { +void MultiSelect::Item::paint(Painter &p, int outerWidth) { + if (!_cache.isNull() && !_visibility.animating()) { if (_hiding) { return; } else { @@ -45,14 +45,14 @@ void MultiSelect::Item::paint(Painter &p, int outerWidth, crl::time ms) { } } if (_copies.empty()) { - paintOnce(p, _x, _y, outerWidth, ms); + paintOnce(p, _x, _y, outerWidth); } else { for (auto i = _copies.begin(), e = _copies.end(); i != e;) { - auto x = qRound(i->x.current(crl::now(), _x)); + auto x = qRound(i->x.value(_x)); auto y = i->y; auto animating = i->x.animating(); if (animating || (y == _y)) { - paintOnce(p, x, y, outerWidth, ms); + paintOnce(p, x, y, outerWidth); } if (animating) { ++i; @@ -64,7 +64,7 @@ void MultiSelect::Item::paint(Painter &p, int outerWidth, crl::time ms) { } } -void MultiSelect::Item::paintOnce(Painter &p, int x, int y, int outerWidth, crl::time ms) { +void MultiSelect::Item::paintOnce(Painter &p, int x, int y, int outerWidth) { if (!_cache.isNull()) { paintCached(p, x, y, outerWidth); return; @@ -90,7 +90,7 @@ void MultiSelect::Item::paintOnce(Painter &p, int x, int y, int outerWidth, crl: p.setClipping(false); } - auto overOpacity = _overOpacity.current(ms, _over ? 1. : 0.); + auto overOpacity = _overOpacity.value(_over ? 1. : 0.); if (overOpacity < 1.) { _paintRoundImage(p, x, y, outerWidth, _st.height); } @@ -122,7 +122,7 @@ void MultiSelect::Item::paintDeleteButton(Painter &p, int x, int y, int outerWid bool MultiSelect::Item::paintCached(Painter &p, int x, int y, int outerWidth) { PainterHighQualityEnabler hq(p); - auto opacity = _visibility.current(_hiding ? 0. : 1.); + auto opacity = _visibility.value(_hiding ? 0. : 1.); auto scale = opacity + _st.minScale * (1. - opacity); auto height = opacity * _cache.height() / _cache.devicePixelRatio(); auto width = opacity * _cache.width() / _cache.devicePixelRatio(); @@ -210,7 +210,7 @@ void MultiSelect::Item::prepareCache() { data.setDevicePixelRatio(cRetinaFactor()); { Painter p(&data); - paintOnce(p, _width * (kWideScale - 1) / 2, _st.height * (kWideScale - 1) / 2, cacheWidth, crl::now()); + paintOnce(p, _width * (kWideScale - 1) / 2, _st.height * (kWideScale - 1) / 2, cacheWidth); } _cache = App::pixmapFromImageInPlace(std::move(data)); } @@ -487,10 +487,6 @@ int MultiSelect::Inner::resizeGetHeight(int newWidth) { void MultiSelect::Inner::paintEvent(QPaintEvent *e) { Painter p(this); - auto ms = crl::now(); - _height.step(ms); - _iconOpacity.step(ms); - auto paintRect = e->rect(); p.fillRect(paintRect, _st.bg); @@ -499,7 +495,7 @@ void MultiSelect::Inner::paintEvent(QPaintEvent *e) { paintRect.translate(-offset); auto outerWidth = width() - _st.padding.left() - _st.padding.right(); - auto iconOpacity = _iconOpacity.current(_items.empty() ? 1. : 0.); + auto iconOpacity = _iconOpacity.value(_items.empty() ? 1. : 0.); if (iconOpacity > 0.) { p.setOpacity(iconOpacity); _st.fieldIcon.paint(p, 0, 0, outerWidth); @@ -513,7 +509,7 @@ void MultiSelect::Inner::paintEvent(QPaintEvent *e) { auto itemRect = item->paintArea(outerWidth); itemRect = itemRect.marginsAdded(paintMargins); if (checkRect.intersects(itemRect)) { - item->paint(p, outerWidth, ms); + item->paint(p, outerWidth); } if (item->hideFinished()) { i = _removingItems.erase(i); @@ -522,13 +518,13 @@ void MultiSelect::Inner::paintEvent(QPaintEvent *e) { ++i; } } - for_const (auto &item, _items) { + for (const auto &item : _items) { auto itemRect = item->paintArea(outerWidth); itemRect = itemRect.marginsAdded(paintMargins); if (checkRect.y() + checkRect.height() <= itemRect.y()) { break; } else if (checkRect.intersects(itemRect)) { - item->paint(p, outerWidth, ms); + item->paint(p, outerWidth); } } } @@ -699,7 +695,7 @@ void MultiSelect::Inner::updateItemsGeometry() { } void MultiSelect::Inner::updateHeightStep() { - auto newHeight = qRound(_height.current(_newHeight)); + auto newHeight = qRound(_height.value(_newHeight)); if (auto heightDelta = newHeight - height()) { resize(width(), newHeight); if (_resizedCallback) { @@ -710,7 +706,7 @@ void MultiSelect::Inner::updateHeightStep() { } void MultiSelect::Inner::finishHeightAnimation() { - _height.finish(); + _height.stop(); updateHeightStep(); } diff --git a/Telegram/SourceFiles/ui/widgets/multi_select.h b/Telegram/SourceFiles/ui/widgets/multi_select.h index 2e18376cc..4e5664524 100644 --- a/Telegram/SourceFiles/ui/widgets/multi_select.h +++ b/Telegram/SourceFiles/ui/widgets/multi_select.h @@ -9,6 +9,7 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL #include "styles/style_widgets.h" #include "ui/rp_widget.h" +#include "ui/effects/animations.h" namespace Ui { @@ -132,7 +133,7 @@ private: QMargins itemPaintMargins() const; const style::MultiSelect &_st; - Animation _iconOpacity; + Ui::Animations::Simple _iconOpacity; ScrollCallback _scrollCallback; @@ -151,7 +152,7 @@ private: object_ptr _cancel; int _newHeight = 0; - Animation _height; + Ui::Animations::Simple _height; Fn _queryChangedCallback; Fn _submittedCallback; @@ -187,7 +188,7 @@ public: _updateCallback = updateCallback; } void setText(const QString &text); - void paint(Painter &p, int outerWidth, crl::time ms); + void paint(Painter &p, int outerWidth); void mouseMoveEvent(QPoint point); void leaveEvent(); @@ -205,7 +206,7 @@ public: private: void setOver(bool over); - void paintOnce(Painter &p, int x, int y, int outerWidth, crl::time ms); + void paintOnce(Painter &p, int x, int y, int outerWidth); void paintDeleteButton(Painter &p, int x, int y, int outerWidth, float64 overOpacity); bool paintCached(Painter &p, int x, int y, int outerWidth); void prepareCache(); @@ -221,7 +222,7 @@ private: , y(y) { x.start(updateCallback, fromX, toX, duration); } - Animation x; + Ui::Animations::Simple x; int fromX, toX; int y; }; @@ -233,8 +234,8 @@ private: style::color _color; bool _over = false; QPixmap _cache; - Animation _visibility; - Animation _overOpacity; + Ui::Animations::Simple _visibility; + Ui::Animations::Simple _overOpacity; bool _overDelete = false; bool _active = false; PaintRoundImage _paintRoundImage; diff --git a/Telegram/SourceFiles/ui/widgets/popup_menu.cpp b/Telegram/SourceFiles/ui/widgets/popup_menu.cpp index 3d37fc544..8395caa87 100644 --- a/Telegram/SourceFiles/ui/widgets/popup_menu.cpp +++ b/Telegram/SourceFiles/ui/widgets/popup_menu.cpp @@ -121,13 +121,12 @@ void PopupMenu::paintEvent(QPaintEvent *e) { Platform::StartTranslucentPaint(p, e); } - auto ms = crl::now(); - if (_a_show.animating(ms)) { - if (auto opacity = _a_opacity.current(ms, _hiding ? 0. : 1.)) { - _showAnimation->paintFrame(p, 0, 0, width(), _a_show.current(1.), opacity); + if (_a_show.animating()) { + if (auto opacity = _a_opacity.value(_hiding ? 0. : 1.)) { + _showAnimation->paintFrame(p, 0, 0, width(), _a_show.value(1.), opacity); } - } else if (_a_opacity.animating(ms)) { - p.setOpacity(_a_opacity.current(0.)); + } else if (_a_opacity.animating()) { + p.setOpacity(_a_opacity.value(0.)); p.drawPixmap(0, 0, _cache); } else if (_hiding || isHidden()) { hideFinished(); @@ -308,12 +307,12 @@ void PopupMenu::hideFast() { if (isHidden()) return; _hiding = false; - _a_opacity.finish(); + _a_opacity.stop(); hideFinished(); } void PopupMenu::hideFinished() { - _a_show.finish(); + _a_show.stop(); _cache = QPixmap(); if (!isHidden()) { hide(); @@ -334,7 +333,7 @@ void PopupMenu::prepareCache() { void PopupMenu::startOpacityAnimation(bool hiding) { _hiding = false; if (!_useTransparency) { - _a_opacity.finish(); + _a_opacity.stop(); if (hiding) { hideFinished(); } else { @@ -361,7 +360,7 @@ void PopupMenu::showStarted() { void PopupMenu::startShowAnimation() { if (!_useTransparency) { - _a_show.finish(); + _a_show.stop(); update(); return; } @@ -433,8 +432,8 @@ void PopupMenu::popup(const QPoint &p) { void PopupMenu::showMenu(const QPoint &p, PopupMenu *parent, TriggeredSource source) { if (!parent && InactiveMacApplication()) { _hiding = false; - _a_opacity.finish(); - _a_show.finish(); + _a_opacity.stop(); + _a_show.stop(); _cache = QPixmap(); hide(); if (_deleteOnHide) { diff --git a/Telegram/SourceFiles/ui/widgets/popup_menu.h b/Telegram/SourceFiles/ui/widgets/popup_menu.h index 4e550de1c..6126b4317 100644 --- a/Telegram/SourceFiles/ui/widgets/popup_menu.h +++ b/Telegram/SourceFiles/ui/widgets/popup_menu.h @@ -10,6 +10,7 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL #include "styles/style_widgets.h" #include "ui/rp_widget.h" #include "ui/widgets/menu.h" +#include "ui/effects/animations.h" #include "ui/effects/panel_animation.h" namespace Ui { @@ -114,12 +115,12 @@ private: PanelAnimation::Origin _origin = PanelAnimation::Origin::TopLeft; std::unique_ptr _showAnimation; - Animation _a_show; + Ui::Animations::Simple _a_show; bool _useTransparency = true; bool _hiding = false; QPixmap _cache; - Animation _a_opacity; + Ui::Animations::Simple _a_opacity; bool _deleteOnHide = true; bool _triggering = false; diff --git a/Telegram/SourceFiles/ui/widgets/scroll_area.cpp b/Telegram/SourceFiles/ui/widgets/scroll_area.cpp index e1eb28a3f..5d5dfffb8 100644 --- a/Telegram/SourceFiles/ui/widgets/scroll_area.cpp +++ b/Telegram/SourceFiles/ui/widgets/scroll_area.cpp @@ -165,17 +165,16 @@ void ScrollBar::paintEvent(QPaintEvent *e) { hide(); return; } - auto ms = crl::now(); - auto opacity = _a_opacity.current(ms, _hiding ? 0. : 1.); + auto opacity = _a_opacity.value(_hiding ? 0. : 1.); if (opacity == 0.) return; Painter p(this); auto deltal = _vertical ? _st->deltax : 0, deltar = _vertical ? _st->deltax : 0; auto deltat = _vertical ? 0 : _st->deltax, deltab = _vertical ? 0 : _st->deltax; p.setPen(Qt::NoPen); - auto bg = anim::color(_st->bg, _st->bgOver, _a_over.current(ms, (_over || _moving) ? 1. : 0.)); + auto bg = anim::color(_st->bg, _st->bgOver, _a_over.value((_over || _moving) ? 1. : 0.)); bg.setAlpha(anim::interpolate(0, bg.alpha(), opacity)); - auto bar = anim::color(_st->barBg, _st->barBgOver, _a_barOver.current(ms, (_overbar || _moving) ? 1. : 0.)); + auto bar = anim::color(_st->barBg, _st->barBgOver, _a_barOver.value((_overbar || _moving) ? 1. : 0.)); bar.setAlpha(anim::interpolate(0, bar.alpha(), opacity)); if (_st->round) { PainterHighQualityEnabler hq(p); diff --git a/Telegram/SourceFiles/ui/widgets/scroll_area.h b/Telegram/SourceFiles/ui/widgets/scroll_area.h index 8ec3c348a..757766917 100644 --- a/Telegram/SourceFiles/ui/widgets/scroll_area.h +++ b/Telegram/SourceFiles/ui/widgets/scroll_area.h @@ -7,8 +7,8 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL */ #pragma once -#include #include "ui/rp_widget.h" +#include "ui/effects/animations.h" #include "styles/style_widgets.h" namespace Ui { @@ -102,9 +102,9 @@ private: crl::time _hideIn = 0; QTimer _hideTimer; - Animation _a_over; - Animation _a_barOver; - Animation _a_opacity; + Ui::Animations::Simple _a_over; + Ui::Animations::Simple _a_barOver; + Ui::Animations::Simple _a_opacity; QRect _bar; }; diff --git a/Telegram/SourceFiles/ui/widgets/separate_panel.cpp b/Telegram/SourceFiles/ui/widgets/separate_panel.cpp index a0cf910c0..3de767913 100644 --- a/Telegram/SourceFiles/ui/widgets/separate_panel.cpp +++ b/Telegram/SourceFiles/ui/widgets/separate_panel.cpp @@ -61,7 +61,7 @@ void SeparatePanel::initControls() { st::fadeWrapDuration); }, _back->lifetime()); _back->hide(anim::type::instant); - _titleLeft.finish(); + _titleLeft.stop(); } void SeparatePanel::updateTitleGeometry(int newWidth) { @@ -75,7 +75,7 @@ void SeparatePanel::updateTitlePosition() { if (!_title) { return; } - const auto progress = _titleLeft.current(_back->toggled() ? 1. : 0.); + const auto progress = _titleLeft.value(_back->toggled() ? 1. : 0.); const auto left = anim::interpolate( st::separatePanelTitleLeft, _back->width() + st::separatePanelTitleSkip, @@ -376,9 +376,7 @@ void SeparatePanel::updateControlsGeometry() { void SeparatePanel::paintEvent(QPaintEvent *e) { Painter p(this); if (!_animationCache.isNull()) { - auto opacity = _opacityAnimation.current( - crl::now(), - _visible ? 1. : 0.); + auto opacity = _opacityAnimation.value(_visible ? 1. : 0.); if (!_opacityAnimation.animating()) { finishAnimating(); if (isHidden()) return; diff --git a/Telegram/SourceFiles/ui/widgets/separate_panel.h b/Telegram/SourceFiles/ui/widgets/separate_panel.h index c00145478..bb286c759 100644 --- a/Telegram/SourceFiles/ui/widgets/separate_panel.h +++ b/Telegram/SourceFiles/ui/widgets/separate_panel.h @@ -8,6 +8,7 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL #pragma once #include "ui/rp_widget.h" +#include "ui/effects/animations.h" #include "boxes/abstract_box.h" namespace Ui { @@ -97,10 +98,10 @@ private: QPoint _dragStartMousePosition; QPoint _dragStartMyPosition; - Animation _titleLeft; + Ui::Animations::Simple _titleLeft; bool _visible = false; - Animation _opacityAnimation; + Ui::Animations::Simple _opacityAnimation; QPixmap _animationCache; QPixmap _borderParts; diff --git a/Telegram/SourceFiles/ui/widgets/tooltip.cpp b/Telegram/SourceFiles/ui/widgets/tooltip.cpp index c7bbf7766..d9623d801 100644 --- a/Telegram/SourceFiles/ui/widgets/tooltip.cpp +++ b/Telegram/SourceFiles/ui/widgets/tooltip.cpp @@ -312,7 +312,7 @@ void ImportantTooltip::toggleFast(bool visible) { setVisible(_visible); } if (_visibleAnimation.animating() || _visible != visible) { - _visibleAnimation.finish(); + _visibleAnimation.stop(); _visible = visible; checkAnimationFinish(); } @@ -347,7 +347,7 @@ void ImportantTooltip::updateGeometry() { accumulate_min(left, areaMiddle - _st.arrow - _st.arrowSkipMin); auto countTop = [this] { - auto shift = anim::interpolate(_st.shift, 0, _visibleAnimation.current(_visible ? 1. : 0.)); + auto shift = anim::interpolate(_st.shift, 0, _visibleAnimation.value(_visible ? 1. : 0.)); if (_side & RectPart::Top) { return _area.y() - height() - shift; } @@ -375,7 +375,7 @@ void ImportantTooltip::paintEvent(QPaintEvent *e) { auto inner = countInner(); if (_useTransparency) { if (!_cache.isNull()) { - auto opacity = _visibleAnimation.current(_visible ? 1. : 0.); + auto opacity = _visibleAnimation.value(_visible ? 1. : 0.); p.setOpacity(opacity); p.drawPixmap(0, 0, _cache); } else { diff --git a/Telegram/SourceFiles/ui/widgets/tooltip.h b/Telegram/SourceFiles/ui/widgets/tooltip.h index 09e6196da..f0f03fd7a 100644 --- a/Telegram/SourceFiles/ui/widgets/tooltip.h +++ b/Telegram/SourceFiles/ui/widgets/tooltip.h @@ -8,6 +8,7 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL #pragma once #include "base/timer.h" +#include "ui/effects/animations.h" namespace style { struct Tooltip; @@ -80,8 +81,8 @@ public: } protected: - void resizeEvent(QResizeEvent *e); - void paintEvent(QPaintEvent *e); + void resizeEvent(QResizeEvent *e) override; + void paintEvent(QPaintEvent *e) override; private: void animationCallback(); @@ -99,7 +100,7 @@ private: RectParts _side = RectPart::Top | RectPart::Left; QPixmap _arrow; - Animation _visibleAnimation; + Ui::Animations::Simple _visibleAnimation; bool _visible = false; Fn _hiddenCallback; bool _useTransparency = true; diff --git a/Telegram/SourceFiles/ui/wrap/slide_wrap.cpp b/Telegram/SourceFiles/ui/wrap/slide_wrap.cpp index d55e7559f..93e834662 100644 --- a/Telegram/SourceFiles/ui/wrap/slide_wrap.cpp +++ b/Telegram/SourceFiles/ui/wrap/slide_wrap.cpp @@ -73,7 +73,7 @@ SlideWrap *SlideWrap::toggle( } SlideWrap *SlideWrap::finishAnimating() { - _animation.finish(); + _animation.stop(); animationStep(); return this; } @@ -96,7 +96,7 @@ void SlideWrap::animationStep() { weak->moveToLeft(margins.left(), margins.top()); newWidth = weak->width(); } - auto current = _animation.current(_toggled ? 1. : 0.); + auto current = _animation.value(_toggled ? 1. : 0.); auto newHeight = wrapped() ? (_animation.animating() ? anim::interpolate(0, wrapped()->heightNoMargins(), current) diff --git a/Telegram/SourceFiles/ui/wrap/slide_wrap.h b/Telegram/SourceFiles/ui/wrap/slide_wrap.h index ae3f35ee6..d53aefb77 100644 --- a/Telegram/SourceFiles/ui/wrap/slide_wrap.h +++ b/Telegram/SourceFiles/ui/wrap/slide_wrap.h @@ -7,6 +7,7 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL */ #pragma once +#include "ui/effects/animations.h" #include "ui/wrap/padding_wrap.h" namespace Ui { @@ -62,7 +63,7 @@ private: bool _toggled = true; rpl::event_stream _toggledChanged; - Animation _animation; + Ui::Animations::Simple _animation; int _duration = 0; }; diff --git a/Telegram/SourceFiles/window/layer_widget.cpp b/Telegram/SourceFiles/window/layer_widget.cpp index 27192a17b..6f574da04 100644 --- a/Telegram/SourceFiles/window/layer_widget.cpp +++ b/Telegram/SourceFiles/window/layer_widget.cpp @@ -83,10 +83,10 @@ private: bool _wasAnimating = false; bool _inPaintEvent = false; - Animation _a_shown; - Animation _a_mainMenuShown; - Animation _a_specialLayerShown; - Animation _a_layerShown; + Ui::Animations::Simple _a_shown; + Ui::Animations::Simple _a_mainMenuShown; + Ui::Animations::Simple _a_specialLayerShown; + Ui::Animations::Simple _a_layerShown; QRect _specialLayerBox, _specialLayerCacheBox; QRect _layerBox, _layerCacheBox; @@ -217,8 +217,7 @@ void LayerStackWidget::BackgroundWidget::paintEvent(QPaintEvent *e) { auto specialLayerBox = _specialLayerCache.isNull() ? _specialLayerBox : _specialLayerCacheBox; auto layerBox = _layerCache.isNull() ? _layerBox : _layerCacheBox; - auto ms = crl::now(); - auto mainMenuProgress = _a_mainMenuShown.current(ms, -1); + auto mainMenuProgress = _a_mainMenuShown.value(-1); auto mainMenuRight = (_mainMenuCache.isNull() || mainMenuProgress < 0) ? _mainMenuRight : (mainMenuProgress < 0) ? _mainMenuRight : anim::interpolate(0, _mainMenuCacheWidth, mainMenuProgress); if (mainMenuRight) { // Move showing boxes to the right while main menu is hiding. @@ -229,9 +228,9 @@ void LayerStackWidget::BackgroundWidget::paintEvent(QPaintEvent *e) { layerBox.moveLeft(layerBox.left() + mainMenuRight / 2); } } - auto bgOpacity = _a_shown.current(ms, isShown() ? 1. : 0.); - auto specialLayerOpacity = _a_specialLayerShown.current(ms, _specialLayerShown ? 1. : 0.); - auto layerOpacity = _a_layerShown.current(ms, _layerShown ? 1. : 0.); + auto bgOpacity = _a_shown.value(isShown() ? 1. : 0.); + auto specialLayerOpacity = _a_specialLayerShown.value(_specialLayerShown ? 1. : 0.); + auto layerOpacity = _a_layerShown.value(_layerShown ? 1. : 0.); if (bgOpacity == 0.) { return; } @@ -320,10 +319,10 @@ void LayerStackWidget::BackgroundWidget::paintEvent(QPaintEvent *e) { } void LayerStackWidget::BackgroundWidget::finishAnimating() { - _a_shown.finish(); - _a_mainMenuShown.finish(); - _a_specialLayerShown.finish(); - _a_layerShown.finish(); + _a_shown.stop(); + _a_mainMenuShown.stop(); + _a_specialLayerShown.stop(); + _a_layerShown.stop(); checkIfDone(); } @@ -863,7 +862,7 @@ void MediaPreviewWidget::paintEvent(QPaintEvent *e) { auto image = currentImage(); int w = image.width() / cIntRetinaFactor(), h = image.height() / cIntRetinaFactor(); - auto shown = _a_shown.current(crl::now(), _hiding ? 0. : 1.); + auto shown = _a_shown.value(_hiding ? 0. : 1.); if (!_a_shown.animating()) { if (_hiding) { hide(); @@ -964,8 +963,8 @@ void MediaPreviewWidget::fillEmojiString() { while (_emojiList.size() > kStickerPreviewEmojiLimit) { _emojiList.pop_back(); } - } else if (auto emoji = Ui::Emoji::Find(sticker->alt)) { - _emojiList.push_back(emoji); + } else if (const auto emoji = Ui::Emoji::Find(sticker->alt)) { + _emojiList.emplace_back(emoji); } } } diff --git a/Telegram/SourceFiles/window/layer_widget.h b/Telegram/SourceFiles/window/layer_widget.h index 7c8623d94..fb3b30dd9 100644 --- a/Telegram/SourceFiles/window/layer_widget.h +++ b/Telegram/SourceFiles/window/layer_widget.h @@ -8,6 +8,7 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL #pragma once #include "ui/rp_widget.h" +#include "ui/effects/animations.h" #include "data/data_file_origin.h" namespace Window { @@ -221,7 +222,7 @@ private: not_null _controller; - Animation _a_shown; + Ui::Animations::Simple _a_shown; bool _hiding = false; Data::FileOrigin _origin; DocumentData *_document = nullptr; diff --git a/Telegram/SourceFiles/window/notifications_manager_default.cpp b/Telegram/SourceFiles/window/notifications_manager_default.cpp index 8a1bb5683..862c52ece 100644 --- a/Telegram/SourceFiles/window/notifications_manager_default.cpp +++ b/Telegram/SourceFiles/window/notifications_manager_default.cpp @@ -132,7 +132,7 @@ void Manager::demoMasterOpacityCallback() { } float64 Manager::demoMasterOpacity() const { - return _demoMasterOpacity.current(Global::NotificationsDemoIsShown() ? 0. : 1.); + return _demoMasterOpacity.value(Global::NotificationsDemoIsShown() ? 0. : 1.); } void Manager::checkLastInput() { @@ -444,7 +444,7 @@ void Widget::hideAnimated(float64 duration, const anim::transition &func) { } void Widget::updateOpacity() { - setWindowOpacity(_a_opacity.current(_hiding ? 0. : 1.) * _manager->demoMasterOpacity()); + setWindowOpacity(_a_opacity.value(_hiding ? 0. : 1.) * _manager->demoMasterOpacity()); } void Widget::changeShift(int top) { @@ -632,8 +632,8 @@ void Notification::paintEvent(QPaintEvent *e) { auto buttonsLeft = st::notifyPhotoPos.x() + st::notifyPhotoSize + st::notifyTextLeft; auto buttonsTop = st::notifyTextTop + st::msgNameFont->height; - if (a_actionsOpacity.animating(crl::now())) { - p.setOpacity(a_actionsOpacity.current()); + if (a_actionsOpacity.animating()) { + p.setOpacity(a_actionsOpacity.value(1.)); p.drawPixmapRight(st::notifyBorderWidth, buttonsTop, width(), _buttonsCache); } else if (_actionsVisible) { p.drawPixmapRight(st::notifyBorderWidth, buttonsTop, width(), _buttonsCache); diff --git a/Telegram/SourceFiles/window/notifications_manager_default.h b/Telegram/SourceFiles/window/notifications_manager_default.h index b002a73d2..a453ca068 100644 --- a/Telegram/SourceFiles/window/notifications_manager_default.h +++ b/Telegram/SourceFiles/window/notifications_manager_default.h @@ -93,7 +93,7 @@ private: }; std::deque _queuedNotifications; - Animation _demoMasterOpacity; + Ui::Animations::Simple _demoMasterOpacity; mutable QPixmap _hiddenUserpicPlaceholder; @@ -147,7 +147,7 @@ private: bool _hiding = false; bool _deleted = false; base::binary_guard _hidingDelayed; - Animation _a_opacity; + Ui::Animations::Simple _a_opacity; QPoint _startPosition; Direction _direction; @@ -214,7 +214,7 @@ private: bool _hideReplyButton = false; bool _actionsVisible = false; - Animation a_actionsOpacity; + Ui::Animations::Simple a_actionsOpacity; QPixmap _buttonsCache; crl::time _started; diff --git a/Telegram/SourceFiles/window/themes/window_theme_editor_block.cpp b/Telegram/SourceFiles/window/themes/window_theme_editor_block.cpp index b98970ce3..0e38d6907 100644 --- a/Telegram/SourceFiles/window/themes/window_theme_editor_block.cpp +++ b/Telegram/SourceFiles/window/themes/window_theme_editor_block.cpp @@ -623,19 +623,18 @@ void EditorBlock::paintEvent(QPaintEvent *e) { p.drawText(QRect(0, 0, width(), st::noContactsHeight), lang(lng_theme_editor_no_keys)); } - auto ms = crl::now(); auto cliptop = clip.y(); auto clipbottom = cliptop + clip.height(); - enumerateRowsFrom(cliptop, [this, &p, clipbottom, ms](int index, const Row &row) { + enumerateRowsFrom(cliptop, [&](int index, const Row &row) { if (row.top() >= clipbottom) { return false; } - paintRow(p, index, row, ms); + paintRow(p, index, row); return true; }); } -void EditorBlock::paintRow(Painter &p, int index, const Row &row, crl::time ms) { +void EditorBlock::paintRow(Painter &p, int index, const Row &row) { auto rowTop = row.top() + st::themeEditorMargin.top(); auto rect = QRect(0, row.top(), width(), row.height()); @@ -643,7 +642,7 @@ void EditorBlock::paintRow(Painter &p, int index, const Row &row, crl::time ms) auto active = (findRowIndex(&row) == _editing); p.fillRect(rect, active ? st::dialogsBgActive : selected ? st::dialogsBgOver : st::dialogsBg); if (auto ripple = row.ripple()) { - ripple->paint(p, 0, row.top(), width(), ms, &(active ? st::activeButtonBgRipple : st::windowBgRipple)->c); + ripple->paint(p, 0, row.top(), width(), &(active ? st::activeButtonBgRipple : st::windowBgRipple)->c); if (ripple->empty()) { row.resetRipple(); } diff --git a/Telegram/SourceFiles/window/themes/window_theme_editor_block.h b/Telegram/SourceFiles/window/themes/window_theme_editor_block.h index c81b680df..45ad9df51 100644 --- a/Telegram/SourceFiles/window/themes/window_theme_editor_block.h +++ b/Telegram/SourceFiles/window/themes/window_theme_editor_block.h @@ -107,7 +107,7 @@ private: Row *findRow(const QString &name); int findRowIndex(const Row *row); void updateRow(const Row &row); - void paintRow(Painter &p, int index, const Row &row, crl::time ms); + void paintRow(Painter &p, int index, const Row &row); void updateSelected(QPoint localPosition); void setSelected(int selected); diff --git a/Telegram/SourceFiles/window/themes/window_theme_warning.cpp b/Telegram/SourceFiles/window/themes/window_theme_warning.cpp index e10e1bd86..dcb6db221 100644 --- a/Telegram/SourceFiles/window/themes/window_theme_warning.cpp +++ b/Telegram/SourceFiles/window/themes/window_theme_warning.cpp @@ -42,12 +42,12 @@ void WarningWidget::paintEvent(QPaintEvent *e) { Painter p(this); if (!_cache.isNull()) { - if (!_animation.animating(crl::now())) { + if (!_animation.animating()) { if (isHidden()) { return; } } - p.setOpacity(_animation.current(_hiding ? 0. : 1.)); + p.setOpacity(_animation.value(_hiding ? 0. : 1.)); p.drawPixmap(_outer.topLeft(), _cache); if (!_animation.animating()) { _cache = QPixmap(); diff --git a/Telegram/SourceFiles/window/themes/window_theme_warning.h b/Telegram/SourceFiles/window/themes/window_theme_warning.h index aaef1abbe..b72466d9b 100644 --- a/Telegram/SourceFiles/window/themes/window_theme_warning.h +++ b/Telegram/SourceFiles/window/themes/window_theme_warning.h @@ -8,6 +8,7 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL #pragma once #include "base/timer.h" +#include "ui/effects/animations.h" namespace Ui { class RoundButton; @@ -41,7 +42,7 @@ private: void handleTimer(); bool _hiding = false; - Animation _animation; + Ui::Animations::Simple _animation; QPixmap _cache; QRect _inner, _outer; diff --git a/Telegram/SourceFiles/window/window_connecting_widget.cpp b/Telegram/SourceFiles/window/window_connecting_widget.cpp index d00b1001a..72fdf5062 100644 --- a/Telegram/SourceFiles/window/window_connecting_widget.cpp +++ b/Telegram/SourceFiles/window/window_connecting_widget.cpp @@ -245,11 +245,11 @@ void ConnectionState::raise() { void ConnectionState::finishAnimating() { if (_contentWidth.animating()) { - _contentWidth.finish(); + _contentWidth.stop(); updateWidth(); } if (_visibility.animating()) { - _visibility.finish(); + _visibility.stop(); updateVisibility(); } } @@ -376,14 +376,14 @@ void ConnectionState::refreshProgressVisibility() { void ConnectionState::updateVisibility() { const auto value = currentVisibility(); if (value == 0. && _contentWidth.animating()) { - _contentWidth.finish(); + _contentWidth.stop(); updateWidth(); } _visibilityValues.fire_copy(value); } float64 ConnectionState::currentVisibility() const { - return _visibility.current(_currentLayout.visible ? 1. : 0.); + return _visibility.value(_currentLayout.visible ? 1. : 0.); } rpl::producer ConnectionState::visibility() const { @@ -427,7 +427,7 @@ auto ConnectionState::computeLayout(const State &state) const -> Layout { } void ConnectionState::updateWidth() { - const auto current = _contentWidth.current(_currentLayout.contentWidth); + const auto current = _contentWidth.value(_currentLayout.contentWidth); const auto height = st::connectingLeft.height(); const auto desired = QRect(0, 0, current, height).marginsAdded( style::margins( diff --git a/Telegram/SourceFiles/window/window_connecting_widget.h b/Telegram/SourceFiles/window/window_connecting_widget.h index 29bf329f0..1cadf42b7 100644 --- a/Telegram/SourceFiles/window/window_connecting_widget.h +++ b/Telegram/SourceFiles/window/window_connecting_widget.h @@ -9,6 +9,7 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL #include "base/timer.h" #include "base/unique_qptr.h" +#include "ui/effects/animations.h" namespace Ui { class RpWidget; @@ -76,8 +77,8 @@ private: State _state; Layout _currentLayout; crl::time _connectingStartedAt = 0; - Animation _contentWidth; - Animation _visibility; + Ui::Animations::Simple _contentWidth; + Ui::Animations::Simple _visibility; rpl::event_stream _visibilityValues; rpl::lifetime _lifetime; diff --git a/Telegram/SourceFiles/window/window_history_hider.cpp b/Telegram/SourceFiles/window/window_history_hider.cpp index d4addfc52..49b4e08fc 100644 --- a/Telegram/SourceFiles/window/window_history_hider.cpp +++ b/Telegram/SourceFiles/window/window_history_hider.cpp @@ -38,7 +38,7 @@ void HistoryHider::refreshLang() { void HistoryHider::paintEvent(QPaintEvent *e) { Painter p(this); - auto opacity = _a_opacity.current(crl::now(), _hiding ? 0. : 1.); + auto opacity = _a_opacity.value(_hiding ? 0. : 1.); if (opacity == 0.) { if (_hiding) { _hidden.fire({}); diff --git a/Telegram/SourceFiles/window/window_history_hider.h b/Telegram/SourceFiles/window/window_history_hider.h index 9e843905b..da5507206 100644 --- a/Telegram/SourceFiles/window/window_history_hider.h +++ b/Telegram/SourceFiles/window/window_history_hider.h @@ -8,6 +8,7 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL #pragma once #include "ui/rp_widget.h" +#include "ui/effects/animations.h" namespace Ui { class RoundButton; @@ -56,7 +57,7 @@ private: QString _text; Fn _confirm; - Animation _a_opacity; + Ui::Animations::Simple _a_opacity; QRect _box; bool _hiding = false; diff --git a/Telegram/SourceFiles/window/window_lock_widgets.cpp b/Telegram/SourceFiles/window/window_lock_widgets.cpp index db8237dc1..a3520f179 100644 --- a/Telegram/SourceFiles/window/window_lock_widgets.cpp +++ b/Telegram/SourceFiles/window/window_lock_widgets.cpp @@ -40,7 +40,7 @@ void LockWidget::showAnimated(const QPixmap &bgAnimCache, bool back) { _showBack = back; (_showBack ? _cacheOver : _cacheUnder) = bgAnimCache; - _a_show.finish(); + _a_show.stop(); showChildren(); setInnerFocus(); @@ -71,7 +71,7 @@ void LockWidget::animationCallback() { void LockWidget::paintEvent(QPaintEvent *e) { Painter p(this); - auto progress = _a_show.current(crl::now(), 1.); + auto progress = _a_show.value(1.); if (_a_show.animating()) { auto coordUnder = _showBack ? anim::interpolate(-st::slideShift, 0, progress) : anim::interpolate(0, -st::slideShift, progress); auto coordOver = _showBack ? anim::interpolate(0, width(), progress) : anim::interpolate(width(), 0, progress); @@ -258,9 +258,8 @@ void TermsBox::prepare() { }); const auto errorAnimationCallback = [=] { - // lambda 'this' gets deleted in _ageErrorAnimation.current() call. const auto check = ageCheck; - const auto error = _ageErrorAnimation.current( + const auto error = _ageErrorAnimation.value( _ageErrorShown ? 1. : 0.); if (error == 0.) { check->setUntoggledOverride(std::nullopt); diff --git a/Telegram/SourceFiles/window/window_lock_widgets.h b/Telegram/SourceFiles/window/window_lock_widgets.h index 3b9a56e5b..e256746af 100644 --- a/Telegram/SourceFiles/window/window_lock_widgets.h +++ b/Telegram/SourceFiles/window/window_lock_widgets.h @@ -8,6 +8,7 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL #pragma once #include "ui/rp_widget.h" +#include "ui/effects/animations.h" #include "boxes/abstract_box.h" #include "base/bytes.h" @@ -35,7 +36,7 @@ protected: private: void animationCallback(); - Animation _a_show; + Ui::Animations::Simple _a_show; bool _showBack = false; QPixmap _cacheUnder, _cacheOver; @@ -113,7 +114,7 @@ private: bool _attentionAgree = false; bool _ageErrorShown = false; - Animation _ageErrorAnimation; + Ui::Animations::Simple _ageErrorAnimation; }; diff --git a/Telegram/SourceFiles/window/window_slide_animation.cpp b/Telegram/SourceFiles/window/window_slide_animation.cpp index f8a518393..6612fd52e 100644 --- a/Telegram/SourceFiles/window/window_slide_animation.cpp +++ b/Telegram/SourceFiles/window/window_slide_animation.cpp @@ -15,8 +15,7 @@ namespace Window { void SlideAnimation::paintContents(Painter &p, const QRect &update) const { int retina = cIntRetinaFactor(); - // Animation callback can destroy "this", so we don't pass "ms". - auto progress = _animation.current((_direction == SlideDirection::FromLeft) ? 0. : 1.); + auto progress = _animation.value((_direction == SlideDirection::FromLeft) ? 0. : 1.); if (_withFade) { p.fillRect(update, st::boxBg); diff --git a/Telegram/SourceFiles/window/window_slide_animation.h b/Telegram/SourceFiles/window/window_slide_animation.h index 206e50fed..54d80e9e7 100644 --- a/Telegram/SourceFiles/window/window_slide_animation.h +++ b/Telegram/SourceFiles/window/window_slide_animation.h @@ -7,6 +7,8 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL */ #pragma once +#include "ui/effects/animations.h" + namespace Window { enum class SlideDirection { @@ -42,7 +44,7 @@ private: bool _topBarShadowEnabled = false; bool _withFade = false; - mutable Animation _animation; + mutable Ui::Animations::Simple _animation; QPixmap _cacheUnder, _cacheOver; RepaintCallback _repaintCallback;