Moved shadow drawing from paintEvent in MainMenu::refreshBackground.

This commit is contained in:
23rd 2019-05-27 14:43:23 +03:00 committed by John Preston
parent 159f90a42c
commit b2e5ab36d4
2 changed files with 21 additions and 20 deletions

View File

@ -146,7 +146,6 @@ MainMenu::MainMenu(
Window::Theme::ToggleNightMode();
Window::Theme::KeepApplied();
}
refreshBackground();
}
});
@ -174,6 +173,8 @@ MainMenu::MainMenu(
subscribe(Window::Theme::Background(), [this](const Window::Theme::BackgroundUpdate &update) {
if (update.type == Window::Theme::BackgroundUpdate::Type::ApplyingTheme) {
refreshMenu();
}
if (update.type == Window::Theme::BackgroundUpdate::Type::New) {
refreshBackground();
}
});
@ -256,12 +257,24 @@ void MainMenu::refreshBackground() {
QImage::Format_ARGB32_Premultiplied);
QPainter p(&backgroundImage);
const auto drawShadow = [](QPainter &p) {
st::mainMenuShadow.paint(
p,
0,
st::mainMenuCoverHeight - st::mainMenuShadow.height(),
st::mainMenuWidth,
IntensityOfColor(st::mainMenuCoverFg->c) < 0.5
? Qt::white
: Qt::black);
};
// Solid color.
if (const auto color = Window::Theme::Background()->colorForFill()) {
const auto intensity = IntensityOfColor(*color);
_isShadowShown =
(std::abs(intensity - intensityText) < kMinDiffIntensity);
p.fillRect(fill, *color);
if (std::abs(intensity - intensityText) < kMinDiffIntensity) {
drawShadow(p);
}
_background = backgroundImage;
return;
}
@ -271,9 +284,6 @@ void MainMenu::refreshBackground() {
QRect to, from;
Window::Theme::ComputeBackgroundRects(fill, pixmap.size(), to, from);
p.drawPixmap(to, pixmap, from);
_background = backgroundImage;
// Cut off the part of the background that is under text.
const QRect underText(
st::mainMenuCoverTextLeft,
@ -283,7 +293,11 @@ void MainMenu::refreshBackground() {
st::normalFont->width(_phoneText)),
st::semiboldFont->height * 2);
_isShadowShown = IsShadowShown(backgroundImage, underText, intensityText);
p.drawPixmap(to, pixmap, from);
if (IsShadowShown(backgroundImage, underText, intensityText)) {
drawShadow(p);
}
_background = backgroundImage;
}
void MainMenu::resizeEvent(QResizeEvent *e) {
@ -326,18 +340,6 @@ void MainMenu::paintEvent(QPaintEvent *e) {
const auto widthText = _cloudButton
? _cloudButton->x() - st::mainMenuCloudSize
: width() - 2 * st::mainMenuCoverTextLeft;
if (_isShadowShown) {
st::mainMenuShadow.paint(
p,
0,
st::mainMenuCoverHeight - st::mainMenuShadow.height(),
st::mainMenuWidth,
IntensityOfColor(st::mainMenuCoverFg->c) < 0.5
? Qt::white
: Qt::black);
}
p.setPen(st::mainMenuCoverFg);
p.setFont(st::semiboldFont);
Auth().user()->nameText.drawLeftElided(

View File

@ -53,7 +53,6 @@ private:
QString _phoneText;
QImage _background;
bool _isShadowShown = false;
};