Skip to content

Commit

Permalink
Merge pull request #12170 from Filoppi/custom_aspect_ratio
Browse files Browse the repository at this point in the history
Add support for custom aspect ratios
  • Loading branch information
AdmiralCurtiss committed Dec 18, 2023
2 parents de8bc32 + a6dfeed commit 715a551
Show file tree
Hide file tree
Showing 16 changed files with 209 additions and 88 deletions.
4 changes: 4 additions & 0 deletions Source/Core/Core/Config/GraphicsSettings.cpp
Expand Up @@ -21,6 +21,10 @@ const Info<int> GFX_ADAPTER{{System::GFX, "Hardware", "Adapter"}, 0};

const Info<bool> GFX_WIDESCREEN_HACK{{System::GFX, "Settings", "wideScreenHack"}, false};
const Info<AspectMode> GFX_ASPECT_RATIO{{System::GFX, "Settings", "AspectRatio"}, AspectMode::Auto};
const Info<int> GFX_CUSTOM_ASPECT_RATIO_WIDTH{{System::GFX, "Settings", "CustomAspectRatioWidth"},
1};
const Info<int> GFX_CUSTOM_ASPECT_RATIO_HEIGHT{{System::GFX, "Settings", "CustomAspectRatioHeight"},
1};
const Info<AspectMode> GFX_SUGGESTED_ASPECT_RATIO{{System::GFX, "Settings", "SuggestedAspectRatio"},
AspectMode::Auto};
const Info<u32> GFX_WIDESCREEN_HEURISTIC_TRANSITION_THRESHOLD{
Expand Down
2 changes: 2 additions & 0 deletions Source/Core/Core/Config/GraphicsSettings.h
Expand Up @@ -28,6 +28,8 @@ extern const Info<int> GFX_ADAPTER;

extern const Info<bool> GFX_WIDESCREEN_HACK;
extern const Info<AspectMode> GFX_ASPECT_RATIO;
extern const Info<int> GFX_CUSTOM_ASPECT_RATIO_WIDTH;
extern const Info<int> GFX_CUSTOM_ASPECT_RATIO_HEIGHT;
extern const Info<AspectMode> GFX_SUGGESTED_ASPECT_RATIO;
extern const Info<u32> GFX_WIDESCREEN_HEURISTIC_TRANSITION_THRESHOLD;
extern const Info<float> GFX_WIDESCREEN_HEURISTIC_ASPECT_RATIO_SLOP;
Expand Down
2 changes: 1 addition & 1 deletion Source/Core/Core/HW/VideoInterface.cpp
Expand Up @@ -477,7 +477,7 @@ float VideoInterfaceManager::GetAspectRatio() const
// signal (which would be 4:3)

// This function only deals with standard aspect ratios. For widescreen aspect ratios,
// multiply the result by 1.33333..
// multiply the result by 1.33333... (the ratio between 16:9 and 4:3)

// 1. Get our active area in BT.601 samples (more or less pixels)
int active_lines = m_vertical_timing_register.ACV;
Expand Down
4 changes: 2 additions & 2 deletions Source/Core/Core/HW/VideoInterface.h
Expand Up @@ -388,9 +388,9 @@ class VideoInterfaceManager
u32 GetTicksPerHalfLine() const;
u32 GetTicksPerField() const;

// Get the aspect ratio of VI's active area.
// Get the aspect ratio of VI's active area (rarely matching pure 4:3).
// This function only deals with standard aspect ratios. For widescreen aspect ratios, multiply
// the result by 1.33333..
// the result by 1.33333... (the ratio between 16:9 and 4:3)
float GetAspectRatio() const;

// Create a fake VI mode for a fifolog
Expand Down
5 changes: 3 additions & 2 deletions Source/Core/DolphinQt/Config/Graphics/AdvancedWidget.cpp
Expand Up @@ -359,8 +359,9 @@ void AdvancedWidget::AddDescriptions()
"level 9 but finish in significantly less time.<br><br>"
"<dolphin_emphasis>If unsure, leave this at 6.</dolphin_emphasis>");
static const char TR_CROPPING_DESCRIPTION[] = QT_TR_NOOP(
"Crops the picture from its native aspect ratio to 4:3 or "
"16:9.<br><br><dolphin_emphasis>If unsure, leave this unchecked.</dolphin_emphasis>");
"Crops the picture from its native aspect ratio (which rarely exactly matches 4:3 or 16:9),"
" to the specific user target aspect ratio (e.g. 4:3 or 16:9).<br><br>"
"<dolphin_emphasis>If unsure, leave this unchecked.</dolphin_emphasis>");
static const char TR_PROGRESSIVE_SCAN_DESCRIPTION[] = QT_TR_NOOP(
"Enables progressive scan if supported by the emulated software. Most games don't have "
"any issue with this.<br><br><dolphin_emphasis>If unsure, leave this "
Expand Down
11 changes: 5 additions & 6 deletions Source/Core/DolphinQt/Config/Graphics/EnhancementsWidget.cpp
Expand Up @@ -561,12 +561,11 @@ void EnhancementsWidget::AddDescriptions()
"causes slowdowns or graphical issues.<br><br><dolphin_emphasis>If unsure, leave "
"this unchecked.</dolphin_emphasis>");
static const char TR_WIDESCREEN_HACK_DESCRIPTION[] = QT_TR_NOOP(
"Forces the game to output graphics for any aspect ratio. Use with \"Aspect Ratio\" set to "
"\"Force 16:9\" to force 4:3-only games to run at 16:9.<br><br>Rarely produces good "
"results and "
"often partially breaks graphics and game UIs. Unnecessary (and detrimental) if using any "
"AR/Gecko-code widescreen patches.<br><br><dolphin_emphasis>If unsure, leave "
"this unchecked.</dolphin_emphasis>");
"Forces the game to output graphics at any aspect ratio by expanding the view frustum "
"without stretching the image.<br>This is a hack, and its results will vary widely game "
"to game (it often causes the UI to stretch).<br>"
"Game-specific AR/Gecko-code aspect ratio patches are preferable over this if available."
"<br><br><dolphin_emphasis>If unsure, leave this unchecked.</dolphin_emphasis>");
static const char TR_REMOVE_FOG_DESCRIPTION[] =
QT_TR_NOOP("Makes distant objects more visible by removing fog, thus increasing the overall "
"detail.<br><br>Disabling fog will break some games which rely on proper fog "
Expand Down
64 changes: 51 additions & 13 deletions Source/Core/DolphinQt/Config/Graphics/GeneralWidget.cpp
Expand Up @@ -20,6 +20,7 @@

#include "DolphinQt/Config/ConfigControls/ConfigBool.h"
#include "DolphinQt/Config/ConfigControls/ConfigChoice.h"
#include "DolphinQt/Config/ConfigControls/ConfigInteger.h"
#include "DolphinQt/Config/ConfigControls/ConfigRadio.h"
#include "DolphinQt/Config/Graphics/GraphicsWindow.h"
#include "DolphinQt/Config/ToolTipControls/ToolTipComboBox.h"
Expand Down Expand Up @@ -54,9 +55,20 @@ void GeneralWidget::CreateWidgets()
m_video_layout = new QGridLayout();

m_backend_combo = new ToolTipComboBox();
m_aspect_combo =
new ConfigChoice({tr("Auto"), tr("Force 16:9"), tr("Force 4:3"), tr("Stretch to Window")},
Config::GFX_ASPECT_RATIO);
m_aspect_combo = new ConfigChoice(
{tr("Auto"), tr("Force 16:9"), tr("Force 4:3"), tr("Stretch to Window"), tr("Custom")},
Config::GFX_ASPECT_RATIO);
m_custom_aspect_label = new QLabel(tr("Custom Aspect Ratio:"));
m_custom_aspect_label->setHidden(true);
constexpr int MAX_CUSTOM_ASPECT_RATIO_RESOLUTION = 10000;
m_custom_aspect_width = new ConfigInteger(1, MAX_CUSTOM_ASPECT_RATIO_RESOLUTION,
Config::GFX_CUSTOM_ASPECT_RATIO_WIDTH);
m_custom_aspect_width->setEnabled(false);
m_custom_aspect_width->setHidden(true);
m_custom_aspect_height = new ConfigInteger(1, MAX_CUSTOM_ASPECT_RATIO_RESOLUTION,
Config::GFX_CUSTOM_ASPECT_RATIO_HEIGHT);
m_custom_aspect_height->setEnabled(false);
m_custom_aspect_height->setHidden(true);
m_adapter_combo = new ToolTipComboBox;
m_enable_vsync = new ConfigBool(tr("V-Sync"), Config::GFX_VSYNC);
m_enable_fullscreen = new ConfigBool(tr("Start in Fullscreen"), Config::MAIN_FULLSCREEN);
Expand All @@ -70,16 +82,20 @@ void GeneralWidget::CreateWidgets()
}

