Added support of second colors for empty userpic backgrounds.

This commit is contained in:
23rd 2022-12-03 18:57:15 +03:00
parent c8d273c2a3
commit 5df0b08a42
11 changed files with 96 additions and 49 deletions

View file

@ -241,7 +241,7 @@ ConfirmInviteBox::ConfirmInviteBox(
} }
} else { } else {
_photoEmpty = std::make_unique<Ui::EmptyUserpic>( _photoEmpty = std::make_unique<Ui::EmptyUserpic>(
Data::PeerUserpicColor(0), Ui::PeerUserpicColor(0),
invite.title); invite.title);
} }
} }

View file

@ -248,7 +248,7 @@ void PaintFilterChatsTypeIcon(
int y, int y,
int outerWidth, int outerWidth,
int size) { int size) {
const auto &color = [&]() -> const style::color& { const auto &color1 = [&]() -> const style::color& {
switch (flag) { switch (flag) {
case Flag::Contacts: return st::historyPeer4UserpicBg; case Flag::Contacts: return st::historyPeer4UserpicBg;
case Flag::NonContacts: return st::historyPeer7UserpicBg; case Flag::NonContacts: return st::historyPeer7UserpicBg;
@ -261,6 +261,19 @@ void PaintFilterChatsTypeIcon(
} }
Unexpected("Flag in color paintFlagIcon."); Unexpected("Flag in color paintFlagIcon.");
}(); }();
const auto &color2 = [&]() -> const style::color& {
switch (flag) {
case Flag::Contacts: return st::historyPeer4UserpicBg2;
case Flag::NonContacts: return st::historyPeer7UserpicBg2;
case Flag::Groups: return st::historyPeer2UserpicBg2;
case Flag::Channels: return st::historyPeer1UserpicBg2;
case Flag::Bots: return st::historyPeer6UserpicBg2;
case Flag::NoMuted: return st::historyPeer6UserpicBg2;
case Flag::NoArchived: return st::historyPeer4UserpicBg2;
case Flag::NoRead: return st::historyPeer7UserpicBg2;
}
Unexpected("Flag in color paintFlagIcon.");
}();
const auto &icon = [&]() -> const style::icon& { const auto &icon = [&]() -> const style::icon& {
switch (flag) { switch (flag) {
case Flag::Contacts: return st::windowFilterTypeContacts; case Flag::Contacts: return st::windowFilterTypeContacts;
@ -276,7 +289,9 @@ void PaintFilterChatsTypeIcon(
}(); }();
const auto rect = style::rtlrect(x, y, size, size, outerWidth); const auto rect = style::rtlrect(x, y, size, size, outerWidth);
auto hq = PainterHighQualityEnabler(p); auto hq = PainterHighQualityEnabler(p);
p.setBrush(color->b); auto bg = QLinearGradient(x, y, x, y + size);
bg.setStops({ { 0., color1->c }, { 1., color2->c } });
p.setBrush(bg);
p.setPen(Qt::NoPen); p.setPen(Qt::NoPen);
p.drawEllipse(rect); p.drawEllipse(rect);
icon.paintInCenter(p, rect); icon.paintInCenter(p, rect);

View file

@ -197,7 +197,7 @@ void Userpic::createCache(Image *image) {
{ {
auto p = QPainter(&filled); auto p = QPainter(&filled);
Ui::EmptyUserpic( Ui::EmptyUserpic(
Data::PeerUserpicColor(_peer->id), Ui::PeerUserpicColor(_peer->id),
_peer->name() _peer->name()
).paint(p, 0, 0, size, size); ).paint(p, 0, 0, size, size);
} }

View file

@ -69,20 +69,6 @@ int PeerColorIndex(PeerId peerId) {
return PeerColorIndex(peerId.value & PeerId::kChatTypeMask); return PeerColorIndex(peerId.value & PeerId::kChatTypeMask);
} }
style::color PeerUserpicColor(PeerId peerId) {
const style::color colors[] = {
st::historyPeer1UserpicBg,
st::historyPeer2UserpicBg,
st::historyPeer3UserpicBg,
st::historyPeer4UserpicBg,
st::historyPeer5UserpicBg,
st::historyPeer6UserpicBg,
st::historyPeer7UserpicBg,
st::historyPeer8UserpicBg,
};
return colors[PeerColorIndex(peerId)];
}
PeerId FakePeerIdForJustName(const QString &name) { PeerId FakePeerIdForJustName(const QString &name) {
constexpr auto kShift = (0xFEULL << 32); constexpr auto kShift = (0xFEULL << 32);
const auto base = name.isEmpty() const auto base = name.isEmpty()
@ -250,7 +236,7 @@ not_null<Ui::EmptyUserpic*> PeerData::ensureEmptyUserpic() const {
if (!_userpicEmpty) { if (!_userpicEmpty) {
const auto user = asUser(); const auto user = asUser();
_userpicEmpty = std::make_unique<Ui::EmptyUserpic>( _userpicEmpty = std::make_unique<Ui::EmptyUserpic>(
Data::PeerUserpicColor(id), Ui::PeerUserpicColor(id),
user && user->isInaccessible() user && user->isInaccessible()
? Ui::EmptyUserpic::InaccessibleName() ? Ui::EmptyUserpic::InaccessibleName()
: name()); : name());

View file

@ -41,7 +41,6 @@ struct ReactionId;
int PeerColorIndex(PeerId peerId); int PeerColorIndex(PeerId peerId);
int PeerColorIndex(BareId bareId); int PeerColorIndex(BareId bareId);
style::color PeerUserpicColor(PeerId peerId);
// Must be used only for PeerColor-s. // Must be used only for PeerColor-s.
PeerId FakePeerIdForJustName(const QString &name); PeerId FakePeerIdForJustName(const QString &name);

View file

@ -105,7 +105,7 @@ HiddenSenderInfo::HiddenSenderInfo(const QString &name, bool external)
: name(name) : name(name)
, colorPeerId(Data::FakePeerIdForJustName(name)) , colorPeerId(Data::FakePeerIdForJustName(name))
, emptyUserpic( , emptyUserpic(
Data::PeerUserpicColor(colorPeerId), Ui::PeerUserpicColor(colorPeerId),
(external (external
? Ui::EmptyUserpic::ExternalName() ? Ui::EmptyUserpic::ExternalName()
: name)) { : name)) {

View file

@ -122,7 +122,7 @@ QSize Contact::countOptimalSize() {
} else { } else {
const auto full = _name.toString(); const auto full = _name.toString();
_photoEmpty = std::make_unique<Ui::EmptyUserpic>( _photoEmpty = std::make_unique<Ui::EmptyUserpic>(
Data::PeerUserpicColor(_userId Ui::PeerUserpicColor(_userId
? peerFromUser(_userId) ? peerFromUser(_userId)
: Data::FakePeerIdForJustName(full)), : Data::FakePeerIdForJustName(full)),
full); full);

View file

@ -158,11 +158,14 @@ Image *ItemBase::getResultThumb(Data::FileOrigin origin) const {
QPixmap ItemBase::getResultContactAvatar(int width, int height) const { QPixmap ItemBase::getResultContactAvatar(int width, int height) const {
if (_result->_type == Result::Type::Contact) { if (_result->_type == Result::Type::Contact) {
auto result = Ui::EmptyUserpic( auto result = Ui::EmptyUserpic(
Data::PeerUserpicColor(FakeChatId(BareId(qHash(_result->_id)))), Ui::PeerUserpicColor(FakeChatId(BareId(qHash(_result->_id)))),
_result->getLayoutTitle() _result->getLayoutTitle()
).generate(width); ).generate(width);
if (result.height() != height * cIntRetinaFactor()) { if (result.height() != height * cIntRetinaFactor()) {
result = result.scaled(QSize(width, height) * cIntRetinaFactor(), Qt::IgnoreAspectRatio, Qt::SmoothTransformation); result = result.scaled(
QSize(width, height) * cIntRetinaFactor(),
Qt::IgnoreAspectRatio,
Qt::SmoothTransformation);
} }
return result; return result;
} }

View file

@ -210,8 +210,8 @@ template <typename Callback>
} // namespace } // namespace
EmptyUserpic::EmptyUserpic(const style::color &color, const QString &name) EmptyUserpic::EmptyUserpic(const BgColors &colors, const QString &name)
: _color(color) { : _colors(colors) {
fillString(name); fillString(name);
} }
@ -238,7 +238,14 @@ void EmptyUserpic::paint(
font.setPixelSize(fontsize); font.setPixelSize(fontsize);
PainterHighQualityEnabler hq(p); PainterHighQualityEnabler hq(p);
p.setBrush(_color); {
auto gradient = QLinearGradient(x, y, x, y + size);
gradient.setStops({
{ 0., _colors.color1->c },
{ 1., _colors.color2->c }
});
p.setBrush(gradient);
}
p.setPen(Qt::NoPen); p.setPen(Qt::NoPen);
paintBackground(); paintBackground();
@ -295,9 +302,13 @@ void EmptyUserpic::PaintSavedMessages(
int y, int y,
int outerWidth, int outerWidth,
int size) { int size) {
const auto &bg = st::historyPeerSavedMessagesBg; auto bg = QLinearGradient(x, y, x, y + size);
bg.setStops({
{ 0., st::historyPeerSavedMessagesBg->c },
{ 1., st::historyPeerSavedMessagesBg2->c }
});
const auto &fg = st::historyPeerUserpicFg; const auto &fg = st::historyPeerUserpicFg;
PaintSavedMessages(p, x, y, outerWidth, size, bg, fg); PaintSavedMessages(p, x, y, outerWidth, size, QBrush(bg), fg);
} }
void EmptyUserpic::PaintSavedMessagesRounded( void EmptyUserpic::PaintSavedMessagesRounded(
@ -306,9 +317,13 @@ void EmptyUserpic::PaintSavedMessagesRounded(
int y, int y,
int outerWidth, int outerWidth,
int size) { int size) {
const auto &bg = st::historyPeerSavedMessagesBg; auto bg = QLinearGradient(x, y, x, y + size);
bg.setStops({
{ 0., st::historyPeerSavedMessagesBg->c },
{ 1., st::historyPeerSavedMessagesBg2->c }
});
const auto &fg = st::historyPeerUserpicFg; const auto &fg = st::historyPeerUserpicFg;
PaintSavedMessagesRounded(p, x, y, outerWidth, size, bg, fg); PaintSavedMessagesRounded(p, x, y, outerWidth, size, QBrush(bg), fg);
} }
void EmptyUserpic::PaintSavedMessages( void EmptyUserpic::PaintSavedMessages(
@ -317,12 +332,12 @@ void EmptyUserpic::PaintSavedMessages(
int y, int y,
int outerWidth, int outerWidth,
int size, int size,
const style::color &bg, QBrush bg,
const style::color &fg) { const style::color &fg) {
x = rtl() ? (outerWidth - x - size) : x; x = rtl() ? (outerWidth - x - size) : x;
PainterHighQualityEnabler hq(p); PainterHighQualityEnabler hq(p);
p.setBrush(bg); p.setBrush(std::move(bg));
p.setPen(Qt::NoPen); p.setPen(Qt::NoPen);
p.drawEllipse(x, y, size, size); p.drawEllipse(x, y, size, size);
@ -335,12 +350,12 @@ void EmptyUserpic::PaintSavedMessagesRounded(
int y, int y,
int outerWidth, int outerWidth,
int size, int size,
const style::color &bg, QBrush bg,
const style::color &fg) { const style::color &fg) {
x = rtl() ? (outerWidth - x - size) : x; x = rtl() ? (outerWidth - x - size) : x;
PainterHighQualityEnabler hq(p); PainterHighQualityEnabler hq(p);
p.setBrush(bg); p.setBrush(std::move(bg));
p.setPen(Qt::NoPen); p.setPen(Qt::NoPen);
p.drawRoundedRect(x, y, size, size, st::roundRadiusSmall, st::roundRadiusSmall); p.drawRoundedRect(x, y, size, size, st::roundRadiusSmall, st::roundRadiusSmall);
@ -365,9 +380,13 @@ void EmptyUserpic::PaintRepliesMessages(
int y, int y,
int outerWidth, int outerWidth,
int size) { int size) {
const auto &bg = st::historyPeerSavedMessagesBg; auto bg = QLinearGradient(x, y, x, y + size);
bg.setStops({
{ 0., st::historyPeerSavedMessagesBg->c },
{ 1., st::historyPeerSavedMessagesBg2->c }
});
const auto &fg = st::historyPeerUserpicFg; const auto &fg = st::historyPeerUserpicFg;
PaintRepliesMessages(p, x, y, outerWidth, size, bg, fg); PaintRepliesMessages(p, x, y, outerWidth, size, QBrush(bg), fg);
} }
void EmptyUserpic::PaintRepliesMessagesRounded( void EmptyUserpic::PaintRepliesMessagesRounded(
@ -376,9 +395,13 @@ void EmptyUserpic::PaintRepliesMessagesRounded(
int y, int y,
int outerWidth, int outerWidth,
int size) { int size) {
const auto &bg = st::historyPeerSavedMessagesBg; auto bg = QLinearGradient(x, y, x, y + size);
bg.setStops({
{ 0., st::historyPeerSavedMessagesBg->c },
{ 1., st::historyPeerSavedMessagesBg2->c }
});
const auto &fg = st::historyPeerUserpicFg; const auto &fg = st::historyPeerUserpicFg;
PaintRepliesMessagesRounded(p, x, y, outerWidth, size, bg, fg); PaintRepliesMessagesRounded(p, x, y, outerWidth, size, QBrush(bg), fg);
} }
void EmptyUserpic::PaintRepliesMessages( void EmptyUserpic::PaintRepliesMessages(
@ -387,7 +410,7 @@ void EmptyUserpic::PaintRepliesMessages(
int y, int y,
int outerWidth, int outerWidth,
int size, int size,
const style::color &bg, QBrush bg,
const style::color &fg) { const style::color &fg) {
x = rtl() ? (outerWidth - x - size) : x; x = rtl() ? (outerWidth - x - size) : x;
@ -405,7 +428,7 @@ void EmptyUserpic::PaintRepliesMessagesRounded(
int y, int y,
int outerWidth, int outerWidth,
int size, int size,
const style::color &bg, QBrush bg,
const style::color &fg) { const style::color &fg) {
x = rtl() ? (outerWidth - x - size) : x; x = rtl() ? (outerWidth - x - size) : x;
@ -431,7 +454,7 @@ QPixmap EmptyUserpic::GenerateRepliesMessagesRounded(int size) {
InMemoryKey EmptyUserpic::uniqueKey() const { InMemoryKey EmptyUserpic::uniqueKey() const {
const auto first = (uint64(0xFFFFFFFFU) << 32) const auto first = (uint64(0xFFFFFFFFU) << 32)
| anim::getPremultiplied(_color->c); | anim::getPremultiplied(_colors.color1->c);
auto second = uint64(0); auto second = uint64(0);
memcpy(&second, _string.constData(), qMin(sizeof(second), _string.size() * sizeof(QChar))); memcpy(&second, _string.constData(), qMin(sizeof(second), _string.size() * sizeof(QChar)));
return InMemoryKey(first, second); return InMemoryKey(first, second);
@ -512,4 +535,18 @@ void EmptyUserpic::fillString(const QString &name) {
EmptyUserpic::~EmptyUserpic() = default; EmptyUserpic::~EmptyUserpic() = default;
EmptyUserpic::BgColors PeerUserpicColor(PeerId peerId) {
const EmptyUserpic::BgColors colors[] = {
{ st::historyPeer1UserpicBg, st::historyPeer1UserpicBg2 },
{ st::historyPeer2UserpicBg, st::historyPeer2UserpicBg2 },
{ st::historyPeer3UserpicBg, st::historyPeer3UserpicBg2 },
{ st::historyPeer4UserpicBg, st::historyPeer4UserpicBg2 },
{ st::historyPeer5UserpicBg, st::historyPeer5UserpicBg2 },
{ st::historyPeer6UserpicBg, st::historyPeer6UserpicBg2 },
{ st::historyPeer7UserpicBg, st::historyPeer7UserpicBg2 },
{ st::historyPeer8UserpicBg, st::historyPeer8UserpicBg2 },
};
return colors[Data::PeerColorIndex(peerId)];
}
} // namespace Ui } // namespace Ui

View file

@ -11,10 +11,15 @@ namespace Ui {
class EmptyUserpic { class EmptyUserpic {
public: public:
struct BgColors {
const style::color color1;
const style::color color2;
};
[[nodiscard]] static QString ExternalName(); [[nodiscard]] static QString ExternalName();
[[nodiscard]] static QString InaccessibleName(); [[nodiscard]] static QString InaccessibleName();
EmptyUserpic(const style::color &color, const QString &name); EmptyUserpic(const BgColors &colors, const QString &name);
void paint( void paint(
QPainter &p, QPainter &p,
@ -56,7 +61,7 @@ public:
int y, int y,
int outerWidth, int outerWidth,
int size, int size,
const style::color &bg, QBrush bg,
const style::color &fg); const style::color &fg);
static void PaintSavedMessagesRounded( static void PaintSavedMessagesRounded(
QPainter &p, QPainter &p,
@ -64,7 +69,7 @@ public:
int y, int y,
int outerWidth, int outerWidth,
int size, int size,
const style::color &bg, QBrush bg,
const style::color &fg); const style::color &fg);
static QPixmap GenerateSavedMessages(int size); static QPixmap GenerateSavedMessages(int size);
static QPixmap GenerateSavedMessagesRounded(int size); static QPixmap GenerateSavedMessagesRounded(int size);
@ -87,7 +92,7 @@ public:
int y, int y,
int outerWidth, int outerWidth,
int size, int size,
const style::color &bg, QBrush bg,
const style::color &fg); const style::color &fg);
static void PaintRepliesMessagesRounded( static void PaintRepliesMessagesRounded(
QPainter &p, QPainter &p,
@ -95,7 +100,7 @@ public:
int y, int y,
int outerWidth, int outerWidth,
int size, int size,
const style::color &bg, QBrush bg,
const style::color &fg); const style::color &fg);
static QPixmap GenerateRepliesMessages(int size); static QPixmap GenerateRepliesMessages(int size);
static QPixmap GenerateRepliesMessagesRounded(int size); static QPixmap GenerateRepliesMessagesRounded(int size);
@ -114,9 +119,11 @@ private:
void fillString(const QString &name); void fillString(const QString &name);
style::color _color; const BgColors _colors;
QString _string; QString _string;
}; };
[[nodiscard]] EmptyUserpic::BgColors PeerUserpicColor(PeerId peerId);
} // namespace Ui } // namespace Ui

@ -1 +1 @@
Subproject commit ff821bc3d79761a2b801bd067d38d2a4d7f766e3 Subproject commit eb285b14c70e0410cd155a58e7f3b1e4891820cd