Allow requesting low-quality scaling of custom emoji.

This commit is contained in:
John Preston 2022-08-23 17:46:56 +03:00
parent 8162619cb1
commit 01c4ba869a
3 changed files with 28 additions and 21 deletions

View file

@ -1724,13 +1724,12 @@ private:
_customEmojiSize = AdjustCustomEmojiSize(st::emojiSize); _customEmojiSize = AdjustCustomEmojiSize(st::emojiSize);
_customEmojiSkip = (st::emojiSize - _customEmojiSize) / 2; _customEmojiSkip = (st::emojiSize - _customEmojiSize) / 2;
} }
custom->paint( custom->paint(*_p, {
*_p, .preview = _textPalette->spoilerActiveBg->c,
x + _customEmojiSkip, .now = _now,
y + _customEmojiSkip, .position = { x + _customEmojiSkip, y + _customEmojiSkip },
_now, .paused = _p->inactive(),
_textPalette->spoilerActiveBg->c, });
_p->inactive());
} }
} }
if (hasSpoiler) { if (hasSpoiler) {

View file

@ -166,17 +166,24 @@ private:
}; };
struct CustomEmojiPaintContext {
QColor preview;
QSize size; // Required only when scaled = true, for path scaling.
crl::time now = 0;
float64 scale = 0.;
QPoint position;
bool paused = false;
bool scaled = false;
};
class CustomEmoji { class CustomEmoji {
public: public:
virtual ~CustomEmoji() = default; virtual ~CustomEmoji() = default;
[[nodiscard]] virtual QString entityData() = 0; [[nodiscard]] virtual QString entityData() = 0;
virtual void paint(
QPainter &p, using Context = CustomEmojiPaintContext;
int x, virtual void paint(QPainter &p, const Context &context) = 0;
int y,
crl::time now,
const QColor &preview,
bool paused) = 0;
virtual void unload() = 0; virtual void unload() = 0;
}; };

View file

@ -1424,13 +1424,14 @@ void CustomEmojiObject::drawObject(
if (i == end(_emoji)) { if (i == end(_emoji)) {
return; return;
} }
i->second->paint( i->second->paint(*painter, {
*painter, .preview = st::defaultTextPalette.spoilerActiveBg->c,
int(base::SafeRound(rect.x())) + st::emojiPadding + _skip, .now = _now,
int(base::SafeRound(rect.y())) + _skip, .position = QPoint(
_now, int(base::SafeRound(rect.x())) + st::emojiPadding + _skip,
st::defaultTextPalette.spoilerActiveBg->c, int(base::SafeRound(rect.y())) + _skip),
_paused && _paused()); .paused = _paused && _paused(),
});
} }
void CustomEmojiObject::clear() { void CustomEmojiObject::clear() {