mirror of
https://github.com/AyuGram/AyuGramDesktop.git
synced 2025-06-05 06:33:57 +02:00
Show path gradient while loading sticker preview.
This commit is contained in:
parent
b1dd3b2a19
commit
d1cb558b43
1 changed files with 34 additions and 14 deletions
|
@ -15,7 +15,9 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL
|
||||||
#include "lang/lang_keys.h"
|
#include "lang/lang_keys.h"
|
||||||
#include "main/main_session.h"
|
#include "main/main_session.h"
|
||||||
#include "ui/chat/chat_theme.h"
|
#include "ui/chat/chat_theme.h"
|
||||||
|
#include "ui/chat/chat_style.h"
|
||||||
#include "ui/layers/generic_box.h"
|
#include "ui/layers/generic_box.h"
|
||||||
|
#include "ui/effects/path_shift_gradient.h"
|
||||||
#include "ui/effects/premium_graphics.h"
|
#include "ui/effects/premium_graphics.h"
|
||||||
#include "ui/widgets/buttons.h"
|
#include "ui/widgets/buttons.h"
|
||||||
#include "ui/widgets/gradient_round_button.h"
|
#include "ui/widgets/gradient_round_button.h"
|
||||||
|
@ -23,6 +25,7 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL
|
||||||
#include "settings/settings_premium.h"
|
#include "settings/settings_premium.h"
|
||||||
#include "lottie/lottie_single_player.h"
|
#include "lottie/lottie_single_player.h"
|
||||||
#include "history/view/media/history_view_sticker.h"
|
#include "history/view/media/history_view_sticker.h"
|
||||||
|
#include "history/view/history_view_element.h"
|
||||||
#include "window/window_session_controller.h"
|
#include "window/window_session_controller.h"
|
||||||
#include "styles/style_layers.h"
|
#include "styles/style_layers.h"
|
||||||
#include "styles/style_chat_helpers.h"
|
#include "styles/style_chat_helpers.h"
|
||||||
|
@ -50,16 +53,18 @@ void PreloadSticker(const std::shared_ptr<Data::DocumentMedia> &media) {
|
||||||
|
|
||||||
[[nodiscard]] object_ptr<Ui::RpWidget> StickerPreview(
|
[[nodiscard]] object_ptr<Ui::RpWidget> StickerPreview(
|
||||||
QWidget *parent,
|
QWidget *parent,
|
||||||
|
not_null<Window::SessionController*> controller,
|
||||||
const std::shared_ptr<Data::DocumentMedia> &media,
|
const std::shared_ptr<Data::DocumentMedia> &media,
|
||||||
const QImage &back,
|
const QImage &back,
|
||||||
int size) {
|
QSize size) {
|
||||||
auto result = object_ptr<Ui::FixedHeightWidget>(parent, size);
|
auto result = object_ptr<Ui::FixedHeightWidget>(parent, size.height());
|
||||||
const auto raw = result.data();
|
const auto raw = result.data();
|
||||||
auto &lifetime = raw->lifetime();
|
auto &lifetime = raw->lifetime();
|
||||||
|
|
||||||
struct State {
|
struct State {
|
||||||
std::unique_ptr<Lottie::SinglePlayer> lottie;
|
std::unique_ptr<Lottie::SinglePlayer> lottie;
|
||||||
std::unique_ptr<Lottie::SinglePlayer> effect;
|
std::unique_ptr<Lottie::SinglePlayer> effect;
|
||||||
|
std::unique_ptr<Ui::PathShiftGradient> pathGradient;
|
||||||
};
|
};
|
||||||
const auto state = lifetime.make_state<State>();
|
const auto state = lifetime.make_state<State>();
|
||||||
|
|
||||||
|
@ -97,6 +102,9 @@ void PreloadSticker(const std::shared_ptr<Data::DocumentMedia> &media) {
|
||||||
state->lottie->updates() | rpl::start_with_next(update, lifetime);
|
state->lottie->updates() | rpl::start_with_next(update, lifetime);
|
||||||
state->effect->updates() | rpl::start_with_next(update, lifetime);
|
state->effect->updates() | rpl::start_with_next(update, lifetime);
|
||||||
};
|
};
|
||||||
|
state->pathGradient = MakePathShiftGradient(
|
||||||
|
controller->chatStyle(),
|
||||||
|
[=] { raw->update(); });
|
||||||
|
|
||||||
raw->paintRequest(
|
raw->paintRequest(
|
||||||
) | rpl::start_with_next([=] {
|
) | rpl::start_with_next([=] {
|
||||||
|
@ -104,9 +112,22 @@ void PreloadSticker(const std::shared_ptr<Data::DocumentMedia> &media) {
|
||||||
|
|
||||||
auto p = QPainter(raw);
|
auto p = QPainter(raw);
|
||||||
p.drawImage(0, 0, back);
|
p.drawImage(0, 0, back);
|
||||||
|
|
||||||
|
const auto zero = (size.width() - effectSize.width()) / 2;
|
||||||
|
const auto left = zero
|
||||||
|
+ effectSize.width()
|
||||||
|
- int(lottieSize.width() * (1. + kPremiumShift));
|
||||||
|
const auto top = (effectSize.height() - lottieSize.height()) / 2;
|
||||||
|
const auto r = QRect(QPoint(left, top), lottieSize);
|
||||||
if (!state->lottie
|
if (!state->lottie
|
||||||
|| !state->lottie->ready()
|
|| !state->lottie->ready()
|
||||||
|| !state->effect->ready()) {
|
|| !state->effect->ready()) {
|
||||||
|
p.setBrush(controller->chatStyle()->msgServiceBg());
|
||||||
|
ChatHelpers::PaintStickerThumbnailPath(
|
||||||
|
p,
|
||||||
|
media.get(),
|
||||||
|
r,
|
||||||
|
state->pathGradient.get());
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -121,13 +142,8 @@ void PreloadSticker(const std::shared_ptr<Data::DocumentMedia> &media) {
|
||||||
// ? state->effect->framesCount()
|
// ? state->effect->framesCount()
|
||||||
// : 1;
|
// : 1;
|
||||||
|
|
||||||
const auto left = effectSize.width()
|
p.drawImage(r, frame.image);
|
||||||
- int(lottieSize.width() * (1. + kPremiumShift));
|
p.drawImage(QRect(QPoint(zero, 0), effectSize), effect.image);
|
||||||
const auto top = (effectSize.height() - lottieSize.height()) / 2;
|
|
||||||
p.drawImage(
|
|
||||||
QRect(QPoint(left, top), lottieSize),
|
|
||||||
state->lottie->frame());
|
|
||||||
p.drawImage(raw->rect(), state->effect->frame());
|
|
||||||
|
|
||||||
if (!frame.image.isNull()/*
|
if (!frame.image.isNull()/*
|
||||||
&& ((frame.index % effectsCount) <= effect.index)*/) {
|
&& ((frame.index % effectsCount) <= effect.index)*/) {
|
||||||
|
@ -183,16 +199,18 @@ void StickerBox(
|
||||||
not_null<Window::SessionController*> controller,
|
not_null<Window::SessionController*> controller,
|
||||||
const std::shared_ptr<Data::DocumentMedia> &media,
|
const std::shared_ptr<Data::DocumentMedia> &media,
|
||||||
const QImage &back) {
|
const QImage &back) {
|
||||||
const auto size = st::boxWideWidth;
|
const auto size = QSize(
|
||||||
box->setWidth(size);
|
st::boxWideWidth,
|
||||||
|
HistoryView::Sticker::PremiumEffectSize(media->owner()).height());
|
||||||
|
box->setWidth(size.width());
|
||||||
box->setNoContentMargin(true);
|
box->setNoContentMargin(true);
|
||||||
box->addRow(StickerPreview(box, media, back, size), {});
|
box->addRow(StickerPreview(box, controller, media, back, size), {});
|
||||||
const auto padding = st::premiumPreviewAboutPadding;
|
const auto padding = st::premiumPreviewAboutPadding;
|
||||||
auto label = object_ptr<Ui::FlatLabel>(
|
auto label = object_ptr<Ui::FlatLabel>(
|
||||||
box,
|
box,
|
||||||
tr::lng_sticker_premium_about(),
|
tr::lng_sticker_premium_about(),
|
||||||
st::premiumPreviewAbout);
|
st::premiumPreviewAbout);
|
||||||
label->resizeToWidth(size - padding.left() - padding.right());
|
label->resizeToWidth(size.width() - padding.left() - padding.right());
|
||||||
box->addRow(
|
box->addRow(
|
||||||
object_ptr<Ui::CenterWrap<Ui::FlatLabel>>(
|
object_ptr<Ui::CenterWrap<Ui::FlatLabel>>(
|
||||||
box,
|
box,
|
||||||
|
@ -200,7 +218,9 @@ void StickerBox(
|
||||||
padding);
|
padding);
|
||||||
box->setStyle(st::premiumPreviewBox);
|
box->setStyle(st::premiumPreviewBox);
|
||||||
const auto buttonPadding = st::premiumPreviewBox.buttonPadding;
|
const auto buttonPadding = st::premiumPreviewBox.buttonPadding;
|
||||||
const auto width = size - buttonPadding.left() - buttonPadding.right();
|
const auto width = size.width()
|
||||||
|
- buttonPadding.left()
|
||||||
|
- buttonPadding.right();
|
||||||
auto button = CreateUnlockButton(box, width);
|
auto button = CreateUnlockButton(box, width);
|
||||||
button->setClickedCallback([=] {
|
button->setClickedCallback([=] {
|
||||||
Settings::ShowPremium(controller, "premium_stickers");
|
Settings::ShowPremium(controller, "premium_stickers");
|
||||||
|
|
Loading…
Add table
Reference in a new issue