mirror of
https://github.com/AyuGram/AyuGramDesktop.git
synced 2025-06-05 06:33:57 +02:00
Fix background sample generation.
This commit is contained in:
parent
c2b1187948
commit
ba7e976fe2
4 changed files with 56 additions and 32 deletions
|
@ -547,10 +547,6 @@ void BackgroundPreviewBox::paintEvent(QPaintEvent *e) {
|
||||||
void BackgroundPreviewBox::paintImage(Painter &p) {
|
void BackgroundPreviewBox::paintImage(Painter &p) {
|
||||||
Expects(!_scaled.isNull());
|
Expects(!_scaled.isNull());
|
||||||
|
|
||||||
const auto master = _paper.isPattern()
|
|
||||||
? std::clamp(_paper.patternIntensity() / 100., 0., 1.)
|
|
||||||
: 1.;
|
|
||||||
|
|
||||||
const auto factor = cIntRetinaFactor();
|
const auto factor = cIntRetinaFactor();
|
||||||
const auto size = st::boxWideWidth;
|
const auto size = st::boxWideWidth;
|
||||||
const auto from = QRect(
|
const auto from = QRect(
|
||||||
|
@ -567,7 +563,7 @@ void BackgroundPreviewBox::paintImage(Painter &p) {
|
||||||
const auto &pixmap = (!_blurred.isNull() && _paper.isBlurred())
|
const auto &pixmap = (!_blurred.isNull() && _paper.isBlurred())
|
||||||
? _blurred
|
? _blurred
|
||||||
: _scaled;
|
: _scaled;
|
||||||
p.setOpacity(master * fade);
|
p.setOpacity(fade);
|
||||||
p.drawPixmap(rect(), pixmap, from);
|
p.drawPixmap(rect(), pixmap, from);
|
||||||
checkBlurAnimationStart();
|
checkBlurAnimationStart();
|
||||||
}
|
}
|
||||||
|
|
|
@ -55,6 +55,10 @@ constexpr auto kVersion = 1;
|
||||||
int(serialized & 0xFFU)));
|
int(serialized & 0xFFU)));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
[[nodiscard]] QColor DefaultBackgroundColor() {
|
||||||
|
return QColor(213, 223, 233);
|
||||||
|
}
|
||||||
|
|
||||||
[[nodiscard]] std::optional<QColor> MaybeColorFromSerialized(
|
[[nodiscard]] std::optional<QColor> MaybeColorFromSerialized(
|
||||||
const tl::conditional<MTPint> &mtp) {
|
const tl::conditional<MTPint> &mtp) {
|
||||||
return mtp ? MaybeColorFromSerialized(mtp->v) : std::nullopt;
|
return mtp ? MaybeColorFromSerialized(mtp->v) : std::nullopt;
|
||||||
|
@ -460,7 +464,7 @@ std::optional<WallPaper> WallPaper::Create(
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
if (result.isPattern() && result.backgroundColors().empty()) {
|
if (result.isPattern() && result.backgroundColors().empty()) {
|
||||||
return std::nullopt;
|
result._backgroundColors.push_back(DefaultBackgroundColor());
|
||||||
}
|
}
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
@ -489,7 +493,7 @@ std::optional<WallPaper> WallPaper::Create(const MTPDwallPaperNoFile &data) {
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
if (result.backgroundColors().empty()) {
|
if (result.backgroundColors().empty()) {
|
||||||
return std::nullopt;
|
result._backgroundColors.push_back(DefaultBackgroundColor());
|
||||||
}
|
}
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
@ -625,7 +629,7 @@ std::optional<WallPaper> WallPaper::FromSerialized(
|
||||||
result._intensity = intensity;
|
result._intensity = intensity;
|
||||||
result._rotation = rotation;
|
result._rotation = rotation;
|
||||||
if (result.isPattern() && result.backgroundColors().empty()) {
|
if (result.isPattern() && result.backgroundColors().empty()) {
|
||||||
return std::nullopt;
|
result._backgroundColors.push_back(DefaultBackgroundColor());
|
||||||
}
|
}
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
@ -643,7 +647,7 @@ std::optional<WallPaper> WallPaper::FromLegacySerialized(
|
||||||
result._backgroundColors.push_back(*color);
|
result._backgroundColors.push_back(*color);
|
||||||
}
|
}
|
||||||
if (result.isPattern() && result.backgroundColors().empty()) {
|
if (result.isPattern() && result.backgroundColors().empty()) {
|
||||||
return std::nullopt;
|
result._backgroundColors.push_back(DefaultBackgroundColor());
|
||||||
}
|
}
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
@ -755,28 +759,36 @@ bool IsCloudWallPaper(const WallPaper &paper) {
|
||||||
}
|
}
|
||||||
|
|
||||||
QImage PreparePatternImage(
|
QImage PreparePatternImage(
|
||||||
QImage image,
|
QSize size,
|
||||||
|
Fn<void(QPainter&)> drawPattern,
|
||||||
const std::vector<QColor> &bg,
|
const std::vector<QColor> &bg,
|
||||||
int rotation,
|
int rotation,
|
||||||
float64 opacity) {
|
float64 opacity) {
|
||||||
if (image.format() != QImage::Format_ARGB32_Premultiplied) {
|
auto result = QImage(size, QImage::Format_ARGB32_Premultiplied);
|
||||||
image = std::move(image).convertToFormat(
|
|
||||||
QImage::Format_ARGB32_Premultiplied);
|
|
||||||
}
|
|
||||||
|
|
||||||
auto result = QImage(image.size(), QImage::Format_ARGB32_Premultiplied);
|
|
||||||
if (bg.size() < 2) {
|
if (bg.size() < 2) {
|
||||||
result.fill(bg.empty() ? QColor(213, 223, 233) : bg.front());
|
result.fill(bg.empty() ? DefaultBackgroundColor() : bg.front());
|
||||||
} else {
|
} else {
|
||||||
result = FillDitheredGradient(std::move(result), bg, rotation);
|
result = FillDitheredGradient(std::move(result), bg, rotation);
|
||||||
}
|
}
|
||||||
auto p = QPainter(&result);
|
auto p = QPainter(&result);
|
||||||
p.setCompositionMode(QPainter::CompositionMode_SoftLight);
|
p.setCompositionMode(QPainter::CompositionMode_SoftLight);
|
||||||
p.setOpacity(opacity);
|
p.setOpacity(opacity);
|
||||||
p.drawImage(QRect(QPoint(), image.size()), image);
|
drawPattern(p);
|
||||||
p.end();
|
p.end();
|
||||||
|
|
||||||
image = QImage();
|
return result;
|
||||||
|
}
|
||||||
|
|
||||||
|
QImage PreparePatternImage(
|
||||||
|
QImage pattern,
|
||||||
|
const std::vector<QColor> &bg,
|
||||||
|
int rotation,
|
||||||
|
float64 opacity) {
|
||||||
|
auto result = PreparePatternImage(pattern.size(), [&](QPainter &p) {
|
||||||
|
p.drawImage(QRect(QPoint(), pattern.size()), pattern);
|
||||||
|
}, bg, rotation, opacity);
|
||||||
|
|
||||||
|
pattern = QImage();
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -123,7 +123,13 @@ private:
|
||||||
[[nodiscard]] bool IsCloudWallPaper(const WallPaper &paper);
|
[[nodiscard]] bool IsCloudWallPaper(const WallPaper &paper);
|
||||||
|
|
||||||
[[nodiscard]] QImage PreparePatternImage(
|
[[nodiscard]] QImage PreparePatternImage(
|
||||||
QImage image,
|
QSize size,
|
||||||
|
Fn<void(QPainter&)> drawPattern,
|
||||||
|
const std::vector<QColor> &bg,
|
||||||
|
int rotation,
|
||||||
|
float64 opacity);
|
||||||
|
[[nodiscard]] QImage PreparePatternImage(
|
||||||
|
QImage pattern,
|
||||||
const std::vector<QColor> &bg,
|
const std::vector<QColor> &bg,
|
||||||
int rotation,
|
int rotation,
|
||||||
float64 opacity);
|
float64 opacity);
|
||||||
|
|
|
@ -87,7 +87,6 @@ constexpr auto kMinDiffIntensity = 0.25;
|
||||||
|
|
||||||
[[nodiscard]] bool IsFilledCover() {
|
[[nodiscard]] bool IsFilledCover() {
|
||||||
const auto background = Window::Theme::Background();
|
const auto background = Window::Theme::Background();
|
||||||
return false; AssertIsDebug();
|
|
||||||
return background->tile()
|
return background->tile()
|
||||||
|| background->colorForFill().has_value()
|
|| background->colorForFill().has_value()
|
||||||
|| !background->gradientForFill().isNull()
|
|| !background->gradientForFill().isNull()
|
||||||
|
@ -985,12 +984,25 @@ void MainMenu::refreshMenu() {
|
||||||
}
|
}
|
||||||
|
|
||||||
void MainMenu::refreshBackground() {
|
void MainMenu::refreshBackground() {
|
||||||
const auto fill = QRect(0, 0, width(), st::mainMenuCoverHeight);
|
const auto fill = QRect(0, 0, st::mainMenuWidth, st::mainMenuCoverHeight);
|
||||||
const auto intensityText = IntensityOfColor(st::mainMenuCoverFg->c);
|
const auto intensityText = IntensityOfColor(st::mainMenuCoverFg->c);
|
||||||
QImage backgroundImage(
|
const auto background = Window::Theme::Background();
|
||||||
st::mainMenuWidth * cIntRetinaFactor(),
|
const auto &paper = background->paper();
|
||||||
st::mainMenuCoverHeight * cIntRetinaFactor(),
|
const auto &pixmap = background->pixmap();
|
||||||
QImage::Format_ARGB32_Premultiplied);
|
|
||||||
|
QRect to, from;
|
||||||
|
Window::Theme::ComputeBackgroundRects(fill, pixmap.size(), to, from);
|
||||||
|
|
||||||
|
auto backgroundImage = paper.isPattern()
|
||||||
|
? Data::PreparePatternImage(
|
||||||
|
fill.size() * cIntRetinaFactor(),
|
||||||
|
[&](QPainter &p) { p.drawPixmap(to, pixmap, from); },
|
||||||
|
paper.backgroundColors(),
|
||||||
|
paper.gradientRotation(),
|
||||||
|
paper.patternOpacity())
|
||||||
|
: QImage(
|
||||||
|
fill.size() * cIntRetinaFactor(),
|
||||||
|
QImage::Format_ARGB32_Premultiplied);
|
||||||
QPainter p(&backgroundImage);
|
QPainter p(&backgroundImage);
|
||||||
|
|
||||||
const auto drawShadow = [](QPainter &p) {
|
const auto drawShadow = [](QPainter &p) {
|
||||||
|
@ -1005,7 +1017,7 @@ void MainMenu::refreshBackground() {
|
||||||
};
|
};
|
||||||
|
|
||||||
// Solid color.
|
// Solid color.
|
||||||
if (const auto color = Window::Theme::Background()->colorForFill()) {
|
if (const auto color = background->colorForFill()) {
|
||||||
const auto intensity = IntensityOfColor(*color);
|
const auto intensity = IntensityOfColor(*color);
|
||||||
p.fillRect(fill, *color);
|
p.fillRect(fill, *color);
|
||||||
if (std::abs(intensity - intensityText) < kMinDiffIntensity) {
|
if (std::abs(intensity - intensityText) < kMinDiffIntensity) {
|
||||||
|
@ -1016,9 +1028,9 @@ void MainMenu::refreshBackground() {
|
||||||
}
|
}
|
||||||
|
|
||||||
// Background image.
|
// Background image.
|
||||||
const auto &pixmap = Window::Theme::Background()->pixmap();
|
if (!paper.isPattern()) {
|
||||||
QRect to, from;
|
p.drawPixmap(to, pixmap, from);
|
||||||
Window::Theme::ComputeBackgroundRects(fill, pixmap.size(), to, from);
|
}
|
||||||
|
|
||||||
// Cut off the part of the background that is under text.
|
// Cut off the part of the background that is under text.
|
||||||
const QRect underText(
|
const QRect underText(
|
||||||
|
@ -1029,8 +1041,6 @@ void MainMenu::refreshBackground() {
|
||||||
_controller->session().user()->nameText().toString()),
|
_controller->session().user()->nameText().toString()),
|
||||||
st::normalFont->width(_phoneText)),
|
st::normalFont->width(_phoneText)),
|
||||||
st::semiboldFont->height * 2);
|
st::semiboldFont->height * 2);
|
||||||
|
|
||||||
p.drawPixmap(to, pixmap, from);
|
|
||||||
if (IsShadowShown(backgroundImage, underText, intensityText)) {
|
if (IsShadowShown(backgroundImage, underText, intensityText)) {
|
||||||
drawShadow(p);
|
drawShadow(p);
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Reference in a new issue