From 6fe471c1c6338d9812fe719f32b1c3c963fc589c Mon Sep 17 00:00:00 2001 From: Pieter van der Kloet Date: Tue, 26 Jun 2012 02:41:54 +0200 Subject: [PATCH 1/5] Resolutions are now sorted descendingly and removed some debug stuff --- apps/launcher/graphicspage.cpp | 17 ++++++++++++++++- apps/launcher/maindialog.cpp | 1 - apps/launcher/pluginsview.cpp | 1 - 3 files changed, 16 insertions(+), 3 deletions(-) diff --git a/apps/launcher/graphicspage.cpp b/apps/launcher/graphicspage.cpp index 0af127edc5..e3c678f7fe 100644 --- a/apps/launcher/graphicspage.cpp +++ b/apps/launcher/graphicspage.cpp @@ -7,6 +7,17 @@ #include #include +//sort resolutions descending +bool resolutionLessThan(const QString &str1, const QString &str2) +{ + // Get the first parts of the resolution strings + int width1 = str1.left(str1.indexOf(" ")).toInt(); + int width2 = str2.left(str2.indexOf(" ")).toInt(); + + return (width1 > width2); +} + + GraphicsPage::GraphicsPage(Files::ConfigurationManager &cfg, QWidget *parent) : QWidget(parent) , mCfgMgr(cfg) @@ -162,7 +173,7 @@ bool GraphicsPage::setupOgre() mAntiAliasingComboBox->clear(); mResolutionComboBox->clear(); mAntiAliasingComboBox->addItems(getAvailableOptions(QString("FSAA"), mSelectedRenderSystem)); - mResolutionComboBox->addItems(getAvailableOptions(QString("Video Mode"), mSelectedRenderSystem)); + mResolutionComboBox->addItems(getAvailableResolutions(mSelectedRenderSystem)); readConfig(); return true; @@ -229,6 +240,8 @@ QStringList GraphicsPage::getAvailableOptions(const QString &key, Ogre::RenderSy } + // Sort ascending + result.sort(); return result; } @@ -265,6 +278,8 @@ QStringList GraphicsPage::getAvailableResolutions(Ogre::RenderSystem *renderer) } + // Sort the resolutions in descending order + qSort(result.begin(), result.end(), resolutionLessThan); return result; } diff --git a/apps/launcher/maindialog.cpp b/apps/launcher/maindialog.cpp index ab6eb0b73e..ed67eb3b5a 100644 --- a/apps/launcher/maindialog.cpp +++ b/apps/launcher/maindialog.cpp @@ -229,7 +229,6 @@ void MainDialog::closeEvent(QCloseEvent *event) // Save user settings const std::string settingspath = (mCfgMgr.getUserPath() / "settings.cfg").string(); - qDebug() << QString::fromStdString(settingspath); mSettings.saveUser(settingspath); event->accept(); diff --git a/apps/launcher/pluginsview.cpp b/apps/launcher/pluginsview.cpp index 27af45c569..26cf337fb7 100644 --- a/apps/launcher/pluginsview.cpp +++ b/apps/launcher/pluginsview.cpp @@ -1,4 +1,3 @@ -#include #include #include "pluginsview.hpp" From 77ac8760d1e5d81dea01d3872f69ff10c60fd662 Mon Sep 17 00:00:00 2001 From: Pieter van der Kloet Date: Tue, 26 Jun 2012 03:07:54 +0200 Subject: [PATCH 2/5] Cleaned up the GUI of the Graphics page --- apps/launcher/graphicspage.cpp | 57 ++++++++++++---------------------- 1 file changed, 19 insertions(+), 38 deletions(-) diff --git a/apps/launcher/graphicspage.cpp b/apps/launcher/graphicspage.cpp index e3c678f7fe..e517454c78 100644 --- a/apps/launcher/graphicspage.cpp +++ b/apps/launcher/graphicspage.cpp @@ -32,57 +32,38 @@ GraphicsPage::GraphicsPage(Files::ConfigurationManager &cfg, QWidget *parent) renderSystemLayout->addWidget(rendererLabel, 0, 0, 1, 1); renderSystemLayout->addWidget(mRendererComboBox, 0, 1, 1, 1); - QVBoxLayout *rendererGroupLayout = new QVBoxLayout(rendererGroup); - - rendererGroupLayout->addLayout(renderSystemLayout); - // Display QGroupBox *displayGroup = new QGroupBox(tr("Display"), this); - mDisplayStackedWidget = new QStackedWidget(displayGroup); + mVSyncCheckBox = new QCheckBox(tr("Vertical Sync"), displayGroup); + mFullScreenCheckBox = new QCheckBox(tr("Full Screen"), displayGroup); - QVBoxLayout *displayGroupLayout = new QVBoxLayout(displayGroup); - QSpacerItem *vSpacer3 = new QSpacerItem(20, 10, QSizePolicy::Minimum, QSizePolicy::Expanding); + QLabel *antiAliasingLabel = new QLabel(tr("Antialiasing:"), displayGroup); + QLabel *resolutionLabel = new QLabel(tr("Resolution:"), displayGroup); - displayGroupLayout->addWidget(mDisplayStackedWidget); - displayGroupLayout->addItem(vSpacer3); + mResolutionComboBox = new QComboBox(displayGroup); + mAntiAliasingComboBox = new QComboBox(displayGroup); + + QVBoxLayout *rendererGroupLayout = new QVBoxLayout(rendererGroup); + rendererGroupLayout->addLayout(renderSystemLayout); + + QGridLayout *displayGroupLayout = new QGridLayout(displayGroup); + displayGroupLayout->addWidget(mVSyncCheckBox, 0, 0, 1, 1); + displayGroupLayout->addWidget(mFullScreenCheckBox, 1, 0, 1, 1); + displayGroupLayout->addWidget(antiAliasingLabel, 2, 0, 1, 1); + displayGroupLayout->addWidget(mAntiAliasingComboBox, 2, 1, 1, 1); + displayGroupLayout->addWidget(resolutionLabel, 3, 0, 1, 1); + displayGroupLayout->addWidget(mResolutionComboBox, 3, 1, 1, 1); // Layout for the whole page QVBoxLayout *pageLayout = new QVBoxLayout(this); + QSpacerItem *vSpacer1 = new QSpacerItem(20, 10, QSizePolicy::Minimum, QSizePolicy::Expanding); pageLayout->addWidget(rendererGroup); pageLayout->addWidget(displayGroup); + pageLayout->addItem(vSpacer1); connect(mRendererComboBox, SIGNAL(currentIndexChanged(const QString&)), this, SLOT(rendererChanged(const QString&))); - - createPages(); -} - -void GraphicsPage::createPages() -{ - QWidget *main = new QWidget(); - QGridLayout *grid = new QGridLayout(main); - - mVSyncCheckBox = new QCheckBox(tr("Vertical Sync"), main); - grid->addWidget(mVSyncCheckBox, 0, 0, 1, 1); - - mFullScreenCheckBox = new QCheckBox(tr("Full Screen"), main); - grid->addWidget(mFullScreenCheckBox, 1, 0, 1, 1); - - QLabel *antiAliasingLabel = new QLabel(tr("Antialiasing:"), main); - mAntiAliasingComboBox = new QComboBox(main); - grid->addWidget(antiAliasingLabel, 2, 0, 1, 1); - grid->addWidget(mAntiAliasingComboBox, 2, 1, 1, 1); - - QLabel *resolutionLabel = new QLabel(tr("Resolution:"), main); - mResolutionComboBox = new QComboBox(main); - grid->addWidget(resolutionLabel, 3, 0, 1, 1); - grid->addWidget(mResolutionComboBox, 3, 1, 1, 1); - - QSpacerItem *vSpacer1 = new QSpacerItem(20, 10, QSizePolicy::Minimum, QSizePolicy::Expanding); - grid->addItem(vSpacer1, 4, 0, 1, 1); - - mDisplayStackedWidget->addWidget(main); } bool GraphicsPage::setupOgre() From e5159a19507affcbe62d9e19780b6a6c5ef79281 Mon Sep 17 00:00:00 2001 From: Pieter van der Kloet Date: Tue, 26 Jun 2012 15:37:40 +0200 Subject: [PATCH 3/5] Modified sorting of the values in the Graphics Page --- apps/launcher/graphicspage.cpp | 101 ++++++++++++++++----------------- apps/launcher/naturalsort.cpp | 10 ++++ apps/launcher/naturalsort.hpp | 4 +- 3 files changed, 61 insertions(+), 54 deletions(-) diff --git a/apps/launcher/graphicspage.cpp b/apps/launcher/graphicspage.cpp index e517454c78..b202b1ecf3 100644 --- a/apps/launcher/graphicspage.cpp +++ b/apps/launcher/graphicspage.cpp @@ -1,22 +1,10 @@ -#include "graphicspage.hpp" - #include -#include - #include #include -//sort resolutions descending -bool resolutionLessThan(const QString &str1, const QString &str2) -{ - // Get the first parts of the resolution strings - int width1 = str1.left(str1.indexOf(" ")).toInt(); - int width2 = str2.left(str2.indexOf(" ")).toInt(); - - return (width1 > width2); -} - +#include "graphicspage.hpp" +#include "naturalsort.hpp" GraphicsPage::GraphicsPage(Files::ConfigurationManager &cfg, QWidget *parent) : QWidget(parent) @@ -77,11 +65,11 @@ bool GraphicsPage::setupOgre() try { - #if defined(ENABLE_PLUGIN_GL) || defined(ENABLE_PLUGIN_Direct3D9) +#if defined(ENABLE_PLUGIN_GL) || defined(ENABLE_PLUGIN_Direct3D9) mOgre = new Ogre::Root("", "", "./launcherOgre.log"); - #else +#else mOgre = new Ogre::Root(pluginCfg.toStdString(), "", "./launcherOgre.log"); - #endif +#endif } catch(Ogre::Exception &ex) { @@ -100,14 +88,14 @@ bool GraphicsPage::setupOgre() return false; } - #ifdef ENABLE_PLUGIN_GL - mGLPlugin = new Ogre::GLPlugin(); - mOgre->installPlugin(mGLPlugin); - #endif - #ifdef ENABLE_PLUGIN_Direct3D9 - mD3D9Plugin = new Ogre::D3D9Plugin(); - mOgre->installPlugin(mD3D9Plugin); - #endif +#ifdef ENABLE_PLUGIN_GL + mGLPlugin = new Ogre::GLPlugin(); + mOgre->installPlugin(mGLPlugin); +#endif +#ifdef ENABLE_PLUGIN_Direct3D9 + mD3D9Plugin = new Ogre::D3D9Plugin(); + mOgre->installPlugin(mD3D9Plugin); +#endif // Get the available renderers and put them in the combobox const Ogre::RenderSystemList &renderers = mOgre->getAvailableRenderers(); @@ -117,30 +105,16 @@ bool GraphicsPage::setupOgre() mRendererComboBox->addItem((*r)->getName().c_str()); } - int index = mRendererComboBox->findText(QString::fromStdString(Settings::Manager::getString("render system", "Video"))); - - if ( index != -1) { - mRendererComboBox->setCurrentIndex(index); - } - else - { -#if OGRE_PLATFORM == OGRE_PLATFORM_WIN32 - mRendererComboBox->setCurrentIndex(mRendererComboBox->findText("Direct3D9 Rendering Subsystem")); -#else - mRendererComboBox->setCurrentIndex(mRendererComboBox->findText("OpenGL Rendering Subsystem")); -#endif - } + QString openGLName = QString("OpenGL Rendering Subsystem"); + QString direct3DName = QString("Direct3D9 Rendering Subsystem"); // Create separate rendersystems - QString openGLName = mRendererComboBox->itemText(mRendererComboBox->findText(QString("OpenGL"), Qt::MatchStartsWith)); - QString direct3DName = mRendererComboBox->itemText(mRendererComboBox->findText(QString("Direct3D"), Qt::MatchStartsWith)); - mOpenGLRenderSystem = mOgre->getRenderSystemByName(openGLName.toStdString()); mDirect3DRenderSystem = mOgre->getRenderSystemByName(direct3DName.toStdString()); if (!mOpenGLRenderSystem && !mDirect3DRenderSystem) { QMessageBox msgBox; - msgBox.setWindowTitle("Error creating renderer"); + msgBox.setWindowTitle(tr("Error creating renderer")); msgBox.setIcon(QMessageBox::Critical); msgBox.setStandardButtons(QMessageBox::Ok); msgBox.setText(tr("
Could not select a valid render system

