mirror of
				https://github.com/OpenMW/openmw.git
				synced 2025-10-26 14:56:39 +00:00 
			
		
		
		
	Merge remote-tracking branch 'swick/multimonitor'
Conflicts: apps/launcher/graphicspage.cpp
This commit is contained in:
		
						commit
						0829548106
					
				
					 6 changed files with 155 additions and 49 deletions
				
			
		|  | @ -90,6 +90,7 @@ target_link_libraries(omwlauncher | |||
|     ${Boost_LIBRARIES} | ||||
|     ${OGRE_LIBRARIES} | ||||
|     ${OGRE_STATIC_PLUGINS} | ||||
|     ${SDL2_LIBRARY} | ||||
|     ${QT_LIBRARIES} | ||||
|     components | ||||
| ) | ||||
|  |  | |||
|  | @ -3,6 +3,7 @@ | |||
| #include <QDesktopWidget> | ||||
| #include <QMessageBox> | ||||
| #include <QDir> | ||||
| #include <SDL.h> | ||||
| 
 | ||||
| #include <cstdlib> | ||||
| 
 | ||||
|  | @ -42,6 +43,7 @@ GraphicsPage::GraphicsPage(Files::ConfigurationManager &cfg, GraphicsSettings &g | |||
|     connect(rendererComboBox, SIGNAL(currentIndexChanged(const QString&)), this, SLOT(rendererChanged(const QString&))); | ||||
|     connect(fullScreenCheckBox, SIGNAL(stateChanged(int)), this, SLOT(slotFullScreenChanged(int))); | ||||
|     connect(standardRadioButton, SIGNAL(toggled(bool)), this, SLOT(slotStandardToggled(bool))); | ||||
|     connect(screenComboBox, SIGNAL(currentIndexChanged(const QString&)), this, SLOT(screenChanged(const QString&))); | ||||
| 
 | ||||
| } | ||||
| 
 | ||||
|  | @ -144,17 +146,97 @@ bool GraphicsPage::setupOgre() | |||
|     } | ||||
| 
 | ||||
|     antiAliasingComboBox->clear(); | ||||
|     resolutionComboBox->clear(); | ||||
|     antiAliasingComboBox->addItems(getAvailableOptions(QString("FSAA"), mSelectedRenderSystem)); | ||||
|     resolutionComboBox->addItems(getAvailableResolutions(mSelectedRenderSystem)); | ||||
| 
 | ||||
|     // Load the rest of the values
 | ||||
|     loadSettings(); | ||||
|     return true; | ||||
| } | ||||
| 
 | ||||
| void GraphicsPage::loadSettings() | ||||
| bool GraphicsPage::setupSDL() | ||||
| { | ||||
|     // FIXME: do setupSDLWordaround here instead.
 | ||||
|     // seems like Qt, SDL and Ogre don't like each other
 | ||||
|     // results in a segfault if SDL is initialized after Qt
 | ||||
| 
 | ||||
|     QStringList screens; | ||||
|     for (int i = 0; i < mScreenCount; i++) | ||||
|     { | ||||
|         screens.append(QString("Screen ") + QString::number(i + 1)); | ||||
|     } | ||||
|     screenComboBox->addItems(screens); | ||||
| 
 | ||||
|     return true; | ||||
| } | ||||
| 
 | ||||
| std::vector<VideoMode> GraphicsPage::mVideoModes; | ||||
| int GraphicsPage::mScreenCount; | ||||
| 
 | ||||
