mirror of
https://github.com/vale981/tdesktop
synced 2025-03-06 10:11:41 -05:00
Allow loading lottie animations from memory.
This commit is contained in:
parent
707aa88974
commit
642deecbbb
3 changed files with 14 additions and 5 deletions
|
@ -94,10 +94,14 @@ QSize HistorySticker::countCurrentSize(int newWidth) {
|
||||||
}
|
}
|
||||||
|
|
||||||
void HistorySticker::draw(Painter &p, const QRect &r, TextSelection selection, crl::time ms) const {
|
void HistorySticker::draw(Painter &p, const QRect &r, TextSelection selection, crl::time ms) const {
|
||||||
if (!_lottie
|
if (!_lottie && _data->filename().endsWith(qstr(".json"))) {
|
||||||
&& _data->loaded()
|
if (_data->loaded()) {
|
||||||
&& Lottie::ValidateFile(_data->filepath())) {
|
_lottie = _data->data().isEmpty()
|
||||||
_lottie = Lottie::FromFile(_data->filepath());
|
? Lottie::FromFile(_data->filepath())
|
||||||
|
: Lottie::FromData(_data->data());
|
||||||
|
} else {
|
||||||
|
_data->automaticLoad(_parent->data()->fullId(), _parent->data());
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
auto sticker = _data->sticker();
|
auto sticker = _data->sticker();
|
||||||
|
|
|
@ -51,7 +51,11 @@ std::unique_ptr<Animation> FromFile(const QString &path) {
|
||||||
if (content.isEmpty()) {
|
if (content.isEmpty()) {
|
||||||
return nullptr;
|
return nullptr;
|
||||||
}
|
}
|
||||||
return std::make_unique<Lottie::Animation>(content);
|
return FromData(content);
|
||||||
|
}
|
||||||
|
|
||||||
|
std::unique_ptr<Animation> FromData(const QByteArray &data) {
|
||||||
|
return std::make_unique<Lottie::Animation>(data);
|
||||||
}
|
}
|
||||||
|
|
||||||
Animation::Animation(const QByteArray &content) {
|
Animation::Animation(const QByteArray &content) {
|
||||||
|
|
|
@ -25,6 +25,7 @@ class Animation;
|
||||||
|
|
||||||
bool ValidateFile(const QString &path);
|
bool ValidateFile(const QString &path);
|
||||||
std::unique_ptr<Animation> FromFile(const QString &path);
|
std::unique_ptr<Animation> FromFile(const QString &path);
|
||||||
|
std::unique_ptr<Animation> FromData(const QByteArray &data);
|
||||||
|
|
||||||
struct PlaybackOptions {
|
struct PlaybackOptions {
|
||||||
float64 speed = 1.;
|
float64 speed = 1.;
|
||||||
|
|
Loading…
Add table
Reference in a new issue