Skip to content

Commit 1ac33d3

Browse files
committed
Version 5.10.2: Improve gifts layout.
1 parent 658cb43 commit 1ac33d3

File tree

8 files changed

+144
-64
lines changed

8 files changed

+144
-64
lines changed

Telegram/SourceFiles/boxes/star_gift_box.cpp

Lines changed: 77 additions & 43 deletions
Original file line numberDiff line numberDiff line change
@@ -298,48 +298,6 @@ auto GenerateGiftMedia(
298298
};
299299
}
300300

301-
struct PatternPoint {
302-
QPointF position;
303-
float64 scale = 1.;
304-
float64 opacity = 1.;
305-
};
306-
[[nodiscard]] const std::vector<PatternPoint> &PatternPoints() {
307-
static const auto kSmall = 0.7;
308-
static const auto kFaded = 0.3;
309-
static const auto kLarge = 0.85;
310-
static const auto kOpaque = 0.5;
311-
static const auto result = std::vector<PatternPoint>{
312-
{ { 0.5, 0.066 }, kSmall, kFaded },
313-
314-
{ { 0.177, 0.168 }, kSmall, kFaded },
315-
{ { 0.822, 0.168 }, kSmall, kFaded },
316-
317-
{ { 0.37, 0.168 }, kLarge, kOpaque },
318-
{ { 0.63, 0.168 }, kLarge, kOpaque },
319-
320-
{ { 0.277, 0.308 }, kSmall, kOpaque },
321-
{ { 0.723, 0.308 }, kSmall, kOpaque },
322-
323-
{ { 0.13, 0.42 }, kSmall, kFaded },
324-
{ { 0.87, 0.42 }, kSmall, kFaded },
325-
326-
{ { 0.27, 0.533 }, kLarge, kOpaque },
327-
{ { 0.73, 0.533 }, kLarge, kOpaque },
328-
329-
{ { 0.2, 0.73 }, kSmall, kFaded },
330-
{ { 0.8, 0.73 }, kSmall, kFaded },
331-
332-
{ { 0.302, 0.825 }, kLarge, kOpaque },
333-
{ { 0.698, 0.825 }, kLarge, kOpaque },
334-
335-
{ { 0.5, 0.876 }, kLarge, kFaded },
336-
337-
{ { 0.144, 0.936 }, kSmall, kFaded },
338-
{ { 0.856, 0.936 }, kSmall, kFaded },
339-
};
340-
return result;
341-
}
342-
343301
[[nodiscard]] QImage CreateGradient(
344302
QSize size,
345303
const Data::UniqueGift &gift) {
@@ -2108,6 +2066,7 @@ void AddUniqueGiftCover(
21082066

21092067
PaintPoints(
21102068
p,
2069+
PatternPoints(),
21112070
gift.emojis,
21122071
gift.emoji.get(),
21132072
*gift.gift,
@@ -2383,8 +2342,83 @@ void UpgradeBox(
23832342
AddUniqueCloseButton(box);
23842343
}
23852344

2345+
const std::vector<PatternPoint> &PatternPoints() {
2346+
static const auto kSmall = 0.7;
2347+
static const auto kFaded = 0.2;
2348+
static const auto kLarge = 0.85;
2349+
static const auto kOpaque = 0.3;
2350+
static const auto result = std::vector<PatternPoint>{
2351+
{ { 0.5, 0.066 }, kSmall, kFaded },
2352+
2353+
{ { 0.177, 0.168 }, kSmall, kFaded },
2354+
{ { 0.822, 0.168 }, kSmall, kFaded },
2355+
2356+
{ { 0.37, 0.168 }, kLarge, kOpaque },
2357+
{ { 0.63, 0.168 }, kLarge, kOpaque },
2358+
2359+
{ { 0.277, 0.308 }, kSmall, kOpaque },
2360+
{ { 0.723, 0.308 }, kSmall, kOpaque },
2361+
2362+
{ { 0.13, 0.42 }, kSmall, kFaded },
2363+
{ { 0.87, 0.42 }, kSmall, kFaded },
2364+
2365+
{ { 0.27, 0.533 }, kLarge, kOpaque },
2366+
{ { 0.73, 0.533 }, kLarge, kOpaque },
2367+
2368+
{ { 0.2, 0.73 }, kSmall, kFaded },
2369+
{ { 0.8, 0.73 }, kSmall, kFaded },
2370+
2371+
{ { 0.302, 0.825 }, kLarge, kOpaque },
2372+
{ { 0.698, 0.825 }, kLarge, kOpaque },
2373+
2374+
{ { 0.5, 0.876 }, kLarge, kFaded },
2375+
2376+
{ { 0.144, 0.936 }, kSmall, kFaded },
2377+
{ { 0.856, 0.936 }, kSmall, kFaded },
2378+
};
2379+
return result;
2380+
}
2381+
2382+
const std::vector<PatternPoint> &PatternPointsSmall() {
2383+
static const auto kSmall = 0.45;
2384+
static const auto kFaded = 0.2;
2385+
static const auto kLarge = 0.55;
2386+
static const auto kOpaque = 0.3;
2387+
static const auto result = std::vector<PatternPoint>{
2388+
{ { 0.5, 0.066 }, kSmall, kFaded },
2389+
2390+
{ { 0.177, 0.168 }, kSmall, kFaded },
2391+
{ { 0.822, 0.168 }, kSmall, kFaded },
2392+
2393+
{ { 0.37, 0.168 }, kLarge, kOpaque },
2394+
{ { 0.63, 0.168 }, kLarge, kOpaque },
2395+
2396+
{ { 0.277, 0.308 }, kSmall, kOpaque },
2397+
{ { 0.723, 0.308 }, kSmall, kOpaque },
2398+
2399+
{ { 0.13, 0.42 }, kSmall, kFaded },
2400+
{ { 0.87, 0.42 }, kSmall, kFaded },
2401+
2402+
{ { 0.27, 0.533 }, kLarge, kOpaque },
2403+
{ { 0.73, 0.533 }, kLarge, kOpaque },
2404+
2405+
{ { 0.2, 0.73 }, kSmall, kFaded },
2406+
{ { 0.8, 0.73 }, kSmall, kFaded },
2407+
2408+
{ { 0.302, 0.825 }, kLarge, kOpaque },
2409+
{ { 0.698, 0.825 }, kLarge, kOpaque },
2410+
2411+
{ { 0.5, 0.876 }, kLarge, kFaded },
2412+
2413+
{ { 0.144, 0.936 }, kSmall, kFaded },
2414+
{ { 0.856, 0.936 }, kSmall, kFaded },
2415+
};
2416+
return result;
2417+
}
2418+
23862419
void PaintPoints(
23872420
QPainter &p,
2421+
const std::vector<PatternPoint> &points,
23882422
base::flat_map<float64, QImage> &cache,
23892423
not_null<Text::CustomEmoji*> emoji,
23902424
const Data::UniqueGift &gift,
@@ -2417,7 +2451,7 @@ void PaintPoints(
24172451
}
24182452
}
24192453
};
2420-
for (const auto point : PatternPoints()) {
2454+
for (const auto &point : points) {
24212455
paintPoint(point);
24222456
}
24232457
}

Telegram/SourceFiles/boxes/star_gift_box.h

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -42,8 +42,17 @@ void AddUniqueGiftCover(
4242
rpl::producer<Data::UniqueGift> data,
4343
rpl::producer<QString> subtitleOverride = nullptr);
4444

45+
struct PatternPoint {
46+
QPointF position;
47+
float64 scale = 1.;
48+
float64 opacity = 1.;
49+
};
50+
[[nodiscard]] const std::vector<PatternPoint> &PatternPoints();
51+
[[nodiscard]] const std::vector<PatternPoint> &PatternPointsSmall();
52+
4553
void PaintPoints(
4654
QPainter &p,
55+
const std::vector<PatternPoint> &points,
4756
base::flat_map<float64, QImage> &cache,
4857
not_null<Text::CustomEmoji*> emoji,
4958
const Data::UniqueGift &gift,

Telegram/SourceFiles/history/view/media/history_view_premium_gift.cpp

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -312,7 +312,8 @@ QImage PremiumGift::cornerTag(const PaintContext &context) {
312312
if (_data.unique) {
313313
badge = {
314314
.text = tr::lng_gift_collectible_tag(tr::now),
315-
.bg = _data.unique->backdrop.patternColor,
315+
.bg1 = _data.unique->backdrop.edgeColor,
316+
.bg2 = _data.unique->backdrop.patternColor,
316317
.fg = QColor(255, 255, 255),
317318
};
318319
} else if (const auto count = _data.limitedCount) {
@@ -325,7 +326,7 @@ QImage PremiumGift::cornerTag(const PaintContext &context) {
325326
(((count % 1000) && (count < 10'000))
326327
? Lang::FormatCountDecimal(count)
327328
: Lang::FormatCountToShort(count).string))),
328-
.bg = context.st->msgServiceBg()->c,
329+
.bg1 = context.st->msgServiceBg()->c,
329330
.fg = context.st->msgServiceFg()->c,
330331
};
331332
} else {

Telegram/SourceFiles/history/view/media/history_view_unique_gift.cpp

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -525,7 +525,13 @@ Fn<void(Painter&, const Ui::ChatPaintContext &)> UniqueGiftBg(
525525
const auto doubled = width + 2 * shift;
526526
const auto outer = QRect(-shift, -shift, doubled, doubled);
527527
p.setClipRect(inner);
528-
Ui::PaintPoints(p, state->cache, state->pattern.get(), *gift, outer);
528+
Ui::PaintPoints(
529+
p,
530+
Ui::PatternPoints(),
531+
state->cache,
532+
state->pattern.get(),
533+
*gift,
534+
outer);
529535
p.setClipping(false);
530536

531537
const auto add = style::ConvertScale(2);
@@ -536,7 +542,8 @@ Fn<void(Painter&, const Ui::ChatPaintContext &)> UniqueGiftBg(
536542
inner.height() + 2 * add);
537543
auto badge = Info::PeerGifts::GiftBadge{
538544
.text = tr::lng_gift_collectible_tag(tr::now),
539-
.bg = gift->backdrop.patternColor,
545+
.bg1 = gift->backdrop.edgeColor,
546+
.bg2 = gift->backdrop.patternColor,
540547
.fg = gift->backdrop.textColor,
541548
};
542549
if (state->badgeCache.isNull() || state->badgeKey != badge) {

Telegram/SourceFiles/info/peer_gifts/info_peer_gifts_common.cpp

Lines changed: 37 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -42,10 +42,14 @@ std::strong_ordering operator<=>(const GiftBadge &a, const GiftBadge &b) {
4242
if (result1 != std::strong_ordering::equal) {
4343
return result1;
4444
}
45-
const auto result2 = (a.bg.rgb() <=> b.bg.rgb());
45+
const auto result2 = (a.bg1.rgb() <=> b.bg1.rgb());
4646
if (result2 != std::strong_ordering::equal) {
4747
return result2;
4848
}
49+
const auto result3 = (a.bg2.rgb() <=> b.bg2.rgb());
50+
if (result3 != std::strong_ordering::equal) {
51+
return result3;
52+
}
4953
return a.fg.rgb() <=> b.fg.rgb();
5054
}
5155

@@ -148,6 +152,7 @@ void GiftButton::setDescriptor(const GiftDescriptor &descriptor, Mode mode) {
148152

149153
if (mode != Mode::Full) {
150154
_button = QRect();
155+
_small = true;
151156
return;
152157
}
153158
const auto buttonw = _price.maxWidth();
@@ -263,11 +268,11 @@ void GiftButton::cacheUniqueBackground(
263268
if (!_patterned && _uniquePatternEmoji->ready()) {
264269
_patterned = true;
265270
auto p = QPainter(&_uniqueBackgroundCache);
266-
p.setOpacity(0.5);
267271
p.setClipRect(inner);
268272
const auto skip = inner.width() / 3;
269273
Ui::PaintPoints(
270274
p,
275+
Ui::PatternPointsSmall(),
271276
_uniquePatternCache,
272277
_uniquePatternEmoji.get(),
273278
*unique,
@@ -338,7 +343,9 @@ void GiftButton::paintEvent(QPaintEvent *e) {
338343
p.drawImage(
339344
QRect(
340345
(width - size.width()) / 2,
341-
(_text.isEmpty()
346+
(_small
347+
? st::giftBoxSmallStickerTop
348+
: _text.isEmpty()
342349
? st::giftBoxStickerStarTop
343350
: st::giftBoxStickerTop),
344351
size.width(),
@@ -348,7 +355,9 @@ void GiftButton::paintEvent(QPaintEvent *e) {
348355
if (hidden) {
349356
const auto topleft = QPoint(
350357
(width - st::giftBoxStickerSize.width()) / 2,
351-
(_text.isEmpty()
358+
(_small
359+
? st::giftBoxSmallStickerTop
360+
: _text.isEmpty()
352361
? st::giftBoxStickerStarTop
353362
: st::giftBoxStickerTop));
354363
_delegate->hiddenMark()->paint(
@@ -372,8 +381,9 @@ void GiftButton::paintEvent(QPaintEvent *e) {
372381
const auto kMinus = QChar(0x2212);
373382
return GiftBadge{
374383
.text = kMinus + QString::number(data.discountPercent) + '%',
375-
.bg = st::attentionButtonFg->c,
384+
.bg1 = st::attentionButtonFg->c,
376385
.fg = st::windowBg->c,
386+
.small = true,
377387
};
378388
}
379389
return GiftBadge();
@@ -383,7 +393,7 @@ void GiftButton::paintEvent(QPaintEvent *e) {
383393
return GiftBadge{
384394
.text = (soldOut
385395
? tr::lng_gift_stars_sold_out(tr::now)
386-
: !data.userpic
396+
: (!data.userpic && !data.info.unique)
387397
? tr::lng_gift_stars_limited(tr::now)
388398
: (count == 1)
389399
? tr::lng_gift_limited_of_one(tr::now)
@@ -393,28 +403,32 @@ void GiftButton::paintEvent(QPaintEvent *e) {
393403
(((count % 1000) && (count < 10'000))
394404
? Lang::FormatCountDecimal(count)
395405
: Lang::FormatCountToShort(count).string))),
396-
.bg = (unique
397-
? unique->backdrop.patternColor
406+
.bg1 = (unique
407+
? unique->backdrop.edgeColor
398408
: soldOut
399409
? st::attentionButtonFg->c
400410
: st::windowActiveTextFg->c),
411+
.bg2 = (unique
412+
? unique->backdrop.patternColor
413+
: QColor(0, 0, 0, 0)),
401414
.fg = unique ? QColor(255, 255, 255) : st::windowBg->c,
415+
.small = true,
402416
};
403417
}
404418
return GiftBadge();
405419
});
406420

407421
if (badge) {
408-
const auto rubberOut = _extend.top();
422+
const auto rubberOut = st::lineWidth;
409423
const auto inner = rect().marginsRemoved(_extend);
410424
p.setClipRect(inner.marginsAdded(
411425
{ rubberOut, rubberOut, rubberOut, rubberOut }));
412426

413427
const auto cached = _delegate->cachedBadge(badge);
414428
const auto width = cached.width() / cached.devicePixelRatio();
415429
p.drawImage(
416-
position.x() + singlew + _extend.top() - width,
417-
position.y() - _extend.top(),
430+
position.x() + singlew + rubberOut - width,
431+
position.y() - rubberOut,
418432
cached);
419433
}
420434
if (!_button.isEmpty()) {
@@ -633,7 +647,9 @@ rpl::producer<not_null<DocumentData*>> GiftStickerValue(
633647
}
634648

635649
QImage ValidateRotatedBadge(const GiftBadge &badge, int added) {
636-
const auto &font = st::semiboldFont;
650+
const auto &font = badge.small
651+
? st::giftBoxGiftBadgeFont
652+
: st::semiboldFont;
637653
const auto twidth = font->width(badge.text) + 2 * added;
638654
const auto skip = int(std::ceil(twidth / M_SQRT2));
639655
const auto ratio = style::DevicePixelRatio();
@@ -670,12 +686,19 @@ QImage ValidateRotatedBadge(const GiftBadge &badge, int added) {
670686
auto p = QPainter(&result);
671687
auto hq = PainterHighQualityEnabler(p);
672688
p.setPen(Qt::NoPen);
673-
p.setBrush(badge.bg);
689+
p.setBrush(badge.bg1);
674690

675691
p.save();
676692
p.translate(textpos);
677693
p.rotate(45.);
678-
p.drawRect(-5 * twidth, 0, twidth * 12, font->height);
694+
const auto rect = QRect(-5 * twidth, 0, twidth * 12, font->height);
695+
p.drawRect(rect);
696+
if (badge.bg2.alpha() > 0) {
697+
p.setOpacity(0.5);
698+
p.setBrush(badge.bg2);
699+
p.drawRect(rect);
700+
p.setOpacity(1.);
701+
}
679702
p.restore();
680703

681704
p.drawImage(0, 0, scaled);

Telegram/SourceFiles/info/peer_gifts/info_peer_gifts_common.h

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -74,8 +74,10 @@ struct GiftDescriptor : std::variant<GiftTypePremium, GiftTypeStars> {
7474

7575
struct GiftBadge {
7676
QString text;
77-
QColor bg;
77+
QColor bg1;
78+
QColor bg2 = QColor(0, 0, 0, 0);
7879
QColor fg;
80+
bool small = false;
7981

8082
explicit operator bool() const {
8183
return !text.isEmpty();
@@ -148,6 +150,7 @@ class GiftButton final : public Ui::AbstractButton {
148150
std::optional<Ui::Premium::ColoredMiniStars> _stars;
149151
bool _subscribed = false;
150152
bool _patterned = false;
153+
bool _small = false;
151154

152155
QRect _button;
153156
QMargins _extend;

Telegram/SourceFiles/settings/settings_credits_graphics.cpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1348,6 +1348,7 @@ void ReceiptCreditsBox(
13481348
};
13491349
const auto canUpgrade = e.stargiftId
13501350
&& e.canUpgradeGift
1351+
&& (e.in || giftToSelf)
13511352
&& !e.uniqueGift;
13521353
const auto canUpgradeFree = canUpgrade && (e.starsUpgradedBySender > 0);
13531354

0 commit comments

Comments
 (0)