Allow querying in-default-state from custom emoji.
This commit is contained in:
parent
3287bf45c6
commit
6dc6309269
4 changed files with 50 additions and 0 deletions
|
|
@ -220,6 +220,10 @@ int Cache::frames() const {
|
||||||
return _frames;
|
return _frames;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
bool Cache::readyInDefaultState() const {
|
||||||
|
return (_frames > 0) && !_frame;
|
||||||
|
}
|
||||||
|
|
||||||
Cache::Frame Cache::frame(int index) const {
|
Cache::Frame Cache::frame(int index) const {
|
||||||
Expects(index < _frames);
|
Expects(index < _frames);
|
||||||
|
|
||||||
|
|
@ -401,6 +405,10 @@ PaintFrameResult Cached::paint(QPainter &p, const Context &context) {
|
||||||
return _cache.paintCurrentFrame(p, context);
|
return _cache.paintCurrentFrame(p, context);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
bool Cached::inDefaultState() const {
|
||||||
|
return _cache.readyInDefaultState();
|
||||||
|
}
|
||||||
|
|
||||||
Preview Cached::makePreview() const {
|
Preview Cached::makePreview() const {
|
||||||
return _cache.makePreview();
|
return _cache.makePreview();
|
||||||
}
|
}
|
||||||
|
|
@ -534,6 +542,10 @@ Preview Renderer::makePreview() const {
|
||||||
return _cache.makePreview();
|
return _cache.makePreview();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
bool Renderer::readyInDefaultState() const {
|
||||||
|
return _cache.readyInDefaultState();
|
||||||
|
}
|
||||||
|
|
||||||
void Renderer::setRepaintCallback(Fn<void()> repaint) {
|
void Renderer::setRepaintCallback(Fn<void()> repaint) {
|
||||||
_repaint = std::move(repaint);
|
_repaint = std::move(repaint);
|
||||||
}
|
}
|
||||||
|
|
@ -659,6 +671,20 @@ bool Instance::ready() {
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
bool Instance::readyInDefaultState() {
|
||||||
|
return v::match(_state, [&](Loading &state) {
|
||||||
|
if (state.hasImagePreview()) {
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
load(state);
|
||||||
|
return false;
|
||||||
|
}, [](Caching &state) {
|
||||||
|
return state.renderer->readyInDefaultState();
|
||||||
|
}, [](Cached &state) {
|
||||||
|
return state.inDefaultState();
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
void Instance::load(Loading &state) {
|
void Instance::load(Loading &state) {
|
||||||
state.load([=](Loader::LoadResult result) {
|
state.load([=](Loader::LoadResult result) {
|
||||||
if (auto caching = std::get_if<Caching>(&result)) {
|
if (auto caching = std::get_if<Caching>(&result)) {
|
||||||
|
|
@ -768,6 +794,14 @@ bool Object::ready() {
|
||||||
return _instance->ready();
|
return _instance->ready();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
bool Object::readyInDefaultState() {
|
||||||
|
if (!_using) {
|
||||||
|
_using = true;
|
||||||
|
_instance->incrementUsage(this);
|
||||||
|
}
|
||||||
|
return _instance->readyInDefaultState();
|
||||||
|
}
|
||||||
|
|
||||||
void Object::repaint() {
|
void Object::repaint() {
|
||||||
_repaint();
|
_repaint();
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -81,6 +81,7 @@ public:
|
||||||
|
|
||||||
[[nodiscard]] int size() const;
|
[[nodiscard]] int size() const;
|
||||||
[[nodiscard]] int frames() const;
|
[[nodiscard]] int frames() const;
|
||||||
|
[[nodiscard]] bool readyInDefaultState() const;
|
||||||
[[nodiscard]] Frame frame(int index) const;
|
[[nodiscard]] Frame frame(int index) const;
|
||||||
void reserve(int frames);
|
void reserve(int frames);
|
||||||
void add(crl::time duration, const QImage &frame);
|
void add(crl::time duration, const QImage &frame);
|
||||||
|
|
@ -122,6 +123,7 @@ public:
|
||||||
[[nodiscard]] QString entityData() const;
|
[[nodiscard]] QString entityData() const;
|
||||||
[[nodiscard]] Preview makePreview() const;
|
[[nodiscard]] Preview makePreview() const;
|
||||||
PaintFrameResult paint(QPainter &p, const Context &context);
|
PaintFrameResult paint(QPainter &p, const Context &context);
|
||||||
|
[[nodiscard]] bool inDefaultState() const;
|
||||||
[[nodiscard]] Loading unload();
|
[[nodiscard]] Loading unload();
|
||||||
|
|
||||||
private:
|
private:
|
||||||
|
|
@ -149,6 +151,7 @@ public:
|
||||||
|
|
||||||
[[nodiscard]] bool canMakePreview() const;
|
[[nodiscard]] bool canMakePreview() const;
|
||||||
[[nodiscard]] Preview makePreview() const;
|
[[nodiscard]] Preview makePreview() const;
|
||||||
|
[[nodiscard]] bool readyInDefaultState() const;
|
||||||
|
|
||||||
void setRepaintCallback(Fn<void()> repaint);
|
void setRepaintCallback(Fn<void()> repaint);
|
||||||
[[nodiscard]] Cache takeCache();
|
[[nodiscard]] Cache takeCache();
|
||||||
|
|
@ -227,6 +230,7 @@ public:
|
||||||
[[nodiscard]] QString entityData() const;
|
[[nodiscard]] QString entityData() const;
|
||||||
void paint(QPainter &p, const Context &context);
|
void paint(QPainter &p, const Context &context);
|
||||||
[[nodiscard]] bool ready();
|
[[nodiscard]] bool ready();
|
||||||
|
[[nodiscard]] bool readyInDefaultState();
|
||||||
[[nodiscard]] bool hasImagePreview() const;
|
[[nodiscard]] bool hasImagePreview() const;
|
||||||
[[nodiscard]] Preview imagePreview() const;
|
[[nodiscard]] Preview imagePreview() const;
|
||||||
void updatePreview(Preview preview);
|
void updatePreview(Preview preview);
|
||||||
|
|
@ -260,6 +264,7 @@ public:
|
||||||
void paint(QPainter &p, const Context &context) override;
|
void paint(QPainter &p, const Context &context) override;
|
||||||
void unload() override;
|
void unload() override;
|
||||||
bool ready() override;
|
bool ready() override;
|
||||||
|
bool readyInDefaultState() override;
|
||||||
|
|
||||||
void repaint();
|
void repaint();
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -37,6 +37,10 @@ bool ShiftedEmoji::ready() {
|
||||||
return _wrapped->ready();
|
return _wrapped->ready();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
bool ShiftedEmoji::readyInDefaultState() {
|
||||||
|
return _wrapped->readyInDefaultState();
|
||||||
|
}
|
||||||
|
|
||||||
FirstFrameEmoji::FirstFrameEmoji(std::unique_ptr<CustomEmoji> wrapped)
|
FirstFrameEmoji::FirstFrameEmoji(std::unique_ptr<CustomEmoji> wrapped)
|
||||||
: _wrapped(std::move(wrapped)) {
|
: _wrapped(std::move(wrapped)) {
|
||||||
}
|
}
|
||||||
|
|
@ -59,4 +63,8 @@ bool FirstFrameEmoji::ready() {
|
||||||
return _wrapped->ready();
|
return _wrapped->ready();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
bool FirstFrameEmoji::readyInDefaultState() {
|
||||||
|
return _wrapped->readyInDefaultState();
|
||||||
|
}
|
||||||
|
|
||||||
} // namespace Ui::Text
|
} // namespace Ui::Text
|
||||||
|
|
|
||||||
|
|
@ -39,6 +39,7 @@ public:
|
||||||
virtual void paint(QPainter &p, const Context &context) = 0;
|
virtual void paint(QPainter &p, const Context &context) = 0;
|
||||||
virtual void unload() = 0;
|
virtual void unload() = 0;
|
||||||
[[nodiscard]] virtual bool ready() = 0;
|
[[nodiscard]] virtual bool ready() = 0;
|
||||||
|
[[nodiscard]] virtual bool readyInDefaultState() = 0;
|
||||||
|
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
@ -54,6 +55,7 @@ public:
|
||||||
void paint(QPainter &p, const Context &context) override;
|
void paint(QPainter &p, const Context &context) override;
|
||||||
void unload() override;
|
void unload() override;
|
||||||
bool ready() override;
|
bool ready() override;
|
||||||
|
bool readyInDefaultState() override;
|
||||||
|
|
||||||
private:
|
private:
|
||||||
const std::unique_ptr<Ui::Text::CustomEmoji> _wrapped;
|
const std::unique_ptr<Ui::Text::CustomEmoji> _wrapped;
|
||||||
|
|
@ -69,6 +71,7 @@ public:
|
||||||
void paint(QPainter &p, const Context &context) override;
|
void paint(QPainter &p, const Context &context) override;
|
||||||
void unload() override;
|
void unload() override;
|
||||||
bool ready() override;
|
bool ready() override;
|
||||||
|
bool readyInDefaultState() override;
|
||||||
|
|
||||||
private:
|
private:
|
||||||
const std::unique_ptr<Ui::Text::CustomEmoji> _wrapped;
|
const std::unique_ptr<Ui::Text::CustomEmoji> _wrapped;
|
||||||
|
|
|
||||||
Loading…
Add table
Reference in a new issue