From 0aaa88cb7950959bb3b9afdb231887ed3ec11a68 Mon Sep 17 00:00:00 2001 From: 23rd <23rd@vivaldi.net> Date: Mon, 1 Feb 2021 09:33:32 +0300 Subject: [PATCH] Added animation to toggle silent broadcast button. --- .../icons/send_control_silent_on.png | Bin 572 -> 0 bytes .../icons/send_control_silent_on@2x.png | Bin 1051 -> 0 bytes .../icons/send_control_silent_on@3x.png | Bin 1895 -> 0 bytes Telegram/SourceFiles/ui/chat/chat.style | 10 ++- Telegram/SourceFiles/ui/special_buttons.cpp | 72 +++++++++++++----- Telegram/SourceFiles/ui/special_buttons.h | 12 ++- 6 files changed, 71 insertions(+), 23 deletions(-) delete mode 100644 Telegram/Resources/icons/send_control_silent_on.png delete mode 100644 Telegram/Resources/icons/send_control_silent_on@2x.png delete mode 100644 Telegram/Resources/icons/send_control_silent_on@3x.png diff --git a/Telegram/Resources/icons/send_control_silent_on.png b/Telegram/Resources/icons/send_control_silent_on.png deleted file mode 100644 index a22728951ad2f05e5377445cec1087a7195df183..0000000000000000000000000000000000000000 GIT binary patch literal 0 HcmV?d00001 literal 572 zcmV-C0>k}@P)L}-GT`csw2|FVd6w8%6%Bh^i0y@Csj;PnInJ0000< KMNUMnLSTXjRsXaA diff --git a/Telegram/Resources/icons/send_control_silent_on@2x.png b/Telegram/Resources/icons/send_control_silent_on@2x.png deleted file mode 100644 index 810b0947009cfc2096dafdffdd312cc9f05bee93..0000000000000000000000000000000000000000 GIT binary patch literal 0 HcmV?d00001 literal 1051 zcmV+$1mydPP)?ue0go#y`~;DxC{1Zul+phclO@rEI1qyfqrl_)VhFj;~zk+ zLofh|L_&7Eos!8UB@zj;*=!_{NCfeM5W{A(;d5B6Rw2BE0eF3VWdP#wc*T9V97UxA zC@jlyTt$5viD9C~_s{+OfF>2Q60 z%^aJr;_~tm)6>({xdS^pJBUOg&}y{>=O-p6kV>VBF8=>vv)LdPi-iMNU0wapER{-O zVPTr?xBoZkJ!sqirCX-bjptrXd>2x~J?BnAD8yg!1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ZAHj7|O`Vppz$0(%G|T>EOYGoH0Ip_>gYj zz8%TwM5Tyn%49MO4Gpo5rqk)f<;#~N%1KY2Jb}SrfLg5%o5!S5Db#8;3BQCNT1J#n>TO9eY%UqVl*{1VSau-tnWY|5YYf_8z3TrP$-1a zXyhEt?aB-J`T2PJ_H9_dU%!4uPEHPgfP$^LxtX(`>FVl&NF<6oq>PLVym;{gzl9k=C0?ot33 zh-#&#rlt+H_5>gzLUnaDXRS0iI2cjUcjd~J^(Bx!1Bi%FT3QOb-OdVWe0&^PSy`O6 zN=iy#x7+s?AR_K3&dwq~KcCZ9Zf-6nCnxt7AR!ln79=JhqP1G7tE-C@lHc#gty{OY zd=9%3P;m6y+S*tl0lRYFYMxaJg@Sr}d+E%XGhzGu{{5RO zD=Wk9cton0$X>sGJ!IZVH2wMW2eq}eJ9~*WHa14IrIRQM1OjMoZr&L{H*Vb66*DK4 zj7DQDwNi9|R#sN{KF=-b`Sa(|)=JR<;wsj5gWkM(6U|;(bbz?FZFY-3fBqclYkDzf z_k?b0wHi}XQ>>8Qzkk1f0THdO1&xf1goLxayo`c^g8dDMXze}gfq{Vya6BFl%F4qAfPzh@)1kY&8*_7WSXo)Y+}s?xySsPt)638U7^IX`Xz~78c%mx_h(k$0 h97+P>P!bS_{sry290_+TN;&`l002ovPDHLkV1hJdbj<(& diff --git a/Telegram/SourceFiles/ui/chat/chat.style b/Telegram/SourceFiles/ui/chat/chat.style index e112415b2e..c34328a02d 100644 --- a/Telegram/SourceFiles/ui/chat/chat.style +++ b/Telegram/SourceFiles/ui/chat/chat.style @@ -418,8 +418,14 @@ historySilentToggle: IconButton(historyBotKeyboardShow) { icon: icon {{ "send_control_silent_off", historyComposeIconFg }}; iconOver: icon {{ "send_control_silent_off", historyComposeIconFgOver }}; } -historySilentToggleOn: icon {{ "send_control_silent_on", historyComposeIconFg }}; -historySilentToggleOnOver: icon {{ "send_control_silent_on", historyComposeIconFgOver }}; + +historySilentToggleCrossLine: CrossLineAnimation { + fg: historyComposeIconFg; + icon: icon {{ "send_control_silent_off", historyComposeIconFg }}; + startPosition: point(5px, 3px); + endPosition: point(21px, 18px); + stroke: 2px; +} historyReplySkip: 51px; historyReplyNameFg: windowActiveTextFg; diff --git a/Telegram/SourceFiles/ui/special_buttons.cpp b/Telegram/SourceFiles/ui/special_buttons.cpp index a353e5465e..a3bad8c0a9 100644 --- a/Telegram/SourceFiles/ui/special_buttons.cpp +++ b/Telegram/SourceFiles/ui/special_buttons.cpp @@ -43,6 +43,8 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL namespace Ui { namespace { +constexpr auto kAnimationDuration = crl::time(120); + QString CropTitle(not_null peer) { if (peer->isChat() || peer->isMegagroup()) { return tr::lng_create_group_crop(tr::now); @@ -858,19 +860,43 @@ void UserpicButton::prepareUserpicPixmap() { //} SilentToggle::SilentToggle(QWidget *parent, not_null channel) -: IconButton(parent, st::historySilentToggle) +: RippleButton(parent, st::historySilentToggle.ripple) +, _st(st::historySilentToggle) +, _colorOver(st::historyComposeIconFgOver->c) , _channel(channel) -, _checked(channel->owner().notifySilentPosts(_channel)) { +, _checked(channel->owner().notifySilentPosts(_channel)) +, _crossLine(st::historySilentToggleCrossLine) { Expects(!channel->owner().notifySilentPostsUnknown(_channel)); - if (_checked) { - refreshIconOverrides(); - } + resize(_st.width, _st.height); + + style::PaletteChanged( + ) | rpl::start_with_next([=] { + _crossLine.invalidate(); + }, lifetime()); + + paintRequest( + ) | rpl::start_with_next([=](const QRect &clip) { + Painter p(this); + paintRipple(p, _st.rippleAreaPosition, nullptr); + + _crossLine.paint( + p, + (width() - _st.icon.width()) / 2, + (height() - _st.icon.height()) / 2, + _crossLineAnimation.value(_checked ? 1. : 0.), + // Since buttons of the compose controls have no duration + // for the over animation, we can skip this animation here. + isOver() + ? std::make_optional(_colorOver) + : std::nullopt); + }, lifetime()); + setMouseTracking(true); } void SilentToggle::mouseMoveEvent(QMouseEvent *e) { - IconButton::mouseMoveEvent(e); + RippleButton::mouseMoveEvent(e); if (rect().contains(e->pos())) { Ui::Tooltip::Show(1000, this); } else { @@ -881,28 +907,22 @@ void SilentToggle::mouseMoveEvent(QMouseEvent *e) { void SilentToggle::setChecked(bool checked) { if (_checked != checked) { _checked = checked; - refreshIconOverrides(); + _crossLineAnimation.start( + [=] { update(); }, + _checked ? 0. : 1., + _checked ? 1. : 0., + kAnimationDuration); } } -void SilentToggle::refreshIconOverrides() { - const auto iconOverride = _checked - ? &st::historySilentToggleOn - : nullptr; - const auto iconOverOverride = _checked - ? &st::historySilentToggleOnOver - : nullptr; - setIconOverride(iconOverride, iconOverOverride); -} - void SilentToggle::leaveEventHook(QEvent *e) { - IconButton::leaveEventHook(e); + RippleButton::leaveEventHook(e); Ui::Tooltip::Hide(); } void SilentToggle::mouseReleaseEvent(QMouseEvent *e) { setChecked(!_checked); - IconButton::mouseReleaseEvent(e); + RippleButton::mouseReleaseEvent(e); Ui::Tooltip::Show(0, this); _channel->owner().updateNotifySettings( _channel, @@ -924,4 +944,18 @@ bool SilentToggle::tooltipWindowActive() const { return Ui::AppInFocus() && InFocusChain(window()); } +QPoint SilentToggle::prepareRippleStartPosition() const { + const auto result = mapFromGlobal(QCursor::pos()) + - _st.rippleAreaPosition; + const auto rect = QRect(0, 0, _st.rippleAreaSize, _st.rippleAreaSize); + return rect.contains(result) + ? result + : DisabledRippleStartPosition(); +} + +QImage SilentToggle::prepareRippleMask() const { + return RippleAnimation::ellipseMask( + QSize(_st.rippleAreaSize, _st.rippleAreaSize)); +} + } // namespace Ui diff --git a/Telegram/SourceFiles/ui/special_buttons.h b/Telegram/SourceFiles/ui/special_buttons.h index 4cc13286f2..fa9f866862 100644 --- a/Telegram/SourceFiles/ui/special_buttons.h +++ b/Telegram/SourceFiles/ui/special_buttons.h @@ -10,6 +10,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 "ui/effects/cross_line.h" #include "styles/style_window.h" #include "styles/style_widgets.h" @@ -183,7 +184,7 @@ private: //}; class SilentToggle - : public Ui::IconButton + : public Ui::RippleButton , public Ui::AbstractTooltipShower { public: SilentToggle(QWidget *parent, not_null channel); @@ -203,12 +204,19 @@ protected: void mouseReleaseEvent(QMouseEvent *e) override; void leaveEventHook(QEvent *e) override; + QImage prepareRippleMask() const override; + QPoint prepareRippleStartPosition() const override; + private: - void refreshIconOverrides(); + const style::IconButton &_st; + const QColor &_colorOver; not_null _channel; bool _checked = false; + Ui::CrossLineAnimation _crossLine; + Ui::Animations::Simple _crossLineAnimation; + }; } // namespace Ui