mirror of
https://github.com/AyuGram/AyuGramDesktop.git
synced 2026-07-25 06:54:43 +00:00
Improved style of credits history entry out for upgrade gifts.
This commit is contained in:
@@ -978,6 +978,64 @@ private:
|
||||
|
||||
};
|
||||
|
||||
[[nodiscard]] PaintRoundImageCallback GenerateGiftUniqueUserpicCallback(
|
||||
not_null<Main::Session*> session,
|
||||
std::shared_ptr<Data::UniqueGift> unique,
|
||||
Fn<void()> update) {
|
||||
struct State {
|
||||
QImage layer;
|
||||
std::shared_ptr<UniqueGiftBackground> bg;
|
||||
std::shared_ptr<Ui::Text::CustomEmoji> sticker;
|
||||
};
|
||||
const auto state = std::make_shared<State>();
|
||||
const auto repaint = [=] {
|
||||
if (update) {
|
||||
update();
|
||||
}
|
||||
};
|
||||
state->bg = std::make_shared<UniqueGiftBackground>(session, unique);
|
||||
state->bg->subscribeToUpdates(repaint);
|
||||
const auto tag = Data::CustomEmojiSizeTag::Isolated;
|
||||
state->sticker = session->data().customEmojiManager().create(
|
||||
unique->model.document,
|
||||
repaint,
|
||||
tag);
|
||||
|
||||
return [=](QPainter &p, int x, int y, int outerw, int size) {
|
||||
const auto ideal = st::boostReplaceUserpic.photoSize;
|
||||
const auto scale = size / float64(ideal);
|
||||
const auto ratio = style::DevicePixelRatio();
|
||||
if (state->layer.size() != QSize(ideal, ideal) * ratio) {
|
||||
state->layer = QImage(
|
||||
QSize(ideal, ideal) * ratio,
|
||||
QImage::Format_ARGB32_Premultiplied);
|
||||
state->layer.setDevicePixelRatio(ratio);
|
||||
}
|
||||
state->layer.fill(Qt::transparent);
|
||||
|
||||
auto q = QPainter(&state->layer);
|
||||
auto hq = PainterHighQualityEnabler(q);
|
||||
const auto esize = Data::FrameSizeFromTag(tag) / ratio;
|
||||
q.drawImage(QRect(0, 0, ideal, ideal), state->bg->image(ideal));
|
||||
state->sticker->paint(q, {
|
||||
.textColor = st::windowFg->c,
|
||||
.now = crl::now(),
|
||||
.position = QPoint((ideal - esize) / 2, (ideal - esize) / 2),
|
||||
});
|
||||
q.end();
|
||||
|
||||
if (scale != 1.) {
|
||||
p.save();
|
||||
p.translate(x, y);
|
||||
p.scale(scale, scale);
|
||||
p.drawImage(0, 0, state->layer);
|
||||
p.restore();
|
||||
} else {
|
||||
p.drawImage(x, y, state->layer);
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
object_ptr<Ui::RpWidget> CreateGiftTransfer(
|
||||
not_null<Ui::RpWidget*> parent,
|
||||
std::shared_ptr<Data::UniqueGift> unique,
|
||||
@@ -985,8 +1043,7 @@ object_ptr<Ui::RpWidget> CreateGiftTransfer(
|
||||
struct State {
|
||||
QImage layer;
|
||||
QPoint giftPosition;
|
||||
std::shared_ptr<UniqueGiftBackground> bg;
|
||||
std::shared_ptr<Ui::Text::CustomEmoji> sticker;
|
||||
PaintRoundImageCallback paintGift;
|
||||
};
|
||||
const auto st = &st::boostReplaceUserpicsRow;
|
||||
const auto full = st->button.size.height()
|
||||
@@ -998,18 +1055,10 @@ object_ptr<Ui::RpWidget> CreateGiftTransfer(
|
||||
const auto overlay = CreateChild<Ui::RpWidget>(raw);
|
||||
|
||||
const auto state = raw->lifetime().make_state<State>();
|
||||
state->bg = std::make_shared<UniqueGiftBackground>(
|
||||
state->paintGift = GenerateGiftUniqueUserpicCallback(
|
||||
&to->session(),
|
||||
unique);
|
||||
state->bg->subscribeToUpdates([=] {
|
||||
overlay->update();
|
||||
});
|
||||
const auto tag = Data::CustomEmojiSizeTag::Isolated;
|
||||
state->sticker = to->owner().customEmojiManager().create(
|
||||
unique->model.document,
|
||||
[=] { overlay->update(); },
|
||||
tag);
|
||||
overlay->update();
|
||||
unique,
|
||||
[=] { raw->update(); });
|
||||
|
||||
raw->widthValue(
|
||||
) | rpl::on_next([=](int width) {
|
||||
@@ -1034,18 +1083,14 @@ object_ptr<Ui::RpWidget> CreateGiftTransfer(
|
||||
}
|
||||
state->layer.fill(Qt::transparent);
|
||||
|
||||
auto q = QPainter(&state->layer);
|
||||
auto q = Painter(&state->layer);
|
||||
auto hq = PainterHighQualityEnabler(q);
|
||||
const auto from = QRect(state->giftPosition, right->size());
|
||||
const auto esize = Data::FrameSizeFromTag(tag) / ratio;
|
||||
q.drawImage(from, state->bg->image(from.width()));
|
||||
state->sticker->paint(q, {
|
||||
.textColor = st::windowFg->c,
|
||||
.now = crl::now(),
|
||||
.position = from.topLeft() + QPoint(
|
||||
(from.width() - esize) / 2,
|
||||
(from.height() - esize) / 2),
|
||||
});
|
||||
state->paintGift(
|
||||
q,
|
||||
state->giftPosition.x(),
|
||||
state->giftPosition.y(),
|
||||
outerw,
|
||||
right->width());
|
||||
|
||||
const auto size = st::boostReplaceArrow.size();
|
||||
st::boostReplaceArrow.paint(
|
||||
@@ -1063,3 +1108,4 @@ object_ptr<Ui::RpWidget> CreateGiftTransfer(
|
||||
}, overlay->lifetime());
|
||||
return result;
|
||||
}
|
||||
|
||||
|
||||
@@ -83,3 +83,15 @@ enum class UserpicsTransferType {
|
||||
not_null<Ui::RpWidget*> parent,
|
||||
std::shared_ptr<Data::UniqueGift> unique,
|
||||
not_null<PeerData*> to);
|
||||
|
||||
using PaintRoundImageCallback = Fn<void(
|
||||
Painter &p,
|
||||
int x,
|
||||
int y,
|
||||
int outerWidth,
|
||||
int size)>;
|
||||
|
||||
[[nodiscard]] PaintRoundImageCallback GenerateGiftUniqueUserpicCallback(
|
||||
not_null<Main::Session*> session,
|
||||
std::shared_ptr<Data::UniqueGift> unique,
|
||||
Fn<void()> update);
|
||||
|
||||
@@ -9,6 +9,7 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL
|
||||
|
||||
#include "api/api_credits.h"
|
||||
#include "api/api_statistics.h"
|
||||
#include "boxes/peers/replace_boost_box.h" // GenerateGiftUniqueUserpicCallback
|
||||
#include "boxes/peer_list_controllers.h"
|
||||
#include "boxes/peer_list_widgets.h"
|
||||
#include "info/channel_statistics/earn/earn_icons.h"
|
||||
@@ -886,8 +887,9 @@ void CreditsRow::init() {
|
||||
? name
|
||||
: _entry.postsSearch
|
||||
? tr::lng_credits_box_history_entry_posts_search(tr::now)
|
||||
: (_entry.giftUpgraded && _entry.uniqueGift && !isSpecial)
|
||||
? u"%1 #%2"_q.arg(_entry.uniqueGift->title).arg(_entry.uniqueGift->number)
|
||||
: ((!_entry.subscriptionUntil.isNull() && !isSpecial)
|
||||
|| (_entry.giftUpgraded && !isSpecial)
|
||||
|| (_entry.giftResale && !isSpecial)
|
||||
|| _entry.title.isEmpty())
|
||||
? name
|
||||
@@ -922,6 +924,8 @@ void CreditsRow::init() {
|
||||
? tr::lng_credits_box_history_entry_fragment(tr::now)
|
||||
: (_entry.gift && isSpecial)
|
||||
? tr::lng_credits_box_history_entry_anonymous(tr::now)
|
||||
: _entry.giftUpgraded
|
||||
? tr::lng_credits_box_history_entry_gift_upgrade(tr::now)
|
||||
: (_name == name)
|
||||
? Ui::GenerateEntryName(_entry).text
|
||||
: name;
|
||||
@@ -938,7 +942,7 @@ void CreditsRow::init() {
|
||||
langDayOfMonthFull(_subscription.until.date())));
|
||||
_description.setText(st::defaultTextStyle, _subscription.title);
|
||||
}
|
||||
if (_entry.bareGiftStickerId) {
|
||||
if (_entry.bareGiftStickerId && !_entry.giftUpgraded) {
|
||||
_description.setMarkedText(
|
||||
st::defaultTextStyle,
|
||||
Ui::Text::SingleCustomEmoji(
|
||||
@@ -1001,7 +1005,12 @@ void CreditsRow::init() {
|
||||
}
|
||||
}
|
||||
if (!_paintUserpicCallback) {
|
||||
_paintUserpicCallback = (isSpecial || _entry.postsSearch)
|
||||
_paintUserpicCallback = _entry.giftUpgraded
|
||||
? GenerateGiftUniqueUserpicCallback(
|
||||
_session,
|
||||
_entry.uniqueGift,
|
||||
_context.repaint)
|
||||
: (isSpecial || _entry.postsSearch)
|
||||
? Ui::GenerateCreditsPaintUserpicCallback(_entry)
|
||||
: PeerListRow::generatePaintUserpicCallback(false);
|
||||
}
|
||||
|
||||
@@ -585,8 +585,6 @@ TextWithEntities GenerateEntryName(const Data::CreditsHistoryEntry &entry) {
|
||||
? tr::lng_credits_box_history_entry_api
|
||||
: entry.reaction
|
||||
? tr::lng_credits_box_history_entry_reaction_name
|
||||
: entry.giftUpgraded
|
||||
? tr::lng_credits_box_history_entry_gift_upgrade
|
||||
: entry.giftResale
|
||||
? (entry.in
|
||||
? tr::lng_credits_box_history_entry_gift_sold
|
||||
|
||||
Reference in New Issue
Block a user