mirror of
https://github.com/kotatogram/kotatogram-desktop
synced 2025-08-31 06:35:14 +00:00
Extract some Lottie::Animation code to Lottie::Player.
This commit is contained in:
@@ -19,7 +19,7 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL
|
||||
#include "mainwindow.h"
|
||||
#include "ui/toast/toast.h"
|
||||
#include "ui/emoji_config.h"
|
||||
#include "lottie/lottie_animation.h"
|
||||
#include "lottie/lottie_single_player.h"
|
||||
#include "styles/style_chat_helpers.h"
|
||||
|
||||
namespace Stickers {
|
||||
@@ -1092,7 +1092,7 @@ RecentStickerPack &GetRecentPack() {
|
||||
return cRefRecentStickers();
|
||||
}
|
||||
|
||||
std::unique_ptr<Lottie::Animation> LottieFromDocument(
|
||||
std::unique_ptr<Lottie::SinglePlayer> LottiePlayerFromDocument(
|
||||
not_null<DocumentData*> document,
|
||||
LottieSize sizeTag,
|
||||
QSize box) {
|
||||
@@ -1100,9 +1100,8 @@ std::unique_ptr<Lottie::Animation> LottieFromDocument(
|
||||
const auto filepath = document->filepath();
|
||||
if (box.width() & box.height() > kDontCacheLottieAfterArea) {
|
||||
// Don't use frame caching for large stickers.
|
||||
return Lottie::FromContent(
|
||||
data,
|
||||
filepath,
|
||||
return std::make_unique<Lottie::SinglePlayer>(
|
||||
Lottie::ReadContent(data, filepath),
|
||||
Lottie::FrameRequest{ box });
|
||||
}
|
||||
if (const auto baseKey = document->bigFileBaseCacheKey()) {
|
||||
@@ -1121,14 +1120,15 @@ std::unique_ptr<Lottie::Animation> LottieFromDocument(
|
||||
weak->data().cacheBigFile().put(key, std::move(data));
|
||||
});
|
||||
};
|
||||
return Lottie::FromCached(
|
||||
return std::make_unique<Lottie::SinglePlayer>(
|
||||
get,
|
||||
put,
|
||||
data,
|
||||
filepath,
|
||||
Lottie::ReadContent(data, filepath),
|
||||
Lottie::FrameRequest{ box });
|
||||
}
|
||||
return Lottie::FromContent(data, filepath, Lottie::FrameRequest{ box });
|
||||
return std::make_unique<Lottie::SinglePlayer>(
|
||||
Lottie::ReadContent(data, filepath),
|
||||
Lottie::FrameRequest{ box });
|
||||
}
|
||||
|
||||
} // namespace Stickers
|
||||
|
@@ -12,7 +12,7 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL
|
||||
class DocumentData;
|
||||
|
||||
namespace Lottie {
|
||||
class Animation;
|
||||
class SinglePlayer;
|
||||
} // namespace Lottie
|
||||
|
||||
namespace Stickers {
|
||||
@@ -113,11 +113,9 @@ enum class LottieSize : uchar {
|
||||
MessageHistory,
|
||||
StickerSet,
|
||||
StickersPanel,
|
||||
StickersColumn,
|
||||
MediaPreview,
|
||||
};
|
||||
|
||||
std::unique_ptr<Lottie::Animation> LottieFromDocument(
|
||||
std::unique_ptr<Lottie::SinglePlayer> LottiePlayerFromDocument(
|
||||
not_null<DocumentData*> document,
|
||||
LottieSize sizeTag,
|
||||
QSize box);
|
||||
|
@@ -14,7 +14,7 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL
|
||||
#include "ui/effects/animations.h"
|
||||
#include "ui/effects/ripple_animation.h"
|
||||
#include "ui/image/image.h"
|
||||
#include "lottie/lottie_animation.h"
|
||||
#include "lottie/lottie_single_player.h"
|
||||
#include "boxes/stickers_box.h"
|
||||
#include "inline_bots/inline_bot_result.h"
|
||||
#include "chat_helpers/stickers.h"
|
||||
@@ -1368,9 +1368,9 @@ void StickersListWidget::setupLottie(Set &set, int section, int index) {
|
||||
auto &sticker = set.stickers[index];
|
||||
const auto document = sticker.document;
|
||||
|
||||
sticker.animated = Stickers::LottieFromDocument(
|
||||
sticker.animated = Stickers::LottiePlayerFromDocument(
|
||||
document,
|
||||
Stickers::LottieSize::StickersColumn, // #TODO stickers
|
||||
Stickers::LottieSize::StickersPanel,
|
||||
boundingBoxSize() * cIntRetinaFactor());
|
||||
const auto animation = sticker.animated.get();
|
||||
|
||||
@@ -1424,9 +1424,10 @@ void StickersListWidget::paintSticker(Painter &p, Set &set, int y, int section,
|
||||
if (!paused) {
|
||||
sticker.animated->markFrameShown();
|
||||
}
|
||||
const auto frame = sticker.animated->frame(request);
|
||||
p.drawImage(
|
||||
QRect(ppos, QSize(w, h)),
|
||||
sticker.animated->frame(request));
|
||||
QRect(ppos, frame.size() / cIntRetinaFactor()),
|
||||
frame);
|
||||
} else if (const auto image = document->getStickerSmall()) {
|
||||
if (image->loaded()) {
|
||||
p.drawPixmapLeft(
|
||||
|
@@ -22,7 +22,7 @@ class RippleAnimation;
|
||||
} // namespace Ui
|
||||
|
||||
namespace Lottie {
|
||||
class Animation;
|
||||
class SinglePlayer;
|
||||
} // namespace Lottie
|
||||
|
||||
namespace ChatHelpers {
|
||||
@@ -98,20 +98,22 @@ private:
|
||||
};
|
||||
|
||||
struct OverSticker {
|
||||
int section;
|
||||
int index;
|
||||
bool overDelete;
|
||||
int section = 0;
|
||||
int index = 0;
|
||||
bool overDelete = false;
|
||||
};
|
||||
struct OverSet {
|
||||
int section;
|
||||
int section = 0;
|
||||
};
|
||||
struct OverButton {
|
||||
int section;
|
||||
int section = 0;
|
||||
};
|
||||
struct OverGroupAdd {
|
||||
};
|
||||
friend inline bool operator==(OverSticker a, OverSticker b) {
|
||||
return (a.section == b.section) && (a.index == b.index) && (a.overDelete == b.overDelete);
|
||||
return (a.section == b.section)
|
||||
&& (a.index == b.index)
|
||||
&& (a.overDelete == b.overDelete);
|
||||
}
|
||||
friend inline bool operator==(OverSet a, OverSet b) {
|
||||
return (a.section == b.section);
|
||||
@@ -122,7 +124,11 @@ private:
|
||||
friend inline bool operator==(OverGroupAdd a, OverGroupAdd b) {
|
||||
return true;
|
||||
}
|
||||
using OverState = base::optional_variant<OverSticker, OverSet, OverButton, OverGroupAdd>;
|
||||
using OverState = base::optional_variant<
|
||||
OverSticker,
|
||||
OverSet,
|
||||
OverButton,
|
||||
OverGroupAdd>;
|
||||
|
||||
struct SectionInfo {
|
||||
int section = 0;
|
||||
@@ -135,7 +141,7 @@ private:
|
||||
|
||||
struct Sticker {
|
||||
not_null<DocumentData*> document;
|
||||
std::unique_ptr<Lottie::Animation> animated;
|
||||
std::unique_ptr<Lottie::SinglePlayer> animated;
|
||||
};
|
||||
|
||||
struct Set {
|
||||
|
@@ -45,14 +45,16 @@ TabbedPanel::TabbedPanel(
|
||||
, _maxContentHeight(st::emojiPanMaxHeight) {
|
||||
_selector->setParent(this);
|
||||
_selector->setRoundRadius(st::buttonRadius);
|
||||
_selector->setAfterShownCallback([this](SelectorTab tab) {
|
||||
if (tab == SelectorTab::Gifs) {
|
||||
_controller->enableGifPauseReason(Window::GifPauseReason::SavedGifs);
|
||||
_selector->setAfterShownCallback([=](SelectorTab tab) {
|
||||
if (tab == SelectorTab::Gifs || tab == SelectorTab::Stickers) {
|
||||
_controller->enableGifPauseReason(
|
||||
Window::GifPauseReason::SavedGifs);
|
||||
}
|
||||
});
|
||||
_selector->setBeforeHidingCallback([this](SelectorTab tab) {
|
||||
if (tab == SelectorTab::Gifs) {
|
||||
_controller->disableGifPauseReason(Window::GifPauseReason::SavedGifs);
|
||||
_selector->setBeforeHidingCallback([=](SelectorTab tab) {
|
||||
if (tab == SelectorTab::Gifs || tab == SelectorTab::Stickers) {
|
||||
_controller->disableGifPauseReason(
|
||||
Window::GifPauseReason::SavedGifs);
|
||||
}
|
||||
});
|
||||
_selector->showRequests(
|
||||
|
Reference in New Issue
Block a user