diff --git a/Telegram/SourceFiles/boxes/background_box.cpp b/Telegram/SourceFiles/boxes/background_box.cpp index 877cf556e..59729b7fe 100644 --- a/Telegram/SourceFiles/boxes/background_box.cpp +++ b/Telegram/SourceFiles/boxes/background_box.cpp @@ -40,11 +40,11 @@ namespace { constexpr auto kBackgroundsInRow = 3; QImage TakeMiddleSample(QImage original, QSize size) { - size *= cIntRetinaFactor(); + size *= style::DevicePixelRatio(); const auto from = original.size(); if (from.isEmpty()) { auto result = original.scaled(size); - result.setDevicePixelRatio(cRetinaFactor()); + result.setDevicePixelRatio(style::DevicePixelRatio()); return result; } @@ -58,7 +58,7 @@ QImage TakeMiddleSample(QImage original, QSize size) { take.width(), take.height() ).scaled(size, Qt::IgnoreAspectRatio, Qt::SmoothTransformation); - result.setDevicePixelRatio(cRetinaFactor()); + result.setDevicePixelRatio(style::DevicePixelRatio()); return result; } @@ -657,10 +657,10 @@ void BackgroundBox::Inner::validatePaperThumbnail( } else if (!paper.data.backgroundColors().empty()) { paper.thumbnail = Ui::PixmapFromImage( Ui::GenerateBackgroundImage( - st::backgroundSize * cIntRetinaFactor(), + st::backgroundSize * style::DevicePixelRatio(), paper.data.backgroundColors(), paper.data.gradientRotation())); - paper.thumbnail.setDevicePixelRatio(cRetinaFactor()); + paper.thumbnail.setDevicePixelRatio(style::DevicePixelRatio()); return; } else { return; @@ -680,7 +680,7 @@ void BackgroundBox::Inner::validatePaperThumbnail( paper.thumbnail = Ui::PixmapFromImage(TakeMiddleSample( original, st::backgroundSize)); - paper.thumbnail.setDevicePixelRatio(cRetinaFactor()); + paper.thumbnail.setDevicePixelRatio(style::DevicePixelRatio()); } bool BackgroundBox::Inner::forChannel() const { diff --git a/Telegram/SourceFiles/boxes/background_preview_box.cpp b/Telegram/SourceFiles/boxes/background_preview_box.cpp index d445ce1f5..3a9917719 100644 --- a/Telegram/SourceFiles/boxes/background_preview_box.cpp +++ b/Telegram/SourceFiles/boxes/background_preview_box.cpp @@ -467,14 +467,14 @@ void BackgroundPreviewBox::generateBackground() { return; } const auto size = QSize(st::boxWideWidth, st::boxWideWidth) - * cIntRetinaFactor(); + * style::DevicePixelRatio(); _generated = Ui::PixmapFromImage((_paper.patternOpacity() >= 0.) ? Ui::GenerateBackgroundImage( size, _paper.backgroundColors(), _paper.gradientRotation()) : BlackImage(size)); - _generated.setDevicePixelRatio(cRetinaFactor()); + _generated.setDevicePixelRatio(style::DevicePixelRatio()); } not_null BackgroundPreviewBox::delegate() { @@ -889,7 +889,7 @@ void BackgroundPreviewBox::paintEvent(QPaintEvent *e) { void BackgroundPreviewBox::paintImage(Painter &p) { Expects(!_scaled.isNull()); - const auto factor = cIntRetinaFactor(); + const auto factor = style::DevicePixelRatio(); const auto size = st::boxWideWidth; const auto from = QRect( 0, diff --git a/Telegram/SourceFiles/boxes/peers/edit_peer_invite_link.cpp b/Telegram/SourceFiles/boxes/peers/edit_peer_invite_link.cpp index a9c92c745..fcdc646a5 100644 --- a/Telegram/SourceFiles/boxes/peers/edit_peer_invite_link.cpp +++ b/Telegram/SourceFiles/boxes/peers/edit_peer_invite_link.cpp @@ -228,8 +228,8 @@ QImage QrExact(const Qr::Data &data, int pixel, QColor color) { skip, skip, Intro::details::TelegramLogoImage().scaled( - logoSize * cIntRetinaFactor(), - logoSize * cIntRetinaFactor(), + logoSize * style::DevicePixelRatio(), + logoSize * style::DevicePixelRatio(), Qt::IgnoreAspectRatio, Qt::SmoothTransformation)); } diff --git a/Telegram/SourceFiles/boxes/sticker_set_box.cpp b/Telegram/SourceFiles/boxes/sticker_set_box.cpp index 82e4e3deb..6f5966de6 100644 --- a/Telegram/SourceFiles/boxes/sticker_set_box.cpp +++ b/Telegram/SourceFiles/boxes/sticker_set_box.cpp @@ -1221,7 +1221,7 @@ void StickerSetBox::Inner::setupLottie(int index) { getLottiePlayer(), element.documentMedia.get(), ChatHelpers::StickerLottieSize::StickerSet, - boundingBoxSize() * cIntRetinaFactor()); + boundingBoxSize() * style::DevicePixelRatio()); } void StickerSetBox::Inner::setupWebm(int index) { @@ -1345,7 +1345,7 @@ void StickerSetBox::Inner::paintSticker( } else if (element.lottie && element.lottie->ready()) { lottieFrame = element.lottie->frame(); p.drawImage( - QRect(ppos, lottieFrame.size() / cIntRetinaFactor()), + QRect(ppos, lottieFrame.size() / style::DevicePixelRatio()), lottieFrame); _lottiePlayer->unpause(element.lottie); diff --git a/Telegram/SourceFiles/boxes/stickers_box.cpp b/Telegram/SourceFiles/boxes/stickers_box.cpp index 7d72ebf5a..94c11d00f 100644 --- a/Telegram/SourceFiles/boxes/stickers_box.cpp +++ b/Telegram/SourceFiles/boxes/stickers_box.cpp @@ -1539,7 +1539,7 @@ void StickersBox::Inner::paintRowThumbnail( const auto y = _st.photoPosition.y() + (_st.photoSize - row->pixh) / 2; if (row->lottie && row->lottie->ready()) { const auto frame = row->lottie->frame(); - const auto size = frame.size() / cIntRetinaFactor(); + const auto size = frame.size() / style::DevicePixelRatio(); p.drawImage( QRect( left + (_st.photoSize - size.width()) / 2, @@ -1578,7 +1578,7 @@ void StickersBox::Inner::validateLottieAnimation(not_null row) { row->thumbnailMedia.get(), row->stickerMedia.get(), ChatHelpers::StickerLottieSize::SetsListThumbnail, - QSize(_st.photoSize, _st.photoSize) * cIntRetinaFactor()); + QSize(_st.photoSize, _st.photoSize) * style::DevicePixelRatio()); if (!player) { return; } diff --git a/Telegram/SourceFiles/calls/calls_emoji_fingerprint.cpp b/Telegram/SourceFiles/calls/calls_emoji_fingerprint.cpp index a39ae87ed..d6b6ca32a 100644 --- a/Telegram/SourceFiles/calls/calls_emoji_fingerprint.cpp +++ b/Telegram/SourceFiles/calls/calls_emoji_fingerprint.cpp @@ -210,7 +210,7 @@ object_ptr CreateFingerprintAndSignalBars( // Geometry. const auto print = ComputeEmojiFingerprint(call); auto realSize = Ui::Emoji::GetSizeNormal(); - auto size = realSize / cIntRetinaFactor(); + auto size = realSize / style::DevicePixelRatio(); auto count = print.size(); const auto printSize = QSize( count * size + (count - 1) * st::callFingerprintSkip, @@ -234,9 +234,9 @@ object_ptr CreateFingerprintAndSignalBars( // Paint. const auto background = raw->lifetime().make_state( - fullSize * cIntRetinaFactor(), + fullSize * style::DevicePixelRatio(), QImage::Format_ARGB32_Premultiplied); - background->setDevicePixelRatio(cRetinaFactor()); + background->setDevicePixelRatio(style::DevicePixelRatio()); rpl::merge( rpl::single(rpl::empty), Ui::Emoji::Updated(), @@ -274,7 +274,7 @@ object_ptr CreateFingerprintAndSignalBars( // Emoji. const auto realSize = Ui::Emoji::GetSizeNormal(); - const auto size = realSize / cIntRetinaFactor(); + const auto size = realSize / style::DevicePixelRatio(); auto left = st::callFingerprintPadding.left(); const auto top = st::callFingerprintPadding.top(); p.setClipping(false); diff --git a/Telegram/SourceFiles/calls/calls_userpic.cpp b/Telegram/SourceFiles/calls/calls_userpic.cpp index 38f467170..a57b6ff19 100644 --- a/Telegram/SourceFiles/calls/calls_userpic.cpp +++ b/Telegram/SourceFiles/calls/calls_userpic.cpp @@ -170,7 +170,7 @@ void Userpic::refreshPhoto() { void Userpic::createCache(Image *image) { const auto size = this->size(); - const auto real = size * cIntRetinaFactor(); + const auto real = size * style::DevicePixelRatio(); //_useTransparency // ? (Images::Option::RoundLarge // | Images::Option::RoundSkipBottomLeft @@ -192,12 +192,12 @@ void Userpic::createCache(Image *image) { .options = Images::Option::RoundCircle, .outer = { size, size }, }); - _userPhoto.setDevicePixelRatio(cRetinaFactor()); + _userPhoto.setDevicePixelRatio(style::DevicePixelRatio()); } else { auto filled = QImage( QSize(real, real), QImage::Format_ARGB32_Premultiplied); - filled.setDevicePixelRatio(cRetinaFactor()); + filled.setDevicePixelRatio(style::DevicePixelRatio()); filled.fill(Qt::transparent); { auto p = QPainter(&filled); diff --git a/Telegram/SourceFiles/calls/calls_video_bubble.cpp b/Telegram/SourceFiles/calls/calls_video_bubble.cpp index 043ee8c41..b6866e9fd 100644 --- a/Telegram/SourceFiles/calls/calls_video_bubble.cpp +++ b/Telegram/SourceFiles/calls/calls_video_bubble.cpp @@ -126,7 +126,7 @@ void VideoBubble::paint() { const auto padding = st::boxRoundShadow.extend; const auto inner = _content.rect().marginsRemoved(padding); Ui::Shadow::paint(p, inner, _content.width(), st::boxRoundShadow); - const auto factor = cIntRetinaFactor(); + const auto factor = style::DevicePixelRatio(); const auto left = _mirrored ? (_frame.width() - (inner.width() * factor)) : 0; @@ -145,8 +145,8 @@ void VideoBubble::prepareFrame() { return; } const auto padding = st::boxRoundShadow.extend; - const auto size = _content.rect().marginsRemoved(padding).size() - * cIntRetinaFactor(); + const auto size = (_content.rect() - padding).size() + * style::DevicePixelRatio(); // Should we check 'original' and 'size' aspect ratios?.. const auto request = Webrtc::FrameRequest{ diff --git a/Telegram/SourceFiles/calls/calls_video_incoming.cpp b/Telegram/SourceFiles/calls/calls_video_incoming.cpp index 9ea9fe41c..9ab16d73d 100644 --- a/Telegram/SourceFiles/calls/calls_video_incoming.cpp +++ b/Telegram/SourceFiles/calls/calls_video_incoming.cpp @@ -472,7 +472,7 @@ void Panel::Incoming::RendererSW::paintFallback( void Panel::Incoming::RendererSW::initBottomShadow() { auto image = QImage( - QSize(1, st::callBottomShadowSize) * cIntRetinaFactor(), + QSize(1, st::callBottomShadowSize) * style::DevicePixelRatio(), QImage::Format_ARGB32_Premultiplied); const auto colorFrom = uint32(0); const auto colorTill = uint32(kBottomShadowAlphaMax); @@ -527,7 +527,7 @@ void Panel::Incoming::RendererSW::fillBottomShadow(QPainter &p) { if (fill.isEmpty()) { return; } - const auto factor = cIntRetinaFactor(); + const auto factor = style::DevicePixelRatio(); p.drawImage( fill, _bottomShadow, diff --git a/Telegram/SourceFiles/calls/group/calls_group_members.cpp b/Telegram/SourceFiles/calls/group/calls_group_members.cpp index 73ac7d1b9..ce806928c 100644 --- a/Telegram/SourceFiles/calls/group/calls_group_members.cpp +++ b/Telegram/SourceFiles/calls/group/calls_group_members.cpp @@ -1865,11 +1865,11 @@ void Members::updateControlsGeometry() { void Members::setupFakeRoundCorners() { const auto size = st::roundRadiusLarge; const auto full = 3 * size; - const auto imagePartSize = size * cIntRetinaFactor(); - const auto imageSize = full * cIntRetinaFactor(); + const auto imagePartSize = size * style::DevicePixelRatio(); + const auto imageSize = full * style::DevicePixelRatio(); const auto image = std::make_shared( QImage(imageSize, imageSize, QImage::Format_ARGB32_Premultiplied)); - image->setDevicePixelRatio(cRetinaFactor()); + image->setDevicePixelRatio(style::DevicePixelRatio()); const auto refreshImage = [=] { image->fill(st::groupCallBg->c); diff --git a/Telegram/SourceFiles/calls/group/calls_group_members_row.cpp b/Telegram/SourceFiles/calls/group/calls_group_members_row.cpp index 78484dadc..a9f41b35a 100644 --- a/Telegram/SourceFiles/calls/group/calls_group_members_row.cpp +++ b/Telegram/SourceFiles/calls/group/calls_group_members_row.cpp @@ -356,11 +356,13 @@ void MembersRow::ensureUserpicCache( const auto user = peer(); const auto key = user->userpicUniqueKey(view); - const auto full = QSize(size, size) * kWideScale * cIntRetinaFactor(); + const auto full = QSize(size, size) + * kWideScale + * style::DevicePixelRatio(); auto &cache = _blobsAnimation->userpicCache; if (cache.isNull()) { cache = QImage(full, QImage::Format_ARGB32_Premultiplied); - cache.setDevicePixelRatio(cRetinaFactor()); + cache.setDevicePixelRatio(style::DevicePixelRatio()); } else if (_blobsAnimation->userpicKey == key && cache.size() == full) { return; diff --git a/Telegram/SourceFiles/calls/group/calls_group_panel.cpp b/Telegram/SourceFiles/calls/group/calls_group_panel.cpp index f0720b885..9e967b50e 100644 --- a/Telegram/SourceFiles/calls/group/calls_group_panel.cpp +++ b/Telegram/SourceFiles/calls/group/calls_group_panel.cpp @@ -1871,7 +1871,7 @@ void Panel::setupControlsBackgroundNarrow() { _controlsBackgroundNarrow->blocker.show(); auto &lifetime = _controlsBackgroundNarrow->shadow.lifetime(); - const auto factor = cIntRetinaFactor(); + const auto factor = style::DevicePixelRatio(); const auto height = std::max( st::groupCallMembersShadowHeight, st::groupCallMembersFadeSkip + st::groupCallMembersFadeHeight); @@ -1929,7 +1929,7 @@ void Panel::setupControlsBackgroundNarrow() { _members->y() - _controlsBackgroundNarrow->shadow.y()); const auto faded = clip.intersected(inner); if (!faded.isEmpty()) { - const auto factor = cIntRetinaFactor(); + const auto factor = style::DevicePixelRatio(); p.drawImage( faded, *full, diff --git a/Telegram/SourceFiles/calls/group/calls_group_viewport_opengl.cpp b/Telegram/SourceFiles/calls/group/calls_group_viewport_opengl.cpp index e11644e68..63e5105fa 100644 --- a/Telegram/SourceFiles/calls/group/calls_group_viewport_opengl.cpp +++ b/Telegram/SourceFiles/calls/group/calls_group_viewport_opengl.cpp @@ -585,11 +585,12 @@ void Viewport::RendererGL::paintTile( _paused); const auto pauseRect = transformRect(pauseIcon.geometry); + const auto factor = style::DevicePixelRatio(); const auto pausedPosition = QPoint( - x + (width - (_pausedTextRect.width() / cIntRetinaFactor())) / 2, + x + (width - (_pausedTextRect.width() / factor)) / 2, pauseTextTop); const auto pausedText = _names.texturedRect( - QRect(pausedPosition, _pausedTextRect.size() / cIntRetinaFactor()), + QRect(pausedPosition, _pausedTextRect.size() / factor), _pausedTextRect); const auto pausedRect = transformRect(pausedText.geometry); @@ -627,7 +628,7 @@ void Viewport::RendererGL::paintTile( x + st.namePosition.x(), nameTop + nameShift); const auto name = _names.texturedRect( - QRect(namePosition, tileData.nameRect.size() / cIntRetinaFactor()), + QRect(namePosition, tileData.nameRect.size() / factor), tileData.nameRect, geometry); const auto nameRect = transformRect(name.geometry); @@ -1194,7 +1195,7 @@ void Viewport::RendererGL::validateDatas() { const auto &tiles = _owner->_tiles; const auto &st = st::groupCallVideoTile; const auto count = int(tiles.size()); - const auto factor = cIntRetinaFactor(); + const auto factor = style::DevicePixelRatio(); const auto nameHeight = st::semiboldFont->height * factor; const auto pausedText = tr::lng_group_call_video_paused(tr::now); const auto pausedBottom = nameHeight; diff --git a/Telegram/SourceFiles/chat_helpers/emoji_sets_manager.cpp b/Telegram/SourceFiles/chat_helpers/emoji_sets_manager.cpp index fed24fc5b..f620f700f 100644 --- a/Telegram/SourceFiles/chat_helpers/emoji_sets_manager.cpp +++ b/Telegram/SourceFiles/chat_helpers/emoji_sets_manager.cpp @@ -449,7 +449,7 @@ void Row::setupLabels(const Set &set) { } void Row::setupPreview(const Set &set) { - const auto size = st::manageEmojiPreview * cIntRetinaFactor(); + const auto size = st::manageEmojiPreview * style::DevicePixelRatio(); const auto original = QImage(set.previewPath); const auto full = original.height(); auto &&preview = ranges::views::zip(_preview, ranges::views::ints(0, int(_preview.size()))); @@ -457,7 +457,7 @@ void Row::setupPreview(const Set &set) { pixmap = Ui::PixmapFromImage(original.copy( { full * index, 0, full, full } ).scaledToWidth(size, Qt::SmoothTransformation)); - pixmap.setDevicePixelRatio(cRetinaFactor()); + pixmap.setDevicePixelRatio(style::DevicePixelRatio()); } } diff --git a/Telegram/SourceFiles/chat_helpers/field_autocomplete.cpp b/Telegram/SourceFiles/chat_helpers/field_autocomplete.cpp index d5aba296b..e82ab9b9f 100644 --- a/Telegram/SourceFiles/chat_helpers/field_autocomplete.cpp +++ b/Telegram/SourceFiles/chat_helpers/field_autocomplete.cpp @@ -972,7 +972,9 @@ void FieldAutocomplete::Inner::paintEvent(QPaintEvent *e) { if (sticker.lottie && sticker.lottie->ready()) { lottieFrame = sticker.lottie->frame(); p.drawImage( - QRect(ppos, lottieFrame.size() / cIntRetinaFactor()), + QRect( + ppos, + lottieFrame.size() / style::DevicePixelRatio()), lottieFrame); if (!paused) { sticker.lottie->markFrameShown(); @@ -1465,7 +1467,7 @@ void FieldAutocomplete::Inner::setupLottie(StickerSuggestion &suggestion) { suggestion.lottie = ChatHelpers::LottiePlayerFromDocument( suggestion.documentMedia.get(), ChatHelpers::StickerLottieSize::InlineResults, - stickerBoundingBox() * cIntRetinaFactor(), + stickerBoundingBox() * style::DevicePixelRatio(), Lottie::Quality::Default, getLottieRenderer()); diff --git a/Telegram/SourceFiles/chat_helpers/stickers_emoji_pack.cpp b/Telegram/SourceFiles/chat_helpers/stickers_emoji_pack.cpp index 35af9b1d5..f4cc13c4c 100644 --- a/Telegram/SourceFiles/chat_helpers/stickers_emoji_pack.cpp +++ b/Telegram/SourceFiles/chat_helpers/stickers_emoji_pack.cpp @@ -15,6 +15,7 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL #include "ui/emoji_config.h" #include "ui/text/text_isolated_emoji.h" #include "ui/image/image.h" +#include "ui/rect.h" #include "main/main_session.h" #include "data/data_file_origin.h" #include "data/data_session.h" @@ -53,10 +54,7 @@ constexpr auto kPremiumCachesCount = 8; [[nodiscard]] QSize SingleSize() { const auto single = st::largeEmojiSize; const auto outline = st::largeEmojiOutline; - return QSize( - 2 * outline + single, - 2 * outline + single - ) * cIntRetinaFactor(); + return Size(2 * outline + single) * style::DevicePixelRatio(); } [[nodiscard]] const Lottie::ColorReplacements *ColorReplacements(int index) { diff --git a/Telegram/SourceFiles/chat_helpers/stickers_list_footer.cpp b/Telegram/SourceFiles/chat_helpers/stickers_list_footer.cpp index 6659343d2..d77a7cafd 100644 --- a/Telegram/SourceFiles/chat_helpers/stickers_list_footer.cpp +++ b/Telegram/SourceFiles/chat_helpers/stickers_list_footer.cpp @@ -1191,7 +1191,7 @@ void StickersListFooter::validateIconLottieAnimation( icon.thumbnailMedia.get(), icon.stickerMedia.get(), StickerLottieSize::StickersFooter, - QSize(icon.pixw, icon.pixh) * cIntRetinaFactor(), + QSize(icon.pixw, icon.pixh) * style::DevicePixelRatio(), _renderer()); if (!player) { return; @@ -1357,10 +1357,11 @@ void StickersListFooter::paintSetIconToCache( }); } else if (icon.lottie && icon.lottie->ready()) { const auto frame = icon.lottie->frame(); - const auto size = frame.size() / cIntRetinaFactor(); + const auto size = frame.size() / style::DevicePixelRatio(); if (icon.savedFrame.isNull()) { icon.savedFrame = frame; - icon.savedFrame.setDevicePixelRatio(cRetinaFactor()); + icon.savedFrame.setDevicePixelRatio( + style::DevicePixelRatio()); } p.drawImage( QRect( @@ -1378,7 +1379,8 @@ void StickersListFooter::paintSetIconToCache( paused ? 0 : now); if (icon.savedFrame.isNull()) { icon.savedFrame = frame; - icon.savedFrame.setDevicePixelRatio(cRetinaFactor()); + icon.savedFrame.setDevicePixelRatio( + style::DevicePixelRatio()); } p.drawImage(x, y, frame); } else if (!icon.savedFrame.isNull()) { diff --git a/Telegram/SourceFiles/chat_helpers/stickers_list_widget.cpp b/Telegram/SourceFiles/chat_helpers/stickers_list_widget.cpp index 543ce497d..a6a52f4be 100644 --- a/Telegram/SourceFiles/chat_helpers/stickers_list_widget.cpp +++ b/Telegram/SourceFiles/chat_helpers/stickers_list_widget.cpp @@ -1187,7 +1187,7 @@ void StickersListWidget::setupLottie(Set &set, int section, int index) { set.lottiePlayer.get(), sticker.documentMedia.get(), StickerLottieSize::StickersPanel, - boundingBoxSize() * cIntRetinaFactor()); + boundingBoxSize() * style::DevicePixelRatio()); } void StickersListWidget::setupWebm(Set &set, int section, int index) { @@ -1385,14 +1385,14 @@ void StickersListWidget::paintSticker( auto lottieFrame = QImage(); if (sticker.lottie && sticker.lottie->ready()) { auto request = Lottie::FrameRequest(); - request.box = boundingBoxSize() * cIntRetinaFactor(); + request.box = boundingBoxSize() * style::DevicePixelRatio(); lottieFrame = sticker.lottie->frame(request); p.drawImage( - QRect(ppos, lottieFrame.size() / cIntRetinaFactor()), + QRect(ppos, lottieFrame.size() / style::DevicePixelRatio()), lottieFrame); if (sticker.savedFrame.isNull()) { sticker.savedFrame = lottieFrame; - sticker.savedFrame.setDevicePixelRatio(cRetinaFactor()); + sticker.savedFrame.setDevicePixelRatio(style::DevicePixelRatio()); sticker.savedFrameFor = _singleSize; } set.lottiePlayer->unpause(sticker.lottie); @@ -1402,7 +1402,7 @@ void StickersListWidget::paintSticker( paused ? 0 : now); if (sticker.savedFrame.isNull()) { sticker.savedFrame = frame; - sticker.savedFrame.setDevicePixelRatio(cRetinaFactor()); + sticker.savedFrame.setDevicePixelRatio(style::DevicePixelRatio()); sticker.savedFrameFor = _singleSize; } p.drawImage(ppos, frame); diff --git a/Telegram/SourceFiles/chat_helpers/tabbed_panel.cpp b/Telegram/SourceFiles/chat_helpers/tabbed_panel.cpp index e8ec060fb..7d399a596 100644 --- a/Telegram/SourceFiles/chat_helpers/tabbed_panel.cpp +++ b/Telegram/SourceFiles/chat_helpers/tabbed_panel.cpp @@ -368,7 +368,11 @@ void TabbedPanel::startShowAnimation() { ? Ui::PanelAnimation::Origin::TopRight : Ui::PanelAnimation::Origin::BottomRight)); auto inner = rect().marginsRemoved(st::emojiPanMargins); - _showAnimation->setFinalImage(std::move(image), QRect(inner.topLeft() * cIntRetinaFactor(), inner.size() * cIntRetinaFactor())); + _showAnimation->setFinalImage( + std::move(image), + QRect( + inner.topLeft() * style::DevicePixelRatio(), + inner.size() * style::DevicePixelRatio())); _showAnimation->setCornerMasks(Images::CornersMask(st::emojiPanRadius)); _showAnimation->start(); } @@ -386,9 +390,9 @@ QImage TabbedPanel::grabForAnimation() { Ui::SendPendingMoveResizeEvents(this); auto result = QImage( - size() * cIntRetinaFactor(), + size() * style::DevicePixelRatio(), QImage::Format_ARGB32_Premultiplied); - result.setDevicePixelRatio(cRetinaFactor()); + result.setDevicePixelRatio(style::DevicePixelRatio()); result.fill(Qt::transparent); if (_selector) { QPainter p(&result); diff --git a/Telegram/SourceFiles/chat_helpers/tabbed_selector.cpp b/Telegram/SourceFiles/chat_helpers/tabbed_selector.cpp index 5841f2c9e..aef9d7406 100644 --- a/Telegram/SourceFiles/chat_helpers/tabbed_selector.cpp +++ b/Telegram/SourceFiles/chat_helpers/tabbed_selector.cpp @@ -87,8 +87,8 @@ void TabbedSelector::SlideAnimation::setFinalImages(Direction direction, QImage Assert(!_rightImage.isNull()); _width = _leftImage.width(); _height = _rightImage.height(); - Assert(!(_width % cIntRetinaFactor())); - Assert(!(_height % cIntRetinaFactor())); + Assert(!(_width % style::DevicePixelRatio())); + Assert(!(_height % style::DevicePixelRatio())); Assert(_leftImage.devicePixelRatio() == _rightImage.devicePixelRatio()); Assert(_rightImage.width() == _width); Assert(_rightImage.height() == _height); @@ -97,19 +97,19 @@ void TabbedSelector::SlideAnimation::setFinalImages(Direction direction, QImage _innerTop = inner.y(); _innerWidth = inner.width(); _innerHeight = inner.height(); - Assert(!(_innerLeft % cIntRetinaFactor())); - Assert(!(_innerTop % cIntRetinaFactor())); - Assert(!(_innerWidth % cIntRetinaFactor())); - Assert(!(_innerHeight % cIntRetinaFactor())); + Assert(!(_innerLeft % style::DevicePixelRatio())); + Assert(!(_innerTop % style::DevicePixelRatio())); + Assert(!(_innerWidth % style::DevicePixelRatio())); + Assert(!(_innerHeight % style::DevicePixelRatio())); _innerRight = _innerLeft + _innerWidth; _innerBottom = _innerTop + _innerHeight; - _painterInnerLeft = _innerLeft / cIntRetinaFactor(); - _painterInnerTop = _innerTop / cIntRetinaFactor(); - _painterInnerRight = _innerRight / cIntRetinaFactor(); - _painterInnerBottom = _innerBottom / cIntRetinaFactor(); - _painterInnerWidth = _innerWidth / cIntRetinaFactor(); - _painterInnerHeight = _innerHeight / cIntRetinaFactor(); + _painterInnerLeft = _innerLeft / style::DevicePixelRatio(); + _painterInnerTop = _innerTop / style::DevicePixelRatio(); + _painterInnerRight = _innerRight / style::DevicePixelRatio(); + _painterInnerBottom = _innerBottom / style::DevicePixelRatio(); + _painterInnerWidth = _innerWidth / style::DevicePixelRatio(); + _painterInnerHeight = _innerHeight / style::DevicePixelRatio(); _painterCategoriesTop = _painterInnerBottom - st::defaultEmojiPan.footer; _wasSectionIcons = wasSectionIcons; @@ -148,10 +148,10 @@ void TabbedSelector::SlideAnimation::paintFrame( auto arrivingCoord = anim::interpolate(_innerWidth, 0, easeOut); auto departingCoord = anim::interpolate(0, _innerWidth, easeIn); - if (auto decrease = (arrivingCoord % cIntRetinaFactor())) { + if (auto decrease = (arrivingCoord % style::DevicePixelRatio())) { arrivingCoord -= decrease; } - if (auto decrease = (departingCoord % cIntRetinaFactor())) { + if (auto decrease = (departingCoord % style::DevicePixelRatio())) { departingCoord -= decrease; } auto arrivingAlpha = easeIn; @@ -165,7 +165,7 @@ void TabbedSelector::SlideAnimation::paintFrame( auto leftTo = _innerLeft + std::clamp(_innerWidth + leftCoord, 0, _innerWidth); auto rightFrom = _innerLeft + std::clamp(rightCoord, 0, _innerWidth); - auto painterRightFrom = rightFrom / cIntRetinaFactor(); + auto painterRightFrom = rightFrom / style::DevicePixelRatio(); if (opacity < 1.) { _frame.fill(Qt::transparent); } @@ -202,18 +202,18 @@ void TabbedSelector::SlideAnimation::paintFrame( outerRight += _shadow.extend.right(); outerBottom += _shadow.extend.bottom(); } - if (cIntRetinaFactor() > 1) { - if (auto skipLeft = (outerLeft % cIntRetinaFactor())) { + if (style::DevicePixelRatio() > 1) { + if (auto skipLeft = (outerLeft % style::DevicePixelRatio())) { outerLeft -= skipLeft; } - if (auto skipTop = (outerTop % cIntRetinaFactor())) { + if (auto skipTop = (outerTop % style::DevicePixelRatio())) { outerTop -= skipTop; } - if (auto skipRight = (outerRight % cIntRetinaFactor())) { - outerRight += (cIntRetinaFactor() - skipRight); + if (auto skipRight = (outerRight % style::DevicePixelRatio())) { + outerRight += (style::DevicePixelRatio() - skipRight); } - if (auto skipBottom = (outerBottom % cIntRetinaFactor())) { - outerBottom += (cIntRetinaFactor() - skipBottom); + if (auto skipBottom = (outerBottom % style::DevicePixelRatio())) { + outerBottom += (style::DevicePixelRatio() - skipBottom); } } @@ -262,7 +262,14 @@ void TabbedSelector::SlideAnimation::paintFrame( // frameInts += _frameIntsPerLineAdded; //} - p.drawImage(outerLeft / cIntRetinaFactor(), outerTop / cIntRetinaFactor(), _frame, outerLeft, outerTop, outerRight - outerLeft, outerBottom - outerTop); + p.drawImage( + outerLeft / style::DevicePixelRatio(), + outerTop / style::DevicePixelRatio(), + _frame, + outerLeft, + outerTop, + outerRight - outerLeft, + outerBottom - outerTop); } TabbedSelector::Tab::Tab( @@ -893,9 +900,9 @@ QImage TabbedSelector::grabForAnimation() { Ui::SendPendingMoveResizeEvents(this); auto result = QImage( - size() * cIntRetinaFactor(), + size() * style::DevicePixelRatio(), QImage::Format_ARGB32_Premultiplied); - result.setDevicePixelRatio(cRetinaFactor()); + result.setDevicePixelRatio(style::DevicePixelRatio()); result.fill(Qt::transparent); render(&result); @@ -1179,9 +1186,9 @@ void TabbedSelector::switchTab() { _slideAnimation = std::make_unique(); const auto slidingRect = QRect( 0, - _scroll->y() * cIntRetinaFactor(), - width() * cIntRetinaFactor(), - (height() - _scroll->y()) * cIntRetinaFactor()); + _scroll->y() * style::DevicePixelRatio(), + width() * style::DevicePixelRatio(), + (height() - _scroll->y()) * style::DevicePixelRatio()); _slideAnimation->setFinalImages( direction, std::move(wasCache), diff --git a/Telegram/SourceFiles/data/data_location.cpp b/Telegram/SourceFiles/data/data_location.cpp index c08c6688f..80727b3ba 100644 --- a/Telegram/SourceFiles/data/data_location.cpp +++ b/Telegram/SourceFiles/data/data_location.cpp @@ -62,7 +62,7 @@ size_t LocationPoint::hash() const { } GeoPointLocation ComputeLocation(const LocationPoint &point) { - const auto scale = 1 + (cScale() * cIntRetinaFactor()) / 200; + const auto scale = 1 + (cScale() * style::DevicePixelRatio()) / 200; const auto zoom = 13 + (scale - 1); const auto w = st::locationSize.width() / scale; const auto h = st::locationSize.height() / scale; diff --git a/Telegram/SourceFiles/dialogs/dialogs_widget.cpp b/Telegram/SourceFiles/dialogs/dialogs_widget.cpp index 6d85f7cef..8ac5c91b3 100644 --- a/Telegram/SourceFiles/dialogs/dialogs_widget.cpp +++ b/Telegram/SourceFiles/dialogs/dialogs_widget.cpp @@ -1479,9 +1479,9 @@ void Widget::startWidthAnimation() { _inner->setNarrowRatio(0.); Ui::SendPendingMoveResizeEvents(_scroll); auto image = QImage( - grabGeometry.size() * cIntRetinaFactor(), + grabGeometry.size() * style::DevicePixelRatio(), QImage::Format_ARGB32_Premultiplied); - image.setDevicePixelRatio(cRetinaFactor()); + image.setDevicePixelRatio(style::DevicePixelRatio()); image.fill(Qt::transparent); { QPainter p(&image); @@ -3097,7 +3097,8 @@ void Widget::paintEvent(QPaintEvent *e) { auto belowTop = _scroll->y() + _scroll->height(); if (!_widthAnimationCache.isNull()) { p.drawPixmapLeft(0, _scroll->y(), width(), _widthAnimationCache); - belowTop = _scroll->y() + (_widthAnimationCache.height() / cIntRetinaFactor()); + belowTop = _scroll->y() + + (_widthAnimationCache.height() / style::DevicePixelRatio()); } auto below = QRect(0, belowTop, width(), height() - belowTop); diff --git a/Telegram/SourceFiles/dialogs/ui/dialogs_video_userpic.cpp b/Telegram/SourceFiles/dialogs/ui/dialogs_video_userpic.cpp index bfc056243..188d512e8 100644 --- a/Telegram/SourceFiles/dialogs/ui/dialogs_video_userpic.cpp +++ b/Telegram/SourceFiles/dialogs/ui/dialogs_video_userpic.cpp @@ -99,7 +99,7 @@ Media::Clip::FrameRequest VideoUserpic::request(int size) const { return { .frame = { size, size }, .outer = { size, size }, - .factor = cIntRetinaFactor(), + .factor = style::DevicePixelRatio(), .radius = ImageRoundRadius::Ellipse, }; } diff --git a/Telegram/SourceFiles/editor/photo_editor_controls.cpp b/Telegram/SourceFiles/editor/photo_editor_controls.cpp index ae0f3355d..72a433865 100644 --- a/Telegram/SourceFiles/editor/photo_editor_controls.cpp +++ b/Telegram/SourceFiles/editor/photo_editor_controls.cpp @@ -87,9 +87,9 @@ void EdgeButton::init() { QImage EdgeButton::rounded(std::optional color) const { auto result = QImage( - _rippleRect.size() * cIntRetinaFactor(), + _rippleRect.size() * style::DevicePixelRatio(), QImage::Format_ARGB32_Premultiplied); - result.setDevicePixelRatio(cIntRetinaFactor()); + result.setDevicePixelRatio(style::DevicePixelRatio()); result.fill(color.value_or(Qt::white)); const auto parts = RectPart::None @@ -170,9 +170,9 @@ ButtonBar::ButtonBar( } auto result = QImage( - size * cIntRetinaFactor(), + size * style::DevicePixelRatio(), QImage::Format_ARGB32_Premultiplied); - result.setDevicePixelRatio(cIntRetinaFactor()); + result.setDevicePixelRatio(style::DevicePixelRatio()); result.fill(bg->c); _roundedBg = Images::Round( diff --git a/Telegram/SourceFiles/editor/scene/scene_item_sticker.cpp b/Telegram/SourceFiles/editor/scene/scene_item_sticker.cpp index c678452e9..2cf42d10c 100644 --- a/Telegram/SourceFiles/editor/scene/scene_item_sticker.cpp +++ b/Telegram/SourceFiles/editor/scene/scene_item_sticker.cpp @@ -43,7 +43,7 @@ ItemSticker::ItemSticker( _mediaView.get(), ChatHelpers::StickerLottieSize::MessageHistory, QSize(kStickerSideSize, kStickerSideSize) - * cIntRetinaFactor(), + * style::DevicePixelRatio(), Lottie::Quality::High); _lottie.player->updates( ) | rpl::start_with_next([=] { diff --git a/Telegram/SourceFiles/history/view/history_view_group_call_bar.cpp b/Telegram/SourceFiles/history/view/history_view_group_call_bar.cpp index 7fc19532a..0b978acb3 100644 --- a/Telegram/SourceFiles/history/view/history_view_group_call_bar.cpp +++ b/Telegram/SourceFiles/history/view/history_view_group_call_bar.cpp @@ -38,13 +38,13 @@ void GenerateUserpicsInRow( const auto single = st.size; const auto shift = st.shift; const auto width = single + (limit - 1) * (single - shift); - if (result.width() != width * cIntRetinaFactor()) { + if (result.width() != width * style::DevicePixelRatio()) { result = QImage( - QSize(width, single) * cIntRetinaFactor(), + QSize(width, single) * style::DevicePixelRatio(), QImage::Format_ARGB32_Premultiplied); } result.fill(Qt::transparent); - result.setDevicePixelRatio(cRetinaFactor()); + result.setDevicePixelRatio(style::DevicePixelRatio()); auto q = Painter(&result); auto hq = PainterHighQualityEnabler(q); diff --git a/Telegram/SourceFiles/history/view/history_view_pinned_bar.cpp b/Telegram/SourceFiles/history/view/history_view_pinned_bar.cpp index 2b82db6f2..d530e4779 100644 --- a/Telegram/SourceFiles/history/view/history_view_pinned_bar.cpp +++ b/Telegram/SourceFiles/history/view/history_view_pinned_bar.cpp @@ -44,12 +44,13 @@ namespace { auto result = ContentWithoutPreview(item, repaint); if (!preview) { static const auto kEmpty = [&] { - const auto size = st::historyReplyHeight * cIntRetinaFactor(); + const auto size = st::historyReplyHeight + * style::DevicePixelRatio(); auto result = QImage( QSize(size, size), QImage::Format_ARGB32_Premultiplied); result.fill(Qt::transparent); - result.setDevicePixelRatio(cRetinaFactor()); + result.setDevicePixelRatio(style::DevicePixelRatio()); return result; }(); result.preview = kEmpty; diff --git a/Telegram/SourceFiles/history/view/history_view_service_message.cpp b/Telegram/SourceFiles/history/view/history_view_service_message.cpp index acd5929f6..ee07aa326 100644 --- a/Telegram/SourceFiles/history/view/history_view_service_message.cpp +++ b/Telegram/SourceFiles/history/view/history_view_service_message.cpp @@ -73,14 +73,14 @@ int PaintBubbleSide( if (style == SideStyle::Rounded) { const auto &corners = st->serviceBgCornersNormal(); const auto left = corners.p[(side == CornerTop) ? 0 : 2]; - const auto leftWidth = left.width() / cIntRetinaFactor(); + const auto leftWidth = left.width() / style::DevicePixelRatio(); p.drawPixmap(x, y, left); const auto right = corners.p[(side == CornerTop) ? 1 : 3]; - const auto rightWidth = right.width() / cIntRetinaFactor(); + const auto rightWidth = right.width() / style::DevicePixelRatio(); p.drawPixmap(x + width - rightWidth, y, right); - const auto cornerHeight = left.height() / cIntRetinaFactor(); + const auto cornerHeight = left.height() / style::DevicePixelRatio(); p.fillRect( x + leftWidth, y, @@ -92,7 +92,7 @@ int PaintBubbleSide( // CornerLeft and CornerRight are inverted in the top part. const auto &corners = st->serviceBgCornersInverted(); const auto left = corners.p[(side == CornerTop) ? 1 : 2]; - const auto leftWidth = left.width() / cIntRetinaFactor(); + const auto leftWidth = left.width() / style::DevicePixelRatio(); p.drawPixmap(x - leftWidth, y, left); const auto right = corners.p[(side == CornerTop) ? 0 : 3]; diff --git a/Telegram/SourceFiles/history/view/media/history_view_gif.cpp b/Telegram/SourceFiles/history/view/media/history_view_gif.cpp index 9b5ff9e12..bda09fe8d 100644 --- a/Telegram/SourceFiles/history/view/media/history_view_gif.cpp +++ b/Telegram/SourceFiles/history/view/media/history_view_gif.cpp @@ -536,7 +536,7 @@ void Gif::draw(Painter &p, const PaintContext &context) const { if (streamed && !skipDrawingContent && !fullHiddenBySpoiler) { auto paused = context.paused; auto request = ::Media::Streaming::FrameRequest{ - .outer = QSize(usew, painth) * cIntRetinaFactor(), + .outer = QSize(usew, painth) * style::DevicePixelRatio(), .blurredBackground = true, }; if (isRound) { @@ -1384,8 +1384,8 @@ void Gif::drawGrouped( { originalWidth, originalHeight }, { geometry.width(), geometry.height() }); auto request = ::Media::Streaming::FrameRequest{ - .resize = pixSize * cIntRetinaFactor(), - .outer = geometry.size() * cIntRetinaFactor(), + .resize = pixSize * style::DevicePixelRatio(), + .outer = geometry.size() * style::DevicePixelRatio(), .rounding = MediaRoundingMask(rounding), }; if (activeOwnPlaying->instance.playerLocked()) { diff --git a/Telegram/SourceFiles/history/view/media/history_view_large_emoji.cpp b/Telegram/SourceFiles/history/view/media/history_view_large_emoji.cpp index 320f6e22c..0f77af125 100644 --- a/Telegram/SourceFiles/history/view/media/history_view_large_emoji.cpp +++ b/Telegram/SourceFiles/history/view/media/history_view_large_emoji.cpp @@ -75,7 +75,7 @@ QSize LargeEmoji::countOptimalSize() { const auto count = _images.size() - ranges::count(_images, LargeEmojiMedia()); - const auto single = LargeEmojiImage::Size() / cIntRetinaFactor(); + const auto single = LargeEmojiImage::Size() / style::DevicePixelRatio(); const auto skip = st::largeEmojiSkip - 2 * st::largeEmojiOutline; const auto inner = count * single.width() + (count - 1) * skip; const auto &padding = st::largeEmojiPadding; @@ -95,7 +95,7 @@ void LargeEmoji::draw( auto x = r.x() + (r.width() - _size.width()) / 2 + padding.left(); const auto y = r.y() + (r.height() - _size.height()) / 2 + padding.top(); const auto skip = st::largeEmojiSkip - 2 * st::largeEmojiOutline; - const auto size = LargeEmojiImage::Size() / cIntRetinaFactor(); + const auto size = LargeEmojiImage::Size() / style::DevicePixelRatio(); const auto selected = context.selected(); if (!selected) { _selectedFrame = QImage(); diff --git a/Telegram/SourceFiles/history/view/media/history_view_sticker.cpp b/Telegram/SourceFiles/history/view/media/history_view_sticker.cpp index 6f182e171..cefaad0c2 100644 --- a/Telegram/SourceFiles/history/view/media/history_view_sticker.cpp +++ b/Telegram/SourceFiles/history/view/media/history_view_sticker.cpp @@ -276,7 +276,7 @@ void Sticker::paintAnimationFrame( base::duplicate(image), context.st->msgStickerOverlay()->c) : image; - const auto size = prepared.size() / cIntRetinaFactor(); + const auto size = prepared.size() / style::DevicePixelRatio(); p.drawImage( QRect( QPoint( diff --git a/Telegram/SourceFiles/history/view/media/history_view_theme_document.cpp b/Telegram/SourceFiles/history/view/media/history_view_theme_document.cpp index 96bd885f3..ef72e8f08 100644 --- a/Telegram/SourceFiles/history/view/media/history_view_theme_document.cpp +++ b/Telegram/SourceFiles/history/view/media/history_view_theme_document.cpp @@ -352,7 +352,7 @@ QImage ThemeDocument::finishServiceThumbnail(QImage image) const { if (!_serviceWidth) { return image; } else if (_isDark && _dimmingIntensity > 0) { - image.setDevicePixelRatio(cIntRetinaFactor()); + image.setDevicePixelRatio(style::DevicePixelRatio()); auto p = QPainter(&image); const auto alpha = 255 * _dimmingIntensity / 100; p.fillRect(0, 0, _pixw, _pixh, QColor(0, 0, 0, alpha)); @@ -366,13 +366,13 @@ QImage ThemeDocument::finishServiceThumbnail(QImage image) const { void ThemeDocument::generateThumbnail() const { auto image = Ui::GenerateBackgroundImage( - QSize(_pixw, _pixh) * cIntRetinaFactor(), + QSize(_pixw, _pixh) * style::DevicePixelRatio(), _background, _gradientRotation, _patternOpacity); _thumbnail = Ui::PixmapFromImage( finishServiceThumbnail(std::move(image))); - _thumbnail.setDevicePixelRatio(cRetinaFactor()); + _thumbnail.setDevicePixelRatio(style::DevicePixelRatio()); _thumbnailGood = 1; } diff --git a/Telegram/SourceFiles/inline_bots/inline_bot_layout_internal.cpp b/Telegram/SourceFiles/inline_bots/inline_bot_layout_internal.cpp index e8b6181fb..616280a7e 100644 --- a/Telegram/SourceFiles/inline_bots/inline_bot_layout_internal.cpp +++ b/Telegram/SourceFiles/inline_bots/inline_bot_layout_internal.cpp @@ -330,7 +330,7 @@ void Gif::validateThumbnail( bool good) const { if (!image || (_thumbGood && !good)) { return; - } else if ((_thumb.size() == size * cIntRetinaFactor()) + } else if ((_thumb.size() == size * style::DevicePixelRatio()) && (_thumbGood || !good)) { return; } @@ -503,7 +503,7 @@ void Sticker::paint(Painter &p, const QRect &clip, const PaintContext *context) prepareThumbnail(); if (_lottie && _lottie->ready()) { const auto frame = _lottie->frame(); - const auto size = frame.size() / cIntRetinaFactor(); + const auto size = frame.size() / style::DevicePixelRatio(); const auto pos = QPoint( (st::stickerPanSize.width() - size.width()) / 2, (st::stickerPanSize.height() - size.height()) / 2); @@ -524,8 +524,11 @@ void Sticker::paint(Painter &p, const QRect &clip, const PaintContext *context) (st::stickerPanSize.height() - size.width()) / 2, frame); } else if (!_thumb.isNull()) { - int w = _thumb.width() / cIntRetinaFactor(), h = _thumb.height() / cIntRetinaFactor(); - QPoint pos = QPoint((st::stickerPanSize.width() - w) / 2, (st::stickerPanSize.height() - h) / 2); + const auto w = _thumb.width() / style::DevicePixelRatio(); + const auto h = _thumb.height() / style::DevicePixelRatio(); + const auto pos = QPoint( + (st::stickerPanSize.width() - w) / 2, + (st::stickerPanSize.height() - h) / 2); p.drawPixmap(pos, _thumb); } else if (context->pathGradient) { const auto thumbSize = getThumbSize(); @@ -583,7 +586,7 @@ void Sticker::setupLottie() const { _lottie = ChatHelpers::LottiePlayerFromDocument( _dataMedia.get(), ChatHelpers::StickerLottieSize::InlineResults, - boundingBox() * cIntRetinaFactor()); + boundingBox() * style::DevicePixelRatio()); _lottie->updates( ) | rpl::start_with_next([=] { @@ -736,7 +739,7 @@ void Photo::validateThumbnail( bool good) const { if (!image || (_thumbGood && !good)) { return; - } else if ((_thumb.size() == size * cIntRetinaFactor()) + } else if ((_thumb.size() == size * style::DevicePixelRatio()) && (_thumbGood || !good)) { return; } @@ -893,7 +896,7 @@ void Video::prepareThumbnail(QSize size) const { if (!thumb) { return; } - if (_thumb.size() != size * cIntRetinaFactor()) { + if (_thumb.size() != size * style::DevicePixelRatio()) { const auto width = size.width(); const auto height = size.height(); auto w = qMax(style::ConvertScale(thumb->width()), 1); @@ -1225,7 +1228,8 @@ TextState Contact::getState( void Contact::prepareThumbnail(int width, int height) const { if (!hasResultThumb()) { - if (_thumb.width() != width * cIntRetinaFactor() || _thumb.height() != height * cIntRetinaFactor()) { + if ((_thumb.width() != width * style::DevicePixelRatio()) + || (_thumb.height() != height * style::DevicePixelRatio())) { _thumb = getResultContactAvatar(width, height); } return; @@ -1234,8 +1238,8 @@ void Contact::prepareThumbnail(int width, int height) const { const auto origin = fileOrigin(); const auto thumb = getResultThumb(origin); if (!thumb - || ((_thumb.width() == width * cIntRetinaFactor()) - && (_thumb.height() == height * cIntRetinaFactor()))) { + || ((_thumb.width() == width * style::DevicePixelRatio()) + && (_thumb.height() == height * style::DevicePixelRatio()))) { return; } auto w = qMax(style::ConvertScale(thumb->width()), 1); @@ -1383,7 +1387,8 @@ TextState Article::getState( void Article::prepareThumbnail(int width, int height) const { if (!hasResultThumb()) { - if (_thumb.width() != width * cIntRetinaFactor() || _thumb.height() != height * cIntRetinaFactor()) { + if ((_thumb.width() != width * style::DevicePixelRatio()) + || (_thumb.height() != height * style::DevicePixelRatio())) { _thumb = getResultContactAvatar(width, height); } return; @@ -1392,8 +1397,8 @@ void Article::prepareThumbnail(int width, int height) const { const auto origin = fileOrigin(); const auto thumb = getResultThumb(origin); if (!thumb - || ((_thumb.width() == width * cIntRetinaFactor()) - && (_thumb.height() == height * cIntRetinaFactor()))) { + || ((_thumb.width() == width * style::DevicePixelRatio()) + && (_thumb.height() == height * style::DevicePixelRatio()))) { return; } auto w = qMax(style::ConvertScale(thumb->width()), 1); @@ -1609,7 +1614,7 @@ void Game::ensureDataMediaCreated(not_null photo) const { void Game::validateThumbnail(Image *image, QSize size, bool good) const { if (!image || (_thumbGood && !good)) { return; - } else if ((_thumb.size() == size * cIntRetinaFactor()) + } else if ((_thumb.size() == size * style::DevicePixelRatio()) && (_thumbGood || !good)) { return; } diff --git a/Telegram/SourceFiles/inline_bots/inline_bot_layout_item.cpp b/Telegram/SourceFiles/inline_bots/inline_bot_layout_item.cpp index 2f5242e85..34acc4093 100644 --- a/Telegram/SourceFiles/inline_bots/inline_bot_layout_item.cpp +++ b/Telegram/SourceFiles/inline_bots/inline_bot_layout_item.cpp @@ -165,9 +165,9 @@ QPixmap ItemBase::getResultContactAvatar(int width, int height) const { BareId(qHash(_result->_id)))), _result->getLayoutTitle() ).generate(width); - if (result.height() != height * cIntRetinaFactor()) { + if (result.height() != height * style::DevicePixelRatio()) { result = result.scaled( - QSize(width, height) * cIntRetinaFactor(), + QSize(width, height) * style::DevicePixelRatio(), Qt::IgnoreAspectRatio, Qt::SmoothTransformation); } diff --git a/Telegram/SourceFiles/inline_bots/inline_bot_result.cpp b/Telegram/SourceFiles/inline_bots/inline_bot_result.cpp index 5931c22c4..612d35769 100644 --- a/Telegram/SourceFiles/inline_bots/inline_bot_result.cpp +++ b/Telegram/SourceFiles/inline_bots/inline_bot_result.cpp @@ -284,7 +284,7 @@ std::unique_ptr Result::Create( }); if (const auto point = result->getLocationPoint()) { - const auto scale = 1 + (cScale() * cIntRetinaFactor()) / 200; + const auto scale = 1 + (cScale() * style::DevicePixelRatio()) / 200; const auto zoom = 15 + (scale - 1); const auto w = st::inlineThumbSize / scale; const auto h = st::inlineThumbSize / scale; diff --git a/Telegram/SourceFiles/inline_bots/inline_results_widget.cpp b/Telegram/SourceFiles/inline_bots/inline_results_widget.cpp index 3808ed989..c6e4b3380 100644 --- a/Telegram/SourceFiles/inline_bots/inline_results_widget.cpp +++ b/Telegram/SourceFiles/inline_bots/inline_results_widget.cpp @@ -236,7 +236,11 @@ void Widget::startShowAnimation() { _showAnimation = std::make_unique(st::emojiPanAnimation, Ui::PanelAnimation::Origin::BottomLeft); auto inner = rect().marginsRemoved(st::emojiPanMargins); - _showAnimation->setFinalImage(std::move(image), QRect(inner.topLeft() * cIntRetinaFactor(), inner.size() * cIntRetinaFactor())); + _showAnimation->setFinalImage( + std::move(image), + QRect( + inner.topLeft() * style::DevicePixelRatio(), + inner.size() * style::DevicePixelRatio())); _showAnimation->setCornerMasks(Images::CornersMask(ImageRoundRadius::Small)); _showAnimation->start(); } @@ -246,8 +250,10 @@ void Widget::startShowAnimation() { QImage Widget::grabForPanelAnimation() { Ui::SendPendingMoveResizeEvents(this); - auto result = QImage(size() * cIntRetinaFactor(), QImage::Format_ARGB32_Premultiplied); - result.setDevicePixelRatio(cRetinaFactor()); + auto result = QImage( + size() * style::DevicePixelRatio(), + QImage::Format_ARGB32_Premultiplied); + result.setDevicePixelRatio(style::DevicePixelRatio()); result.fill(Qt::transparent); _inPanelGrab = true; render(&result); diff --git a/Telegram/SourceFiles/intro/intro_qr.cpp b/Telegram/SourceFiles/intro/intro_qr.cpp index 3ad8aead8..a76f7539d 100644 --- a/Telegram/SourceFiles/intro/intro_qr.cpp +++ b/Telegram/SourceFiles/intro/intro_qr.cpp @@ -119,7 +119,7 @@ namespace { 1, st::introQrPixel); const auto size = has - ? (state->qr.size() / cIntRetinaFactor()) + ? (state->qr.size() / style::DevicePixelRatio()) : QSize(usualSize * pixel, usualSize * pixel); const auto qr = QRect( (result->width() - size.width()) / 2, diff --git a/Telegram/SourceFiles/intro/intro_step.cpp b/Telegram/SourceFiles/intro/intro_step.cpp index 6c8a18227..9c408f412 100644 --- a/Telegram/SourceFiles/intro/intro_step.cpp +++ b/Telegram/SourceFiles/intro/intro_step.cpp @@ -383,10 +383,20 @@ void Step::hideDescription() { void Step::paintContentSnapshot(QPainter &p, const QPixmap &snapshot, float64 alpha, float64 howMuchHidden) { if (!snapshot.isNull()) { - auto contentTop = anim::interpolate(height() - (snapshot.height() / cIntRetinaFactor()), height(), howMuchHidden); + const auto contentTop = anim::interpolate( + height() - (snapshot.height() / style::DevicePixelRatio()), + height(), + howMuchHidden); if (contentTop < height()) { p.setOpacity(alpha); - p.drawPixmap(QPoint(contentLeft(), contentTop), snapshot, QRect(0, 0, snapshot.width(), (height() - contentTop) * cIntRetinaFactor())); + p.drawPixmap( + QPoint(contentLeft(), contentTop), + snapshot, + QRect( + 0, + 0, + snapshot.width(), + (height() - contentTop) * style::DevicePixelRatio())); } } } @@ -394,8 +404,8 @@ void Step::paintContentSnapshot(QPainter &p, const QPixmap &snapshot, float64 al void Step::prepareCoverMask() { if (!_coverMask.isNull()) return; - auto maskWidth = cIntRetinaFactor(); - auto maskHeight = st::introCoverHeight * cIntRetinaFactor(); + auto maskWidth = style::DevicePixelRatio(); + auto maskHeight = st::introCoverHeight * style::DevicePixelRatio(); auto mask = QImage(maskWidth, maskHeight, QImage::Format_ARGB32_Premultiplied); auto maskInts = reinterpret_cast(mask.bits()); Assert(mask.depth() == (sizeof(uint32) << 3)); @@ -416,7 +426,14 @@ void Step::prepareCoverMask() { void Step::paintCover(QPainter &p, int top) { auto coverHeight = top + st::introCoverHeight; if (coverHeight > 0) { - p.drawPixmap(QRect(0, 0, width(), coverHeight), _coverMask, QRect(0, -top * cIntRetinaFactor(), _coverMask.width(), coverHeight * cIntRetinaFactor())); + p.drawPixmap( + QRect(0, 0, width(), coverHeight), + _coverMask, + QRect( + 0, + -top * style::DevicePixelRatio(), + _coverMask.width(), + coverHeight * style::DevicePixelRatio())); } auto left = 0; diff --git a/Telegram/SourceFiles/media/view/media_view_group_thumbs.cpp b/Telegram/SourceFiles/media/view/media_view_group_thumbs.cpp index 6568df3b0..2aff46067 100644 --- a/Telegram/SourceFiles/media/view/media_view_group_thumbs.cpp +++ b/Telegram/SourceFiles/media/view/media_view_group_thumbs.cpp @@ -289,15 +289,15 @@ void GroupThumbs::Thumb::validateImage() { const auto takeWidth = originalWidth * st::mediaviewGroupWidthMax / pixSize.width(); auto original = _image->original(); - original.setDevicePixelRatio(cRetinaFactor()); + original.setDevicePixelRatio(style::DevicePixelRatio()); _full = Ui::PixmapFromImage(original.copy( (originalWidth - takeWidth) / 2, 0, takeWidth, originalHeight ).scaled( - st::mediaviewGroupWidthMax * cIntRetinaFactor(), - pixSize.height() * cIntRetinaFactor(), + st::mediaviewGroupWidthMax * style::DevicePixelRatio(), + pixSize.height() * style::DevicePixelRatio(), Qt::IgnoreAspectRatio, Qt::SmoothTransformation)); } else { @@ -428,7 +428,7 @@ void GroupThumbs::Thumb::paint( if (width == _fullWidth) { p.drawPixmap(left, y, _full); } else { - const auto takeWidth = width * cIntRetinaFactor(); + const auto takeWidth = width * style::DevicePixelRatio(); const auto from = QRect( (_full.width() - takeWidth) / 2, 0, diff --git a/Telegram/SourceFiles/media/view/media_view_overlay_widget.cpp b/Telegram/SourceFiles/media/view/media_view_overlay_widget.cpp index b4965fe6f..b1a1539ec 100644 --- a/Telegram/SourceFiles/media/view/media_view_overlay_widget.cpp +++ b/Telegram/SourceFiles/media/view/media_view_overlay_widget.cpp @@ -443,9 +443,9 @@ OverlayWidget::OverlayWidget() }); _docRectImage = QImage( - st::mediaviewFileSize * cIntRetinaFactor(), + st::mediaviewFileSize * style::DevicePixelRatio(), QImage::Format_ARGB32_Premultiplied); - _docRectImage.setDevicePixelRatio(cIntRetinaFactor()); + _docRectImage.setDevicePixelRatio(style::DevicePixelRatio()); Shortcuts::Requests( ) | rpl::start_with_next([=](not_null request) { @@ -1129,7 +1129,7 @@ void OverlayWidget::setStaticContent(QImage image) { && image.format() != QImage::Format_RGB32) { image = std::move(image).convertToFormat(kGood); } - image.setDevicePixelRatio(cRetinaFactor()); + image.setDevicePixelRatio(style::DevicePixelRatio()); _staticContent = std::move(image); _staticContentTransparent = IsSemitransparent(_staticContent); } @@ -4496,7 +4496,7 @@ void OverlayWidget::validatePhotoImage(Image *image, bool blurred) { return; } const auto use = flipSizeByRotation({ _width, _height }) - * cIntRetinaFactor(); + * style::DevicePixelRatio(); setStaticContent(image->pixNoCache( use, { .options = (blurred ? Images::Option::Blur : Images::Option()) } @@ -4833,7 +4833,7 @@ void OverlayWidget::paintDocumentBubbleContent( } } } else if (const auto thumbnail = _documentMedia->thumbnail()) { - int32 rf(cIntRetinaFactor()); + int32 rf(style::DevicePixelRatio()); p.drawPixmap(icon.topLeft(), thumbnail->pix(_docThumbw), QRect(_docThumbx * rf, _docThumby * rf, st::mediaviewFileIconSize * rf, st::mediaviewFileIconSize * rf)); } } diff --git a/Telegram/SourceFiles/media/view/media_view_pip_opengl.cpp b/Telegram/SourceFiles/media/view/media_view_pip_opengl.cpp index 8fa5f1d13..8e4e8e7c2 100644 --- a/Telegram/SourceFiles/media/view/media_view_pip_opengl.cpp +++ b/Telegram/SourceFiles/media/view/media_view_pip_opengl.cpp @@ -251,9 +251,9 @@ void Pip::RendererGL::createShadowTexture() { const auto size = 2 * st::callShadow.topLeft.size() + QSize(st::roundRadiusLarge, st::roundRadiusLarge); auto image = QImage( - size * cIntRetinaFactor(), + size * style::DevicePixelRatio(), QImage::Format_ARGB32_Premultiplied); - image.setDevicePixelRatio(cRetinaFactor()); + image.setDevicePixelRatio(style::DevicePixelRatio()); image.fill(Qt::transparent); { auto p = QPainter(&image); @@ -433,7 +433,7 @@ void Pip::RendererGL::paintTransformedContent( _f->glActiveTexture(rgbaFrame ? GL_TEXTURE1 : GL_TEXTURE3); _shadowImage.bind(*_f); - const auto globalFactor = cIntRetinaFactor(); + const auto globalFactor = style::DevicePixelRatio(); const auto fadeAlpha = st::radialBg->c.alphaF() * geometry.fade; const auto roundRect = transformRect(RoundingRect(geometry)); program->setUniformValue("roundRect", Uniform(roundRect)); diff --git a/Telegram/SourceFiles/overview/overview_layout.cpp b/Telegram/SourceFiles/overview/overview_layout.cpp index a7eee4c19..69fc9f292 100644 --- a/Telegram/SourceFiles/overview/overview_layout.cpp +++ b/Telegram/SourceFiles/overview/overview_layout.cpp @@ -365,7 +365,8 @@ int32 Photo::resizeGetHeight(int32 width) { void Photo::paint(Painter &p, const QRect &clip, TextSelection selection, const PaintContext *context) { const auto selected = (selection == FullSelection); - const auto widthChanged = _pix.width() != _width * cIntRetinaFactor(); + const auto widthChanged = (_pix.width() + != (_width * style::DevicePixelRatio())); if (!_goodLoaded || widthChanged) { ensureDataMediaCreated(); const auto good = !_spoiler @@ -515,7 +516,7 @@ void Video::paint(Painter &p, const QRect &clip, TextSelection selection, const const auto radialOpacity = radial ? _radial->opacity() : 0.; if ((blurred || thumbnail || good) - && ((_pix.width() != _width * cIntRetinaFactor()) + && ((_pix.width() != _width * style::DevicePixelRatio()) || (_pixBlurred && (thumbnail || good)))) { auto img = good ? good->original() @@ -1847,7 +1848,7 @@ void Link::validateThumbnail() { delegate()->unregisterHeavyItem(this); } else { const auto size = QSize(st::linksPhotoSize, st::linksPhotoSize); - _thumbnail = QPixmap(size * cIntRetinaFactor()); + _thumbnail = QPixmap(size * style::DevicePixelRatio()); _thumbnail.fill(Qt::transparent); auto p = Painter(&_thumbnail); const auto index = _letter.isEmpty() @@ -2061,7 +2062,7 @@ void Gif::validateThumbnail( bool good) { if (!image || (_thumbGood && !good)) { return; - } else if ((_thumb.size() == size * cIntRetinaFactor()) + } else if ((_thumb.size() == size * style::DevicePixelRatio()) && (_thumbGood || !good)) { return; } diff --git a/Telegram/SourceFiles/payments/payments_form.cpp b/Telegram/SourceFiles/payments/payments_form.cpp index 9ca9bc668..d39b17737 100644 --- a/Telegram/SourceFiles/payments/payments_form.cpp +++ b/Telegram/SourceFiles/payments/payments_form.cpp @@ -294,15 +294,15 @@ QImage Form::prepareThumbnail( Qt::KeepAspectRatio, Qt::SmoothTransformation); result = Images::Round(std::move(result), ImageRoundRadius::Large); - result.setDevicePixelRatio(cRetinaFactor()); + result.setDevicePixelRatio(style::DevicePixelRatio()); return result; } QImage Form::prepareEmptyThumbnail() const { auto result = QImage( - st::paymentsThumbnailSize * cIntRetinaFactor(), + st::paymentsThumbnailSize * style::DevicePixelRatio(), QImage::Format_ARGB32_Premultiplied); - result.setDevicePixelRatio(cRetinaFactor()); + result.setDevicePixelRatio(style::DevicePixelRatio()); result.fill(Qt::transparent); return result; } diff --git a/Telegram/SourceFiles/platform/mac/specific_mac_p.mm b/Telegram/SourceFiles/platform/mac/specific_mac_p.mm index 5ec2ed4a0..48c0cdab0 100644 --- a/Telegram/SourceFiles/platform/mac/specific_mac_p.mm +++ b/Telegram/SourceFiles/platform/mac/specific_mac_p.mm @@ -267,7 +267,7 @@ void SetApplicationIcon(const QIcon &icon) { NSImage *image = nil; if (!icon.isNull()) { auto pixmap = icon.pixmap(1024, 1024); - pixmap.setDevicePixelRatio(cRetinaFactor()); + pixmap.setDevicePixelRatio(style::DevicePixelRatio()); image = Q2NSImage(pixmap.toImage()); } [[NSApplication sharedApplication] setApplicationIconImage:image]; diff --git a/Telegram/SourceFiles/platform/mac/touchbar/items/mac_pinned_chats_item.mm b/Telegram/SourceFiles/platform/mac/touchbar/items/mac_pinned_chats_item.mm index 3c6bfd25e..477075719 100644 --- a/Telegram/SourceFiles/platform/mac/touchbar/items/mac_pinned_chats_item.mm +++ b/Telegram/SourceFiles/platform/mac/touchbar/items/mac_pinned_chats_item.mm @@ -57,7 +57,7 @@ inline bool IsRepliesPeer(PeerData *peer) { } QImage PrepareImage() { - const auto s = kCircleDiameter * cIntRetinaFactor(); + const auto s = kCircleDiameter * style::DevicePixelRatio(); auto result = QImage(QSize(s, s), QImage::Format_ARGB32_Premultiplied); result.fill(Qt::transparent); return result; @@ -102,15 +102,15 @@ QImage UnreadBadge(not_null peer) { unreadSt.sizeId = Ui::UnreadBadgeSize::TouchBar; unreadSt.muted = state.unreadMuted; // Use constant values to draw badge regardless of cConfigScale(). - unreadSt.size = kUnreadBadgeSize * cRetinaFactor(); - unreadSt.padding = 4 * cRetinaFactor(); + unreadSt.size = kUnreadBadgeSize * float64(style::DevicePixelRatio()); + unreadSt.padding = 4 * float64(style::DevicePixelRatio()); unreadSt.font = style::font( - 9.5 * cRetinaFactor(), + 9.5 * float64(style::DevicePixelRatio()), unreadSt.font->flags(), unreadSt.font->family()); auto result = QImage( - QSize(kCircleDiameter, kUnreadBadgeSize) * cIntRetinaFactor(), + QSize(kCircleDiameter, kUnreadBadgeSize) * style::DevicePixelRatio(), QImage::Format_ARGB32_Premultiplied); result.fill(Qt::transparent); Painter p(&result); @@ -516,7 +516,7 @@ NSRect PeerRectByIndex(int index) { Painter p(&userpic); pin->peer->paintUserpic(p, pin->userpicView, 0, 0, userpic.width()); - userpic.setDevicePixelRatio(cRetinaFactor()); + userpic.setDevicePixelRatio(style::DevicePixelRatio()); pin->userpic = std::move(userpic); const auto userpicIndex = pin->index + [self shift]; [self setNeedsDisplayInRect:PeerRectByIndex(userpicIndex)]; @@ -816,12 +816,14 @@ NSRect PeerRectByIndex(int index) { const auto rectRight = NSMaxX(rect); if (!pin->unreadBadge.isNull()) { CGImageRef image = pin->unreadBadge.toCGImage(); - const auto w = CGImageGetWidth(image) / cRetinaFactor(); + const auto w = CGImageGetWidth(image) + / float64(style::DevicePixelRatio()); const auto borderRect = CGRectMake( rectRight - w, 0, w, - CGImageGetHeight(image) / cRetinaFactor()); + CGImageGetHeight(image) + / float64(style::DevicePixelRatio())); CGContextDrawImage(context, borderRect, image); CGImageRelease(image); return; diff --git a/Telegram/SourceFiles/platform/mac/touchbar/items/mac_scrubber_item.mm b/Telegram/SourceFiles/platform/mac/touchbar/items/mac_scrubber_item.mm index 7ec68e337..ac97db92d 100644 --- a/Telegram/SourceFiles/platform/mac/touchbar/items/mac_scrubber_item.mm +++ b/Telegram/SourceFiles/platform/mac/touchbar/items/mac_scrubber_item.mm @@ -146,9 +146,9 @@ using Platform::Q2NSImage; NSImage *CreateNSImageFromEmoji(EmojiPtr emoji) { auto image = QImage( - QSize(kIdealIconSize, kIdealIconSize) * cIntRetinaFactor(), + QSize(kIdealIconSize, kIdealIconSize) * style::DevicePixelRatio(), QImage::Format_ARGB32_Premultiplied); - image.setDevicePixelRatio(cRetinaFactor()); + image.setDevicePixelRatio(style::DevicePixelRatio()); image.fill(Qt::black); { Painter paint(&image); diff --git a/Telegram/SourceFiles/platform/mac/touchbar/mac_touchbar_common.mm b/Telegram/SourceFiles/platform/mac/touchbar/mac_touchbar_common.mm index 5a7e8ed37..3f749a22b 100644 --- a/Telegram/SourceFiles/platform/mac/touchbar/mac_touchbar_common.mm +++ b/Telegram/SourceFiles/platform/mac/touchbar/mac_touchbar_common.mm @@ -20,7 +20,7 @@ int WidthFromString(NSString *s) { NSImage *CreateNSImageFromStyleIcon(const style::icon &icon, int size) { auto instance = icon.instance(QColor(255, 255, 255, 255), 100); - instance.setDevicePixelRatio(cRetinaFactor()); + instance.setDevicePixelRatio(style::DevicePixelRatio()); NSImage *image = Platform::Q2NSImage(instance); [image setSize:NSMakeSize(size, size)]; return image; diff --git a/Telegram/SourceFiles/platform/mac/window_title_mac.mm b/Telegram/SourceFiles/platform/mac/window_title_mac.mm index b18d8c287..946312280 100644 --- a/Telegram/SourceFiles/platform/mac/window_title_mac.mm +++ b/Telegram/SourceFiles/platform/mac/window_title_mac.mm @@ -32,7 +32,7 @@ int PreviewTitleHeight() { QImage PreviewWindowSystemButton(QColor inner, QColor border) { auto buttonSize = 12; - auto fullSize = buttonSize * cIntRetinaFactor(); + auto fullSize = buttonSize * style::DevicePixelRatio(); auto result = QImage(fullSize, fullSize, QImage::Format_ARGB32_Premultiplied); result.fill(Qt::transparent); { @@ -43,7 +43,7 @@ QImage PreviewWindowSystemButton(QColor inner, QColor border) { p.setBrush(inner); p.drawEllipse(QRectF(0.5, 0.5, fullSize - 1., fullSize - 1.)); } - result.setDevicePixelRatio(cRetinaFactor()); + result.setDevicePixelRatio(style::DevicePixelRatio()); return result; } @@ -93,17 +93,32 @@ void PreviewWindowTitle(Painter &p, const style::palette &palette, QRect body, i auto maximizeBorder = isGraphite ? graphiteBorder : QColor(21, 164, 41); auto close = PreviewWindowSystemButton(closeInner, closeBorder); auto left = buttonSkip; - p.drawImage(titleRect.x() + left, titleRect.y() + (titleRect.height() - (close.height() / cIntRetinaFactor())) / 2, close); - left += (close.width() / cIntRetinaFactor()) + buttonSkip; + p.drawImage( + titleRect.x() + left, + titleRect.y() + + (titleRect.height() + - (close.height() / style::DevicePixelRatio())) / 2, + close); + left += (close.width() / style::DevicePixelRatio()) + buttonSkip; auto minimize = PreviewWindowSystemButton(minimizeInner, minimizeBorder); - p.drawImage(titleRect.x() + left, titleRect.y() + (titleRect.height() - (minimize.height() / cIntRetinaFactor())) / 2, minimize); - left += (minimize.width() / cIntRetinaFactor()) + buttonSkip; + p.drawImage( + titleRect.x() + left, + titleRect.y() + + (titleRect.height() + - (minimize.height() / style::DevicePixelRatio())) / 2, + minimize); + left += (minimize.width() / style::DevicePixelRatio()) + buttonSkip; auto maximize = PreviewWindowSystemButton(maximizeInner, maximizeBorder); - p.drawImage(titleRect.x() + left, titleRect.y() + (titleRect.height() - (maximize.height() / cIntRetinaFactor())) / 2, maximize); + p.drawImage( + titleRect.x() + left, + titleRect.y() + + (titleRect.height() + - (maximize.height() / style::DevicePixelRatio())) / 2, + maximize); } void PreviewWindowFramePaint(QImage &preview, const style::palette &palette, QRect body, int outerWidth) { - auto retina = cIntRetinaFactor(); + auto retina = style::DevicePixelRatio(); auto titleHeight = PreviewTitleHeight(); { Painter p(&preview); @@ -113,7 +128,7 @@ void PreviewWindowFramePaint(QImage &preview, const style::palette &palette, QRe auto retinaRadius = st::macWindowRoundRadius * retina; auto roundMask = QImage(2 * retinaRadius, 2 * retinaRadius, QImage::Format_ARGB32_Premultiplied); - roundMask.setDevicePixelRatio(cRetinaFactor()); + roundMask.setDevicePixelRatio(style::DevicePixelRatio()); roundMask.fill(Qt::transparent); { Painter p(&roundMask); @@ -135,7 +150,7 @@ void PreviewWindowFramePaint(QImage &preview, const style::palette &palette, QRe inner.width() * retina, inner.height() * retina), corners); - rounded.setDevicePixelRatio(cRetinaFactor()); + rounded.setDevicePixelRatio(style::DevicePixelRatio()); preview.fill(st::themePreviewBg->c); auto topLeft = st::macWindowShadowTopLeft.instance(QColor(0, 0, 0), 100); diff --git a/Telegram/SourceFiles/settings.h b/Telegram/SourceFiles/settings.h index c99ad9597..c0d6f1cbb 100644 --- a/Telegram/SourceFiles/settings.h +++ b/Telegram/SourceFiles/settings.h @@ -126,14 +126,6 @@ inline bool passcodeCanTry() { return dt >= 30000; } -inline float64 cRetinaFactor() { - return style::DevicePixelRatio(); -} - -inline int32 cIntRetinaFactor() { - return style::DevicePixelRatio(); -} - inline int cEvalScale(int scale) { return (scale == style::kScaleAuto) ? cScreenScale() : scale; } diff --git a/Telegram/SourceFiles/settings/settings_chat.cpp b/Telegram/SourceFiles/settings/settings_chat.cpp index d4f1e8b7e..d7c977df6 100644 --- a/Telegram/SourceFiles/settings/settings_chat.cpp +++ b/Telegram/SourceFiles/settings/settings_chat.cpp @@ -478,7 +478,7 @@ void BackgroundRow::paintEvent(QPaintEvent *e) { const auto &pix = backThumb->pix( st::settingsBackgroundThumb, { .options = Images::Option::Blur }); - const auto factor = cIntRetinaFactor(); + const auto factor = style::DevicePixelRatio(); p.drawPixmap( 0, 0, @@ -585,7 +585,7 @@ void BackgroundRow::radialAnimationCallback(crl::time now) { void BackgroundRow::updateImage() { const auto size = st::settingsBackgroundThumb; - const auto fullsize = size * cIntRetinaFactor(); + const auto fullsize = size * style::DevicePixelRatio(); const auto &background = *Window::Theme::Background(); const auto &paper = background.paper(); @@ -619,7 +619,7 @@ void BackgroundRow::updateImage() { auto result = QImage( QSize{ fullsize, fullsize }, QImage::Format_ARGB32_Premultiplied); - result.setDevicePixelRatio(cRetinaFactor()); + result.setDevicePixelRatio(style::DevicePixelRatio()); if (const auto color = background.colorForFill()) { result.fill(*color); return result; @@ -644,7 +644,7 @@ void BackgroundRow::updateImage() { : prepareNormal(); _background = Ui::PixmapFromImage( Images::Round(std::move(back), ImageRoundRadius::Small)); - _background.setDevicePixelRatio(cRetinaFactor()); + _background.setDevicePixelRatio(style::DevicePixelRatio()); rtlupdate(radialRect()); diff --git a/Telegram/SourceFiles/settings/settings_notifications.cpp b/Telegram/SourceFiles/settings/settings_notifications.cpp index ddfb849f8..fdfe37148 100644 --- a/Telegram/SourceFiles/settings/settings_notifications.cpp +++ b/Telegram/SourceFiles/settings/settings_notifications.cpp @@ -390,8 +390,10 @@ int NotificationsCount::resizeGetHeight(int newWidth) { void NotificationsCount::prepareNotificationSampleSmall() { auto width = st::notificationSampleSize.width(); auto height = st::notificationSampleSize.height(); - auto sampleImage = QImage(width * cIntRetinaFactor(), height * cIntRetinaFactor(), QImage::Format_ARGB32_Premultiplied); - sampleImage.setDevicePixelRatio(cRetinaFactor()); + auto sampleImage = QImage( + QSize(width, height) * style::DevicePixelRatio(), + QImage::Format_ARGB32_Premultiplied); + sampleImage.setDevicePixelRatio(style::DevicePixelRatio()); sampleImage.fill(st::notificationBg->c); { Painter p(&sampleImage); @@ -422,28 +424,29 @@ void NotificationsCount::prepareNotificationSampleSmall() { p.fillRect(style::rtlrect(closeLeft, padding, padding, padding, width), st::notificationSampleCloseFg); } _notificationSampleSmall = Ui::PixmapFromImage(std::move(sampleImage)); - _notificationSampleSmall.setDevicePixelRatio(cRetinaFactor()); + _notificationSampleSmall.setDevicePixelRatio(style::DevicePixelRatio()); } void NotificationsCount::prepareNotificationSampleUserpic() { if (_notificationSampleUserpic.isNull()) { _notificationSampleUserpic = Ui::PixmapFromImage( Window::LogoNoMargin().scaled( - st::notifyPhotoSize * cIntRetinaFactor(), - st::notifyPhotoSize * cIntRetinaFactor(), + st::notifyPhotoSize * style::DevicePixelRatio(), + st::notifyPhotoSize * style::DevicePixelRatio(), Qt::IgnoreAspectRatio, Qt::SmoothTransformation)); - _notificationSampleUserpic.setDevicePixelRatio(cRetinaFactor()); + _notificationSampleUserpic.setDevicePixelRatio( + style::DevicePixelRatio()); } } void NotificationsCount::prepareNotificationSampleLarge() { int w = st::notifyWidth, h = st::notifyMinHeight; auto sampleImage = QImage( - w * cIntRetinaFactor(), - h * cIntRetinaFactor(), + w * style::DevicePixelRatio(), + h * style::DevicePixelRatio(), QImage::Format_ARGB32_Premultiplied); - sampleImage.setDevicePixelRatio(cRetinaFactor()); + sampleImage.setDevicePixelRatio(style::DevicePixelRatio()); sampleImage.fill(st::notificationBg->c); { Painter p(&sampleImage); diff --git a/Telegram/SourceFiles/storage/storage_media_prepare.cpp b/Telegram/SourceFiles/storage/storage_media_prepare.cpp index 17ebe996f..8b04450cf 100644 --- a/Telegram/SourceFiles/storage/storage_media_prepare.cpp +++ b/Telegram/SourceFiles/storage/storage_media_prepare.cpp @@ -306,10 +306,10 @@ void PrepareDetails(PreparedFile &file, int previewWidth, int sideLimit) { video->thumbnail, sideLimit); file.preview = std::move(blurred).scaledToWidth( - previewWidth * cIntRetinaFactor(), + previewWidth * style::DevicePixelRatio(), Qt::SmoothTransformation); Assert(!file.preview.isNull()); - file.preview.setDevicePixelRatio(cRetinaFactor()); + file.preview.setDevicePixelRatio(style::DevicePixelRatio()); file.type = PreparedFile::Type::Video; } } else if (const auto song = std::get_if(&file.information->media)) { @@ -335,14 +335,14 @@ void UpdateImageDetails( const auto toWidth = std::min( previewWidth, style::ConvertScale(preview.width()) - ) * cIntRetinaFactor(); + ) * style::DevicePixelRatio(); auto scaled = preview.scaledToWidth( toWidth, Qt::SmoothTransformation); if (scaled.isNull()) { CrashReports::SetAnnotation("Info", QString("%1x%2:%3*%4->%5;%6x%7" ).arg(preview.width()).arg(preview.height() - ).arg(previewWidth).arg(cIntRetinaFactor() + ).arg(previewWidth).arg(style::DevicePixelRatio() ).arg(toWidth ).arg(scaled.width()).arg(scaled.height())); Unexpected("Scaled is null."); @@ -350,7 +350,7 @@ void UpdateImageDetails( Assert(!scaled.isNull()); file.preview = Images::Opaque(std::move(scaled)); Assert(!file.preview.isNull()); - file.preview.setDevicePixelRatio(cRetinaFactor()); + file.preview.setDevicePixelRatio(style::DevicePixelRatio()); } bool ApplyModifications(PreparedList &list) { diff --git a/Telegram/SourceFiles/ui/chat/attach/attach_item_single_media_preview.cpp b/Telegram/SourceFiles/ui/chat/attach/attach_item_single_media_preview.cpp index eb06d363b..b686ee6fe 100644 --- a/Telegram/SourceFiles/ui/chat/attach/attach_item_single_media_preview.cpp +++ b/Telegram/SourceFiles/ui/chat/attach/attach_item_single_media_preview.cpp @@ -208,8 +208,8 @@ bool ItemSingleMediaPreview::tryPaintAnimation(QPainter &p) { const auto paused = _gifPaused(); auto request = ::Media::Streaming::FrameRequest(); - request.outer = s * cIntRetinaFactor(); - request.resize = s * cIntRetinaFactor(); + request.outer = s * style::DevicePixelRatio(); + request.resize = s * style::DevicePixelRatio(); p.drawImage( QRect( previewLeft(), diff --git a/Telegram/SourceFiles/ui/controls/userpic_button.cpp b/Telegram/SourceFiles/ui/controls/userpic_button.cpp index c1d0965b8..1b86567b3 100644 --- a/Telegram/SourceFiles/ui/controls/userpic_button.cpp +++ b/Telegram/SourceFiles/ui/controls/userpic_button.cpp @@ -109,9 +109,9 @@ void CameraBox( template QPixmap CreateSquarePixmap(int width, Callback &&paintCallback) { - auto size = QSize(width, width) * cIntRetinaFactor(); + const auto size = QSize(width, width) * style::DevicePixelRatio(); auto image = QImage(size, QImage::Format_ARGB32_Premultiplied); - image.setDevicePixelRatio(cRetinaFactor()); + image.setDevicePixelRatio(style::DevicePixelRatio()); image.fill(Qt::transparent); { Painter p(&image); @@ -931,7 +931,7 @@ void UserpicButton::showCustom(QImage &&image) { if (_userpicHasImage) { auto size = QSize(_st.photoSize, _st.photoSize); auto small = image.scaled( - size * cIntRetinaFactor(), + size * style::DevicePixelRatio(), Qt::IgnoreAspectRatio, Qt::SmoothTransformation); _userpic = Ui::PixmapFromImage(useForumShape() @@ -945,7 +945,7 @@ void UserpicButton::showCustom(QImage &&image) { fillShape(p, _st.changeButton.textBg); }); } - _userpic.setDevicePixelRatio(cRetinaFactor()); + _userpic.setDevicePixelRatio(style::DevicePixelRatio()); _userpicUniqueKey = {}; _result = std::move(image); diff --git a/Telegram/SourceFiles/ui/filter_icon_panel.cpp b/Telegram/SourceFiles/ui/filter_icon_panel.cpp index f0de41e3c..34299d15c 100644 --- a/Telegram/SourceFiles/ui/filter_icon_panel.cpp +++ b/Telegram/SourceFiles/ui/filter_icon_panel.cpp @@ -377,7 +377,11 @@ void FilterIconPanel::startShowAnimation() { _showAnimation = std::make_unique(st::emojiPanAnimation, Ui::PanelAnimation::Origin::TopRight); auto inner = rect().marginsRemoved(st::emojiPanMargins); - _showAnimation->setFinalImage(std::move(image), QRect(inner.topLeft() * cIntRetinaFactor(), inner.size() * cIntRetinaFactor())); + _showAnimation->setFinalImage( + std::move(image), + QRect( + inner.topLeft() * style::DevicePixelRatio(), + inner.size() * style::DevicePixelRatio())); _showAnimation->setCornerMasks(Images::CornersMask(ImageRoundRadius::Small)); _showAnimation->start(); } @@ -395,9 +399,9 @@ QImage FilterIconPanel::grabForAnimation() { Ui::SendPendingMoveResizeEvents(this); auto result = QImage( - size() * cIntRetinaFactor(), + size() * style::DevicePixelRatio(), QImage::Format_ARGB32_Premultiplied); - result.setDevicePixelRatio(cRetinaFactor()); + result.setDevicePixelRatio(style::DevicePixelRatio()); result.fill(Qt::transparent); if (_inner) { QPainter p(&result); diff --git a/Telegram/SourceFiles/ui/image/image.cpp b/Telegram/SourceFiles/ui/image/image.cpp index 14cefdb5a..1ef41f67a 100644 --- a/Telegram/SourceFiles/ui/image/image.cpp +++ b/Telegram/SourceFiles/ui/image/image.cpp @@ -58,13 +58,13 @@ Image::Image(QImage &&data) not_null Image::Empty() { static auto result = Image([] { - const auto factor = cIntRetinaFactor(); + const auto factor = style::DevicePixelRatio(); auto data = QImage( factor, factor, QImage::Format_ARGB32_Premultiplied); data.fill(Qt::transparent); - data.setDevicePixelRatio(cRetinaFactor()); + data.setDevicePixelRatio(style::DevicePixelRatio()); return data; }()); return &result; @@ -72,13 +72,13 @@ not_null Image::Empty() { not_null Image::BlankMedia() { static auto result = Image([] { - const auto factor = cIntRetinaFactor(); + const auto factor = style::DevicePixelRatio(); auto data = QImage( factor, factor, QImage::Format_ARGB32_Premultiplied); data.fill(Qt::black); - data.setDevicePixelRatio(cRetinaFactor()); + data.setDevicePixelRatio(style::DevicePixelRatio()); return data; }()); return &result; diff --git a/Telegram/SourceFiles/window/notifications_manager_default.cpp b/Telegram/SourceFiles/window/notifications_manager_default.cpp index c1d484374..2ce56b113 100644 --- a/Telegram/SourceFiles/window/notifications_manager_default.cpp +++ b/Telegram/SourceFiles/window/notifications_manager_default.cpp @@ -715,8 +715,11 @@ void Notification::prepareActionsCache() { auto replyRight = _replyPadding - st::notifyBorderWidth; auto actionsCacheWidth = _reply->width() + replyRight + fadeWidth; auto actionsCacheHeight = height() - actionsTop - st::notifyBorderWidth; - auto actionsCacheImg = QImage(QSize(actionsCacheWidth, actionsCacheHeight) * cIntRetinaFactor(), QImage::Format_ARGB32_Premultiplied); - actionsCacheImg.setDevicePixelRatio(cRetinaFactor()); + auto actionsCacheImg = QImage( + QSize(actionsCacheWidth, actionsCacheHeight) + * style::DevicePixelRatio(), + QImage::Format_ARGB32_Premultiplied); + actionsCacheImg.setDevicePixelRatio(style::DevicePixelRatio()); actionsCacheImg.fill(Qt::transparent); { Painter p(&actionsCacheImg); @@ -858,8 +861,10 @@ void Notification::updateNotifyDisplay() { _hideReplyButton = options.hideReplyButton; int32 w = width(), h = height(); - QImage img(w * cIntRetinaFactor(), h * cIntRetinaFactor(), QImage::Format_ARGB32_Premultiplied); - img.setDevicePixelRatio(cRetinaFactor()); + auto img = QImage( + size() * style::DevicePixelRatio(), + QImage::Format_ARGB32_Premultiplied); + img.setDevicePixelRatio(style::DevicePixelRatio()); img.fill(st::notificationBg->c); { @@ -893,7 +898,8 @@ void Notification::updateNotifyDisplay() { if (!options.hideNameAndPhoto) { if (_fromScheduled) { static const auto emoji = Ui::Emoji::Find(QString::fromUtf8("\xF0\x9F\x93\x85")); - const auto size = Ui::Emoji::GetSizeNormal() / cIntRetinaFactor(); + const auto size = Ui::Emoji::GetSizeNormal() + / style::DevicePixelRatio(); const auto top = rectForName.top() + (st::semiboldFont->height - size) / 2; Ui::Emoji::Draw(p, emoji, Ui::Emoji::GetSizeNormal(), rectForName.left(), top); rectForName.setLeft(rectForName.left() + size + st::semiboldFont->spacew); diff --git a/Telegram/SourceFiles/window/section_widget.cpp b/Telegram/SourceFiles/window/section_widget.cpp index 4d7a48c7f..18f3f7d05 100644 --- a/Telegram/SourceFiles/window/section_widget.cpp +++ b/Telegram/SourceFiles/window/section_widget.cpp @@ -357,7 +357,7 @@ void SectionWidget::PaintBackground( const auto paintCache = [&](const Ui::CachedBackground &cache) { const auto to = QRect( QPoint(cache.x, cache.y), - cache.pixmap.size() / cIntRetinaFactor()); + cache.pixmap.size() / style::DevicePixelRatio()); if (cache.waitingForNegativePattern) { // While we wait for pattern being loaded we paint just gradient. // But in case of negative patter opacity we just fill-black. @@ -416,8 +416,8 @@ void SectionWidget::PaintBackground( const auto top = clip.top(); const auto right = clip.left() + clip.width(); const auto bottom = clip.top() + clip.height(); - const auto w = tiled.width() / cRetinaFactor(); - const auto h = tiled.height() / cRetinaFactor(); + const auto w = tiled.width() / float64(style::DevicePixelRatio()); + const auto h = tiled.height() / float64(style::DevicePixelRatio()); const auto sx = qFloor(left / w); const auto sy = qFloor(top / h); const auto cx = qCeil(right / w); diff --git a/Telegram/SourceFiles/window/themes/window_theme.cpp b/Telegram/SourceFiles/window/themes/window_theme.cpp index 53b0c4b81..7409a95ee 100644 --- a/Telegram/SourceFiles/window/themes/window_theme.cpp +++ b/Telegram/SourceFiles/window/themes/window_theme.cpp @@ -450,7 +450,7 @@ bool InitializeFromSaved(Saved &&saved) { image = std::move(image).convertToFormat( QImage::Format_ARGB32_Premultiplied); } - image.setDevicePixelRatio(cRetinaFactor()); + image.setDevicePixelRatio(style::DevicePixelRatio()); if (Data::IsLegacy3DefaultWallPaper(paper)) { return Images::DitherImage(std::move(image)); } @@ -662,7 +662,7 @@ void ChatBackground::set(const Data::WallPaper &paper, QImage image) { } else { if (Data::IsLegacy1DefaultWallPaper(_paper)) { image.load(u":/gui/art/bg_initial.jpg"_q); - const auto scale = cScale() * cIntRetinaFactor(); + const auto scale = cScale() * style::DevicePixelRatio(); if (scale != 100) { image = image.scaledToWidth( style::ConvertScale(image.width(), scale), diff --git a/Telegram/SourceFiles/window/themes/window_theme_editor_box.cpp b/Telegram/SourceFiles/window/themes/window_theme_editor_box.cpp index f101a38c4..d448ca185 100644 --- a/Telegram/SourceFiles/window/themes/window_theme_editor_box.cpp +++ b/Telegram/SourceFiles/window/themes/window_theme_editor_box.cpp @@ -156,9 +156,9 @@ int BackgroundSelector::resizeGetHeight(int newWidth) { void BackgroundSelector::updateThumbnail() { const auto size = _thumbnailSize; auto back = QImage( - QSize(size, size) * cIntRetinaFactor(), + QSize(size, size) * style::DevicePixelRatio(), QImage::Format_ARGB32_Premultiplied); - back.setDevicePixelRatio(cRetinaFactor()); + back.setDevicePixelRatio(style::DevicePixelRatio()); { Painter p(&back); PainterHighQualityEnabler hq(p); @@ -171,7 +171,7 @@ void BackgroundSelector::updateThumbnail() { } _thumbnail = Ui::PixmapFromImage( Images::Round(std::move(back), ImageRoundRadius::Small)); - _thumbnail.setDevicePixelRatio(cRetinaFactor()); + _thumbnail.setDevicePixelRatio(style::DevicePixelRatio()); update(); } diff --git a/Telegram/SourceFiles/window/themes/window_theme_preview.cpp b/Telegram/SourceFiles/window/themes/window_theme_preview.cpp index a77de2d7f..d486e81b3 100644 --- a/Telegram/SourceFiles/window/themes/window_theme_preview.cpp +++ b/Telegram/SourceFiles/window/themes/window_theme_preview.cpp @@ -15,6 +15,7 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL #include "ui/empty_userpic.h" #include "ui/emoji_config.h" #include "ui/painter.h" +#include "ui/rect.h" #include "ui/chat/chat_theme.h" #include "ui/chat/chat_style.h" #include "ui/chat/message_bubble.h" @@ -413,9 +414,9 @@ QImage Generator::generate() { prepare(); auto result = QImage( - _rect.size() * cIntRetinaFactor(), + _rect.size() * style::DevicePixelRatio(), QImage::Format_ARGB32_Premultiplied); - result.setDevicePixelRatio(cRetinaFactor()); + result.setDevicePixelRatio(style::DevicePixelRatio()); result.fill(st::themePreviewBg->c); { @@ -482,13 +483,17 @@ void Generator::paintHistoryBackground() { } background = std::move(background).convertToFormat( QImage::Format_ARGB32_Premultiplied); - background.setDevicePixelRatio(cRetinaFactor()); + background.setDevicePixelRatio(style::DevicePixelRatio()); _p->setClipRect(_history); if (tiled) { auto width = background.width(); auto height = background.height(); - auto repeatTimesX = qCeil(_history.width() * cIntRetinaFactor() / float64(width)); - auto repeatTimesY = qCeil((_history.height() - fromy) * cIntRetinaFactor() / float64(height)); + auto repeatTimesX = qCeil(_history.width() + * style::DevicePixelRatio() + / float64(width)); + auto repeatTimesY = qCeil((_history.height() - fromy) + * style::DevicePixelRatio() + / float64(height)); auto imageForTiled = QImage( width * repeatTimesX, height * repeatTimesY, @@ -993,8 +998,12 @@ void Generator::paintBubble(const Bubble &bubble) { _historyBottom = y - (bubble.attachToTop ? st::msgMarginTopAttached : st::msgMargin.top()); if (isPhoto) { - auto image = bubble.photo.scaled(bubble.photoWidth * cIntRetinaFactor(), bubble.photoHeight * cIntRetinaFactor(), Qt::IgnoreAspectRatio, Qt::SmoothTransformation); - image.setDevicePixelRatio(cRetinaFactor()); + auto image = bubble.photo.scaled( + QSize(bubble.photoWidth, bubble.photoHeight) + * style::DevicePixelRatio(), + Qt::IgnoreAspectRatio, + Qt::SmoothTransformation); + image.setDevicePixelRatio(style::DevicePixelRatio()); _p->drawImage(x, y - bubble.photoHeight, image); _historyBottom -= bubble.photoHeight; } @@ -1025,7 +1034,7 @@ void Generator::paintUserpic(int x, int y, Row::Type type, int index, QString le auto image = QImage( QSize(size, size) * style::DevicePixelRatio(), QImage::Format_ARGB32_Premultiplied); - image.setDevicePixelRatio(cRetinaFactor()); + image.setDevicePixelRatio(style::DevicePixelRatio()); image.fill(Qt::transparent); { Painter p(&image); @@ -1139,8 +1148,10 @@ void DefaultPreviewWindowTitle(Painter &p, const style::palette &palette, QRect } void DefaultPreviewWindowFramePaint(QImage &preview, const style::palette &palette, QRect body, int outerWidth) { - auto mask = QImage(st::windowShadow.size() * cIntRetinaFactor(), QImage::Format_ARGB32_Premultiplied); - mask.setDevicePixelRatio(cRetinaFactor()); + auto mask = QImage( + st::windowShadow.size() * style::DevicePixelRatio(), + QImage::Format_ARGB32_Premultiplied); + mask.setDevicePixelRatio(style::DevicePixelRatio()); { Painter p(&mask); p.setCompositionMode(QPainter::CompositionMode_Source); @@ -1156,18 +1167,20 @@ void DefaultPreviewWindowFramePaint(QImage &preview, const style::palette &palet currentInt = *lastLineInts; ++maxSize; } - if (maxSize % cIntRetinaFactor()) { - maxSize -= (maxSize % cIntRetinaFactor()); + if (maxSize % style::DevicePixelRatio()) { + maxSize -= (maxSize % style::DevicePixelRatio()); } - auto size = maxSize / cIntRetinaFactor(); + auto size = maxSize / style::DevicePixelRatio(); auto bottom = size; auto left = size - st::windowShadowShift; auto right = left; auto top = size - 2 * st::windowShadowShift; auto sprite = st::windowShadow[palette]; - auto topLeft = QImage(sprite.size() * cIntRetinaFactor(), QImage::Format_ARGB32_Premultiplied); - topLeft.setDevicePixelRatio(cRetinaFactor()); + auto topLeft = QImage( + sprite.size() * style::DevicePixelRatio(), + QImage::Format_ARGB32_Premultiplied); + topLeft.setDevicePixelRatio(style::DevicePixelRatio()); { Painter p(&topLeft); p.setCompositionMode(QPainter::CompositionMode_Source); @@ -1182,16 +1195,74 @@ void DefaultPreviewWindowFramePaint(QImage &preview, const style::palette &palet Painter p(&preview); DefaultPreviewWindowTitle(p, palette, body, outerWidth); - auto inner = QRect(body.x(), body.y() - st::defaultWindowTitle.height, body.width(), body.height() + st::defaultWindowTitle.height); - p.setClipRegion(QRegion(inner.marginsAdded(QMargins(size, size, size, size))) - inner); + auto inner = QRect( + body.x(), + body.y() - st::defaultWindowTitle.height, + body.width(), + body.height() + st::defaultWindowTitle.height); + p.setClipRegion(QRegion(inner + Margins(size)) - inner); p.drawImage(inner.x() - left, inner.y() - top, topLeft); - p.drawImage(inner.x() + inner.width() + right - width, inner.y() - top, topRight); - p.drawImage(inner.x() + inner.width() + right - width, inner.y() + inner.height() + bottom - height, bottomRight); - p.drawImage(inner.x() - left, inner.y() + inner.height() + bottom - height, bottomLeft); - p.drawImage(QRect(inner.x() - left, inner.y() - top + height, left, top + inner.height() + bottom - 2 * height), topLeft, QRect(0, topLeft.height() - cIntRetinaFactor(), left * cIntRetinaFactor(), cIntRetinaFactor())); - p.drawImage(QRect(inner.x() - left + width, inner.y() - top, left + inner.width() + right - 2 * width, top), topLeft, QRect(topLeft.width() - cIntRetinaFactor(), 0, cIntRetinaFactor(), top * cIntRetinaFactor())); - p.drawImage(QRect(inner.x() + inner.width(), inner.y() - top + height, right, top + inner.height() + bottom - 2 * height), topRight, QRect(topRight.width() - right * cIntRetinaFactor(), topRight.height() - cIntRetinaFactor(), right * cIntRetinaFactor(), cIntRetinaFactor())); - p.drawImage(QRect(inner.x() - left + width, inner.y() + inner.height(), left + inner.width() + right - 2 * width, bottom), bottomRight, QRect(0, bottomRight.height() - bottom * cIntRetinaFactor(), cIntRetinaFactor(), bottom * cIntRetinaFactor())); + p.drawImage( + inner.x() + inner.width() + right - width, + inner.y() - top, + topRight); + p.drawImage( + inner.x() + inner.width() + right - width, + inner.y() + inner.height() + bottom - height, + bottomRight); + p.drawImage( + inner.x() - left, + inner.y() + inner.height() + bottom - height, + bottomLeft); + p.drawImage( + QRect( + inner.x() - left, + inner.y() - top + height, + left, + top + inner.height() + bottom - 2 * height), + topLeft, + QRect( + 0, + topLeft.height() - style::DevicePixelRatio(), + left * style::DevicePixelRatio(), + style::DevicePixelRatio())); + p.drawImage( + QRect( + inner.x() - left + width, + inner.y() - top, + left + inner.width() + right - 2 * width, + top), + topLeft, + QRect( + topLeft.width() - style::DevicePixelRatio(), + 0, + style::DevicePixelRatio(), + top * style::DevicePixelRatio())); + p.drawImage( + QRect( + inner.x() + inner.width(), + inner.y() - top + height, + right, + top + inner.height() + bottom - 2 * height), + topRight, + QRect( + topRight.width() - right * style::DevicePixelRatio(), + topRight.height() - style::DevicePixelRatio(), + right * style::DevicePixelRatio(), + style::DevicePixelRatio())); + p.drawImage( + QRect( + inner.x() - left + width, + inner.y() + inner.height(), + left + inner.width() + right - 2 * width, + bottom), + bottomRight, + QRect( + 0, + bottomRight.height() - bottom * style::DevicePixelRatio(), + style::DevicePixelRatio(), + bottom * style::DevicePixelRatio())); + } } // namespace Theme diff --git a/Telegram/SourceFiles/window/themes/window_themes_cloud_list.cpp b/Telegram/SourceFiles/window/themes/window_themes_cloud_list.cpp index 4001edae4..0971a1aef 100644 --- a/Telegram/SourceFiles/window/themes/window_themes_cloud_list.cpp +++ b/Telegram/SourceFiles/window/themes/window_themes_cloud_list.cpp @@ -54,7 +54,7 @@ constexpr auto kShowPerRow = 4; return source; } const auto from = source.size(); - const auto to = st::settingsThemePreviewSize * cIntRetinaFactor(); + const auto to = st::settingsThemePreviewSize * style::DevicePixelRatio(); if (to.width() * from.height() > to.height() * from.width()) { const auto small = (from.width() > to.width()) ? source.scaledToWidth(to.width(), Qt::SmoothTransformation) @@ -130,7 +130,7 @@ CloudListColors ColorsFromScheme(const EmbeddedScheme &scheme) { result.radiobuttonActive = scheme.radiobuttonActive; result.radiobuttonInactive = scheme.radiobuttonInactive; result.background = QImage( - QSize(1, 1) * cIntRetinaFactor(), + QSize(1, 1) * style::DevicePixelRatio(), QImage::Format_ARGB32_Premultiplied); result.background.fill(scheme.background); return result; @@ -160,7 +160,8 @@ CloudListCheck::CloudListCheck(bool checked) void CloudListCheck::setColors(const Colors &colors) { _colors = colors; if (!_colors->background.isNull()) { - const auto size = st::settingsThemePreviewSize * cIntRetinaFactor(); + const auto size = st::settingsThemePreviewSize + * style::DevicePixelRatio(); _backgroundFull = (_colors->background.size() == size) ? _colors->background : _colors->background.scaled( @@ -183,8 +184,8 @@ void CloudListCheck::ensureContrast() { - radio.height() - st::settingsThemeRadioBottom; const auto under = QRect( - QPoint(x, y) * cIntRetinaFactor(), - radio * cIntRetinaFactor()); + QPoint(x, y) * style::DevicePixelRatio(), + radio * style::DevicePixelRatio()); const auto image = _backgroundFull.copy(under).convertToFormat( QImage::Format_ARGB32_Premultiplied); const auto active = style::internal::EnsureContrast( @@ -207,7 +208,7 @@ void CloudListCheck::validateBackgroundCache(int width) { return; } _backgroundCacheWidth = width; - const auto imageWidth = width * cIntRetinaFactor(); + const auto imageWidth = width * style::DevicePixelRatio(); _backgroundCache = (width == st::settingsThemePreviewSize.width()) ? _backgroundFull : _backgroundFull.copy( @@ -218,7 +219,7 @@ void CloudListCheck::validateBackgroundCache(int width) { _backgroundCache = Images::Round( std::move(_backgroundCache), ImageRoundRadius::Large); - _backgroundCache.setDevicePixelRatio(cRetinaFactor()); + _backgroundCache.setDevicePixelRatio(style::DevicePixelRatio()); } void CloudListCheck::paint(QPainter &p, int left, int top, int outerWidth) { diff --git a/Telegram/SourceFiles/window/window_connecting_widget.cpp b/Telegram/SourceFiles/window/window_connecting_widget.cpp index 7a757df68..a7b1f3a1f 100644 --- a/Telegram/SourceFiles/window/window_connecting_widget.cpp +++ b/Telegram/SourceFiles/window/window_connecting_widget.cpp @@ -155,9 +155,9 @@ ConnectionState::Widget::ProxyIcon::ProxyIcon(QWidget *parent) : RpWidget(parent void ConnectionState::Widget::ProxyIcon::refreshCacheImages() { const auto prepareCache = [&](const style::icon &icon) { auto image = QImage( - size() * cIntRetinaFactor(), + size() * style::DevicePixelRatio(), QImage::Format_ARGB32_Premultiplied); - image.setDevicePixelRatio(cRetinaFactor()); + image.setDevicePixelRatio(style::DevicePixelRatio()); image.fill(st::windowBg->c); { auto p = QPainter(&image); diff --git a/Telegram/SourceFiles/window/window_media_preview.cpp b/Telegram/SourceFiles/window/window_media_preview.cpp index be931148b..3aa79501d 100644 --- a/Telegram/SourceFiles/window/window_media_preview.cpp +++ b/Telegram/SourceFiles/window/window_media_preview.cpp @@ -40,7 +40,7 @@ MediaPreviewWidget::MediaPreviewWidget( not_null controller) : RpWidget(parent) , _controller(controller) -, _emojiSize(Ui::Emoji::GetSizeLarge() / cIntRetinaFactor()) { +, _emojiSize(Ui::Emoji::GetSizeLarge() / style::DevicePixelRatio()) { setAttribute(Qt::WA_TransparentForMouseEvents); _controller->session().downloaderTaskFinished( ) | rpl::start_with_next([=] { @@ -72,7 +72,7 @@ void MediaPreviewWidget::paintEvent(QPaintEvent *e) { auto p = QPainter(this); const auto r = e->rect(); - const auto factor = cIntRetinaFactor(); + const auto factor = style::DevicePixelRatio(); const auto dimensions = currentDimensions(); const auto frame = (_lottie && _lottie->ready()) ? _lottie->frameInfo({ @@ -266,7 +266,7 @@ QSize MediaPreviewWidget::currentDimensions() const { return _cachedSize; } if (!_document && !_photo) { - _cachedSize = QSize(_cache.width() / cIntRetinaFactor(), _cache.height() / cIntRetinaFactor()); + _cachedSize = _cache.size() * style::DevicePixelRatio(); return _cachedSize; } @@ -325,7 +325,7 @@ void MediaPreviewWidget::createLottieIfReady( void MediaPreviewWidget::setupLottie() { Expects(_document != nullptr); - const auto factor = cIntRetinaFactor(); + const auto factor = style::DevicePixelRatio(); if (_document->isPremiumSticker()) { const auto size = HistoryView::Sticker::Size(_document); _cachedSize = size;