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);
_customEmojiSkip = (st::emojiSize - _customEmojiSize) / 2;
}
custom->paint(
*_p,
x + _customEmojiSkip,
y + _customEmojiSkip,
_now,
_textPalette->spoilerActiveBg->c,
_p->inactive());
custom->paint(*_p, {
.preview = _textPalette->spoilerActiveBg->c,
.now = _now,
.position = { x + _customEmojiSkip, y + _customEmojiSkip },
.paused = _p->inactive(),
});
}
}
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 {
public:
virtual ~CustomEmoji() = default;
[[nodiscard]] virtual QString entityData() = 0;
virtual void paint(
QPainter &p,
int x,
int y,
crl::time now,
const QColor &preview,
bool paused) = 0;
using Context = CustomEmojiPaintContext;
virtual void paint(QPainter &p, const Context &context) = 0;
virtual void unload() = 0;
};

View file

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