mirror of
https://github.com/AyuGram/AyuGramDesktop.git
synced 2025-06-05 06:33:57 +02:00
Show effect loading animation.
This commit is contained in:
parent
ec5d8b7373
commit
8a58ded582
2 changed files with 40 additions and 4 deletions
|
@ -28,6 +28,7 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL
|
||||||
#include "ui/chat/chat_style.h"
|
#include "ui/chat/chat_style.h"
|
||||||
#include "ui/chat/chat_theme.h"
|
#include "ui/chat/chat_theme.h"
|
||||||
#include "ui/effects/path_shift_gradient.h"
|
#include "ui/effects/path_shift_gradient.h"
|
||||||
|
#include "ui/effects/radial_animation.h"
|
||||||
#include "ui/effects/ripple_animation.h"
|
#include "ui/effects/ripple_animation.h"
|
||||||
#include "ui/text/text_utilities.h"
|
#include "ui/text/text_utilities.h"
|
||||||
#include "ui/widgets/buttons.h"
|
#include "ui/widgets/buttons.h"
|
||||||
|
@ -103,6 +104,7 @@ private:
|
||||||
void setupSend(Details details);
|
void setupSend(Details details);
|
||||||
void createLottie();
|
void createLottie();
|
||||||
|
|
||||||
|
bool checkIconBecameLoaded();
|
||||||
[[nodiscard]] bool checkReady();
|
[[nodiscard]] bool checkReady();
|
||||||
|
|
||||||
const EffectId _effectId = 0;
|
const EffectId _effectId = 0;
|
||||||
|
@ -130,6 +132,8 @@ private:
|
||||||
QRect _inner;
|
QRect _inner;
|
||||||
QImage _bg;
|
QImage _bg;
|
||||||
QPoint _itemShift;
|
QPoint _itemShift;
|
||||||
|
QRect _iconRect;
|
||||||
|
std::unique_ptr<Ui::InfiniteRadialAnimation> _loading;
|
||||||
|
|
||||||
rpl::lifetime _readyCheckLifetime;
|
rpl::lifetime _readyCheckLifetime;
|
||||||
|
|
||||||
|
@ -289,6 +293,28 @@ void EffectPreview::paintEvent(QPaintEvent *e) {
|
||||||
_item->draw(p, context);
|
_item->draw(p, context);
|
||||||
p.translate(-_itemShift);
|
p.translate(-_itemShift);
|
||||||
|
|
||||||
|
checkIconBecameLoaded();
|
||||||
|
if (_icon.isNull()) {
|
||||||
|
if (!_loading) {
|
||||||
|
_loading = std::make_unique<Ui::InfiniteRadialAnimation>([=] {
|
||||||
|
update();
|
||||||
|
}, st::effectPreviewLoading);
|
||||||
|
_loading->start(st::defaultInfiniteRadialAnimation.linearPeriod);
|
||||||
|
}
|
||||||
|
const auto loading = _iconRect.marginsRemoved(
|
||||||
|
{ st::lineWidth, st::lineWidth, st::lineWidth, st::lineWidth });
|
||||||
|
auto hq = PainterHighQualityEnabler(p);
|
||||||
|
Ui::InfiniteRadialAnimation::Draw(
|
||||||
|
p,
|
||||||
|
_loading->computeState(),
|
||||||
|
loading.topLeft(),
|
||||||
|
loading.size(),
|
||||||
|
width(),
|
||||||
|
_chatStyle->msgInDateFg(),
|
||||||
|
st::effectPreviewLoading.thickness);
|
||||||
|
} else {
|
||||||
|
_loading = nullptr;
|
||||||
|
}
|
||||||
if (_lottie && _lottie->ready()) {
|
if (_lottie && _lottie->ready()) {
|
||||||
const auto factor = style::DevicePixelRatio();
|
const auto factor = style::DevicePixelRatio();
|
||||||
auto request = Lottie::FrameRequest();
|
auto request = Lottie::FrameRequest();
|
||||||
|
@ -364,6 +390,7 @@ void EffectPreview::setupItem() {
|
||||||
shift + icon.x() + (icon.width() - size.width()) / 2,
|
shift + icon.x() + (icon.width() - size.width()) / 2,
|
||||||
icon.y() + (icon.height() - size.height()) / 2);
|
icon.y() + (icon.height() - size.height()) / 2);
|
||||||
_itemShift = _inner.topLeft() - position;
|
_itemShift = _inner.topLeft() - position;
|
||||||
|
_iconRect = icon.translated(_itemShift);
|
||||||
}
|
}
|
||||||
|
|
||||||
void EffectPreview::repaintBackground() {
|
void EffectPreview::repaintBackground() {
|
||||||
|
@ -462,11 +489,17 @@ void EffectPreview::setupSend(Details details) {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
bool EffectPreview::checkIconBecameLoaded() {
|
||||||
|
if (!_icon.isNull()) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
const auto reactions = &_show->session().data().reactions();
|
||||||
|
_icon = reactions->resolveEffectImageFor(_effect.id.custom());
|
||||||
|
return !_icon.isNull();
|
||||||
|
}
|
||||||
|
|
||||||
bool EffectPreview::checkReady() {
|
bool EffectPreview::checkReady() {
|
||||||
if (_icon.isNull()) {
|
if (checkIconBecameLoaded()) {
|
||||||
const auto reactions = &_show->session().data().reactions();
|
|
||||||
_icon = reactions->resolveEffectImageFor(_effect.id.custom());
|
|
||||||
repaintBackground();
|
|
||||||
update();
|
update();
|
||||||
}
|
}
|
||||||
if (_effect.aroundAnimation) {
|
if (_effect.aroundAnimation) {
|
||||||
|
|
|
@ -1129,3 +1129,6 @@ effectPreviewPromoLabel: FlatLabel(defaultFlatLabel) {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
effectPreviewPromoPadding: margins(4px, 6px, 4px, 6px);
|
effectPreviewPromoPadding: margins(4px, 6px, 4px, 6px);
|
||||||
|
effectPreviewLoading: InfiniteRadialAnimation(defaultInfiniteRadialAnimation) {
|
||||||
|
thickness: 2px;
|
||||||
|
}
|
||||||
|
|
Loading…
Add table
Reference in a new issue