Add 3DS 16:10 aspect ratio and refactor GUI aspect ratio code

This commit is contained in:
Nadia Holmquist Pedersen
2022-05-23 16:59:50 +02:00
parent 067b44fdfd
commit f85925fcd6
2 changed files with 69 additions and 47 deletions

View File

@ -111,6 +111,15 @@ u32 micExtBufferWritePos;
u32 micWavLength; u32 micWavLength;
s16* micWavBuffer; s16* micWavBuffer;
const struct { int id; float ratio; const char* label; } aspectRatios[] =
{
{ 0, 1, "4:3 (native)" },
{ 4, (16.f / 10) / (4.f / 3), "16:10 (3DS)"},
{ 1, (16.f / 9) / (4.f / 3), "16:9" },
{ 2, (21.f / 9) / (4.f / 3), "21:9" },
{ 3, 0, "window" }
};
void micCallback(void* data, Uint8* stream, int len); void micCallback(void* data, Uint8* stream, int len);
@ -746,13 +755,21 @@ void ScreenHandler::screenSetupLayout(int w, int h)
int sizing = Config::ScreenSizing; int sizing = Config::ScreenSizing;
if (sizing == 3) sizing = autoScreenSizing; if (sizing == 3) sizing = autoScreenSizing;
float aspectRatios[] = float aspectTop, aspectBot;
for (auto ratio : aspectRatios)
{ {
1.f, if (ratio.id == Config::ScreenAspectTop)
(16.f/9)/(4.f/3), aspectTop = ratio.ratio;
(21.f/9)/(4.f/3), if (ratio.id == Config::ScreenAspectBot)
((float)w/h)/(4.f/3) aspectBot = ratio.ratio;
}; }
if (aspectTop == 0)
aspectTop = (float) w / h;
if (aspectBot == 0)
aspectBot = (float) w / h;
Frontend::SetupScreenLayout(w, h, Frontend::SetupScreenLayout(w, h,
Config::ScreenLayout, Config::ScreenLayout,
@ -761,8 +778,8 @@ void ScreenHandler::screenSetupLayout(int w, int h)
Config::ScreenGap, Config::ScreenGap,
Config::IntegerScaling != 0, Config::IntegerScaling != 0,
Config::ScreenSwap != 0, Config::ScreenSwap != 0,
aspectRatios[Config::ScreenAspectTop], aspectTop,
aspectRatios[Config::ScreenAspectBot]); aspectBot);
numScreens = Frontend::GetScreenTransforms(screenMatrix[0], screenKind); numScreens = Frontend::GetScreenTransforms(screenMatrix[0], screenKind);
} }
@ -1591,34 +1608,34 @@ MainWindow::MainWindow(QWidget* parent) : QMainWindow(parent)
{ {
QMenu* submenu = menu->addMenu("Aspect ratio"); QMenu* submenu = menu->addMenu("Aspect ratio");
grpScreenAspectTop = new QActionGroup(submenu); grpScreenAspectTop = new QActionGroup(submenu);
const char* aspectRatiosTop[] = {"Top 4:3 (native)", "Top 16:9", "Top 21:9", "Top window"};
for (int i = 0; i < 4; i++)
{
actScreenAspectTop[i] = submenu->addAction(QString(aspectRatiosTop[i]));
actScreenAspectTop[i]->setActionGroup(grpScreenAspectTop);
actScreenAspectTop[i]->setData(QVariant(i));
actScreenAspectTop[i]->setCheckable(true);
}
connect(grpScreenAspectTop, &QActionGroup::triggered, this, &MainWindow::onChangeScreenAspectTop);
submenu->addSeparator();
grpScreenAspectBot = new QActionGroup(submenu); grpScreenAspectBot = new QActionGroup(submenu);
actScreenAspectTop = new QAction*[sizeof(aspectRatios) / sizeof(aspectRatios[0])];
actScreenAspectBot = new QAction*[sizeof(aspectRatios) / sizeof(aspectRatios[0])];
const char* aspectRatiosBot[] = {"Bottom 4:3 (native)", "Bottom 16:9", "Bottom 21:9", "Bottom window"}; for (int i = 0; i < 2; i++)
for (int i = 0; i < 4; i++)
{ {
actScreenAspectBot[i] = submenu->addAction(QString(aspectRatiosBot[i])); QActionGroup* group = grpScreenAspectTop;
actScreenAspectBot[i]->setActionGroup(grpScreenAspectBot); QAction** actions = actScreenAspectTop;
actScreenAspectBot[i]->setData(QVariant(i));
actScreenAspectBot[i]->setCheckable(true);
}
connect(grpScreenAspectBot, &QActionGroup::triggered, this, &MainWindow::onChangeScreenAspectBot); if (i == 1)
{
group = grpScreenAspectBot;
submenu->addSeparator();
actions = actScreenAspectBot;
}
for (int j = 0; j < sizeof(aspectRatios) / sizeof(aspectRatios[0]); j++)
{
auto ratio = aspectRatios[j];
QString label = QString("%1 %2").arg(i ? "Bottom" : "Top", ratio.label);
actions[j] = submenu->addAction(label);
actions[j]->setActionGroup(group);
actions[j]->setData(QVariant(ratio.id));
actions[j]->setCheckable(true);
}
connect(group, &QActionGroup::triggered, this, &MainWindow::onChangeScreenAspect);
}
} }
actScreenFiltering = menu->addAction("Screen filtering"); actScreenFiltering = menu->addAction("Screen filtering");
@ -1709,8 +1726,13 @@ MainWindow::MainWindow(QWidget* parent) : QMainWindow(parent)
actScreenSwap->setChecked(Config::ScreenSwap); actScreenSwap->setChecked(Config::ScreenSwap);
actScreenAspectTop[Config::ScreenAspectTop]->setChecked(true); for (int i = 0; i < sizeof(aspectRatios) / sizeof(aspectRatios[0]); i++)
actScreenAspectBot[Config::ScreenAspectBot]->setChecked(true); {
if (Config::ScreenAspectTop == aspectRatios[i].id)
actScreenAspectTop[i]->setChecked(true);
if (Config::ScreenAspectBot == aspectRatios[i].id)
actScreenAspectBot[i]->setChecked(true);
}
actScreenFiltering->setChecked(Config::ScreenFilter); actScreenFiltering->setChecked(Config::ScreenFilter);
actShowOSD->setChecked(Config::ShowOSD); actShowOSD->setChecked(Config::ShowOSD);
@ -2833,18 +2855,19 @@ void MainWindow::onChangeScreenSizing(QAction* act)
emit screenLayoutChange(); emit screenLayoutChange();
} }
void MainWindow::onChangeScreenAspectTop(QAction* act) void MainWindow::onChangeScreenAspect(QAction* act)
{ {
int aspect = act->data().toInt(); int aspect = act->data().toInt();
Config::ScreenAspectTop = aspect; QActionGroup* group = act->actionGroup();
emit screenLayoutChange(); if (group == grpScreenAspectTop)
} {
Config::ScreenAspectTop = aspect;
void MainWindow::onChangeScreenAspectBot(QAction* act) }
{ else
int aspect = act->data().toInt(); {
Config::ScreenAspectBot = aspect; Config::ScreenAspectBot = aspect;
}
emit screenLayoutChange(); emit screenLayoutChange();
} }

