2
0
mirror of https://github.com/telegramdesktop/tdesktop synced 2025-08-31 06:26:18 +00:00

Implement effects paywalls.

This commit is contained in:
John Preston
2024-05-14 12:16:39 +04:00
parent d102d256a9
commit 732b67ca04
13 changed files with 241 additions and 47 deletions

View File

@@ -73,7 +73,9 @@ using Data::StickersSet;
using Data::StickersPack;
using SetFlag = Data::StickersSetFlag;
[[nodiscard]] std::optional<QColor> ComputeImageColor(const QImage &frame) {
[[nodiscard]] std::optional<QColor> ComputeImageColor(
const style::icon &lockIcon,
const QImage &frame) {
if (frame.isNull()
|| frame.format() != QImage::Format_ARGB32_Premultiplied) {
return {};
@@ -83,7 +85,7 @@ using SetFlag = Data::StickersSetFlag;
auto sb = int64();
auto sa = int64();
const auto factor = frame.devicePixelRatio();
const auto size = st::stickersPremiumLock.size() * factor;
const auto size = lockIcon.size() * factor;
const auto width = std::min(frame.width(), size.width());
const auto height = std::min(frame.height(), size.height());
const auto skipx = (frame.width() - width) / 2;
@@ -110,22 +112,30 @@ using SetFlag = Data::StickersSetFlag;
}
[[nodiscard]] QColor ComputeLockColor(const QImage &frame) {
return ComputeImageColor(frame).value_or(st::windowSubTextFg->c);
[[nodiscard]] QColor ComputeLockColor(
const style::icon &lockIcon,
const QImage &frame) {
return ComputeImageColor(
lockIcon,
frame
).value_or(st::windowSubTextFg->c);
}
void ValidatePremiumLockBg(QImage &image, const QImage &frame) {
void ValidatePremiumLockBg(
const style::icon &lockIcon,
QImage &image,
const QImage &frame) {
if (!image.isNull()) {
return;
}
const auto factor = style::DevicePixelRatio();
const auto size = st::stickersPremiumLock.size();
const auto size = lockIcon.size();
image = QImage(
size * factor,
QImage::Format_ARGB32_Premultiplied);
image.setDevicePixelRatio(factor);
auto p = QPainter(&image);
const auto color = ComputeLockColor(frame);
const auto color = ComputeLockColor(lockIcon, frame);
p.fillRect(
QRect(QPoint(), size),
anim::color(color, st::windowSubTextFg, kGrayLockOpacity));
@@ -134,12 +144,12 @@ void ValidatePremiumLockBg(QImage &image, const QImage &frame) {
image = Images::Circle(std::move(image));
}
void ValidatePremiumStarFg(QImage &image) {
void ValidatePremiumStarFg(const style::icon &lockIcon, QImage &image) {
if (!image.isNull()) {
return;
}
const auto factor = style::DevicePixelRatio();
const auto size = st::stickersPremiumLock.size();
const auto size = lockIcon.size();
image = QImage(
size * factor,
QImage::Format_ARGB32_Premultiplied);
@@ -176,7 +186,10 @@ void ValidatePremiumStarFg(QImage &image) {
} // namespace
StickerPremiumMark::StickerPremiumMark(not_null<Main::Session*> session) {
StickerPremiumMark::StickerPremiumMark(
not_null<Main::Session*> session,
const style::icon &lockIcon)
: _lockIcon(lockIcon) {
style::PaletteChanged(
) | rpl::start_with_next([=] {
_lockGray = QImage();
@@ -202,16 +215,14 @@ void StickerPremiumMark::paint(
const auto factor = style::DevicePixelRatio();
const auto radius = st::roundRadiusSmall;
const auto point = position + QPoint(
(_premium
? (singleSize.width() - (bg.width() / factor) - radius)
: (singleSize.width() - (bg.width() / factor)) / 2),
(singleSize.width() - (bg.width() / factor) - radius),
singleSize.height() - (bg.height() / factor) - radius);
p.drawImage(point, bg);
if (_premium) {
validateStar();
p.drawImage(point, _star);
} else {
st::stickersPremiumLock.paint(p, point, outerWidth);
_lockIcon.paint(p, point, outerWidth);
}
}
@@ -219,11 +230,11 @@ void StickerPremiumMark::validateLock(
const QImage &frame,
QImage &backCache) {
auto &image = frame.isNull() ? _lockGray : backCache;
ValidatePremiumLockBg(image, frame);
ValidatePremiumLockBg(_lockIcon, image, frame);
}
void StickerPremiumMark::validateStar() {
ValidatePremiumStarFg(_star);
ValidatePremiumStarFg(_lockIcon, _star);
}
class StickerSetBox::Inner final : public Ui::RpWidget {
@@ -664,7 +675,7 @@ StickerSetBox::Inner::Inner(
st::windowBgRipple,
st::windowBgOver,
[=] { repaintItems(); }))
, _premiumMark(_session)
, _premiumMark(_session, st::stickersPremiumLock)
, _updateItemsTimer([=] { updateItems(); })
, _input(set)
, _padding((type == Data::StickersType::Emoji)