From 81a6a7cd2f51ea3c64809e844fb0df6f02f736e2 Mon Sep 17 00:00:00 2001 From: Andrei Kortunov Date: Tue, 28 Nov 2023 18:03:04 +0400 Subject: [PATCH 1/2] Rework resolution selection (feature 7709) --- CHANGELOG.md | 1 + apps/launcher/graphicspage.cpp | 32 +---------- apps/openmw/mwgui/settingswindow.cpp | 22 +------- components/CMakeLists.txt | 2 +- components/misc/display.cpp | 82 ++++++++++++++++++++++++++++ components/misc/display.hpp | 11 ++++ files/ui/graphicspage.ui | 2 +- 7 files changed, 101 insertions(+), 51 deletions(-) create mode 100644 components/misc/display.cpp create mode 100644 components/misc/display.hpp diff --git a/CHANGELOG.md b/CHANGELOG.md index 6ab1c0213a..30ad2bae6c 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -133,6 +133,7 @@ Feature #7625: Add some missing console error outputs Feature #7634: Support NiParticleBomb Feature #7652: Sort inactive post processing shaders list properly + Feature #7709: Improve resolution selection in Launcher Task #5896: Do not use deprecated MyGUI properties Task #7113: Move from std::atoi to std::from_char Task #7117: Replace boost::scoped_array with std::vector diff --git a/apps/launcher/graphicspage.cpp b/apps/launcher/graphicspage.cpp index cf2f00fca4..832cb0ef8f 100644 --- a/apps/launcher/graphicspage.cpp +++ b/apps/launcher/graphicspage.cpp @@ -2,6 +2,7 @@ #include "sdlinit.hpp" +#include #include #include @@ -16,22 +17,6 @@ #include #include -#include - -QString getAspect(int x, int y) -{ - int gcd = std::gcd(x, y); - if (gcd == 0) - return QString(); - - int xaspect = x / gcd; - int yaspect = y / gcd; - // special case: 8 : 5 is usually referred to as 16:10 - if (xaspect == 8 && yaspect == 5) - return QString("16:10"); - - return QString(QString::number(xaspect) + ":" + QString::number(yaspect)); -} Launcher::GraphicsPage::GraphicsPage(QWidget* parent) : QWidget(parent) @@ -304,19 +289,8 @@ QStringList Launcher::GraphicsPage::getAvailableResolutions(int screen) return result; } - QString resolution = QString::number(mode.w) + QString(" x ") + QString::number(mode.h); - - QString aspect = getAspect(mode.w, mode.h); - if (aspect == QLatin1String("16:9") || aspect == QLatin1String("16:10")) - { - resolution.append(tr(" (Wide ") + aspect + ")"); - } - else if (aspect == QLatin1String("4:3")) - { - resolution.append(tr(" (Standard 4:3)")); - } - - result.append(resolution); + auto str = Misc::getResolutionText(mode.w, mode.h); + result.append(QString(str.c_str())); } result.removeDuplicates(); diff --git a/apps/openmw/mwgui/settingswindow.cpp b/apps/openmw/mwgui/settingswindow.cpp index 696596a46f..2d9a9d8292 100644 --- a/apps/openmw/mwgui/settingswindow.cpp +++ b/apps/openmw/mwgui/settingswindow.cpp @@ -2,7 +2,6 @@ #include #include -#include #include #include @@ -21,6 +20,7 @@ #include #include #include +#include #include #include #include @@ -93,20 +93,6 @@ namespace return left.first > right.first; } - std::string getAspect(int x, int y) - { - int gcd = std::gcd(x, y); - if (gcd == 0) - return std::string(); - - int xaspect = x / gcd; - int yaspect = y / gcd; - // special case: 8 : 5 is usually referred to as 16:10 - if (xaspect == 8 && yaspect == 5) - return "16 : 10"; - return MyGUI::utility::toString(xaspect) + " : " + MyGUI::utility::toString(yaspect); - } - const std::string_view checkButtonType = "CheckButton"; const std::string_view sliderType = "Slider"; @@ -366,11 +352,7 @@ namespace MWGui std::sort(resolutions.begin(), resolutions.end(), sortResolutions); for (std::pair& resolution : resolutions) { - std::string str - = MyGUI::utility::toString(resolution.first) + " x " + MyGUI::utility::toString(resolution.second); - std::string aspect = getAspect(resolution.first, resolution.second); - if (!aspect.empty()) - str = str + " (" + aspect + ")"; + std::string str = Misc::getResolutionText(resolution.first, resolution.second); if (mResolutionList->findItemIndexWith(str) == MyGUI::ITEM_NONE) mResolutionList->addItem(str); diff --git a/components/CMakeLists.txt b/components/CMakeLists.txt index c9c74957ec..7e3c7aea23 100644 --- a/components/CMakeLists.txt +++ b/components/CMakeLists.txt @@ -273,7 +273,7 @@ add_component_dir (esm4 ) add_component_dir (misc - barrier budgetmeasurement color compression constants convert coordinateconverter endianness float16 frameratelimiter + barrier budgetmeasurement color compression constants convert coordinateconverter display endianness float16 frameratelimiter guarded math mathutil messageformatparser notnullptr objectpool osguservalues progressreporter resourcehelpers rng strongtypedef thread timeconvert timer tuplehelpers tuplemeta utf8stream weakcache windows ) diff --git a/components/misc/display.cpp b/components/misc/display.cpp new file mode 100644 index 0000000000..7570914483 --- /dev/null +++ b/components/misc/display.cpp @@ -0,0 +1,82 @@ +#include "display.hpp" + +#include +#include + +#include + +namespace Misc +{ + std::string getResolutionText(int x, int y) + { + int gcd = std::gcd(x, y); + if (gcd == 0) + return std::string(); + + int xaspect = x / gcd; + int yaspect = y / gcd; + + // It is unclear how to handle 90-degree screen rotation properly. + // So far only swap aspects, apply custom formatting logic and then swap back. + // As result, 1920 x 1200 is displayed as "1200 x 1920 (10:16)" + bool flipped = false; + if (yaspect > xaspect) + { + flipped = true; + std::swap(xaspect, yaspect); + } + + // 683:384 (used in 1366 x 768) is usually referred as 16:9 + if (xaspect == 683 && yaspect == 384) + { + xaspect = 16; + yaspect = 9; + } + // 85:48 (used in 1360 x 768) is usually referred as 16:9 + else if (xaspect == 85 && yaspect == 48) + { + xaspect = 16; + yaspect = 9; + } + // 49:36 (used in 1176 x 864) is usually referred as 4:3 + else if (xaspect == 49 && yaspect == 36) + { + xaspect = 4; + yaspect = 3; + } + // 39:29 (used in 624 x 484) is usually referred as 4:3 + else if (xaspect == 39 && yaspect == 29) + { + xaspect = 4; + yaspect = 3; + } + // 8:5 (used in 1440 x 900) is usually referred as 16:10 + else if (xaspect == 8 && yaspect == 5) + { + xaspect = 16; + yaspect = 10; + } + // 5:3 (used in 1280 x 768) is usually referred as 15:9 + else if (xaspect == 5 && yaspect == 3) + { + xaspect = 15; + yaspect = 9; + } + else + { + // everything between 21:9 and 22:9 + // is usually referred as 21:9 + float ratio = static_cast(xaspect) / yaspect; + if (ratio >= 21 / 9.f && ratio < 22 / 9.f) + { + xaspect = 21; + yaspect = 9; + } + } + + if (flipped) + std::swap(xaspect, yaspect); + + return Misc::StringUtils::format("%i x %i (%i:%i)", x, y, xaspect, yaspect); + } +} diff --git a/components/misc/display.hpp b/components/misc/display.hpp new file mode 100644 index 0000000000..6f60a48cda --- /dev/null +++ b/components/misc/display.hpp @@ -0,0 +1,11 @@ +#ifndef OPENMW_COMPONENTS_MISC_DISPLAY_H +#define OPENMW_COMPONENTS_MISC_DISPLAY_H + +#include + +namespace Misc +{ + std::string getResolutionText(int x, int y); +} + +#endif diff --git a/files/ui/graphicspage.ui b/files/ui/graphicspage.ui index bb900ccb2d..70ab1f0728 100644 --- a/files/ui/graphicspage.ui +++ b/files/ui/graphicspage.ui @@ -22,7 +22,7 @@ - + From 623510c073e5f2034b32f200d5752a1549288030 Mon Sep 17 00:00:00 2001 From: Andrei Kortunov Date: Tue, 28 Nov 2023 22:47:27 +0400 Subject: [PATCH 2/2] Use multiplication character in the launcher instead of 'x' --- apps/launcher/graphicspage.cpp | 6 +++--- apps/openmw/mwgui/settingswindow.cpp | 2 +- components/misc/display.cpp | 4 ++-- components/misc/display.hpp | 2 +- 4 files changed, 7 insertions(+), 7 deletions(-) diff --git a/apps/launcher/graphicspage.cpp b/apps/launcher/graphicspage.cpp index 832cb0ef8f..84d5049d6c 100644 --- a/apps/launcher/graphicspage.cpp +++ b/apps/launcher/graphicspage.cpp @@ -102,7 +102,7 @@ bool Launcher::GraphicsPage::loadSettings() const int width = Settings::video().mResolutionX; const int height = Settings::video().mResolutionY; - QString resolution = QString::number(width) + QString(" x ") + QString::number(height); + QString resolution = QString::number(width) + QString(" × ") + QString::number(height); screenComboBox->setCurrentIndex(Settings::video().mScreen); int resIndex = resolutionComboBox->findText(resolution, Qt::MatchStartsWith); @@ -189,7 +189,7 @@ void Launcher::GraphicsPage::saveSettings() int cHeight = 0; if (standardRadioButton->isChecked()) { - QRegularExpression resolutionRe("^(\\d+) x (\\d+)"); + QRegularExpression resolutionRe("^(\\d+) × (\\d+)"); QRegularExpressionMatch match = resolutionRe.match(resolutionComboBox->currentText().simplified()); if (match.hasMatch()) { @@ -289,7 +289,7 @@ QStringList Launcher::GraphicsPage::getAvailableResolutions(int screen) return result; } - auto str = Misc::getResolutionText(mode.w, mode.h); + auto str = Misc::getResolutionText(mode.w, mode.h, "%i × %i (%i:%i)"); result.append(QString(str.c_str())); } diff --git a/apps/openmw/mwgui/settingswindow.cpp b/apps/openmw/mwgui/settingswindow.cpp index 2d9a9d8292..1060b3a20f 100644 --- a/apps/openmw/mwgui/settingswindow.cpp +++ b/apps/openmw/mwgui/settingswindow.cpp @@ -352,7 +352,7 @@ namespace MWGui std::sort(resolutions.begin(), resolutions.end(), sortResolutions); for (std::pair& resolution : resolutions) { - std::string str = Misc::getResolutionText(resolution.first, resolution.second); + std::string str = Misc::getResolutionText(resolution.first, resolution.second, "%i x %i (%i:%i)"); if (mResolutionList->findItemIndexWith(str) == MyGUI::ITEM_NONE) mResolutionList->addItem(str); diff --git a/components/misc/display.cpp b/components/misc/display.cpp index 7570914483..ee78b2a0c9 100644 --- a/components/misc/display.cpp +++ b/components/misc/display.cpp @@ -7,7 +7,7 @@ namespace Misc { - std::string getResolutionText(int x, int y) + std::string getResolutionText(int x, int y, const std::string& format) { int gcd = std::gcd(x, y); if (gcd == 0) @@ -77,6 +77,6 @@ namespace Misc if (flipped) std::swap(xaspect, yaspect); - return Misc::StringUtils::format("%i x %i (%i:%i)", x, y, xaspect, yaspect); + return Misc::StringUtils::format(format, x, y, xaspect, yaspect); } } diff --git a/components/misc/display.hpp b/components/misc/display.hpp index 6f60a48cda..82037661c8 100644 --- a/components/misc/display.hpp +++ b/components/misc/display.hpp @@ -5,7 +5,7 @@ namespace Misc { - std::string getResolutionText(int x, int y); + std::string getResolutionText(int x, int y, const std::string& format); } #endif