\ @@ -151,6 +125,20 @@ bool GraphicsPage::setupOgre() } // Now fill the GUI elements + int index = mRendererComboBox->findText(QString::fromStdString(Settings::Manager::getString("render system", "Video"))); + + if ( index != -1) { + mRendererComboBox->setCurrentIndex(index); + } + else + { +#if OGRE_PLATFORM == OGRE_PLATFORM_WIN32 + mRendererComboBox->setCurrentIndex(mRendererComboBox->findText(direct3DName)); +#else + mRendererComboBox->setCurrentIndex(mRendererComboBox->findText(openGLName)); +#endif + } + mAntiAliasingComboBox->clear(); mResolutionComboBox->clear(); mAntiAliasingComboBox->addItems(getAvailableOptions(QString("FSAA"), mSelectedRenderSystem)); @@ -172,9 +160,10 @@ void GraphicsPage::readConfig() if (aaIndex != -1) mAntiAliasingComboBox->setCurrentIndex(aaIndex); - std::string resolution = boost::lexical_cast(Settings::Manager::getInt("resolution x", "Video")) - + " x " + boost::lexical_cast(Settings::Manager::getInt("resolution y", "Video")); - int resIndex = mResolutionComboBox->findText(QString::fromStdString(resolution)); + QString resolution = QString::number(Settings::Manager::getInt("resolution x", "Video")); + resolution.append(" x " + QString::number(Settings::Manager::getInt("resolution y", "Video"))); + + int resIndex = mResolutionComboBox->findText(resolution); if (resIndex != -1) mResolutionComboBox->setCurrentIndex(resIndex); } @@ -189,8 +178,9 @@ void GraphicsPage::writeConfig() // parse resolution x and y from a string like "800 x 600" QString resolution = mResolutionComboBox->currentText(); QStringList tokens = resolution.split(" ", QString::SkipEmptyParts); - int resX = boost::lexical_cast(tokens.at(0).toStdString()); - int resY = boost::lexical_cast(tokens.at(2).toStdString()); + + int resX = tokens.at(0).toInt(); + int resY = tokens.at(2).toInt(); Settings::Manager::setInt("resolution x", "Video", resX); Settings::Manager::setInt("resolution y", "Video", resY); } @@ -212,17 +202,21 @@ QStringList GraphicsPage::getAvailableOptions(const QString &key, Ogre::RenderSy if (strcmp (key.toStdString().c_str(), i->first.c_str()) == 0) { - if (key == "FSAA" && *opt_it == "0") - result << QString("none"); - else - result << ((key == "FSAA") ? QString("MSAA ") : QString("")) + QString::fromStdString((*opt_it).c_str()).simplified(); + result << ((key == "FSAA") ? QString("MSAA ") : QString("")) + QString::fromStdString((*opt_it).c_str()).simplified(); } } } // Sort ascending - result.sort(); + qSort(result.begin(), result.end(), naturalSortLessThanCI); + + // Replace the zero option with Off + int index = result.indexOf("MSAA 0"); + + if (index != -1) + result.replace(index, tr("Off")); + return result; } @@ -260,7 +254,8 @@ QStringList GraphicsPage::getAvailableResolutions(Ogre::RenderSystem *renderer) } // Sort the resolutions in descending order - qSort(result.begin(), result.end(), resolutionLessThan); + qSort(result.begin(), result.end(), naturalSortGreaterThanCI); + return result; } diff --git a/apps/launcher/naturalsort.cpp b/apps/launcher/naturalsort.cpp index 648038ed7f..50d1e77de0 100644 --- a/apps/launcher/naturalsort.cpp +++ b/apps/launcher/naturalsort.cpp @@ -93,3 +93,13 @@ bool naturalSortLessThanCI( const QString &left, const QString &right ) { return (naturalCompare( left, right, Qt::CaseInsensitive ) < 0); } + +bool naturalSortGreaterThanCS( const QString &left, const QString &right ) +{ + return (naturalCompare( left, right, Qt::CaseSensitive ) > 0); +} + +bool naturalSortGreaterThanCI( const QString &left, const QString &right ) +{ + return (naturalCompare( left, right, Qt::CaseInsensitive ) > 0); +} diff --git a/apps/launcher/naturalsort.hpp b/apps/launcher/naturalsort.hpp index 2d314396f9..59271547a5 100644 --- a/apps/launcher/naturalsort.hpp +++ b/apps/launcher/naturalsort.hpp @@ -5,5 +5,7 @@ bool naturalSortLessThanCS( const QString &left, const QString &right ); bool naturalSortLessThanCI( const QString &left, const QString &right ); +bool naturalSortGreaterThanCS( const QString &left, const QString &right ); +bool naturalSortGreaterThanCI( const QString &left, const QString &right ); -#endif \ No newline at end of file +#endif From 30e86e1b9d0ecc67126f0d1696d68c70054cfb3d Mon Sep 17 00:00:00 2001 From: scrawl Date: Tue, 26 Jun 2012 15:41:13 +0200 Subject: [PATCH 4/5] settings window resolution sorting, aspect ratio --- apps/openmw/mwgui/settingswindow.cpp | 33 +++++++++++++++++++++++++--- 1 file changed, 30 insertions(+), 3 deletions(-) diff --git a/apps/openmw/mwgui/settingswindow.cpp b/apps/openmw/mwgui/settingswindow.cpp index 8dcea6d894..4fa941681e 100644 --- a/apps/openmw/mwgui/settingswindow.cpp +++ b/apps/openmw/mwgui/settingswindow.cpp @@ -6,6 +6,7 @@ #include #include +#include #include @@ -51,6 +52,24 @@ namespace x = boost::lexical_cast (split[0]); y = boost::lexical_cast (split[1]); } + + bool sortResolutions (std::pair left, std::pair 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(xaspect) + " : " + boost::lexical_cast(yaspect); + } } namespace MWGui @@ -111,13 +130,22 @@ namespace MWGui // fill resolution list 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 > resolutions; for (Ogre::StringVector::const_iterator it=videoModes.begin(); it!=videoModes.end(); ++it) { + int resX, resY; parseResolution (resX, resY, *it); - std::string str = boost::lexical_cast(resX) + " x " + boost::lexical_cast(resY); + resolutions.push_back(std::make_pair(resX, resY)); + } + std::sort(resolutions.begin(), resolutions.end(), sortResolutions); + for (std::vector < std::pair >::const_iterator it=resolutions.begin(); + it!=resolutions.end(); ++it) + { + std::string str = boost::lexical_cast(it->first) + " x " + boost::lexical_cast(it->second) + + " (" + getAspect(it->first,it->second) + ")"; if (mResolutionList->findItemIndexWith(str) == MyGUI::ITEM_NONE) mResolutionList->addItem(str); @@ -185,7 +213,6 @@ namespace MWGui dialog->eventOkClicked.clear(); dialog->eventOkClicked += MyGUI::newDelegate(this, &SettingsWindow::onResolutionAccept); dialog->eventCancelClicked.clear(); - dialog->eventCancelClicked += MyGUI::newDelegate(this, &SettingsWindow::onResolutionAccept); } void SettingsWindow::onResolutionAccept() From b73b39f3c638a93930f87c2e2caa0808b88aa511 Mon Sep 17 00:00:00 2001 From: scrawl Date: Wed, 27 Jun 2012 00:55:25 +0200 Subject: [PATCH 5/5] launcher bugfix, settings was not written when "Play" was selected --- apps/launcher/maindialog.cpp | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/apps/launcher/maindialog.cpp b/apps/launcher/maindialog.cpp index ed67eb3b5a..f7dafd3af5 100644 --- a/apps/launcher/maindialog.cpp +++ b/apps/launcher/maindialog.cpp @@ -240,6 +240,10 @@ void MainDialog::play() mDataFilesPage->writeConfig(); mGraphicsPage->writeConfig(); + // Save user settings + const std::string settingspath = (mCfgMgr.getUserPath() / "settings.cfg").string(); + mSettings.saveUser(settingspath); + #ifdef Q_WS_WIN QString game = "./openmw.exe"; QFile file(game);