mirror of
https://github.com/vale981/tdesktop
synced 2025-03-06 02:01:40 -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 {
|
||||
if (!_lottie
|
||||
&& _data->loaded()
|
||||
&& Lottie::ValidateFile(_data->filepath())) {
|
||||
_lottie = Lottie::FromFile(_data->filepath());
|
||||
if (!_lottie && _data->filename().endsWith(qstr(".json"))) {
|
||||
if (_data->loaded()) {
|
||||
_lottie = _data->data().isEmpty()
|
||||
? Lottie::FromFile(_data->filepath())
|
||||
: Lottie::FromData(_data->data());
|
||||
} else {
|
||||
_data->automaticLoad(_parent->data()->fullId(), _parent->data());
|
||||
}
|
||||
}
|
||||
|
||||
auto sticker = _data->sticker();
|
||||
|
|
|
@ -51,7 +51,11 @@ std::unique_ptr<Animation> FromFile(const QString &path) {
|
|||
if (content.isEmpty()) {
|
||||
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) {
|
||||
|
|
|
@ -25,6 +25,7 @@ class Animation;
|
|||
|
||||
bool ValidateFile(const QString &path);
|
||||
std::unique_ptr<Animation> FromFile(const QString &path);
|
||||
std::unique_ptr<Animation> FromData(const QByteArray &data);
|
||||
|
||||
struct PlaybackOptions {
|
||||
float64 speed = 1.;
|
||||
|
|
Loading…
Add table
Reference in a new issue