diff --git a/Telegram/SourceFiles/application.cpp b/Telegram/SourceFiles/application.cpp index ee6d6c4c68..fc4927712a 100644 --- a/Telegram/SourceFiles/application.cpp +++ b/Telegram/SourceFiles/application.cpp @@ -459,15 +459,16 @@ void connect(const char *signal, QObject *object, const char *method) { void launch() { Assert(application() != 0); - float64 dpi = Application::primaryScreen()->logicalDotsPerInch(); + const auto dpi = Application::primaryScreen()->logicalDotsPerInch(); + LOG(("Primary screen DPI: %1").arg(dpi)); if (dpi <= 108) { // 0-96-108 - cSetScreenScale(dbisOne); + cSetScreenScale(100); } else if (dpi <= 132) { // 108-120-132 - cSetScreenScale(dbisOneAndQuarter); + cSetScreenScale(125); } else if (dpi <= 168) { // 132-144-168 - cSetScreenScale(dbisOneAndHalf); + cSetScreenScale(150); } else { // 168-192-inf - cSetScreenScale(dbisTwo); + cSetScreenScale(200); } auto devicePixelRatio = application()->devicePixelRatio(); @@ -482,8 +483,8 @@ void launch() { cSetRetina(true); cSetRetinaFactor(devicePixelRatio); cSetIntRetinaFactor(int32(cRetinaFactor())); - cSetConfigScale(dbisOne); - cSetRealScale(dbisOne); + cSetConfigScale(100); + cSetRealScale(100); } application()->createMessenger(); diff --git a/Telegram/SourceFiles/boxes/edit_color_box.cpp b/Telegram/SourceFiles/boxes/edit_color_box.cpp index 49d9e489e0..7e14825788 100644 --- a/Telegram/SourceFiles/boxes/edit_color_box.cpp +++ b/Telegram/SourceFiles/boxes/edit_color_box.cpp @@ -60,8 +60,8 @@ private: }; QCursor EditColorBox::Picker::generateCursor() { - auto diameter = convertScale(16); - auto line = convertScale(1); + auto diameter = ConvertScale(16); + auto line = ConvertScale(1); auto size = ((diameter + 2 * line) >= 32) ? 64 : 32; auto cursor = QImage(QSize(size, size) * cIntRetinaFactor(), QImage::Format_ARGB32_Premultiplied); cursor.setDevicePixelRatio(cRetinaFactor()); diff --git a/Telegram/SourceFiles/chat_helpers/message_field.cpp b/Telegram/SourceFiles/chat_helpers/message_field.cpp index 0eb1827898..ac3a45daec 100644 --- a/Telegram/SourceFiles/chat_helpers/message_field.cpp +++ b/Telegram/SourceFiles/chat_helpers/message_field.cpp @@ -312,7 +312,7 @@ void InitMessageField( field->setTagMimeProcessor(std::make_unique()); field->document()->setDocumentMargin(4.); - field->setAdditionalMargin(convertScale(4) - 4); + field->setAdditionalMargin(ConvertScale(4) - 4); field->customTab(true); field->setInstantReplaces(Ui::InstantReplaces::Default()); diff --git a/Telegram/SourceFiles/codegen/style/generator.cpp b/Telegram/SourceFiles/codegen/style/generator.cpp index a99cc0be26..202bdfba47 100644 --- a/Telegram/SourceFiles/codegen/style/generator.cpp +++ b/Telegram/SourceFiles/codegen/style/generator.cpp @@ -1123,20 +1123,12 @@ bool Generator::writePxValuesInit() { void initPxValues() {\n\ if (cRetina()) return;\n\ \n\ - switch (cScale()) {\n"; - for (int i = 1, scalesCount = _scales.size(); i < scalesCount; ++i) { - source_->stream() << "\tcase " << _scaleNames.at(i) << ":\n"; - for (auto it = pxValues_.cbegin(), e = pxValues_.cend(); it != e; ++it) { - auto value = it.key(); - int adjusted = structure::data::pxAdjust(value, _scales.at(i)); - if (adjusted != value) { - source_->stream() << "\t\t" << pxValueName(value) << " = " << adjusted << ";\n"; - } - } - source_->stream() << "\tbreak;\n"; + const auto scale = cScale();\n"; + for (auto it = pxValues_.cbegin(), e = pxValues_.cend(); it != e; ++it) { + auto value = it.key(); + source_->stream() << "\t" << pxValueName(value) << " = ConvertScale(" << value << ", scale);\n"; } source_->stream() << "\ - }\n\ }\n\n"; return true; } diff --git a/Telegram/SourceFiles/codegen/style/generator.h b/Telegram/SourceFiles/codegen/style/generator.h index 84a5d7e1fc..f5f2147073 100644 --- a/Telegram/SourceFiles/codegen/style/generator.h +++ b/Telegram/SourceFiles/codegen/style/generator.h @@ -64,9 +64,6 @@ private: QMap iconMasks_; // icon file -> index std::map> paletteIndices_; - std::vector _scales = { 4, 5, 6, 8 }; // scale / 4 gives our 1.00, 1.25, 1.50, 2.00 - std::vector _scaleNames = { "dbisOne", "dbisOneAndQuarter", "dbisOneAndHalf", "dbisTwo" }; - }; } // namespace style diff --git a/Telegram/SourceFiles/codegen/style/structure_types.h b/Telegram/SourceFiles/codegen/style/structure_types.h index 30403ec731..de6392c06a 100644 --- a/Telegram/SourceFiles/codegen/style/structure_types.h +++ b/Telegram/SourceFiles/codegen/style/structure_types.h @@ -59,13 +59,6 @@ inline bool operator!=(const Type &a, const Type &b) { namespace data { -inline int pxAdjust(int value, int scale) { - if (value < 0) { - return -pxAdjust(-value, scale); - } - return qFloor((value * scale / 4.) + 0.1); -} - struct point { int x, y; }; diff --git a/Telegram/SourceFiles/core/utils.h b/Telegram/SourceFiles/core/utils.h index ac00f6a354..219dc22981 100644 --- a/Telegram/SourceFiles/core/utils.h +++ b/Telegram/SourceFiles/core/utils.h @@ -388,16 +388,6 @@ struct ProxyData { ProxyData ToDirectIpProxy(const ProxyData &proxy, int ipIndex = 0); QNetworkProxy ToNetworkProxy(const ProxyData &proxy); -enum DBIScale { - dbisAuto = 0, - dbisOne = 1, - dbisOneAndQuarter = 2, - dbisOneAndHalf = 3, - dbisTwo = 4, - - dbisScaleCount = 5, -}; - static const int MatrixRowShift = 40000; enum DBIPlatform { diff --git a/Telegram/SourceFiles/dialogs/dialogs_inner_widget.cpp b/Telegram/SourceFiles/dialogs/dialogs_inner_widget.cpp index f9b8d05659..7bb3d2c976 100644 --- a/Telegram/SourceFiles/dialogs/dialogs_inner_widget.cpp +++ b/Telegram/SourceFiles/dialogs/dialogs_inner_widget.cpp @@ -847,7 +847,7 @@ void DialogsInner::mousePressEvent(QMouseEvent *e) { void DialogsInner::checkReorderPinnedStart(QPoint localPosition) { if (_pressed != nullptr && !_dragging && _state == State::Default) { - if (qAbs(localPosition.y() - _dragStart.y()) >= convertScale(kStartReorderThreshold)) { + if (qAbs(localPosition.y() - _dragStart.y()) >= ConvertScale(kStartReorderThreshold)) { _dragging = _pressed; if (updateReorderIndexGetCount() < 2) { _dragging = nullptr; diff --git a/Telegram/SourceFiles/history/history_location_manager.cpp b/Telegram/SourceFiles/history/history_location_manager.cpp index a8de24cd5e..57d4b33a76 100644 --- a/Telegram/SourceFiles/history/history_location_manager.cpp +++ b/Telegram/SourceFiles/history/history_location_manager.cpp @@ -17,15 +17,10 @@ constexpr auto kCoordPrecision = 8; constexpr auto kMaxHttpRedirects = 5; GeoPointLocation ComputeLocation(const LocationCoords &coords) { - int32 w = st::locationSize.width(), h = st::locationSize.height(); - int32 zoom = 15, scale = 1; - if (cScale() == dbisTwo || cRetina()) { - scale = 2; - zoom = 16; - } else { - w = convertScale(w); - h = convertScale(h); - } + const auto scale = 1 + (cScale() * cIntRetinaFactor()) / 200; + const auto zoom = 15 + (scale - 1); + const auto w = ConvertScale(st::locationSize.width()) / scale; + const auto h = ConvertScale(st::locationSize.height()) / scale; auto result = GeoPointLocation(); result.lat = coords.lat(); diff --git a/Telegram/SourceFiles/history/history_media_types.cpp b/Telegram/SourceFiles/history/history_media_types.cpp index a81680d81c..f2c5a85357 100644 --- a/Telegram/SourceFiles/history/history_media_types.cpp +++ b/Telegram/SourceFiles/history/history_media_types.cpp @@ -310,8 +310,8 @@ QSize HistoryPhoto::countOptimalSize() { auto maxWidth = 0; auto minHeight = 0; - auto tw = convertScale(_data->full->width()); - auto th = convertScale(_data->full->height()); + auto tw = ConvertScale(_data->full->width()); + auto th = ConvertScale(_data->full->height()); if (!tw || !th) { tw = th = 1; } @@ -342,7 +342,7 @@ QSize HistoryPhoto::countOptimalSize() { } QSize HistoryPhoto::countCurrentSize(int newWidth) { - int tw = convertScale(_data->full->width()), th = convertScale(_data->full->height()); + int tw = ConvertScale(_data->full->width()), th = ConvertScale(_data->full->height()); if (tw > st::maxMediaSize) { th = (st::maxMediaSize * th) / tw; tw = st::maxMediaSize; @@ -714,8 +714,8 @@ void HistoryPhoto::validateGroupedCache( return; } - const auto originalWidth = convertScale(_data->full->width()); - const auto originalHeight = convertScale(_data->full->height()); + const auto originalWidth = ConvertScale(_data->full->width()); + const auto originalHeight = ConvertScale(_data->full->height()); const auto pixSize = Ui::GetImageScaleSizeForGeometry( { originalWidth, originalHeight }, { width, height }); @@ -778,8 +778,8 @@ QSize HistoryVideo::countOptimalSize() { _parent->skipBlockHeight()); } - auto tw = convertScale(_data->thumb->width()); - auto th = convertScale(_data->thumb->height()); + auto tw = ConvertScale(_data->thumb->width()); + auto th = ConvertScale(_data->thumb->height()); if (!tw || !th) { tw = th = 1; } @@ -809,7 +809,7 @@ QSize HistoryVideo::countOptimalSize() { } QSize HistoryVideo::countCurrentSize(int newWidth) { - int tw = convertScale(_data->thumb->width()), th = convertScale(_data->thumb->height()); + int tw = ConvertScale(_data->thumb->width()), th = ConvertScale(_data->thumb->height()); if (!tw || !th) { tw = th = 1; } @@ -1154,8 +1154,8 @@ void HistoryVideo::validateGroupedCache( return; } - const auto originalWidth = convertScale(_data->thumb->width()); - const auto originalHeight = convertScale(_data->thumb->height()); + const auto originalWidth = ConvertScale(_data->thumb->width()); + const auto originalHeight = ConvertScale(_data->thumb->height()); const auto pixSize = Ui::GetImageScaleSizeForGeometry( { originalWidth, originalHeight }, { width, height }); @@ -1303,8 +1303,8 @@ QSize HistoryDocument::countOptimalSize() { auto thumbed = Get(); if (thumbed) { _data->thumb->load(_realParent->fullId()); - auto tw = convertScale(_data->thumb->width()); - auto th = convertScale(_data->thumb->height()); + auto tw = ConvertScale(_data->thumb->width()); + auto th = ConvertScale(_data->thumb->height()); if (tw > th) { thumbed->_thumbw = (tw * st::msgFileThumbSize) / th; } else { @@ -1978,13 +1978,13 @@ QSize HistoryGif::countOptimalSize() { const auto reader = currentReader(); if (reader) { - tw = convertScale(reader->width()); - th = convertScale(reader->height()); + tw = ConvertScale(reader->width()); + th = ConvertScale(reader->height()); } else { - tw = convertScale(_data->dimensions.width()), th = convertScale(_data->dimensions.height()); + tw = ConvertScale(_data->dimensions.width()), th = ConvertScale(_data->dimensions.height()); if (!tw || !th) { - tw = convertScale(_data->thumb->width()); - th = convertScale(_data->thumb->height()); + tw = ConvertScale(_data->thumb->width()); + th = ConvertScale(_data->thumb->height()); } } if (tw > st::maxGifSize) { @@ -2033,13 +2033,13 @@ QSize HistoryGif::countCurrentSize(int newWidth) { int tw = 0, th = 0; const auto reader = currentReader(); if (reader) { - tw = convertScale(reader->width()); - th = convertScale(reader->height()); + tw = ConvertScale(reader->width()); + th = ConvertScale(reader->height()); } else { - tw = convertScale(_data->dimensions.width()), th = convertScale(_data->dimensions.height()); + tw = ConvertScale(_data->dimensions.width()), th = ConvertScale(_data->dimensions.height()); if (!tw || !th) { - tw = convertScale(_data->thumb->width()); - th = convertScale(_data->thumb->height()); + tw = ConvertScale(_data->thumb->width()); + th = ConvertScale(_data->thumb->height()); } } if (tw > st::maxGifSize) { @@ -3635,7 +3635,7 @@ void HistoryWebPage::draw(Painter &p, const QRect &r, TextSelection selection, T auto pw = qMax(_pixw, lineHeight); auto ph = _pixh; auto pixw = _pixw, pixh = articleThumbHeight(_data->photo, _pixw); - auto maxw = convertScale(_data->photo->medium->width()), maxh = convertScale(_data->photo->medium->height()); + auto maxw = ConvertScale(_data->photo->medium->width()), maxh = ConvertScale(_data->photo->medium->height()); if (pixw * ph != pixh * pw) { float64 coef = (pixw * ph > pixh * pw) ? qMin(ph / float64(pixh), maxh / float64(pixh)) : qMin(pw / float64(pixw), maxw / float64(pixw)); pixh = qRound(pixh * coef); diff --git a/Telegram/SourceFiles/inline_bots/inline_bot_layout_internal.cpp b/Telegram/SourceFiles/inline_bots/inline_bot_layout_internal.cpp index 0d8b262ac7..562e09f8e6 100644 --- a/Telegram/SourceFiles/inline_bots/inline_bot_layout_internal.cpp +++ b/Telegram/SourceFiles/inline_bots/inline_bot_layout_internal.cpp @@ -52,7 +52,7 @@ int FileBase::content_width() const { return document->dimensions.width(); } if (!document->thumb->isNull()) { - return convertScale(document->thumb->width()); + return ConvertScale(document->thumb->width()); } return 0; } @@ -63,7 +63,7 @@ int FileBase::content_height() const { return document->dimensions.height(); } if (!document->thumb->isNull()) { - return convertScale(document->thumb->height()); + return ConvertScale(document->thumb->height()); } return 0; } @@ -665,7 +665,7 @@ void Video::prepareThumb(int32 width, int32 height) const { const auto origin = fileOrigin(); if (thumb->loaded()) { if (_thumb.width() != width * cIntRetinaFactor() || _thumb.height() != height * cIntRetinaFactor()) { - int32 w = qMax(convertScale(thumb->width()), 1), h = qMax(convertScale(thumb->height()), 1); + int32 w = qMax(ConvertScale(thumb->width()), 1), h = qMax(ConvertScale(thumb->height()), 1); if (w * height > h * width) { if (height < h) { w = w * height / h; @@ -989,7 +989,7 @@ void Contact::prepareThumb(int width, int height) const { const auto origin = fileOrigin(); if (thumb->loaded()) { if (_thumb.width() != width * cIntRetinaFactor() || _thumb.height() != height * cIntRetinaFactor()) { - int w = qMax(convertScale(thumb->width()), 1), h = qMax(convertScale(thumb->height()), 1); + int w = qMax(ConvertScale(thumb->width()), 1), h = qMax(ConvertScale(thumb->height()), 1); if (w * height > h * width) { if (height < h) { w = w * height / h; @@ -1137,7 +1137,7 @@ void Article::prepareThumb(int width, int height) const { const auto origin = fileOrigin(); if (thumb->loaded()) { if (_thumb.width() != width * cIntRetinaFactor() || _thumb.height() != height * cIntRetinaFactor()) { - int w = qMax(convertScale(thumb->width()), 1), h = qMax(convertScale(thumb->height()), 1); + int w = qMax(ConvertScale(thumb->width()), 1), h = qMax(ConvertScale(thumb->height()), 1); if (w * height > h * width) { if (height < h) { w = w * height / h; @@ -1317,7 +1317,7 @@ void Game::prepareThumb(int width, int height) const { const auto origin = fileOrigin(); if (thumb->loaded()) { if (_thumb.width() != width * cIntRetinaFactor() || _thumb.height() != height * cIntRetinaFactor()) { - int w = qMax(convertScale(thumb->width()), 1), h = qMax(convertScale(thumb->height()), 1); + int w = qMax(ConvertScale(thumb->width()), 1), h = qMax(ConvertScale(thumb->height()), 1); auto resizeByHeight1 = (w * height > h * width) && (h >= height); auto resizeByHeight2 = (h * width >= w * height) && (w < width); if (resizeByHeight1 || resizeByHeight2) { diff --git a/Telegram/SourceFiles/inline_bots/inline_bot_result.cpp b/Telegram/SourceFiles/inline_bots/inline_bot_result.cpp index 69ba27beff..0c89eaaa1e 100644 --- a/Telegram/SourceFiles/inline_bots/inline_bot_result.cpp +++ b/Telegram/SourceFiles/inline_bots/inline_bot_result.cpp @@ -221,18 +221,22 @@ std::unique_ptr Result::create(uint64 queryId, const MTPBotInlineResult return nullptr; } - LocationCoords location; - if (result->getLocationCoords(&location)) { - int32 w = st::inlineThumbSize, h = st::inlineThumbSize; - int32 zoom = 13, scale = 1; - if (cScale() == dbisTwo || cRetina()) { - scale = 2; - w /= 2; - h /= 2; - } - auto coords = location.latAsString() + ',' + location.lonAsString(); - QString url = qsl("https://maps.googleapis.com/maps/api/staticmap?center=") + coords + qsl("&zoom=%1&size=%2x%3&maptype=roadmap&scale=%4&markers=color:red|size:big|").arg(zoom).arg(w).arg(h).arg(scale) + coords + qsl("&sensor=false"); - result->_locationThumb = ImagePtr(url); + LocationCoords coords; + if (result->getLocationCoords(&coords)) { + const auto scale = 1 + (cScale() * cIntRetinaFactor()) / 200; + const auto zoom = 15 + (scale - 1); + const auto w = ConvertScale(st::inlineThumbSize) / scale; + const auto h = ConvertScale(st::inlineThumbSize) / scale; + + auto location = GeoPointLocation(); + location.lat = coords.lat(); + location.lon = coords.lon(); + location.access = coords.accessHash(); + location.width = w; + location.height = h; + location.zoom = zoom; + location.scale = scale; + result->_locationThumb = ImagePtr(location); } return result; diff --git a/Telegram/SourceFiles/mediaview.cpp b/Telegram/SourceFiles/mediaview.cpp index 647ef4118b..a0ef63cb87 100644 --- a/Telegram/SourceFiles/mediaview.cpp +++ b/Telegram/SourceFiles/mediaview.cpp @@ -1455,8 +1455,8 @@ void MediaView::displayPhoto(not_null photo, HistoryItem *item) { _full = -1; _current = QPixmap(); _down = OverNone; - _w = convertScale(photo->full->width()); - _h = convertScale(photo->full->height()); + _w = ConvertScale(photo->full->width()); + _h = ConvertScale(photo->full->height()); if (isHidden()) { moveToScreen(); } @@ -1600,11 +1600,11 @@ void MediaView::displayDocument(DocumentData *doc, HistoryItem *item) { // empty updateThemePreviewGeometry(); } else if (!_current.isNull()) { _current.setDevicePixelRatio(cRetinaFactor()); - _w = convertScale(_current.width()); - _h = convertScale(_current.height()); + _w = ConvertScale(_current.width()); + _h = ConvertScale(_current.height()); } else { - _w = convertScale(_gif->width()); - _h = convertScale(_gif->height()); + _w = ConvertScale(_gif->width()); + _h = ConvertScale(_gif->height()); } if (isHidden()) { moveToScreen(); @@ -2437,8 +2437,8 @@ void MediaView::setZoomLevel(int newZoom) { if (_zoom == newZoom) return; float64 nx, ny, z = (_zoom == ZoomToScreenLevel) ? _zoomToScreen : _zoom; - _w = gifShown() ? convertScale(_gif->width()) : (convertScale(_current.width()) / cIntRetinaFactor()); - _h = gifShown() ? convertScale(_gif->height()) : (convertScale(_current.height()) / cIntRetinaFactor()); + _w = gifShown() ? ConvertScale(_gif->width()) : (ConvertScale(_current.width()) / cIntRetinaFactor()); + _h = gifShown() ? ConvertScale(_gif->height()) : (ConvertScale(_current.height()) / cIntRetinaFactor()); if (z >= 0) { nx = (_x - width() / 2.) / (z + 1); ny = (_y - height() / 2.) / (z + 1); diff --git a/Telegram/SourceFiles/messenger.cpp b/Telegram/SourceFiles/messenger.cpp index ea8b526e8b..8a34853d04 100644 --- a/Telegram/SourceFiles/messenger.cpp +++ b/Telegram/SourceFiles/messenger.cpp @@ -109,8 +109,8 @@ Messenger::Messenger(not_null launcher) } if (cRetina()) { - cSetConfigScale(dbisOne); - cSetRealScale(dbisOne); + cSetConfigScale(100); + cSetRealScale(100); } _translator = std::make_unique(); diff --git a/Telegram/SourceFiles/overview/overview_layout.cpp b/Telegram/SourceFiles/overview/overview_layout.cpp index 39bb4a79b4..af3938f53e 100644 --- a/Telegram/SourceFiles/overview/overview_layout.cpp +++ b/Telegram/SourceFiles/overview/overview_layout.cpp @@ -838,7 +838,7 @@ Document::Document( if (withThumb()) { _data->thumb->load(parent->fullId()); - int32 tw = convertScale(_data->thumb->width()), th = convertScale(_data->thumb->height()); + int32 tw = ConvertScale(_data->thumb->width()), th = ConvertScale(_data->thumb->height()); if (tw > th) { _thumbw = (tw * _st.fileThumbSize) / th; } else { @@ -1275,15 +1275,15 @@ Link::Link( _page->photo->thumb->load(parent->fullId(), false, false); } - tw = convertScale(_page->photo->thumb->width()); - th = convertScale(_page->photo->thumb->height()); + tw = ConvertScale(_page->photo->thumb->width()); + th = ConvertScale(_page->photo->thumb->height()); } else if (_page && _page->document) { if (!_page->document->thumb->loaded()) { _page->document->thumb->load(parent->fullId(), false, false); } - tw = convertScale(_page->document->thumb->width()); - th = convertScale(_page->document->thumb->height()); + tw = ConvertScale(_page->document->thumb->width()); + th = ConvertScale(_page->document->thumb->height()); } if (tw > st::linksPhotoSize) { if (th > tw) { diff --git a/Telegram/SourceFiles/platform/mac/main_window_mac.mm b/Telegram/SourceFiles/platform/mac/main_window_mac.mm index d786e49db8..aea82dd76e 100644 --- a/Telegram/SourceFiles/platform/mac/main_window_mac.mm +++ b/Telegram/SourceFiles/platform/mac/main_window_mac.mm @@ -379,8 +379,8 @@ MainWindow::MainWindow() auto forceOpenGL = std::make_unique(this); #endif // !OS_MAC_OLD - trayImg = st::macTrayIcon.instance(QColor(0, 0, 0, 180), dbisOne); - trayImgSel = st::macTrayIcon.instance(QColor(255, 255, 255), dbisOne); + trayImg = st::macTrayIcon.instance(QColor(0, 0, 0, 180), 100); + trayImgSel = st::macTrayIcon.instance(QColor(255, 255, 255), 100); _hideAfterFullScreenTimer.setCallback([this] { hideAndDeactivate(); }); diff --git a/Telegram/SourceFiles/platform/mac/window_title_mac.mm b/Telegram/SourceFiles/platform/mac/window_title_mac.mm index 7f6ae5854c..5f0d36eff8 100644 --- a/Telegram/SourceFiles/platform/mac/window_title_mac.mm +++ b/Telegram/SourceFiles/platform/mac/window_title_mac.mm @@ -76,7 +76,7 @@ object_ptr CreateTitleWidget(QWidget *parent) { } // All the window decorations preview is done without taking cScale() into -// account, with dbisOne scale and without "px" dimensions, because thats +// account, with 100% scale and without "px" dimensions, because thats // how it will look in real launched macOS app. int PreviewTitleHeight() { if (auto window = qobject_cast(App::wnd())) { @@ -185,7 +185,7 @@ void PreviewWindowFramePaint(QImage &preview, const style::palette &palette, QRe Images::prepareRound(rounded, corners); preview.fill(st::themePreviewBg->c); - auto topLeft = st::macWindowShadowTopLeft.instance(QColor(0, 0, 0), dbisOne); + auto topLeft = st::macWindowShadowTopLeft.instance(QColor(0, 0, 0), 100); auto topRight = topLeft.mirrored(true, false); auto bottomLeft = topLeft.mirrored(false, true); auto bottomRight = bottomLeft.mirrored(true, false); diff --git a/Telegram/SourceFiles/settings.cpp b/Telegram/SourceFiles/settings.cpp index aff25ee3ad..6b4b56603c 100644 --- a/Telegram/SourceFiles/settings.cpp +++ b/Telegram/SourceFiles/settings.cpp @@ -44,9 +44,9 @@ uint32 gConnectionsInSession = 1; QString gLoggedPhoneNumber; QByteArray gLocalSalt; -DBIScale gRealScale = dbisAuto; -DBIScale gScreenScale = dbisOne; -DBIScale gConfigScale = dbisAuto; +int gRealScale = kInterfaceScaleAuto; +int gScreenScale = kInterfaceScaleAuto; +int gConfigScale = kInterfaceScaleAuto; QString gTimeFormat = qsl("hh:mm"); diff --git a/Telegram/SourceFiles/settings.h b/Telegram/SourceFiles/settings.h index 4ece78ab87..e4f203a07a 100644 --- a/Telegram/SourceFiles/settings.h +++ b/Telegram/SourceFiles/settings.h @@ -90,30 +90,35 @@ DeclareSetting(bool, StartToSettings); DeclareReadSetting(bool, ManyInstance); DeclareSetting(QByteArray, LocalSalt); -DeclareSetting(DBIScale, RealScale); -DeclareSetting(DBIScale, ScreenScale); -DeclareSetting(DBIScale, ConfigScale); +DeclareSetting(int, RealScale); +DeclareSetting(int, ScreenScale); +DeclareSetting(int, ConfigScale); DeclareSetting(QString, TimeFormat); -inline void cChangeTimeFormat(const QString &newFormat) { - if (!newFormat.isEmpty()) cSetTimeFormat(newFormat); +constexpr auto kInterfaceScaleAuto = 0; + +inline int cEvalScale(int scale) { + return (scale == kInterfaceScaleAuto) ? cScreenScale() : scale; } -inline DBIScale cEvalScale(DBIScale scale) { - return (scale == dbisAuto) ? cScreenScale() : scale; -} -inline DBIScale cScale() { +inline int cScale() { return cEvalScale(cRealScale()); } template -T convertScale(T v) { - switch (cScale()) { - case dbisOneAndQuarter: return qRound(float64(v) * 1.25 - 0.01); - case dbisOneAndHalf: return qRound(float64(v) * 1.5 - 0.01); - case dbisTwo: return v * 2; - } - return v; +inline T ConvertScale(T value, int scale) { + return (value < 0.) + ? (-ConvertScale(-value, scale)) + : T(std::round((float64(value) * scale / 100.) - 0.01)); +} + +template +inline T ConvertScale(T value) { + return ConvertScale(value, cScale()); +} + +inline void cChangeTimeFormat(const QString &newFormat) { + if (!newFormat.isEmpty()) cSetTimeFormat(newFormat); } namespace Ui { diff --git a/Telegram/SourceFiles/settings/settings_main.cpp b/Telegram/SourceFiles/settings/settings_main.cpp index cc1102836b..c8c3bb0955 100644 --- a/Telegram/SourceFiles/settings/settings_main.cpp +++ b/Telegram/SourceFiles/settings/settings_main.cpp @@ -112,7 +112,7 @@ void SetupInterfaceScale( container, rpl::event_stream()); - const auto switched = (cConfigScale() == dbisAuto) + const auto switched = (cConfigScale() == kInterfaceScaleAuto) || (cConfigScale() == cScreenScale()); const auto button = AddButton( container, @@ -125,22 +125,33 @@ void SetupInterfaceScale( object_ptr(container, st::settingsSlider), icon ? st::settingsScalePadding : st::settingsBigScalePadding); + static const auto ScaleValues = { 100, 125, 150, 200, 300 }; + const auto sectionFromScale = [](int scale) { + auto result = 0; + for (const auto value : ScaleValues) { + if (scale <= value) { + break; + } + ++result; + } + return (result == ScaleValues.size()) ? (result - 1) : result; + }; const auto inSetScale = Ui::AttachAsChild(container, false); - const auto setScale = std::make_shared>(); - *setScale = [=](DBIScale scale) { + const auto setScale = std::make_shared>(); + *setScale = [=](int scale) { if (*inSetScale) return; *inSetScale = true; const auto guard = gsl::finally([=] { *inSetScale = false; }); if (scale == cScreenScale()) { - scale = dbisAuto; + scale = kInterfaceScaleAuto; } - toggled->fire(scale == dbisAuto); + toggled->fire(scale == kInterfaceScaleAuto); const auto applying = scale; - if (scale == dbisAuto) { + if (scale == kInterfaceScaleAuto) { scale = cScreenScale(); } - slider->setActiveSection(scale - 1); + slider->setActiveSection(sectionFromScale(scale)); if (cEvalScale(scale) != cEvalScale(cRealScale())) { const auto confirmed = crl::guard(button, [=] { @@ -166,46 +177,31 @@ void SetupInterfaceScale( }; button->toggledValue( ) | rpl::start_with_next([=](bool checked) { - auto scale = checked ? dbisAuto : cEvalScale(cConfigScale()); + auto scale = checked ? kInterfaceScaleAuto : cEvalScale(cConfigScale()); if (scale == cScreenScale()) { if (scale != cScale()) { scale = cScale(); } else { - switch (scale) { - case dbisOne: scale = dbisOneAndQuarter; break; - case dbisOneAndQuarter: scale = dbisOne; break; - case dbisOneAndHalf: scale = dbisOneAndQuarter; break; - case dbisTwo: scale = dbisOneAndHalf; break; + scale -= 25; + if (scale < 100) { + scale = 125; } } } (*setScale)(scale); }, button->lifetime()); - const auto label = [](DBIScale scale) { - switch (scale) { - case dbisOne: return qsl("100%"); - case dbisOneAndQuarter: return qsl("125%"); - case dbisOneAndHalf: return qsl("150%"); - case dbisTwo: return qsl("200%"); - } - Unexpected("Value in scale label."); + const auto label = [](int scale) { + return QString::number(scale) + '%'; }; const auto scaleByIndex = [](int index) { - switch (index) { - case 0: return dbisOne; - case 1: return dbisOneAndQuarter; - case 2: return dbisOneAndHalf; - case 3: return dbisTwo; - } - Unexpected("Index in scaleByIndex."); + return *(ScaleValues.begin() + index); }; - slider->addSection(label(dbisOne)); - slider->addSection(label(dbisOneAndQuarter)); - slider->addSection(label(dbisOneAndHalf)); - slider->addSection(label(dbisTwo)); - slider->setActiveSectionFast(cEvalScale(cConfigScale()) - 1); + for (const auto value : ScaleValues) { + slider->addSection(label(value)); + } + slider->setActiveSectionFast(sectionFromScale(cConfigScale())); slider->sectionActivated( ) | rpl::start_with_next([=](int section) { (*setScale)(scaleByIndex(section)); diff --git a/Telegram/SourceFiles/storage/localstorage.cpp b/Telegram/SourceFiles/storage/localstorage.cpp index b53f6cb65a..56320f6d79 100644 --- a/Telegram/SourceFiles/storage/localstorage.cpp +++ b/Telegram/SourceFiles/storage/localstorage.cpp @@ -541,7 +541,7 @@ enum { dbiReplaceEmoji = 0x13, dbiAskDownloadPath = 0x14, dbiDownloadPathOld = 0x15, - dbiScale = 0x16, + dbiScaleOld = 0x16, dbiEmojiTabOld = 0x17, dbiRecentEmojiOldOld = 0x18, dbiLoggedPhoneNumber = 0x19, @@ -597,6 +597,7 @@ enum { dbiTileBackground = 0x55, dbiCacheSettings = 0x56, dbiAnimationsDisabled = 0x57, + dbiScalePercent = 0x58, dbiEncryptedWithSalt = 333, dbiEncrypted = 444, @@ -1364,24 +1365,45 @@ bool _readSetting(quint32 blockId, QDataStream &stream, int version, ReadSetting cSetLastUpdateCheck(v); } break; - case dbiScale: { + case dbiScaleOld: { qint32 v; stream >> v; if (!_checkStreamStatus(stream)) return false; - DBIScale s = cRealScale(); - switch (v) { - case dbisAuto: s = dbisAuto; break; - case dbisOne: s = dbisOne; break; - case dbisOneAndQuarter: s = dbisOneAndQuarter; break; - case dbisOneAndHalf: s = dbisOneAndHalf; break; - case dbisTwo: s = dbisTwo; break; - } - if (cRetina()) s = dbisOne; + const auto s = [&] { + if (cRetina()) { + return 100; + } + + constexpr auto kAuto = 0; + constexpr auto kOne = 1; + constexpr auto kOneAndQuarter = 2; + constexpr auto kOneAndHalf = 3; + constexpr auto kTwo = 4; + switch (v) { + case kAuto: return kInterfaceScaleAuto; + case kOne: return 100; + case kOneAndQuarter: return 125; + case kOneAndHalf: return 150; + case kTwo: return 200; + } + return cRealScale(); + }(); cSetConfigScale(s); cSetRealScale(s); } break; + case dbiScalePercent: { + qint32 v; + stream >> v; + if (!_checkStreamStatus(stream)) return false; + + if (!v || (v >= 100 && v <= (cRetina() ? 150 : 300) && !(v % 25))) { + cSetConfigScale(v); + cSetRealScale(v); + } + } break; + case dbiLangOld: { qint32 v; stream >> v; @@ -2555,7 +2577,7 @@ void writeSettings() { data.stream << quint32(dbiSeenTrayTooltip) << qint32(cSeenTrayTooltip()); data.stream << quint32(dbiAutoUpdate) << qint32(cAutoUpdate()); data.stream << quint32(dbiLastUpdateCheck) << qint32(cLastUpdateCheck()); - data.stream << quint32(dbiScale) << qint32(cConfigScale()); + data.stream << quint32(dbiScalePercent) << qint32(cConfigScale()); data.stream << quint32(dbiDcOptions) << dcOptionsSerialized; data.stream << quint32(dbiLoggedPhoneNumber) << cLoggedPhoneNumber(); data.stream << quint32(dbiTxtDomainString) << Global::TxtDomainString(); diff --git a/Telegram/SourceFiles/storage/storage_media_prepare.cpp b/Telegram/SourceFiles/storage/storage_media_prepare.cpp index cd19cd3935..f4aa6df2ce 100644 --- a/Telegram/SourceFiles/storage/storage_media_prepare.cpp +++ b/Telegram/SourceFiles/storage/storage_media_prepare.cpp @@ -81,7 +81,7 @@ bool PrepareAlbumMediaIsWaiting( if (ValidPhotoForAlbum(*image)) { file.shownDimensions = PrepareShownDimensions(image->data); file.preview = Images::prepareOpaque(image->data.scaledToWidth( - std::min(previewWidth, convertScale(image->data.width())) + std::min(previewWidth, ConvertScale(image->data.width())) * cIntRetinaFactor(), Qt::SmoothTransformation)); Assert(!file.preview.isNull()); diff --git a/Telegram/SourceFiles/ui/emoji_config.cpp b/Telegram/SourceFiles/ui/emoji_config.cpp index 66f2ecf6c5..366a282666 100644 --- a/Telegram/SourceFiles/ui/emoji_config.cpp +++ b/Telegram/SourceFiles/ui/emoji_config.cpp @@ -40,7 +40,6 @@ private: }; -auto Scale = -1.; auto SizeNormal = -1; auto SizeLarge = -1; auto SpritesCount = -1; @@ -292,20 +291,8 @@ void ClearUniversalChecked() { void Init() { internal::Init(); - Scale = [] { - if (cRetina()) { - return 2.; - } - switch (cScale()) { - case dbisOne: return 1.; - case dbisOneAndQuarter: return 1.25; - case dbisOneAndHalf: return 1.5; - case dbisTwo: return 2.; - } - Unexpected("cScale() in Ui::Emoji::Init."); - }(); - SizeNormal = int(std::round(Scale * 18)); - SizeLarge = int(std::round(Scale * 18 * 4 / 3.)); + SizeNormal = ConvertScale(18) * cIntRetinaFactor(); + SizeLarge = int(ConvertScale(18 * 4 / 3.)) * cIntRetinaFactor(); const auto count = internal::FullCount(); const auto persprite = kImagesPerRow * kImageRowsPerSprite; SpritesCount = (count / persprite) + ((count % persprite) ? 1 : 0); @@ -334,12 +321,6 @@ int GetSizeLarge() { return SizeLarge; } -float64 GetScale() { - Expects(Scale > 0.); - - return Scale; -} - int One::variantsCount() const { return hasVariants() ? 5 : 0; } diff --git a/Telegram/SourceFiles/ui/emoji_config.h b/Telegram/SourceFiles/ui/emoji_config.h index fa9fc71d45..c277b8f2ad 100644 --- a/Telegram/SourceFiles/ui/emoji_config.h +++ b/Telegram/SourceFiles/ui/emoji_config.h @@ -20,7 +20,6 @@ void Clear(); int GetSizeNormal(); int GetSizeLarge(); -float64 GetScale(); class One { struct CreationTag { diff --git a/Telegram/SourceFiles/ui/style/style_core.cpp b/Telegram/SourceFiles/ui/style/style_core.cpp index a887a5855e..9b3c99a8d4 100644 --- a/Telegram/SourceFiles/ui/style/style_core.cpp +++ b/Telegram/SourceFiles/ui/style/style_core.cpp @@ -48,7 +48,7 @@ void unregisterModule(ModuleBase *module) { void startManager() { if (cRetina()) { - cSetRealScale(dbisOne); + cSetRealScale(100); } internal::registerFontFamily(qsl("Open Sans")); diff --git a/Telegram/SourceFiles/ui/style/style_core_icon.cpp b/Telegram/SourceFiles/ui/style/style_core_icon.cpp index a2d57943f3..8216418528 100644 --- a/Telegram/SourceFiles/ui/style/style_core_icon.cpp +++ b/Telegram/SourceFiles/ui/style/style_core_icon.cpp @@ -22,14 +22,7 @@ NeverFreedPointer iconMasks; NeverFreedPointer iconPixmaps; NeverFreedPointer iconData; -inline int pxAdjust(int value, int scale) { - if (value < 0) { - return -pxAdjust(-value, scale); - } - return qFloor((value * scale / 4.) + 0.1); -} - -QImage createIconMask(const IconMask *mask, DBIScale scale) { +QImage createIconMask(const IconMask *mask, int scale) { auto maskImage = QImage::fromData(mask->data(), mask->size(), "PNG"); maskImage.setDevicePixelRatio(cRetinaFactor()); Assert(!maskImage.isNull()); @@ -37,26 +30,31 @@ QImage createIconMask(const IconMask *mask, DBIScale scale) { // images are layouted like this: // 100x 200x // 300x + if (cRetina()) { + scale *= 2; + } const auto width = maskImage.width() / 3; const auto height = maskImage.height() / 5; + const auto one = QRect(0, 0, width, height); const auto two = QRect(width, 0, width * 2, height * 2); - if (cRetina() || scale == dbisTwo) { + const auto three = QRect(0, height * 2, width * 3, height * 3); + if (scale == 100) { + return maskImage.copy(one); + } else if (scale == 200) { return maskImage.copy(two); - } else if (scale == dbisOne) { - return maskImage.copy(QRect(0, 0, width, height)); + } else if (scale == 300) { + return maskImage.copy(three); } - const auto width125 = pxAdjust(width, 5); - const auto height125 = pxAdjust(height, 5); - const auto width150 = pxAdjust(width, 6); - const auto height150 = pxAdjust(height, 6); - return maskImage.copy(two).scaled( - (scale == dbisOneAndQuarter) ? width125 : width150, - (scale == dbisOneAndQuarter) ? height125 : height150, + return maskImage.copy( + (scale > 200) ? three : two + ).scaled( + ConvertScale(width, scale), + ConvertScale(height, scale), Qt::IgnoreAspectRatio, Qt::SmoothTransformation); } -QSize readGeneratedSize(const IconMask *mask, DBIScale scale) { +QSize readGeneratedSize(const IconMask *mask, int scale) { auto data = mask->data(); auto size = mask->size(); @@ -76,12 +74,9 @@ QSize readGeneratedSize(const IconMask *mask, DBIScale scale) { stream >> width >> height; Assert(stream.status() == QDataStream::Ok); - switch (scale) { - case dbisOne: return QSize(width, height); - case dbisOneAndQuarter: return QSize(pxAdjust(width, 5), pxAdjust(height, 5)); - case dbisOneAndHalf: return QSize(pxAdjust(width, 6), pxAdjust(height, 6)); - case dbisTwo: return QSize(width * 2, height * 2); - } + return QSize( + ConvertScale(width, scale), + ConvertScale(height, scale)); } else { Unexpected("Bad data in generated icon!"); } @@ -219,8 +214,8 @@ void MonoIcon::fill( } } -QImage MonoIcon::instance(QColor colorOverride, DBIScale scale) const { - if (scale == dbisAuto) { +QImage MonoIcon::instance(QColor colorOverride, int scale) const { + if (scale == kInterfaceScaleAuto) { ensureLoaded(); auto result = QImage(size() * cIntRetinaFactor(), QImage::Format_ARGB32_Premultiplied); result.setDevicePixelRatio(cRetinaFactor()); @@ -311,7 +306,7 @@ void IconData::fill(QPainter &p, const QRect &rect, QColor colorOverride) const } } -QImage IconData::instance(QColor colorOverride, DBIScale scale) const { +QImage IconData::instance(QColor colorOverride, int scale) const { Assert(_parts.size() == 1); auto &part = _parts[0]; Assert(part.offset() == QPoint(0, 0)); diff --git a/Telegram/SourceFiles/ui/style/style_core_icon.h b/Telegram/SourceFiles/ui/style/style_core_icon.h index e7ea1bc82f..43b0dce50c 100644 --- a/Telegram/SourceFiles/ui/style/style_core_icon.h +++ b/Telegram/SourceFiles/ui/style/style_core_icon.h @@ -58,7 +58,7 @@ public: void paint(QPainter &p, const QPoint &pos, int outerw, const style::palette &paletteOverride) const; void fill(QPainter &p, const QRect &rect, const style::palette &paletteOverride) const; - QImage instance(QColor colorOverride, DBIScale scale) const; + QImage instance(QColor colorOverride, int scale) const; ~MonoIcon() { } @@ -116,7 +116,7 @@ public: } void fill(QPainter &p, const QRect &rect, const style::palette &paletteOverride) const; - QImage instance(QColor colorOverride, DBIScale scale) const; + QImage instance(QColor colorOverride, int scale) const; int width() const; int height() const; @@ -205,7 +205,7 @@ public: return _data->fill(p, rect, colorOverride); } - QImage instance(QColor colorOverride, DBIScale scale = dbisAuto) const { + QImage instance(QColor colorOverride, int scale = kInterfaceScaleAuto) const { return _data->instance(colorOverride, scale); } diff --git a/Telegram/SourceFiles/window/layer_widget.cpp b/Telegram/SourceFiles/window/layer_widget.cpp index e7d2aa523f..d5aa95c1e5 100644 --- a/Telegram/SourceFiles/window/layer_widget.cpp +++ b/Telegram/SourceFiles/window/layer_widget.cpp @@ -988,7 +988,7 @@ QSize MediaPreviewWidget::currentDimensions() const { box = QSize(2 * st::maxStickerSize, 2 * st::maxStickerSize); } } - result = QSize(qMax(convertScale(result.width()), 1), qMax(convertScale(result.height()), 1)); + result = QSize(qMax(ConvertScale(result.width()), 1), qMax(ConvertScale(result.height()), 1)); if (result.width() > box.width()) { result.setHeight(qMax((box.width() * result.height()) / result.width(), 1)); result.setWidth(box.width()); diff --git a/Telegram/SourceFiles/window/themes/window_theme.cpp b/Telegram/SourceFiles/window/themes/window_theme.cpp index aa5063cc6b..5040a11519 100644 --- a/Telegram/SourceFiles/window/themes/window_theme.cpp +++ b/Telegram/SourceFiles/window/themes/window_theme.cpp @@ -411,8 +411,8 @@ void ChatBackground::setImage(int32 id, QImage &&image) { image.load(qsl(":/gui/art/bg_initial.jpg")); if (cRetina()) { image = image.scaledToWidth(image.width() * 2, Qt::SmoothTransformation); - } else if (cScale() != dbisOne) { - image = image.scaledToWidth(convertScale(image.width()), Qt::SmoothTransformation); + } else if (cScale() != 100) { + image = image.scaledToWidth(ConvertScale(image.width()), Qt::SmoothTransformation); } } else if (_id == kDefaultBackground || image.isNull()) { _id = kDefaultBackground; diff --git a/Telegram/SourceFiles/window/themes/window_theme_preview.cpp b/Telegram/SourceFiles/window/themes/window_theme_preview.cpp index 322af8422c..a18bbff8bd 100644 --- a/Telegram/SourceFiles/window/themes/window_theme_preview.cpp +++ b/Telegram/SourceFiles/window/themes/window_theme_preview.cpp @@ -278,8 +278,8 @@ void Generator::addDateBubble(QString date) { void Generator::addPhotoBubble(QString image, QString caption, QString date, Status status) { Bubble bubble; bubble.photo.load(image); - bubble.photoWidth = convertScale(bubble.photo.width() / 2); - bubble.photoHeight = convertScale(bubble.photo.height() / 2); + bubble.photoWidth = ConvertScale(bubble.photo.width() / 2); + bubble.photoHeight = ConvertScale(bubble.photo.height() / 2); auto skipBlock = computeSkipBlock(status, date); bubble.text.setRichText(st::messageTextStyle, caption + textcmdSkipBlock(skipBlock.width(), skipBlock.height()), Ui::ItemTextDefaultOptions()); @@ -490,12 +490,7 @@ void Generator::paintComposeArea() { auto inner = QRect(QPoint(attachEmojiLeft + (st::historyAttachEmoji.width - st::historyEmojiCircle.width()) / 2, controlsTop + st::historyEmojiCircleTop), st::historyEmojiCircle); _p->drawEllipse(inner); - auto fakeMargin = 0; - switch (cScale()) { - case dbisOneAndQuarter: fakeMargin = 1; break; - case dbisOneAndHalf: fakeMargin = 2; break; - case dbisTwo: fakeMargin = 4; break; - } + const auto fakeMargin = (cScale() - 100) / 25; auto fieldLeft = _composeArea.x() + st::historyAttach.width + fakeMargin; auto fieldTop = _composeArea.y() + _composeArea.height() - st::historyAttach.height + st::historySendPadding + fakeMargin;