| bool GraphicsPage::setupSDLWordaround() { | ||||
|     if (SDL_Init(SDL_INIT_VIDEO) != 0) | ||||
|     { | ||||
|         std::cout << "SDL_Init failed: " << SDL_GetError() << std::endl; | ||||
|         return false; | ||||
|     } | ||||
| 
 | ||||
|     SDL_DisplayMode mode; | ||||
|     int displayIndex, modeIndex, displays = SDL_GetNumVideoDisplays(); | ||||
|     mScreenCount = displays; | ||||
| 
 | ||||
|     if(displays < 0) | ||||
|     { | ||||
|         std::cout << "SDL_GetNumVideoDisplays failed: " << SDL_GetError() << std::endl; | ||||
|         SDL_Quit(); | ||||
|         return false; | ||||
|     } | ||||
| 
 | ||||
|     for (displayIndex = 0; displayIndex < displays; displayIndex++) | ||||
|     { | ||||
|         int modes = SDL_GetNumDisplayModes(displayIndex); | ||||
|         if(modes < 0) | ||||
|         { | ||||
|             std::cout << "SDL_GetNumDisplayModes failed: " << SDL_GetError() << std::endl; | ||||
|             SDL_Quit(); | ||||
|             return false; | ||||
|         } | ||||
|         for (modeIndex = 0; modeIndex < modes; modeIndex++) | ||||
|         { | ||||
|             if (SDL_GetDisplayMode(displayIndex, modeIndex, &mode) < 0) | ||||
|             { | ||||
|                 std::cout << "SDL_GetDisplayMode failed: " << SDL_GetError() << std::endl; | ||||
|                 SDL_Quit(); | ||||
|                 return false; | ||||
|             } | ||||
| 
 | ||||
|             bool isDouble = false; | ||||
|             for (std::vector<VideoMode>::iterator it = mVideoModes.begin(); it != mVideoModes.end(); it++) | ||||
|             { | ||||
|                 if ((*it).w == mode.w && (*it).h == mode.h && (*it).screen == displayIndex) | ||||
|                 { | ||||
|                     isDouble = true; | ||||
|                     break; | ||||
|                 } | ||||
|             } | ||||
|             if (isDouble) | ||||
|                 continue; | ||||
| 
 | ||||
|             VideoMode vmode; | ||||
|             vmode.w = mode.w; | ||||
|             vmode.h = mode.h; | ||||
|             vmode.screen = displayIndex; | ||||
|             mVideoModes.push_back(vmode); | ||||
|         } | ||||
|     } | ||||
| 
 | ||||
|     SDL_Quit(); | ||||
|     return true; | ||||
| } | ||||
| 
 | ||||
| bool GraphicsPage::loadSettings() | ||||
| { | ||||
|     if (!setupSDL()) | ||||
|         return false; | ||||
|     if (!setupOgre()) | ||||
|         return false; | ||||
| 
 | ||||
|     if (mGraphicsSettings.value(QString("Video/vsync")) == QLatin1String("true")) | ||||
|         vSyncCheckBox->setCheckState(Qt::Checked); | ||||
| 
 | ||||
|  | @ -168,6 +250,11 @@ void GraphicsPage::loadSettings() | |||
|     QString width = mGraphicsSettings.value(QString("Video/resolution x")); | ||||
|     QString height = mGraphicsSettings.value(QString("Video/resolution y")); | ||||
|     QString resolution = width + QString(" x ") + height; | ||||
|     QString screen = mGraphicsSettings.value(QString("Video/screen")); | ||||
| 
 | ||||
|     int screenIndex = screenComboBox->findText(QString("Screen ") + screen); | ||||
|     if (screenIndex != -1) | ||||
|         screenComboBox->setCurrentIndex(screenIndex); | ||||
| 
 | ||||
|     int resIndex = resolutionComboBox->findText(resolution, Qt::MatchStartsWith); | ||||
| 
 | ||||
|  | @ -180,6 +267,8 @@ void GraphicsPage::loadSettings() | |||
|         customHeightSpinBox->setValue(height.toInt()); | ||||
| 
 | ||||
|     } | ||||
| 
 | ||||
|     return true; | ||||
| } | ||||
| 
 | ||||
| void GraphicsPage::saveSettings() | ||||
|  | @ -205,6 +294,11 @@ void GraphicsPage::saveSettings() | |||
|         mGraphicsSettings.setValue(QString("Video/resolution x"), QString::number(customWidthSpinBox->value())); | ||||
|         mGraphicsSettings.setValue(QString("Video/resolution y"), QString::number(customHeightSpinBox->value())); | ||||
|     } | ||||
| 
 | ||||
|     QRegExp screenRe(QString(".*(\\d+)")); | ||||
|     if(screenRe.exactMatch(screenComboBox->currentText())) { | ||||
|         mGraphicsSettings.setValue(QString("Video/screen"), screenRe.cap(1)); | ||||
|     } | ||||
| } | ||||
| 
 | ||||
| QStringList GraphicsPage::getAvailableOptions(const QString &key, Ogre::RenderSystem *renderer) | ||||
|  | @ -240,52 +334,27 @@ QStringList GraphicsPage::getAvailableOptions(const QString &key, Ogre::RenderSy | |||
|     return result; | ||||
| } | ||||
| 
 | ||||