m_video_layout->addWidget(new QLabel(tr("Backend:")), 0, 0);
m_video_layout->addWidget(m_backend_combo, 0, 1);
m_video_layout->addWidget(m_backend_combo, 0, 1, 1, -1);

m_video_layout->addWidget(new QLabel(tr("Adapter:")), 1, 0);
m_video_layout->addWidget(m_adapter_combo, 1, 1);
m_video_layout->addWidget(m_adapter_combo, 1, 1, 1, -1);

m_video_layout->addWidget(new QLabel(tr("Aspect Ratio:")), 3, 0);
m_video_layout->addWidget(m_aspect_combo, 3, 1);
m_video_layout->addWidget(m_aspect_combo, 3, 1, 1, -1);

m_video_layout->addWidget(m_enable_vsync, 4, 0);
m_video_layout->addWidget(m_enable_fullscreen, 4, 1);
m_video_layout->addWidget(m_custom_aspect_label, 4, 0);
m_video_layout->addWidget(m_custom_aspect_width, 4, 1);
m_video_layout->addWidget(m_custom_aspect_height, 4, 2);

m_video_layout->addWidget(m_enable_vsync, 5, 0);
m_video_layout->addWidget(m_enable_fullscreen, 5, 1, 1, -1);

// Other
auto* m_options_box = new QGroupBox(tr("Other"));
Expand Down Expand Up @@ -138,13 +154,28 @@ void GeneralWidget::ConnectWidgets()
Config::SetBaseOrCurrent(Config::GFX_ADAPTER, index);
emit BackendChanged(QString::fromStdString(Config::Get(Config::MAIN_GFX_BACKEND)));
});
connect(m_aspect_combo, qOverload<int>(&QComboBox::currentIndexChanged), this, [&](int index) {
const bool is_custom_aspect_ratio = (index == static_cast<int>(AspectMode::Custom));
m_custom_aspect_width->setEnabled(is_custom_aspect_ratio);
m_custom_aspect_height->setEnabled(is_custom_aspect_ratio);
m_custom_aspect_label->setHidden(!is_custom_aspect_ratio);
m_custom_aspect_width->setHidden(!is_custom_aspect_ratio);
m_custom_aspect_height->setHidden(!is_custom_aspect_ratio);
});
}

void GeneralWidget::LoadSettings()
{
// Video Backend
m_backend_combo->setCurrentIndex(m_backend_combo->findData(
QVariant(QString::fromStdString(Config::Get(Config::MAIN_GFX_BACKEND)))));

const bool is_custom_aspect_ratio = (Config::Get(Config::GFX_ASPECT_RATIO) == AspectMode::Custom);
m_custom_aspect_width->setEnabled(is_custom_aspect_ratio);
m_custom_aspect_height->setEnabled(is_custom_aspect_ratio);
m_custom_aspect_label->setHidden(!is_custom_aspect_ratio);
m_custom_aspect_width->setHidden(!is_custom_aspect_ratio);
m_custom_aspect_height->setHidden(!is_custom_aspect_ratio);
}

void GeneralWidget::SaveSettings()
Expand Down Expand Up @@ -207,11 +238,15 @@ void GeneralWidget::AddDescriptions()
QT_TR_NOOP("Uses the main Dolphin window for rendering rather than "
"a separate render window.<br><br><dolphin_emphasis>If unsure, leave "
"this unchecked.</dolphin_emphasis>");
static const char TR_ASPECT_RATIO_DESCRIPTION[] = QT_TR_NOOP(
"Selects which aspect ratio to use when rendering.<br><br>Auto: Uses the native aspect "
"ratio<br>Force 16:9: Mimics an analog TV with a widescreen aspect ratio.<br>Force 4:3: "
"Mimics a standard 4:3 analog TV.<br>Stretch to Window: Stretches the picture to the "
"window size.<br><br><dolphin_emphasis>If unsure, select Auto.</dolphin_emphasis>");
static const char TR_ASPECT_RATIO_DESCRIPTION[] =
QT_TR_NOOP("Selects which aspect ratio to use when rendering.<br>"
"Each game can have a slightly different native aspect ratio."
"<br><br>Auto: Uses the native aspect ratio"
"<br>Force 16:9: Mimics an analog TV with a widescreen aspect ratio."
"<br>Force 4:3: Mimics a standard 4:3 analog TV."
"<br>Stretch to Window: Stretches the picture to the window size."
"<br>Custom: For games running with specific custom aspect ratio cheats.<br><br>"
"<dolphin_emphasis>If unsure, select Auto.</dolphin_emphasis>");
static const char TR_VSYNC_DESCRIPTION[] = QT_TR_NOOP(
"Waits for vertical blanks in order to prevent tearing.<br><br>Decreases performance "
"if emulation speed is below 100%.<br><br><dolphin_emphasis>If unsure, leave "
Expand Down Expand Up @@ -260,6 +295,9 @@ void GeneralWidget::AddDescriptions()
m_aspect_combo->SetTitle(tr("Aspect Ratio"));
m_aspect_combo->SetDescription(tr(TR_ASPECT_RATIO_DESCRIPTION));

m_custom_aspect_width->SetTitle(tr("Custom Aspect Ratio Width"));
m_custom_aspect_height->SetTitle(tr("Custom Aspect Ratio Height"));

m_enable_vsync->SetDescription(tr(TR_VSYNC_DESCRIPTION));

m_enable_fullscreen->SetDescription(tr(TR_FULLSCREEN_DESCRIPTION));
Expand Down
5 changes: 5 additions & 0 deletions Source/Core/DolphinQt/Config/Graphics/GeneralWidget.h
Expand Up @@ -9,10 +9,12 @@

class ConfigBool;
class ConfigChoice;
class ConfigInteger;
class ConfigRadioInt;
class GraphicsWindow;
class QCheckBox;
class QComboBox;
class QLabel;
class QRadioButton;
class QGridLayout;
class ToolTipComboBox;
Expand Down Expand Up @@ -41,6 +43,9 @@ class GeneralWidget final : public QWidget
ToolTipComboBox* m_backend_combo;
ToolTipComboBox* m_adapter_combo;
ConfigChoice* m_aspect_combo;
QLabel* m_custom_aspect_label;
ConfigInteger* m_custom_aspect_width;
ConfigInteger* m_custom_aspect_height;
ConfigBool* m_enable_vsync;
ConfigBool* m_enable_fullscreen;

Expand Down
7 changes: 5 additions & 2 deletions Source/Core/DolphinQt/HotkeyScheduler.cpp
Expand Up @@ -402,12 +402,15 @@ void HotkeyScheduler::Run()
case AspectMode::Stretch:
OSD::AddMessage("Stretch");
break;
case AspectMode::Analog:
case AspectMode::ForceStandard:
OSD::AddMessage("Force 4:3");
break;
case AspectMode::AnalogWide:
case AspectMode::ForceWide:
OSD::AddMessage("Force 16:9");
break;
case AspectMode::Custom:
OSD::AddMessage("Custom");
break;
case AspectMode::Auto:
default:
OSD::AddMessage("Auto");
Expand Down

0 comments on commit 715a551

Please sign in to comment.