mirror of
https://gitlab.com/OpenMW/openmw.git
synced 2025-09-23 11:54:58 -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;
|
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()));
|
result.append(QString(str.c_str()));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -85,17 +85,6 @@ namespace
|
|||||||
return MyGUI::LanguageManager::getInstance().replaceTags(result);
|
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)
|
bool sortResolutions(std::pair<int, int> left, std::pair<int, int> right)
|
||||||
{
|
{
|
||||||
if (left.first == right.first)
|
if (left.first == right.first)
|
||||||
@ -368,10 +357,10 @@ 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 = 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)
|
if (mResolutionList->findItemIndexWith(str) == MyGUI::ITEM_NONE)
|
||||||
mResolutionList->addItem(str);
|
mResolutionList->addItem(str, resolution);
|
||||||
}
|
}
|
||||||
highlightCurrentResolution();
|
highlightCurrentResolution();
|
||||||
|
|
||||||
@ -493,15 +482,15 @@ namespace MWGui
|
|||||||
|
|
||||||
void SettingsWindow::onResolutionAccept()
|
void SettingsWindow::onResolutionAccept()
|
||||||
{
|
{
|
||||||
const std::string& resStr = mResolutionList->getItemNameAt(mResolutionList->getIndexSelected());
|
auto resultion = mResolutionList->getItemDataAt<std::pair<int, int>>(mResolutionList->getIndexSelected());
|
||||||
int resX, resY;
|
if (resultion)
|
||||||
parseResolution(resX, resY, resStr);
|
{
|
||||||
|
Settings::video().mResolutionX.set(resultion->first);
|
||||||
Settings::video().mResolutionX.set(resX);
|
Settings::video().mResolutionY.set(resultion->second);
|
||||||
Settings::video().mResolutionY.set(resY);
|
|
||||||
|
|
||||||
apply();
|
apply();
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
void SettingsWindow::onResolutionCancel()
|
void SettingsWindow::onResolutionCancel()
|
||||||
{
|
{
|
||||||
@ -517,10 +506,8 @@ namespace MWGui
|
|||||||
|
|
||||||
for (size_t i = 0; i < mResolutionList->getItemCount(); ++i)
|
for (size_t i = 0; i < mResolutionList->getItemCount(); ++i)
|
||||||
{
|
{
|
||||||
int resX, resY;
|
auto resultion = mResolutionList->getItemDataAt<std::pair<int, int>>(i);
|
||||||
parseResolution(resX, resY, mResolutionList->getItemNameAt(i));
|
if (resultion && resultion->first == currentX && resultion->second == currentY)
|
||||||
|
|
||||||
if (resX == currentX && resY == currentY)
|
|
||||||
{
|
{
|
||||||
mResolutionList->setIndexSelected(i);
|
mResolutionList->setIndexSelected(i);
|
||||||
break;
|
break;
|
||||||
@ -886,28 +873,31 @@ namespace MWGui
|
|||||||
// check if this resolution is supported in fullscreen
|
// check if this resolution is supported in fullscreen
|
||||||
if (mResolutionList->getIndexSelected() != MyGUI::ITEM_NONE)
|
if (mResolutionList->getIndexSelected() != MyGUI::ITEM_NONE)
|
||||||
{
|
{
|
||||||
const std::string& resStr = mResolutionList->getItemNameAt(mResolutionList->getIndexSelected());
|
auto resultion
|
||||||
int resX, resY;
|
= mResolutionList->getItemDataAt<std::pair<int, int>>(mResolutionList->getIndexSelected());
|
||||||
parseResolution(resX, resY, resStr);
|
if (resultion)
|
||||||
Settings::video().mResolutionX.set(resX);
|
{
|
||||||
Settings::video().mResolutionY.set(resY);
|
Settings::video().mResolutionX.set(resultion->first);
|
||||||
|
Settings::video().mResolutionY.set(resultion->second);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
bool supported = false;
|
bool supported = false;
|
||||||
int fallbackX = 0, fallbackY = 0;
|
int fallbackX = 0, fallbackY = 0;
|
||||||
for (size_t i = 0; i < mResolutionList->getItemCount(); ++i)
|
for (size_t i = 0; i < mResolutionList->getItemCount(); ++i)
|
||||||
{
|
{
|
||||||
const std::string& resStr = mResolutionList->getItemNameAt(i);
|
auto resultion = mResolutionList->getItemDataAt<std::pair<int, int>>(i);
|
||||||
int resX, resY;
|
if (!resultion)
|
||||||
parseResolution(resX, resY, resStr);
|
continue;
|
||||||
|
|
||||||
if (i == 0)
|
if (i == 0)
|
||||||
{
|
{
|
||||||
fallbackX = resX;
|
fallbackX = resultion->first;
|
||||||
fallbackY = resY;
|
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;
|
supported = true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -1,13 +1,12 @@
|
|||||||
#include "display.hpp"
|
#include "display.hpp"
|
||||||
|
|
||||||
|
#include <format>
|
||||||
#include <numeric>
|
#include <numeric>
|
||||||
#include <string>
|
#include <string>
|
||||||
|
|
||||||
#include <components/misc/strings/format.hpp>
|
|
||||||
|
|
||||||
namespace Misc
|
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);
|
int gcd = std::gcd(x, y);
|
||||||
if (gcd == 0)
|
if (gcd == 0)
|
||||||
@ -77,6 +76,6 @@ namespace Misc
|
|||||||
if (flipped)
|
if (flipped)
|
||||||
std::swap(xaspect, yaspect);
|
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
|
namespace Misc
|
||||||
{
|
{
|
||||||
std::string getResolutionText(int x, int y, const std::string& format);
|
std::string getResolutionText(int x, int y);
|
||||||
}
|
}
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
Loading…
x
Reference in New Issue
Block a user