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 {
_photoEmpty = std::make_unique<Ui::EmptyUserpic>(
Data::PeerUserpicColor(0),
Ui::PeerUserpicColor(0),
invite.title);
}
}

View File

@ -248,7 +248,7 @@ void PaintFilterChatsTypeIcon(
int y,
int outerWidth,
int size) {
const auto &color = [&]() -> const style::color& {
const auto &color1 = [&]() -> const style::color& {
switch (flag) {
case Flag::Contacts: return st::historyPeer4UserpicBg;
case Flag::NonContacts: return st::historyPeer7UserpicBg;
@ -261,6 +261,19 @@ void PaintFilterChatsTypeIcon(
}
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& {
switch (flag) {
case Flag::Contacts: return st::windowFilterTypeContacts;
@ -276,7 +289,9 @@ void PaintFilterChatsTypeIcon(
}();
const auto rect = style::rtlrect(x, y, size, size, outerWidth);
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.drawEllipse(rect);
icon.paintInCenter(p, rect);

View File

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

View File

@ -69,20 +69,6 @@ int PeerColorIndex(PeerId peerId) {
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) {
constexpr auto kShift = (0xFEULL << 32);
const auto base = name.isEmpty()
@ -250,7 +236,7 @@ not_null<Ui::EmptyUserpic*> PeerData::ensureEmptyUserpic() const {
if (!_userpicEmpty) {
const auto user = asUser();
_userpicEmpty = std::make_unique<Ui::EmptyUserpic>(
Data::PeerUserpicColor(id),
Ui::PeerUserpicColor(id),
user && user->isInaccessible()
? Ui::EmptyUserpic::InaccessibleName()
: name());

View File

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

View File

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

View File

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

View File

@ -158,11 +158,14 @@ Image *ItemBase::getResultThumb(Data::FileOrigin origin) const {
QPixmap ItemBase::getResultContactAvatar(int width, int height) const {
if (_result->_type == Result::Type::Contact) {
auto result = Ui::EmptyUserpic(
Data::PeerUserpicColor(FakeChatId(BareId(qHash(_result->_id)))),
Ui::PeerUserpicColor(FakeChatId(BareId(qHash(_result->_id)))),
_result->getLayoutTitle()
).generate(width);
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;
}

View File

@ -210,8 +210,8 @@ template <typename Callback>
} // namespace
EmptyUserpic::EmptyUserpic(const style::color &color, const QString &name)
: _color(color) {
EmptyUserpic::EmptyUserpic(const BgColors &colors, const QString &name)
: _colors(colors) {
fillString(name);
}
@ -238,7 +238,14 @@ void EmptyUserpic::paint(
font.setPixelSize(fontsize);
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);
paintBackground();
@ -295,9 +302,13 @@ void EmptyUserpic::PaintSavedMessages(
int y,
int outerWidth,
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;
PaintSavedMessages(p, x, y, outerWidth, size, bg, fg);
PaintSavedMessages(p, x, y, outerWidth, size, QBrush(bg), fg);
}
void EmptyUserpic::PaintSavedMessagesRounded(
@ -306,9 +317,13 @@ void EmptyUserpic::PaintSavedMessagesRounded(
int y,
int outerWidth,
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;
PaintSavedMessagesRounded(p, x, y, outerWidth, size, bg, fg);
PaintSavedMessagesRounded(p, x, y, outerWidth, size, QBrush(bg), fg);
}
void EmptyUserpic::PaintSavedMessages(
@ -317,12 +332,12 @@ void EmptyUserpic::PaintSavedMessages(
int y,
int outerWidth,
int size,
const style::color &bg,
QBrush bg,
const style::color &fg) {
x = rtl() ? (outerWidth - x - size) : x;
PainterHighQualityEnabler hq(p);
p.setBrush(bg);
p.setBrush(std::move(bg));
p.setPen(Qt::NoPen);
p.drawEllipse(x, y, size, size);
@ -335,12 +350,12 @@ void EmptyUserpic::PaintSavedMessagesRounded(
int y,
int outerWidth,
int size,
const style::color &bg,
QBrush bg,
const style::color &fg) {
x = rtl() ? (outerWidth - x - size) : x;
PainterHighQualityEnabler hq(p);
p.setBrush(bg);
p.setBrush(std::move(bg));
p.setPen(Qt::NoPen);
p.drawRoundedRect(x, y, size, size, st::roundRadiusSmall, st::roundRadiusSmall);
@ -365,9 +380,13 @@ void EmptyUserpic::PaintRepliesMessages(
int y,
int outerWidth,
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;
PaintRepliesMessages(p, x, y, outerWidth, size, bg, fg);
PaintRepliesMessages(p, x, y, outerWidth, size, QBrush(bg), fg);
}
void EmptyUserpic::PaintRepliesMessagesRounded(
@ -376,9 +395,13 @@ void EmptyUserpic::PaintRepliesMessagesRounded(
int y,
int outerWidth,
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;
PaintRepliesMessagesRounded(p, x, y, outerWidth, size, bg, fg);
PaintRepliesMessagesRounded(p, x, y, outerWidth, size, QBrush(bg), fg);
}
void EmptyUserpic::PaintRepliesMessages(
@ -387,7 +410,7 @@ void EmptyUserpic::PaintRepliesMessages(
int y,
int outerWidth,
int size,
const style::color &bg,
QBrush bg,
const style::color &fg) {
x = rtl() ? (outerWidth - x - size) : x;
@ -405,7 +428,7 @@ void EmptyUserpic::PaintRepliesMessagesRounded(
int y,
int outerWidth,
int size,
const style::color &bg,
QBrush bg,
const style::color &fg) {
x = rtl() ? (outerWidth - x - size) : x;
@ -431,7 +454,7 @@ QPixmap EmptyUserpic::GenerateRepliesMessagesRounded(int size) {
InMemoryKey EmptyUserpic::uniqueKey() const {
const auto first = (uint64(0xFFFFFFFFU) << 32)
| anim::getPremultiplied(_color->c);
| anim::getPremultiplied(_colors.color1->c);
auto second = uint64(0);
memcpy(&second, _string.constData(), qMin(sizeof(second), _string.size() * sizeof(QChar)));
return InMemoryKey(first, second);
@ -512,4 +535,18 @@ void EmptyUserpic::fillString(const QString &name) {
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

View File

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

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