From 46db0c0823d1cb544e4fcfec87678ababef5f3ab Mon Sep 17 00:00:00 2001 From: Clayton Groeneveld Date: Wed, 22 Jan 2020 12:25:05 -0600 Subject: [PATCH] UI: Fix aspect ratio triggering settings change --- UI/window-basic-settings.cpp | 47 ++++++++++++++++++++---------------- 1 file changed, 26 insertions(+), 21 deletions(-) diff --git a/UI/window-basic-settings.cpp b/UI/window-basic-settings.cpp index 3a434969c..f5db1f779 100644 --- a/UI/window-basic-settings.cpp +++ b/UI/window-basic-settings.cpp @@ -247,6 +247,25 @@ static void PopulateAACBitrates(initializer_list boxes) } } +static int gcd(int a, int b) +{ + return b == 0 ? a : gcd(b, a % b); +} + +static std::tuple aspect_ratio(int cx, int cy) +{ + int common = gcd(cx, cy); + int newCX = cx / common; + int newCY = cy / common; + + if (newCX == 8 && newCY == 5) { + newCX = 16; + newCY = 10; + } + + return std::make_tuple(newCX, newCY); +} + void RestrictResetBitrates(initializer_list boxes, int maxbitrate); void OBSBasicSettings::HookWidget(QWidget *widget, const char *signal, @@ -760,8 +779,6 @@ OBSBasicSettings::OBSBasicSettings(QWidget *parent) UpdateAutomaticReplayBufferCheckboxes(); - on_baseResolution_editTextChanged(ui->baseResolution->currentText()); - App()->DisableHotkeys(); channelIndex = ui->channelSetup->currentIndex(); @@ -1406,6 +1423,13 @@ void OBSBasicSettings::LoadResolutionLists() ResetDownscales(cx, cy); ui->outputResolution->lineEdit()->setText(outputResString.c_str()); + + std::tuple aspect = aspect_ratio(cx, cy); + + ui->baseAspect->setText( + QTStr("AspectRatio") + .arg(QString::number(std::get<0>(aspect)), + QString::number(std::get<1>(aspect)))); } static inline void LoadFPSCommon(OBSBasic *main, Ui::OBSBasicSettings *ui) @@ -3753,25 +3777,6 @@ static bool ValidResolutions(Ui::OBSBasicSettings *ui) return true; } -static int gcd(int a, int b) -{ - return b == 0 ? a : gcd(b, a % b); -} - -static std::tuple aspect_ratio(int cx, int cy) -{ - int common = gcd(cx, cy); - int newCX = cx / common; - int newCY = cy / common; - - if (newCX == 8 && newCY == 5) { - newCX = 16; - newCY = 10; - } - - return std::make_tuple(newCX, newCY); -} - void OBSBasicSettings::RecalcOutputResPixels(const char *resText) { uint32_t newCX;