| QStringList GraphicsPage::getAvailableResolutions(Ogre::RenderSystem *renderer) | ||||
| QStringList GraphicsPage::getAvailableResolutions(int screen) | ||||
| { | ||||
|     QString key("Video Mode"); | ||||
|     QStringList result; | ||||
| 
 | ||||
|     uint row = 0; | ||||
|     Ogre::ConfigOptionMap options = renderer->getConfigOptions(); | ||||
| 
 | ||||
|     for (Ogre::ConfigOptionMap::iterator i = options.begin (); i != options.end (); i++, row++) | ||||
|     for (std::vector<VideoMode>::iterator it = mVideoModes.begin(); it != mVideoModes.end(); it++) | ||||
|     { | ||||
|         if (key.toStdString() != i->first) | ||||
|         VideoMode mode = *it; | ||||
|         if(mode.screen != screen) | ||||
|             continue; | ||||
| 
 | ||||
|         Ogre::StringVector::iterator opt_it; | ||||
|         uint idx = 0; | ||||
| 
 | ||||
|         for (opt_it = i->second.possibleValues.begin (); | ||||
|              opt_it != i->second.possibleValues.end (); opt_it++, idx++) | ||||
|         { | ||||
|             QRegExp resolutionRe(QString("(\\d+) x (\\d+).*")); | ||||
|             QString resolution = QString::fromStdString(*opt_it).simplified(); | ||||
| 
 | ||||
|             if (resolutionRe.exactMatch(resolution)) { | ||||
| 
 | ||||
|                 int width = resolutionRe.cap(1).toInt(); | ||||
|                 int height = resolutionRe.cap(2).toInt(); | ||||
| 
 | ||||
|                 QString aspect = getAspect(width, height); | ||||
|                 QString cleanRes = resolutionRe.cap(1) + QString(" x ") + resolutionRe.cap(2); | ||||
|         QString aspect = getAspect(mode.w, mode.h); | ||||
|         QString resolution = QString::number(mode.w) + QString(" x ") + QString::number(mode.h); | ||||
| 
 | ||||
|         if (aspect == QLatin1String("16:9") || aspect == QLatin1String("16:10")) { | ||||
|                     cleanRes.append(tr("\t(Wide ") + aspect + ")"); | ||||
|             resolution.append(tr("\t(Wide ") + aspect + ")"); | ||||
| 
 | ||||
|         } else if (aspect == QLatin1String("4:3")) { | ||||
|                     cleanRes.append(tr("\t(Standard 4:3)")); | ||||
|                 } | ||||
|                 // do not add duplicate resolutions
 | ||||
|                 if (!result.contains(cleanRes)) | ||||
|                     result.append(cleanRes); | ||||
|             } | ||||
|         } | ||||
|             resolution.append(tr("\t(Standard 4:3)")); | ||||
|         } | ||||
| 
 | ||||
|     // Sort the resolutions in descending order
 | ||||
|     qSort(result.begin(), result.end(), naturalSortGreaterThanCI); | ||||
| 
 | ||||
|         result.append(resolution); | ||||
|     } | ||||
|     return result; | ||||
| } | ||||
| 
 | ||||
|  | @ -309,10 +378,17 @@ void GraphicsPage::rendererChanged(const QString &renderer) | |||
|     mSelectedRenderSystem = mOgre->getRenderSystemByName(renderer.toStdString()); | ||||
| 
 | ||||
|     antiAliasingComboBox->clear(); | ||||
|     resolutionComboBox->clear(); | ||||
| 
 | ||||
|     antiAliasingComboBox->addItems(getAvailableOptions(QString("FSAA"), mSelectedRenderSystem)); | ||||
|     resolutionComboBox->addItems(getAvailableResolutions(mSelectedRenderSystem)); | ||||
| } | ||||
| 
 | ||||
| void GraphicsPage::screenChanged(const QString &screen) | ||||
| { | ||||
|     QRegExp screenRe(QString(".*(\\d+)")); | ||||
|     if(screenRe.exactMatch(screen)) { | ||||
|         resolutionComboBox->clear(); | ||||
|         resolutionComboBox->addItems(getAvailableResolutions(screenRe.cap(1).toInt() - 1)); | ||||
|     } | ||||
| } | ||||
| 
 | ||||
| void GraphicsPage::slotFullScreenChanged(int state) | ||||
|  |  | |||
|  | @ -18,6 +18,13 @@ | |||
| 
 | ||||
