diff --git a/apps/openmw/mwgui/settingswindow.cpp b/apps/openmw/mwgui/settingswindow.cpp index eafbd3462..8dcea6d89 100644 --- a/apps/openmw/mwgui/settingswindow.cpp +++ b/apps/openmw/mwgui/settingswindow.cpp @@ -5,6 +5,7 @@ #include #include +#include #include @@ -39,6 +40,17 @@ namespace else return "Trilinear"; } + + void parseResolution (int &x, int &y, const std::string& str) + { + std::vector split; + boost::algorithm::split (split, str, boost::is_any_of("x")); + assert (split.size() >= 2); + boost::trim(split[0]); + boost::trim(split[1]); + x = boost::lexical_cast (split[0]); + y = boost::lexical_cast (split[1]); + } } namespace MWGui @@ -103,7 +115,12 @@ namespace MWGui for (Ogre::StringVector::const_iterator it=videoModes.begin(); it!=videoModes.end(); ++it) { - mResolutionList->addItem(*it); + int resX, resY; + parseResolution (resX, resY, *it); + std::string str = boost::lexical_cast(resX) + " x " + boost::lexical_cast(resY); + + if (mResolutionList->findItemIndexWith(str) == MyGUI::ITEM_NONE) + mResolutionList->addItem(str); } // read settings @@ -174,13 +191,8 @@ namespace MWGui void SettingsWindow::onResolutionAccept() { std::string resStr = mResolutionList->getItemNameAt(mResolutionList->getIndexSelected()); - size_t xPos = resStr.find("x"); - std::string resXStr = resStr.substr(0, xPos-1); - Ogre::StringUtil::trim(resXStr); - std::string resYStr = resStr.substr(xPos+2, resStr.size()-(xPos+2)); - Ogre::StringUtil::trim(resYStr); - int resX = boost::lexical_cast(resXStr); - int resY = boost::lexical_cast(resYStr); + int resX, resY; + parseResolution (resX, resY, resStr); Settings::Manager::setInt("resolution x", "Video", resX); Settings::Manager::setInt("resolution y", "Video", resY); @@ -217,13 +229,8 @@ namespace MWGui for (unsigned int i=0; igetItemCount(); ++i) { std::string resStr = mResolutionList->getItemNameAt(i); - size_t xPos = resStr.find("x"); - std::string resXStr = resStr.substr(0, xPos-1); - Ogre::StringUtil::trim(resXStr); - std::string resYStr = resStr.substr(xPos+2, resStr.size()-(xPos+2)); - Ogre::StringUtil::trim(resYStr); - int resX = boost::lexical_cast(resXStr); - int resY = boost::lexical_cast(resYStr); + int resX, resY; + parseResolution (resX, resY, resStr); if (resX == Settings::Manager::getInt("resolution x", "Video") && resY == Settings::Manager::getInt("resolution y", "Video")) diff --git a/components/settings/settings.cpp b/components/settings/settings.cpp index 9b941e253..dd89dde65 100644 --- a/components/settings/settings.cpp +++ b/components/settings/settings.cpp @@ -66,6 +66,8 @@ void Manager::saveUser(const std::string& file) } fout << it->first.second << " = " << it->second << '\n'; } + + fout.close(); } const std::string Manager::getString (const std::string& setting, const std::string& category)