mirror of
https://github.com/OpenMW/openmw.git
synced 2025-01-21 12:53:53 +00:00
Merge branch 'rework_resolutions' into 'master'
Rework resolution selection Closes #7709 See merge request OpenMW/openmw!3622
This commit is contained in:
commit
d230c89a56
7 changed files with 103 additions and 53 deletions
|
@ -133,6 +133,7 @@
|
||||||
Feature #7625: Add some missing console error outputs
|
Feature #7625: Add some missing console error outputs
|
||||||
Feature #7634: Support NiParticleBomb
|
Feature #7634: Support NiParticleBomb
|
||||||
Feature #7652: Sort inactive post processing shaders list properly
|
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 #5896: Do not use deprecated MyGUI properties
|
||||||
Task #7113: Move from std::atoi to std::from_char
|
Task #7113: Move from std::atoi to std::from_char
|
||||||
Task #7117: Replace boost::scoped_array with std::vector
|
Task #7117: Replace boost::scoped_array with std::vector
|
||||||
|
|
|
@ -2,6 +2,7 @@
|
||||||
|
|
||||||
#include "sdlinit.hpp"
|
#include "sdlinit.hpp"
|
||||||
|
|
||||||
|
#include <components/misc/display.hpp>
|
||||||
#include <components/settings/values.hpp>
|
#include <components/settings/values.hpp>
|
||||||
|
|
||||||
#include <QMessageBox>
|
#include <QMessageBox>
|
||||||
|
@ -16,22 +17,6 @@
|
||||||
#include <SDL_video.h>
|
#include <SDL_video.h>
|
||||||
|
|
||||||
#include <array>
|
#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)
|
Launcher::GraphicsPage::GraphicsPage(QWidget* parent)
|
||||||
: QWidget(parent)
|
: QWidget(parent)
|
||||||
|
@ -117,7 +102,7 @@ bool Launcher::GraphicsPage::loadSettings()
|
||||||
|
|
||||||
const int width = Settings::video().mResolutionX;
|
const int width = Settings::video().mResolutionX;
|
||||||
const int height = Settings::video().mResolutionY;
|
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);
|
screenComboBox->setCurrentIndex(Settings::video().mScreen);
|
||||||
|
|
||||||
int resIndex = resolutionComboBox->findText(resolution, Qt::MatchStartsWith);
|
int resIndex = resolutionComboBox->findText(resolution, Qt::MatchStartsWith);
|
||||||
|
@ -204,7 +189,7 @@ void Launcher::GraphicsPage::saveSettings()
|
||||||
int cHeight = 0;
|
int cHeight = 0;
|
||||||
if (standardRadioButton->isChecked())
|
if (standardRadioButton->isChecked())
|
||||||
{
|
{
|
||||||
QRegularExpression resolutionRe("^(\\d+) x (\\d+)");
|
QRegularExpression resolutionRe("^(\\d+) × (\\d+)");
|
||||||
QRegularExpressionMatch match = resolutionRe.match(resolutionComboBox->currentText().simplified());
|
QRegularExpressionMatch match = resolutionRe.match(resolutionComboBox->currentText().simplified());
|
||||||
if (match.hasMatch())
|
if (match.hasMatch())
|
||||||
{
|
{
|
||||||
|
@ -304,19 +289,8 @@ QStringList Launcher::GraphicsPage::getAvailableResolutions(int screen)
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
QString resolution = QString::number(mode.w) + QString(" x ") + QString::number(mode.h);
|
auto str = Misc::getResolutionText(mode.w, mode.h, "%i × %i (%i:%i)");
|
||||||
|
result.append(QString(str.c_str()));
|
||||||
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);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
result.removeDuplicates();
|
result.removeDuplicates();
|
||||||
|
|
|
@ -2,7 +2,6 @@
|
||||||
|
|
||||||
#include <array>
|
#include <array>
|
||||||
#include <iomanip>
|
#include <iomanip>
|
||||||
#include <numeric>
|
|
||||||
#include <regex>
|
#include <regex>
|
||||||
|
|
||||||
#include <unicode/locid.h>
|
#include <unicode/locid.h>
|
||||||
|
@ -21,6 +20,7 @@
|
||||||
#include <components/debug/debuglog.hpp>
|
#include <components/debug/debuglog.hpp>
|
||||||
#include <components/lua_ui/scriptsettings.hpp>
|
#include <components/lua_ui/scriptsettings.hpp>
|
||||||
#include <components/misc/constants.hpp>
|
#include <components/misc/constants.hpp>
|
||||||
|
#include <components/misc/display.hpp>
|
||||||
#include <components/misc/pathhelpers.hpp>
|
#include <components/misc/pathhelpers.hpp>
|
||||||
#include <components/misc/strings/algorithm.hpp>
|
#include <components/misc/strings/algorithm.hpp>
|
||||||
#include <components/misc/strings/format.hpp>
|
#include <components/misc/strings/format.hpp>
|
||||||
|
@ -93,20 +93,6 @@ namespace
|
||||||
return left.first > right.first;
|
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 checkButtonType = "CheckButton";
|
||||||
const std::string_view sliderType = "Slider";
|
const std::string_view sliderType = "Slider";
|
||||||
|
|
||||||
|
@ -366,11 +352,7 @@ namespace MWGui
|
||||||
std::sort(resolutions.begin(), resolutions.end(), sortResolutions);
|
std::sort(resolutions.begin(), resolutions.end(), sortResolutions);
|
||||||
for (std::pair<int, int>& resolution : resolutions)
|
for (std::pair<int, int>& resolution : resolutions)
|
||||||
{
|
{
|
||||||
std::string str
|
std::string str = Misc::getResolutionText(resolution.first, resolution.second, "%i x %i (%i:%i)");
|
||||||
= 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 + ")";
|
|
||||||
|
|
||||||
if (mResolutionList->findItemIndexWith(str) == MyGUI::ITEM_NONE)
|
if (mResolutionList->findItemIndexWith(str) == MyGUI::ITEM_NONE)
|
||||||
mResolutionList->addItem(str);
|
mResolutionList->addItem(str);
|
||||||
|
|
|
@ -273,7 +273,7 @@ add_component_dir (esm4
|
||||||
)
|
)
|
||||||
|
|
||||||
add_component_dir (misc
|
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
|
guarded math mathutil messageformatparser notnullptr objectpool osguservalues progressreporter resourcehelpers rng
|
||||||
strongtypedef thread timeconvert timer tuplehelpers tuplemeta utf8stream weakcache windows
|
strongtypedef thread timeconvert timer tuplehelpers tuplemeta utf8stream weakcache windows
|
||||||
)
|
)
|
||||||
|
|
82
components/misc/display.cpp
Normal file
82
components/misc/display.cpp
Normal file
|
@ -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, const std::string& format)
|
||||||
|
{
|
||||||
|
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(format, x, y, xaspect, yaspect);
|
||||||
|
}
|
||||||
|
}
|
11
components/misc/display.hpp
Normal file
11
components/misc/display.hpp
Normal file
|
@ -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, const std::string& format);
|
||||||
|
}
|
||||||
|
|
||||||
|
#endif
|
|
@ -22,7 +22,7 @@
|
||||||
</attribute>
|
</attribute>
|
||||||
<layout class="QHBoxLayout" name="horizontalLayout_2">
|
<layout class="QHBoxLayout" name="horizontalLayout_2">
|
||||||
<item>
|
<item>
|
||||||
<layout class="QGridLayout" name="gridLayout_4" columnstretch="1,0">
|
<layout class="QGridLayout" name="gridLayout_4" columnstretch="1,1">
|
||||||
<item row="5" column="0">
|
<item row="5" column="0">
|
||||||
<widget class="QLabel" name="screenLabel">
|
<widget class="QLabel" name="screenLabel">
|
||||||
<property name="text">
|
<property name="text">
|
||||||
|
|
Loading…
Reference in a new issue