Add custom-emoji wrapper with limited loops count.
This commit is contained in:
parent
51657b3c8a
commit
4d45396174
2 changed files with 65 additions and 1 deletions
|
|
@ -67,4 +67,50 @@ bool FirstFrameEmoji::readyInDefaultState() {
|
|||
return _wrapped->readyInDefaultState();
|
||||
}
|
||||
|
||||
LimitedLoopsEmoji::LimitedLoopsEmoji(
|
||||
std::unique_ptr<CustomEmoji> wrapped,
|
||||
int limit)
|
||||
: _wrapped(std::move(wrapped))
|
||||
, _limit(limit) {
|
||||
}
|
||||
|
||||
QString LimitedLoopsEmoji::entityData() {
|
||||
return _wrapped->entityData();
|
||||
}
|
||||
|
||||
void LimitedLoopsEmoji::paint(QPainter &p, const Context &context) {
|
||||
if (_played < _limit) {
|
||||
if (_wrapped->readyInDefaultState()) {
|
||||
if (_inLoop) {
|
||||
_inLoop = false;
|
||||
++_played;
|
||||
}
|
||||
} else if (_wrapped->ready()) {
|
||||
_inLoop = true;
|
||||
}
|
||||
}
|
||||
if (_played == _limit) {
|
||||
const auto was = context.firstFrameOnly;
|
||||
context.firstFrameOnly = true;
|
||||
_wrapped->paint(p, context);
|
||||
context.firstFrameOnly = was;
|
||||
} else {
|
||||
_wrapped->paint(p, context);
|
||||
}
|
||||
}
|
||||
|
||||
void LimitedLoopsEmoji::unload() {
|
||||
_wrapped->unload();
|
||||
_inLoop = false;
|
||||
_played = 0;
|
||||
}
|
||||
|
||||
bool LimitedLoopsEmoji::ready() {
|
||||
return _wrapped->ready();
|
||||
}
|
||||
|
||||
bool LimitedLoopsEmoji::readyInDefaultState() {
|
||||
return _wrapped->readyInDefaultState();
|
||||
}
|
||||
|
||||
} // namespace Ui::Text
|
||||
|
|
|
|||
|
|
@ -31,7 +31,7 @@ struct CustomEmojiPaintContext {
|
|||
crl::time now = 0;
|
||||
float64 scale = 0.;
|
||||
QPoint position;
|
||||
bool firstFrameOnly = false;
|
||||
mutable bool firstFrameOnly = false;
|
||||
bool paused = false;
|
||||
bool scaled = false;
|
||||
};
|
||||
|
|
@ -85,4 +85,22 @@ private:
|
|||
|
||||
};
|
||||
|
||||
class LimitedLoopsEmoji final : public CustomEmoji {
|
||||
public:
|
||||
LimitedLoopsEmoji(std::unique_ptr<CustomEmoji> wrapped, int limit);
|
||||
|
||||
QString entityData() override;
|
||||
void paint(QPainter &p, const Context &context) override;
|
||||
void unload() override;
|
||||
bool ready() override;
|
||||
bool readyInDefaultState() override;
|
||||
|
||||
private:
|
||||
const std::unique_ptr<Ui::Text::CustomEmoji> _wrapped;
|
||||
const int _limit = 0;
|
||||
int _played = 0;
|
||||
bool _inLoop = false;
|
||||
|
||||
};
|
||||
|
||||
} // namespace Ui::Text
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue