2013-02-25 20:22:07 +00:00
|
|
|
|
#include "graphicspage.hpp"
|
|
|
|
|
|
2022-07-30 17:10:36 +00:00
|
|
|
|
#include "sdlinit.hpp"
|
|
|
|
|
|
2023-11-28 14:03:04 +00:00
|
|
|
|
#include <components/misc/display.hpp>
|
2023-10-08 11:58:49 +00:00
|
|
|
|
#include <components/settings/values.hpp>
|
|
|
|
|
|
2013-03-12 00:29:13 +00:00
|
|
|
|
#include <QMessageBox>
|
2019-11-28 05:48:59 +00:00
|
|
|
|
#include <QScreen>
|
|
|
|
|
|
2013-11-10 16:58:57 +00:00
|
|
|
|
#ifdef MAC_OS_X_VERSION_MIN_REQUIRED
|
|
|
|
|
#undef MAC_OS_X_VERSION_MIN_REQUIRED
|
2013-09-01 19:17:41 +00:00
|
|
|
|
// We need to do this because of Qt: https://bugreports.qt-project.org/browse/QTBUG-22154
|
|
|
|
|
#define MAC_OS_X_VERSION_MIN_REQUIRED __ENVIRONMENT_MAC_OS_X_VERSION_MIN_REQUIRED__
|
2013-11-10 16:58:57 +00:00
|
|
|
|
#endif // MAC_OS_X_VERSION_MIN_REQUIRED
|
|
|
|
|
|
2015-01-31 22:27:34 +00:00
|
|
|
|
#include <SDL_video.h>
|
2011-04-24 19:42:56 +00:00
|
|
|
|
|
2021-07-26 03:49:17 +00:00
|
|
|
|
#include <array>
|
2012-06-29 17:13:12 +00:00
|
|
|
|
|
2021-05-09 04:28:29 +00:00
|
|
|
|
Launcher::GraphicsPage::GraphicsPage(QWidget* parent)
|
2015-05-01 00:24:27 +00:00
|
|
|
|
: QWidget(parent)
|
2011-05-02 20:21:42 +00:00
|
|
|
|
{
|
2013-10-07 02:13:47 +00:00
|
|
|
|
setObjectName("GraphicsPage");
|
2013-03-05 01:17:28 +00:00
|
|
|
|
setupUi(this);
|
2011-05-10 23:12:25 +00:00
|
|
|
|
|
2013-03-05 01:17:28 +00:00
|
|
|
|
// Set the maximum res we can set in windowed mode
|
2013-06-22 17:15:13 +00:00
|
|
|
|
QRect res = getMaximumResolution();
|
2013-03-05 01:17:28 +00:00
|
|
|
|
customWidthSpinBox->setMaximum(res.width());
|
|
|
|
|
customHeightSpinBox->setMaximum(res.height());
|
2011-05-10 23:12:25 +00:00
|
|
|
|
|
2022-08-23 17:35:54 +00:00
|
|
|
|
connect(windowModeComboBox, qOverload<int>(&QComboBox::currentIndexChanged), this,
|
|
|
|
|
&GraphicsPage::slotFullScreenChanged);
|
|
|
|
|
connect(standardRadioButton, &QRadioButton::toggled, this, &GraphicsPage::slotStandardToggled);
|
|
|
|
|
connect(screenComboBox, qOverload<int>(&QComboBox::currentIndexChanged), this, &GraphicsPage::screenChanged);
|
|
|
|
|
connect(framerateLimitCheckBox, &QCheckBox::toggled, this, &GraphicsPage::slotFramerateLimitToggled);
|
2021-11-29 12:18:49 +00:00
|
|
|
|
}
|
2011-05-10 23:12:25 +00:00
|
|
|
|
|
2013-10-25 16:17:26 +00:00
|
|
|
|
bool Launcher::GraphicsPage::setupSDL()
|
2011-05-10 23:12:25 +00:00
|
|
|
|
{
|
2018-08-07 18:57:16 +00:00
|
|
|
|
bool sdlConnectSuccessful = initSDL();
|
2018-06-15 00:39:24 +00:00
|
|
|
|
if (!sdlConnectSuccessful)
|
|
|
|
|
{
|
|
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
|
2013-06-23 18:45:24 +00:00
|
|
|
|
int displays = SDL_GetNumVideoDisplays();
|
2013-06-23 01:49:30 +00:00
|
|
|
|
|
2013-06-23 18:53:50 +00:00
|
|
|
|
if (displays < 0)
|
2013-06-23 01:49:30 +00:00
|
|
|
|
{
|
2013-06-23 19:16:51 +00:00
|
|
|
|
QMessageBox msgBox;
|
|
|
|
|
msgBox.setWindowTitle(tr("Error receiving number of screens"));
|
|
|
|
|
msgBox.setIcon(QMessageBox::Critical);
|
|
|
|
|
msgBox.setStandardButtons(QMessageBox::Ok);
|
2020-08-25 23:16:14 +00:00
|
|
|
|
msgBox.setText(
|
|
|
|
|
tr("<br><b>SDL_GetNumVideoDisplays failed:</b><br><br>") + QString::fromUtf8(SDL_GetError()) + "<br>");
|
2013-06-23 19:16:51 +00:00
|
|
|
|
msgBox.exec();
|
2013-06-23 01:49:30 +00:00
|
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
|
2014-11-19 12:19:02 +00:00
|
|
|
|
screenComboBox->clear();
|
2020-08-26 15:58:51 +00:00
|
|
|
|
mResolutionsPerScreen.clear();
|
2013-06-23 18:45:24 +00:00
|
|
|
|
for (int i = 0; i < displays; i++)
|
2013-06-23 01:49:30 +00:00
|
|
|
|
{
|
2020-08-26 15:58:51 +00:00
|
|
|
|
mResolutionsPerScreen.append(getAvailableResolutions(i));
|
2013-06-23 19:56:27 +00:00
|
|
|
|
screenComboBox->addItem(QString(tr("Screen ")) + QString::number(i + 1));
|
2013-06-23 01:49:30 +00:00
|
|
|
|
}
|
2020-08-26 15:58:12 +00:00
|
|
|
|
screenChanged(0);
|
2013-06-23 01:49:30 +00:00
|
|
|
|
|
2018-06-15 00:39:24 +00:00
|
|
|
|
// Disconnect from SDL processes
|
2018-08-07 18:57:16 +00:00
|
|
|
|
quitSDL();
|
2018-06-15 00:39:24 +00:00
|
|
|
|
|
2013-06-23 01:49:30 +00:00
|
|
|
|
return true;
|
|
|
|
|
}
|
|
|
|
|
|
2013-10-25 16:17:26 +00:00
|
|
|
|
bool Launcher::GraphicsPage::loadSettings()
|
2013-06-23 01:49:30 +00:00
|
|
|
|
{
|
|
|
|
|
if (!setupSDL())
|
|
|
|
|
return false;
|
|
|
|
|
|
2021-05-18 23:05:54 +00:00
|
|
|
|
// Visuals
|
2023-02-26 09:19:58 +00:00
|
|
|
|
|
2023-10-27 10:24:42 +00:00
|
|
|
|
const int vsync = Settings::video().mVsyncMode;
|
2023-02-26 09:19:58 +00:00
|
|
|
|
|
|
|
|
|
vSyncComboBox->setCurrentIndex(vsync);
|
2011-06-26 21:35:23 +00:00
|
|
|
|
|
2023-10-27 10:24:42 +00:00
|
|
|
|
const Settings::WindowMode windowMode = Settings::video().mWindowMode;
|
2011-05-10 23:12:25 +00:00
|
|
|
|
|
2023-10-27 10:24:42 +00:00
|
|
|
|
windowModeComboBox->setCurrentIndex(static_cast<int>(windowMode));
|
|
|
|
|
handleWindowModeChange(windowMode);
|
|
|
|
|
|
|
|
|
|
if (Settings::video().mWindowBorder)
|
2014-12-24 14:09:50 +00:00
|
|
|
|
windowBorderCheckBox->setCheckState(Qt::Checked);
|
2014-12-22 01:44:20 +00:00
|
|
|
|
|
2015-11-25 18:17:03 +00:00
|
|
|
|
// aaValue is the actual value (0, 1, 2, 4, 8, 16)
|
2023-10-27 10:24:42 +00:00
|
|
|
|
const int aaValue = Settings::video().mAntialiasing;
|
2015-11-25 18:17:03 +00:00
|
|
|
|
// aaIndex is the index into the allowed values in the pull down.
|
2023-10-27 10:24:42 +00:00
|
|
|
|
const int aaIndex = antiAliasingComboBox->findText(QString::number(aaValue));
|
2013-02-25 20:22:07 +00:00
|
|
|
|
if (aaIndex != -1)
|
2013-03-05 01:17:28 +00:00
|
|
|
|
antiAliasingComboBox->setCurrentIndex(aaIndex);
|
2011-05-10 23:12:25 +00:00
|
|
|
|
|
2023-10-27 10:24:42 +00:00
|
|
|
|
const int width = Settings::video().mResolutionX;
|
|
|
|
|
const int height = Settings::video().mResolutionY;
|
2023-11-28 18:47:27 +00:00
|
|
|
|
QString resolution = QString::number(width) + QString(" × ") + QString::number(height);
|
2023-10-27 10:24:42 +00:00
|
|
|
|
screenComboBox->setCurrentIndex(Settings::video().mScreen);
|
2012-06-26 13:37:40 +00:00
|
|
|
|
|
2013-03-05 01:17:28 +00:00
|
|
|
|
int resIndex = resolutionComboBox->findText(resolution, Qt::MatchStartsWith);
|
2013-02-24 23:56:04 +00:00
|
|
|
|
|
2013-03-05 01:17:28 +00:00
|
|
|
|
if (resIndex != -1)
|
|
|
|
|
{
|
|
|
|
|
standardRadioButton->toggle();
|
|
|
|
|
resolutionComboBox->setCurrentIndex(resIndex);
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
customRadioButton->toggle();
|
2015-11-25 18:17:03 +00:00
|
|
|
|
customWidthSpinBox->setValue(width);
|
|
|
|
|
customHeightSpinBox->setValue(height);
|
2013-03-05 01:17:28 +00:00
|
|
|
|
}
|
2013-06-23 01:49:30 +00:00
|
|
|
|
|
2023-10-27 10:24:42 +00:00
|
|
|
|
const float fpsLimit = Settings::video().mFramerateLimit;
|
2019-05-30 04:11:13 +00:00
|
|
|
|
if (fpsLimit != 0)
|
|
|
|
|
{
|
|
|
|
|
framerateLimitCheckBox->setCheckState(Qt::Checked);
|
|
|
|
|
framerateLimitSpinBox->setValue(fpsLimit);
|
|
|
|
|
}
|
|
|
|
|
|
2013-06-23 01:49:30 +00:00
|
|
|
|
return true;
|
2011-05-10 23:12:25 +00:00
|
|
|
|
}
|
|
|
|
|
|
2013-10-25 16:17:26 +00:00
|
|
|
|
void Launcher::GraphicsPage::saveSettings()
|
2011-05-10 23:12:25 +00:00
|
|
|
|
{
|
2021-05-18 23:05:54 +00:00
|
|
|
|
// Visuals
|
|
|
|
|
|
2023-10-27 10:24:42 +00:00
|
|
|
|
Settings::video().mVsyncMode.set(static_cast<SDLUtil::VSyncMode>(vSyncComboBox->currentIndex()));
|
|
|
|
|
Settings::video().mWindowMode.set(static_cast<Settings::WindowMode>(windowModeComboBox->currentIndex()));
|
|
|
|
|
Settings::video().mWindowBorder.set(windowBorderCheckBox->checkState() == Qt::Checked);
|
|
|
|
|
Settings::video().mAntialiasing.set(antiAliasingComboBox->currentText().toInt());
|
2013-01-27 15:39:51 +00:00
|
|
|
|
|
2015-11-26 02:30:04 +00:00
|
|
|
|
int cWidth = 0;
|
|
|
|
|
int cHeight = 0;
|
2013-03-06 00:35:32 +00:00
|
|
|
|
if (standardRadioButton->isChecked())
|
|
|
|
|
{
|
2023-11-28 18:47:27 +00:00
|
|
|
|
QRegularExpression resolutionRe("^(\\d+) × (\\d+)");
|
2023-01-10 18:12:13 +00:00
|
|
|
|
QRegularExpressionMatch match = resolutionRe.match(resolutionComboBox->currentText().simplified());
|
|
|
|
|
if (match.hasMatch())
|
2013-03-06 00:35:32 +00:00
|
|
|
|
{
|
2023-01-10 18:12:13 +00:00
|
|
|
|
cWidth = match.captured(1).toInt();
|
|
|
|
|
cHeight = match.captured(2).toInt();
|
2013-03-06 00:35:32 +00:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
2015-11-26 02:30:04 +00:00
|
|
|
|
cWidth = customWidthSpinBox->value();
|
|
|
|
|
cHeight = customHeightSpinBox->value();
|
2013-01-27 15:39:51 +00:00
|
|
|
|
}
|
2013-06-23 01:49:30 +00:00
|
|
|
|
|
2023-10-27 10:24:42 +00:00
|
|
|
|
Settings::video().mResolutionX.set(cWidth);
|
|
|
|
|
Settings::video().mResolutionY.set(cHeight);
|
|
|
|
|
Settings::video().mScreen.set(screenComboBox->currentIndex());
|
2019-05-30 04:11:13 +00:00
|
|
|
|
|
2021-01-09 09:19:41 +00:00
|
|
|
|
if (framerateLimitCheckBox->checkState() != Qt::Unchecked)
|
2019-05-30 04:11:13 +00:00
|
|
|
|
{
|
2023-10-27 10:24:42 +00:00
|
|
|
|
Settings::video().mFramerateLimit.set(framerateLimitSpinBox->value());
|
2019-05-30 04:11:13 +00:00
|
|
|
|
}
|
2023-10-27 10:24:42 +00:00
|
|
|
|
else if (Settings::video().mFramerateLimit != 0)
|
2019-05-30 04:11:13 +00:00
|
|
|
|
{
|
2023-10-27 10:24:42 +00:00
|
|
|
|
Settings::video().mFramerateLimit.set(0);
|
2019-05-30 04:11:13 +00:00
|
|
|
|
}
|
2011-05-10 23:12:25 +00:00
|
|
|
|
}
|
|
|
|
|
|
2013-10-25 16:17:26 +00:00
|
|
|
|
QStringList Launcher::GraphicsPage::getAvailableResolutions(int screen)
|
2012-06-19 13:57:58 +00:00
|
|
|
|
{
|
|
|
|
|
QStringList result;
|
2013-06-23 18:45:24 +00:00
|
|
|
|
SDL_DisplayMode mode;
|
|
|
|
|
int modeIndex, modes = SDL_GetNumDisplayModes(screen);
|
|
|
|
|
|
2013-06-23 18:53:50 +00:00
|
|
|
|
if (modes < 0)
|
2013-06-23 18:45:24 +00:00
|
|
|
|
{
|
2013-06-23 19:16:51 +00:00
|
|
|
|
QMessageBox msgBox;
|
|
|
|
|
msgBox.setWindowTitle(tr("Error receiving resolutions"));
|
|
|
|
|
msgBox.setIcon(QMessageBox::Critical);
|
|
|
|
|
msgBox.setStandardButtons(QMessageBox::Ok);
|
2015-02-06 17:05:02 +00:00
|
|
|
|
msgBox.setText(
|
|
|
|
|
tr("<br><b>SDL_GetNumDisplayModes failed:</b><br><br>") + QString::fromUtf8(SDL_GetError()) + "<br>");
|
2013-06-23 19:16:51 +00:00
|
|
|
|
msgBox.exec();
|
2013-06-23 18:45:24 +00:00
|
|
|
|
return result;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
for (modeIndex = 0; modeIndex < modes; modeIndex++)
|
2012-06-19 13:57:58 +00:00
|
|
|
|
{
|
2013-06-23 18:45:24 +00:00
|
|
|
|
if (SDL_GetDisplayMode(screen, modeIndex, &mode) < 0)
|
|
|
|
|
{
|
2013-06-23 19:16:51 +00:00
|
|
|
|
QMessageBox msgBox;
|
|
|
|
|
msgBox.setWindowTitle(tr("Error receiving resolutions"));
|
|
|
|
|
msgBox.setIcon(QMessageBox::Critical);
|
|
|
|
|
msgBox.setStandardButtons(QMessageBox::Ok);
|
2015-02-06 17:05:02 +00:00
|
|
|
|
msgBox.setText(
|
|
|
|
|
tr("<br><b>SDL_GetDisplayMode failed:</b><br><br>") + QString::fromUtf8(SDL_GetError()) + "<br>");
|
2013-06-23 19:16:51 +00:00
|
|
|
|
msgBox.exec();
|
2013-06-23 18:45:24 +00:00
|
|
|
|
return result;
|
|
|
|
|
}
|
|
|
|
|
|
2023-11-28 18:47:27 +00:00
|
|
|
|
auto str = Misc::getResolutionText(mode.w, mode.h, "%i × %i (%i:%i)");
|
2023-11-28 14:03:04 +00:00
|
|
|
|
result.append(QString(str.c_str()));
|
2013-06-23 01:49:30 +00:00
|
|
|
|
}
|
2013-06-23 18:45:24 +00:00
|
|
|
|
|
2013-06-23 19:04:49 +00:00
|
|
|
|
result.removeDuplicates();
|
2012-06-19 13:57:58 +00:00
|
|
|
|
return result;
|
|
|
|
|
}
|
|
|
|
|
|
2013-10-25 16:17:26 +00:00
|
|
|
|
QRect Launcher::GraphicsPage::getMaximumResolution()
|
2013-06-22 17:15:13 +00:00
|
|
|
|
{
|
2013-06-22 18:32:11 +00:00
|
|
|
|
QRect max;
|
2019-11-28 05:48:59 +00:00
|
|
|
|
|
|
|
|
|
for (QScreen* screen : QGuiApplication::screens())
|
|
|
|
|
{
|
|
|
|
|
QRect res = screen->geometry();
|
|
|
|
|
if (res.width() > max.width())
|
|
|
|
|
max.setWidth(res.width());
|
|
|
|
|
if (res.height() > max.height())
|
|
|
|
|
max.setHeight(res.height());
|
|
|
|
|
}
|
2013-06-22 17:15:13 +00:00
|
|
|
|
return max;
|
|
|
|
|
}
|
|
|
|
|
|
2013-10-25 16:17:26 +00:00
|
|
|
|
void Launcher::GraphicsPage::screenChanged(int screen)
|
2013-06-23 01:49:30 +00:00
|
|
|
|
{
|
2013-06-23 19:56:27 +00:00
|
|
|
|
if (screen >= 0)
|
|
|
|
|
{
|
2013-06-23 01:49:30 +00:00
|
|
|
|
resolutionComboBox->clear();
|
2020-08-26 15:58:51 +00:00
|
|
|
|
resolutionComboBox->addItems(mResolutionsPerScreen[screen]);
|
2013-06-23 01:49:30 +00:00
|
|
|
|
}
|
2013-03-05 01:17:28 +00:00
|
|
|
|
}
|
2011-05-02 20:21:42 +00:00
|
|
|
|
|
2022-05-04 05:50:31 +00:00
|
|
|
|
void Launcher::GraphicsPage::slotFullScreenChanged(int mode)
|
2013-03-05 01:17:28 +00:00
|
|
|
|
{
|
2023-10-27 10:24:42 +00:00
|
|
|
|
handleWindowModeChange(static_cast<Settings::WindowMode>(mode));
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void Launcher::GraphicsPage::handleWindowModeChange(Settings::WindowMode mode)
|
|
|
|
|
{
|
|
|
|
|
if (mode == Settings::WindowMode::Fullscreen || mode == Settings::WindowMode::WindowedFullscreen)
|
2022-05-09 05:56:35 +00:00
|
|
|
|
{
|
2013-03-05 01:17:28 +00:00
|
|
|
|
standardRadioButton->toggle();
|
|
|
|
|
customRadioButton->setEnabled(false);
|
|
|
|
|
customWidthSpinBox->setEnabled(false);
|
|
|
|
|
customHeightSpinBox->setEnabled(false);
|
2014-12-24 14:09:50 +00:00
|
|
|
|
windowBorderCheckBox->setEnabled(false);
|
2013-03-05 01:17:28 +00:00
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
customRadioButton->setEnabled(true);
|
|
|
|
|
customWidthSpinBox->setEnabled(true);
|
|
|
|
|
customHeightSpinBox->setEnabled(true);
|
2014-12-24 14:09:50 +00:00
|
|
|
|
windowBorderCheckBox->setEnabled(true);
|
2013-03-05 01:17:28 +00:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2013-10-25 16:17:26 +00:00
|
|
|
|
void Launcher::GraphicsPage::slotStandardToggled(bool checked)
|
2013-03-05 01:17:28 +00:00
|
|
|
|
{
|
|
|
|
|
if (checked)
|
|
|
|
|
{
|
|
|
|
|
resolutionComboBox->setEnabled(true);
|
|
|
|
|
customWidthSpinBox->setEnabled(false);
|
|
|
|
|
customHeightSpinBox->setEnabled(false);
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
resolutionComboBox->setEnabled(false);
|
|
|
|
|
customWidthSpinBox->setEnabled(true);
|
|
|
|
|
customHeightSpinBox->setEnabled(true);
|
|
|
|
|
}
|
2011-09-02 18:01:24 +00:00
|
|
|
|
}
|
2019-05-30 04:11:13 +00:00
|
|
|
|
|
|
|
|
|
void Launcher::GraphicsPage::slotFramerateLimitToggled(bool checked)
|
|
|
|
|
{
|
|
|
|
|
framerateLimitSpinBox->setEnabled(checked);
|
|
|
|
|
}
|