| #include "ui_graphicspage.h" | ||||
| 
 | ||||
| struct VideoMode | ||||
| { | ||||
|     int w; | ||||
|     int h; | ||||
|     int screen; | ||||
| }; | ||||
| 
 | ||||
| class GraphicsSettings; | ||||
| 
 | ||||
| namespace Files { struct ConfigurationManager; } | ||||
|  | @ -30,10 +37,14 @@ public: | |||
|     GraphicsPage(Files::ConfigurationManager &cfg, GraphicsSettings &graphicsSettings, QWidget *parent = 0); | ||||
| 
 | ||||
|     void saveSettings(); | ||||
|     bool setupOgre(); | ||||
|     bool loadSettings(); | ||||
| 
 | ||||
|     // SDL workaround
 | ||||
|     static bool setupSDLWordaround(); | ||||
| 
 | ||||
| public slots: | ||||
|     void rendererChanged(const QString &renderer); | ||||
|     void screenChanged(const QString &screen); | ||||
| 
 | ||||
| private slots: | ||||
|     void slotFullScreenChanged(int state); | ||||
|  | @ -55,11 +66,14 @@ private: | |||
|     GraphicsSettings &mGraphicsSettings; | ||||
| 
 | ||||
|     QStringList getAvailableOptions(const QString &key, Ogre::RenderSystem *renderer); | ||||
|     QStringList getAvailableResolutions(Ogre::RenderSystem *renderer); | ||||
|     QStringList getAvailableResolutions(int screen); | ||||
|     QRect getMaximumResolution(); | ||||
| 
 | ||||
|     void loadSettings(); | ||||
|     static std::vector<VideoMode> mVideoModes; | ||||
|     static int mScreenCount; | ||||
| 
 | ||||
|     bool setupOgre(); | ||||
|     bool setupSDL(); | ||||
| }; | ||||
| 
 | ||||
| #endif | ||||
|  |  | |||
|  | @ -3,9 +3,14 @@ | |||
| #include <QDir> | ||||
| 
 | ||||
| #include "maindialog.hpp" | ||||
| // SDL workaround
 | ||||
| #include "graphicspage.hpp" | ||||
| 
 | ||||
| int main(int argc, char *argv[]) | ||||
| { | ||||
|     // SDL woraround
 | ||||
|     GraphicsPage::setupSDLWordaround(); | ||||
| 
 | ||||
|     QApplication app(argc, argv); | ||||
| 
 | ||||
|     // Now we make sure the current dir is set to application path
 | ||||
|  |  | |||
|  | @ -292,8 +292,8 @@ bool MainDialog::setup() | |||
|     // Now create the pages as they need the settings
 | ||||
|     createPages(); | ||||
| 
 | ||||
|     // Call this so we can exit on Ogre errors before mainwindow is shown
 | ||||
|     if (!mGraphicsPage->setupOgre()) | ||||
|     // Call this so we can exit on Ogre/SDL errors before mainwindow is shown
 | ||||
|     if (!mGraphicsPage->loadSettings()) | ||||
|         return false; | ||||
| 
 | ||||
|     loadSettings(); | ||||
|  |  | |||
|  | @ -58,6 +58,13 @@ | |||
|        </widget> | ||||
|       </item> | ||||
|       <item row="3" column="0"> | ||||
|        <widget class="QLabel" name="screenLabel"> | ||||
|         <property name="text"> | ||||
|          <string>Screen:</string> | ||||
|         </property> | ||||
|        </widget> | ||||
|       </item> | ||||
|       <item row="4" column="0"> | ||||
|        <widget class="QLabel" name="resolutionLabel"> | ||||
|         <property name="text"> | ||||
|          <string>Resolution:</string> | ||||
|  | @ -71,6 +78,9 @@ | |||
|        <widget class="QComboBox" name="antiAliasingComboBox"/> | ||||
|       </item> | ||||
|       <item row="3" column="1"> | ||||
|        <widget class="QComboBox" name="screenComboBox"/> | ||||
|       </item> | ||||
|       <item row="4" column="1"> | ||||
|        <layout class="QGridLayout" name="resolutionLayout"> | ||||
|         <item row="1" column="2"> | ||||
|          <layout class="QHBoxLayout" name="customResolutionLayout" stretch="1,0,1"> | ||||
|  |  | |||
		Loading…
	
		Reference in a new issue