mirror of
				https://github.com/TES3MP/openmw-tes3mp.git
				synced 2025-10-31 17:26:42 +00:00 
			
		
		
		
	
						commit
						c37b14f5f7
					
				
					 5 changed files with 84 additions and 83 deletions
				
			
		|  | @ -1,12 +1,11 @@ | |||
| #include "graphicspage.hpp" | ||||
| 
 | ||||
| #include <QtGui> | ||||
| 
 | ||||
| #include <boost/lexical_cast.hpp> | ||||
| 
 | ||||
| #include <components/files/configurationmanager.hpp> | ||||
| #include <components/settings/settings.hpp> | ||||
| 
 | ||||
| #include "graphicspage.hpp" | ||||
| #include "naturalsort.hpp" | ||||
| 
 | ||||
| GraphicsPage::GraphicsPage(Files::ConfigurationManager &cfg, QWidget *parent) | ||||
|     : QWidget(parent) | ||||
|     , mCfgMgr(cfg) | ||||
|  | @ -21,57 +20,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() | ||||
|  | @ -85,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) | ||||
|     { | ||||
|  | @ -108,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(); | ||||
|  | @ -125,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("<br><b>Could not select a valid render system</b><br><br> \
 | ||||
|  | @ -159,10 +125,24 @@ 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)); | ||||
|     mResolutionComboBox->addItems(getAvailableOptions(QString("Video Mode"), mSelectedRenderSystem)); | ||||
|     mResolutionComboBox->addItems(getAvailableResolutions(mSelectedRenderSystem)); | ||||
| 
 | ||||
|     readConfig(); | ||||
|     return true; | ||||
|  | @ -180,9 +160,10 @@ void GraphicsPage::readConfig() | |||
|     if (aaIndex != -1) | ||||
|         mAntiAliasingComboBox->setCurrentIndex(aaIndex); | ||||
| 
 | ||||
|     std::string resolution = boost::lexical_cast<std::string>(Settings::Manager::getInt("resolution x", "Video")) | ||||
|         + " x " + boost::lexical_cast<std::string>(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); | ||||
| } | ||||
|  | @ -197,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<int>(tokens.at(0).toStdString()); | ||||
|     int resY = boost::lexical_cast<int>(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); | ||||
| } | ||||
|  | @ -220,15 +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
 | ||||
|     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; | ||||
| } | ||||
| 
 | ||||
|  | @ -265,6 +253,9 @@ QStringList GraphicsPage::getAvailableResolutions(Ogre::RenderSystem *renderer) | |||
| 
 | ||||
|     } | ||||
| 
 | ||||
|     // Sort the resolutions in descending order
 | ||||
|     qSort(result.begin(), result.end(), naturalSortGreaterThanCI); | ||||
| 
 | ||||
|     return result; | ||||
| } | ||||
| 
 | ||||
|  |  | |||
|  | @ -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(); | ||||
|  |  | |||
|  | @ -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); | ||||
| } | ||||
|  |  | |||
|  | @ -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 | ||||
| #endif | ||||
|  |  | |||
|  | @ -1,4 +1,3 @@ | |||
| #include <QDebug> | ||||
| #include <QSortFilterProxyModel> | ||||
| 
 | ||||
| #include "pluginsview.hpp" | ||||
|  |  | |||
		Loading…
	
		Reference in a new issue