forked from teamnwah/openmw-tes3coop
settings window resolution sorting, aspect ratio
This commit is contained in:
parent
797c2c538d
commit
30e86e1b9d
1 changed files with 30 additions and 3 deletions
|
@ -6,6 +6,7 @@
|
||||||
|
|
||||||
#include <boost/lexical_cast.hpp>
|
#include <boost/lexical_cast.hpp>
|
||||||
#include <boost/algorithm/string.hpp>
|
#include <boost/algorithm/string.hpp>
|
||||||
|
#include <boost/math/common_factor_rt.hpp>
|
||||||
|
|
||||||
#include <components/settings/settings.hpp>
|
#include <components/settings/settings.hpp>
|
||||||
|
|
||||||
|
@ -51,6 +52,24 @@ namespace
|
||||||
x = boost::lexical_cast<int> (split[0]);
|
x = boost::lexical_cast<int> (split[0]);
|
||||||
y = boost::lexical_cast<int> (split[1]);
|
y = boost::lexical_cast<int> (split[1]);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
bool sortResolutions (std::pair<int, int> left, std::pair<int, int> right)
|
||||||
|
{
|
||||||
|
if (left.first == right.first)
|
||||||
|
return left.second > right.second;
|
||||||
|
return left.first > right.first;
|
||||||
|
}
|
||||||
|
|
||||||
|
std::string getAspect (int x, int y)
|
||||||
|
{
|
||||||
|
int gcd = boost::math::gcd (x, y);
|
||||||
|
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 boost::lexical_cast<std::string>(xaspect) + " : " + boost::lexical_cast<std::string>(yaspect);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
namespace MWGui
|
namespace MWGui
|
||||||
|
@ -111,13 +130,22 @@ namespace MWGui
|
||||||
|
|
||||||
// fill resolution list
|
// fill resolution list
|
||||||
Ogre::RenderSystem* rs = Ogre::Root::getSingleton().getRenderSystem();
|
Ogre::RenderSystem* rs = Ogre::Root::getSingleton().getRenderSystem();
|
||||||
const Ogre::StringVector& videoModes = rs->getConfigOptions()["Video Mode"].possibleValues;
|
Ogre::StringVector videoModes = rs->getConfigOptions()["Video Mode"].possibleValues;
|
||||||
|
std::vector < std::pair<int, int> > resolutions;
|
||||||
for (Ogre::StringVector::const_iterator it=videoModes.begin();
|
for (Ogre::StringVector::const_iterator it=videoModes.begin();
|
||||||
it!=videoModes.end(); ++it)
|
it!=videoModes.end(); ++it)
|
||||||
{
|
{
|
||||||
|
|
||||||
int resX, resY;
|
int resX, resY;
|
||||||
parseResolution (resX, resY, *it);
|
parseResolution (resX, resY, *it);
|
||||||
std::string str = boost::lexical_cast<std::string>(resX) + " x " + boost::lexical_cast<std::string>(resY);
|
resolutions.push_back(std::make_pair(resX, resY));
|
||||||
|
}
|
||||||
|
std::sort(resolutions.begin(), resolutions.end(), sortResolutions);
|
||||||
|
for (std::vector < std::pair<int, int> >::const_iterator it=resolutions.begin();
|
||||||
|
it!=resolutions.end(); ++it)
|
||||||
|
{
|
||||||
|
std::string str = boost::lexical_cast<std::string>(it->first) + " x " + boost::lexical_cast<std::string>(it->second)
|
||||||
|
+ " (" + getAspect(it->first,it->second) + ")";
|
||||||
|
|
||||||
if (mResolutionList->findItemIndexWith(str) == MyGUI::ITEM_NONE)
|
if (mResolutionList->findItemIndexWith(str) == MyGUI::ITEM_NONE)
|
||||||
mResolutionList->addItem(str);
|
mResolutionList->addItem(str);
|
||||||
|
@ -185,7 +213,6 @@ namespace MWGui
|
||||||
dialog->eventOkClicked.clear();
|
dialog->eventOkClicked.clear();
|
||||||
dialog->eventOkClicked += MyGUI::newDelegate(this, &SettingsWindow::onResolutionAccept);
|
dialog->eventOkClicked += MyGUI::newDelegate(this, &SettingsWindow::onResolutionAccept);
|
||||||
dialog->eventCancelClicked.clear();
|
dialog->eventCancelClicked.clear();
|
||||||
dialog->eventCancelClicked += MyGUI::newDelegate(this, &SettingsWindow::onResolutionAccept);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void SettingsWindow::onResolutionAccept()
|
void SettingsWindow::onResolutionAccept()
|
||||||
|
|
Loading…
Reference in a new issue