View File

@ -280,8 +280,7 @@ private slots:
void onChangeScreenLayout(QAction* act); void onChangeScreenLayout(QAction* act);
void onChangeScreenSwap(bool checked); void onChangeScreenSwap(bool checked);
void onChangeScreenSizing(QAction* act); void onChangeScreenSizing(QAction* act);
void onChangeScreenAspectTop(QAction* act); void onChangeScreenAspect(QAction* act);
void onChangeScreenAspectBot(QAction* act);
void onChangeIntegerScaling(bool checked); void onChangeIntegerScaling(bool checked);
void onChangeScreenFiltering(bool checked); void onChangeScreenFiltering(bool checked);
void onChangeShowOSD(bool checked); void onChangeShowOSD(bool checked);
@ -368,9 +367,9 @@ public:
QAction* actScreenSizing[6]; QAction* actScreenSizing[6];
QAction* actIntegerScaling; QAction* actIntegerScaling;
QActionGroup* grpScreenAspectTop; QActionGroup* grpScreenAspectTop;
QAction* actScreenAspectTop[4]; QAction** actScreenAspectTop;
QActionGroup* grpScreenAspectBot; QActionGroup* grpScreenAspectBot;
QAction* actScreenAspectBot[4]; QAction** actScreenAspectBot;
QAction* actScreenFiltering; QAction* actScreenFiltering;
QAction* actShowOSD; QAction* actShowOSD;
QAction* actLimitFramerate; QAction* actLimitFramerate;