mirror of
https://gitlab.com/OpenMW/openmw.git
synced 2025-09-22 03:13:15 -04:00
Replace StringUtils::format in components/misc
This commit is contained in:
parent
9cce6bad68
commit
2321086876
@ -201,7 +201,7 @@ QStringList Launcher::GraphicsPage::getAvailableResolutions(int screen)
|
||||
return result;
|
||||
}
|
||||
|
||||
auto str = Misc::getResolutionText(mode.w, mode.h, "%i × %i (%i:%i)");
|
||||
auto str = Misc::getResolutionText(mode.w, mode.h);
|
||||
result.append(QString(str.c_str()));
|
||||
}
|
||||
|
||||
|
@ -85,17 +85,6 @@ namespace
|
||||
return MyGUI::LanguageManager::getInstance().replaceTags(result);
|
||||
}
|
||||
|
||||
void parseResolution(int& x, int& y, const std::string& str)
|
||||
{
|
||||
std::vector<std::string> split;
|
||||
Misc::StringUtils::split(str, split, "@(x");
|
||||
assert(split.size() >= 2);
|
||||
Misc::StringUtils::trim(split[0]);
|
||||
Misc::StringUtils::trim(split[1]);
|
||||
x = MyGUI::utility::parseInt(split[0]);
|
||||
y = MyGUI::utility::parseInt(split[1]);
|
||||
}
|
||||
|
||||
bool sortResolutions(std::pair<int, int> left, std::pair<int, int> right)
|
||||
{
|
||||
if (left.first == right.first)
|
||||
@ -368,10 +357,10 @@ namespace MWGui
|
||||
std::sort(resolutions.begin(), resolutions.end(), sortResolutions);
|
||||
for (std::pair<int, int>& resolution : resolutions)
|
||||
{
|
||||
std::string str = Misc::getResolutionText(resolution.first, resolution.second, "%i x %i (%i:%i)");
|
||||
std::string str = Misc::getResolutionText(resolution.first, resolution.second);
|
||||
|
||||
if (mResolutionList->findItemIndexWith(str) == MyGUI::ITEM_NONE)
|
||||
mResolutionList->addItem(str);
|
||||
mResolutionList->addItem(str, resolution);
|
||||
}
|
||||
highlightCurrentResolution();
|
||||
|
||||
@ -493,14 +482,14 @@ namespace MWGui
|
||||
|
||||
void SettingsWindow::onResolutionAccept()
|
||||
{
|
||||
const std::string& resStr = mResolutionList->getItemNameAt(mResolutionList->getIndexSelected());
|
||||
int resX, resY;
|
||||
parseResolution(resX, resY, resStr);
|
||||
auto resultion = mResolutionList->getItemDataAt<std::pair<int, int>>(mResolutionList->getIndexSelected());
|
||||
if (resultion)
|
||||
{
|
||||
Settings::video().mResolutionX.set(resultion->first);
|
||||
Settings::video().mResolutionY.set(resultion->second);
|
||||
|
||||
Settings::video().mResolutionX.set(resX);
|
||||
Settings::video().mResolutionY.set(resY);
|
||||
|
||||
apply();
|
||||
apply();
|
||||
}
|
||||
}
|
||||
|
||||
void SettingsWindow::onResolutionCancel()
|
||||
@ -517,10 +506,8 @@ namespace MWGui
|
||||
|
||||
for (size_t i = 0; i < mResolutionList->getItemCount(); ++i)
|
||||
{
|
||||
int resX, resY;
|
||||
parseResolution(resX, resY, mResolutionList->getItemNameAt(i));
|
||||
|
||||
if (resX == currentX && resY == currentY)
|
||||
auto resultion = mResolutionList->getItemDataAt<std::pair<int, int>>(i);
|
||||
if (resultion && resultion->first == currentX && resultion->second == currentY)
|
||||
{
|
||||
mResolutionList->setIndexSelected(i);
|
||||
break;
|
||||
@ -886,28 +873,31 @@ namespace MWGui
|
||||
// check if this resolution is supported in fullscreen
|
||||
if (mResolutionList->getIndexSelected() != MyGUI::ITEM_NONE)
|
||||
{
|
||||
const std::string& resStr = mResolutionList->getItemNameAt(mResolutionList->getIndexSelected());
|
||||
int resX, resY;
|
||||
parseResolution(resX, resY, resStr);
|
||||
Settings::video().mResolutionX.set(resX);
|
||||
Settings::video().mResolutionY.set(resY);
|
||||
auto resultion
|
||||
= mResolutionList->getItemDataAt<std::pair<int, int>>(mResolutionList->getIndexSelected());
|
||||
if (resultion)
|
||||
{
|
||||
Settings::video().mResolutionX.set(resultion->first);
|
||||
Settings::video().mResolutionY.set(resultion->second);
|
||||
}
|
||||
}
|
||||
|
||||
bool supported = false;
|
||||
int fallbackX = 0, fallbackY = 0;
|
||||
for (size_t i = 0; i < mResolutionList->getItemCount(); ++i)
|
||||
{
|
||||
const std::string& resStr = mResolutionList->getItemNameAt(i);
|
||||
int resX, resY;
|
||||
parseResolution(resX, resY, resStr);
|
||||
auto resultion = mResolutionList->getItemDataAt<std::pair<int, int>>(i);
|
||||
if (!resultion)
|
||||
continue;
|
||||
|
||||
if (i == 0)
|
||||
{
|
||||
fallbackX = resX;
|
||||
fallbackY = resY;
|
||||
fallbackX = resultion->first;
|
||||
fallbackY = resultion->second;
|
||||
}
|
||||
|
||||
if (resX == Settings::video().mResolutionX && resY == Settings::video().mResolutionY)
|
||||
if (resultion->first == Settings::video().mResolutionX
|
||||
&& resultion->second == Settings::video().mResolutionY)
|
||||
supported = true;
|
||||
}
|
||||
|
||||
|
@ -1,13 +1,12 @@
|
||||
#include "display.hpp"
|
||||
|
||||
#include <format>
|
||||
#include <numeric>
|
||||
#include <string>
|
||||
|
||||
#include <components/misc/strings/format.hpp>
|
||||
|
||||
namespace Misc
|
||||
{
|
||||
std::string getResolutionText(int x, int y, const std::string& format)
|
||||
std::string getResolutionText(int x, int y)
|
||||
{
|
||||
int gcd = std::gcd(x, y);
|
||||
if (gcd == 0)
|
||||
@ -77,6 +76,6 @@ namespace Misc
|
||||
if (flipped)
|
||||
std::swap(xaspect, yaspect);
|
||||
|
||||
return Misc::StringUtils::format(format, x, y, xaspect, yaspect);
|
||||
return std::format("{} × {} ({}:{})", x, y, xaspect, yaspect);
|
||||
}
|
||||
}
|
||||
|
@ -5,7 +5,7 @@
|
||||
|
||||
namespace Misc
|
||||
{
|
||||
std::string getResolutionText(int x, int y, const std::string& format);
|
||||
std::string getResolutionText(int x, int y);
|
||||
}
|
||||
|
||||
#endif
|
||||
|
Loading…
x
Reference in New Issue
Block a user