diff --git a/Telegram/SourceFiles/window/themes/window_theme.cpp b/Telegram/SourceFiles/window/themes/window_theme.cpp index 2e12b3e8c..639c265de 100644 --- a/Telegram/SourceFiles/window/themes/window_theme.cpp +++ b/Telegram/SourceFiles/window/themes/window_theme.cpp @@ -49,6 +49,20 @@ inline bool AreTestingTheme() { return !GlobalApplying.paletteForRevert.isEmpty(); }; +bool CalculateIsMonoColorImage(const QImage &image) { + if (!image.isNull()) { + const auto bits = reinterpret_cast(image.constBits()); + const auto first = bits[0]; + for (auto i = 0; i < image.width() * image.height(); i++) { + if (first != bits[i]) { + return false; + } + } + return true; + } + return false; +} + QByteArray readThemeContent(const QString &path) { QFile file(path); if (!file.exists()) { @@ -580,6 +594,7 @@ void ChatBackground::preparePixmaps(QImage image) { } _pixmapForTiled = App::pixmapFromImageInPlace(std::move(imageForTiled)); } + _isMonoColorImage = CalculateIsMonoColorImage(image); _pixmap = App::pixmapFromImageInPlace(std::move(image)); if (!isSmallForTiled) { _pixmapForTiled = _pixmap; @@ -671,6 +686,10 @@ bool ChatBackground::tileNight() const { return _tileNightValue; } +bool ChatBackground::isMonoColorImage() const { + return _isMonoColorImage; +} + void ChatBackground::ensureStarted() { if (_pixmap.isNull() && !_paper.backgroundColor()) { // We should start first, otherwise the default call diff --git a/Telegram/SourceFiles/window/themes/window_theme.h b/Telegram/SourceFiles/window/themes/window_theme.h index ddf373e89..4d91facfc 100644 --- a/Telegram/SourceFiles/window/themes/window_theme.h +++ b/Telegram/SourceFiles/window/themes/window_theme.h @@ -126,6 +126,7 @@ public: [[nodiscard]] bool tile() const; [[nodiscard]] bool tileDay() const; [[nodiscard]] bool tileNight() const; + [[nodiscard]] bool isMonoColorImage() const; private: struct AdjustableColor { @@ -174,6 +175,8 @@ private: bool _tileDayValue = false; bool _tileNightValue = true; + bool _isMonoColorImage = false; + QString _themeAbsolutePath; QImage _themeImage; bool _themeTile = false; diff --git a/Telegram/SourceFiles/window/window_main_menu.cpp b/Telegram/SourceFiles/window/window_main_menu.cpp index 90807e1d7..08ec868d9 100644 --- a/Telegram/SourceFiles/window/window_main_menu.cpp +++ b/Telegram/SourceFiles/window/window_main_menu.cpp @@ -331,7 +331,14 @@ void MainMenu::paintEvent(QPaintEvent *e) { const auto cover = QRect(0, 0, width(), st::mainMenuCoverHeight) .intersected(e->rect()); - if (!_background.isNull()) { + const auto background = Window::Theme::Background(); + const auto isFill = background->tile() + || background->colorForFill().has_value() + || background->isMonoColorImage() + || background->paper().isPattern() + || Data::IsLegacy1DefaultWallPaper(background->paper()); + + if (!isFill && !_background.isNull()) { PainterHighQualityEnabler hq(p); p.drawImage(0, 0, _background); } @@ -340,6 +347,10 @@ void MainMenu::paintEvent(QPaintEvent *e) { const auto widthText = _cloudButton ? _cloudButton->x() - st::mainMenuCloudSize : width() - 2 * st::mainMenuCoverTextLeft; + + if (isFill) { + p.fillRect(cover, st::mainMenuCoverBg); + } p.setPen(st::mainMenuCoverFg); p.setFont(st::semiboldFont); Auth().user()->nameText.drawLeftElided( @@ -357,8 +368,8 @@ void MainMenu::paintEvent(QPaintEvent *e) { _cloudButton->y() + (_cloudButton->height() - st::mainMenuCloudSize) / 2, width(), st::mainMenuCloudSize, - st::msgServiceBg, - st::mainMenuCloudFg); + isFill ? st::mainMenuCloudBg : st::msgServiceBg, + isFill ? st::mainMenuCloudFg : st::msgServiceFg); } } auto other = QRect(0, st::mainMenuCoverHeight, width(), height() - st::mainMenuCoverHeight).intersected(clip);