Rework resolution selection (feature 7709)

macos_ci_fix
Andrei Kortunov 6 months ago
parent b280f1b1d0
commit 81a6a7cd2f

@ -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

@ -2,6 +2,7 @@
#include "sdlinit.hpp"
#include <components/misc/display.hpp>
#include <components/settings/values.hpp>
#include <QMessageBox>
@ -16,22 +17,6 @@
#include <SDL_video.h>
#include <array>
#include <numeric>
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();

@ -2,7 +2,6 @@
#include <array>
#include <iomanip>
#include <numeric>
#include <regex>
#include <unicode/locid.h>
@ -21,6 +20,7 @@
#include <components/debug/debuglog.hpp>
#include <components/lua_ui/scriptsettings.hpp>
#include <components/misc/constants.hpp>
#include <components/misc/display.hpp>
#include <components/misc/pathhelpers.hpp>
#include <components/misc/strings/algorithm.hpp>
#include <components/misc/strings/format.hpp>
@ -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<int, int>& 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);

@ -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
)

@ -0,0 +1,82 @@
#include "display.hpp"
#include <numeric>
#include <string>
#include <components/misc/strings/format.hpp>
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<float>(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);
}
}

@ -0,0 +1,11 @@
#ifndef OPENMW_COMPONENTS_MISC_DISPLAY_H
#define OPENMW_COMPONENTS_MISC_DISPLAY_H
#include <string>
namespace Misc
{
std::string getResolutionText(int x, int y);
}
#endif

@ -22,7 +22,7 @@
</attribute>
<layout class="QHBoxLayout" name="horizontalLayout_2">
<item>
<layout class="QGridLayout" name="gridLayout_4" columnstretch="1,0">
<layout class="QGridLayout" name="gridLayout_4" columnstretch="1,1">
<item row="5" column="0">
<widget class="QLabel" name="screenLabel">
<property name="text">

Loading…
Cancel
Save