Split the display layout config between landscape and portrait orientations

This commit is contained in:
Henrik Rydgård
2025-10-30 11:18:20 +01:00
parent 3e2edbfe81
commit 67010ff2af
60 changed files with 480 additions and 317 deletions
+41 -33
View File
@@ -60,25 +60,27 @@ static Bounds FRectToBounds(FRect rc) {
class DisplayLayoutBackground : public UI::View {
public:
DisplayLayoutBackground(UI::ChoiceStrip *mode, UI::LayoutParams *layoutParams) : UI::View(layoutParams), mode_(mode) {}
DisplayLayoutBackground(UI::ChoiceStrip *mode, DeviceOrientation orientation, UI::LayoutParams *layoutParams) : UI::View(layoutParams), mode_(mode), orientation_(orientation) {}
bool Touch(const TouchInput &touch) override {
int mode = mode_ ? mode_->GetSelection() : 0;
DisplayLayoutConfig &config = g_Config.GetDisplayLayoutConfig(orientation_);
if ((touch.flags & TOUCH_MOVE) != 0 && dragging_) {
float relativeTouchX = touch.x - startX_;
float relativeTouchY = touch.y - startY_;
switch (mode) {
case MODE_MOVE:
g_Config.fDisplayOffsetX = clamp_value(startDisplayOffsetX_ + relativeTouchX / bounds_.w, 0.0f, 1.0f);
g_Config.fDisplayOffsetY = clamp_value(startDisplayOffsetY_ + relativeTouchY / bounds_.h, 0.0f, 1.0f);
config.fDisplayOffsetX = clamp_value(startDisplayOffsetX_ + relativeTouchX / bounds_.w, 0.0f, 1.0f);
config.fDisplayOffsetY = clamp_value(startDisplayOffsetY_ + relativeTouchY / bounds_.h, 0.0f, 1.0f);
break;
case MODE_RESIZE:
{
// Resize. Vertical = scaling; Up should be bigger so let's negate in that direction
float diffYProp = -relativeTouchY * 0.007f;
g_Config.fDisplayScale = clamp_value(startScale_ * powf(2.0f, diffYProp), 0.2f, 2.0f);
config.fDisplayScale = clamp_value(startScale_ * powf(2.0f, diffYProp), 0.2f, 2.0f);
break;
}
}
@@ -93,9 +95,9 @@ public:
dragging_ = true;
startX_ = touch.x;
startY_ = touch.y;
startDisplayOffsetX_ = g_Config.fDisplayOffsetX;
startDisplayOffsetY_ = g_Config.fDisplayOffsetY;
startScale_ = g_Config.fDisplayScale;
startDisplayOffsetX_ = config.fDisplayOffsetX;
startDisplayOffsetY_ = config.fDisplayOffsetY;
startScale_ = config.fDisplayScale;
}
}
@@ -109,7 +111,7 @@ public:
private:
UI::ChoiceStrip *mode_;
bool dragging_ = false;
const DeviceOrientation orientation_;
// Touch down state for drag to resize etc
float startX_ = 0.0f;
float startY_ = 0.0f;
@@ -127,11 +129,12 @@ void DisplayLayoutScreen::DrawBackground(UIContext &dc) {
// But if it's not present (we're not in game, or skip buffer effects is used),
// we have to draw a substitute ourselves.
UIContext &dc = *screenManager()->getUIContext();
DisplayLayoutConfig &config = g_Config.GetDisplayLayoutConfig(GetDeviceOrientation());
// TODO: Clean this up a bit, this GetScreenFrame/CenterDisplay combo is too common.
FRect screenFrame = GetScreenFrame(g_display.pixel_xres, g_display.pixel_yres);
FRect screenFrame = GetScreenFrame(config.bIgnoreScreenInsets, g_display.pixel_xres, g_display.pixel_yres);
FRect rc;
CalculateDisplayOutputRect(&rc, 480.0f, 272.0f, screenFrame, g_Config.iInternalScreenRotation);
CalculateDisplayOutputRect(config, &rc, 480.0f, 272.0f, screenFrame, config.iInternalScreenRotation);
dc.Flush();
ImageID bg = ImageID("I_PSP_DISPLAY");
@@ -201,7 +204,7 @@ void DisplayLayoutScreen::CreateViews() {
root_ = new AnchorLayout(new LayoutParams(FILL_PARENT, FILL_PARENT));
const bool portrait = UsePortraitLayout();
const bool portrait = GetDeviceOrientation() == DeviceOrientation::Portrait;
// Make it so that a touch can only affect one view. Makes manipulating the background through the buttons
// impossible.
@@ -239,31 +242,36 @@ void DisplayLayoutScreen::CreateViews() {
leftColumn->SetBG(backgroundWithAlpha);
rightColumn->SetBG(backgroundWithAlpha);
DisplayLayoutConfig &config = g_Config.GetDisplayLayoutConfig(GetDeviceOrientation());
if (!IsVREnabled()) {
auto stretch = new CheckBox(&g_Config.bDisplayStretch, gr->T("Stretch"));
stretch->SetDisabledPtr(&g_Config.bDisplayIntegerScale);
auto stretch = new CheckBox(&config.bDisplayStretch, gr->T("Stretch"));
stretch->SetDisabledPtr(&config.bDisplayIntegerScale);
rightColumn->Add(stretch);
PopupSliderChoiceFloat *aspectRatio = new PopupSliderChoiceFloat(&g_Config.fDisplayAspectRatio, 0.1f, 2.0f, 1.0f, gr->T("Aspect Ratio"), screenManager());
PopupSliderChoiceFloat *aspectRatio = new PopupSliderChoiceFloat(&config.fDisplayAspectRatio, 0.1f, 2.0f, 1.0f, gr->T("Aspect Ratio"), screenManager());
rightColumn->Add(aspectRatio);
aspectRatio->SetEnabledFunc([]() {
return !g_Config.bDisplayStretch && !g_Config.bDisplayIntegerScale;
aspectRatio->SetEnabledFunc([config]() {
return !config.bDisplayStretch && !config.bDisplayIntegerScale;
});
aspectRatio->SetHasDropShadow(false);
aspectRatio->SetLiveUpdate(true);
rightColumn->Add(new CheckBox(&g_Config.bDisplayIntegerScale, gr->T("Integer scale factor")));
rightColumn->Add(new CheckBox(&config.bDisplayIntegerScale, gr->T("Integer scale factor")));
bool supportsInsets = false;
#if PPSSPP_PLATFORM(ANDROID)
// Hide insets option if no insets, or OS too old.
if (System_GetPropertyInt(SYSPROP_SYSTEMVERSION) >= 28 &&
(System_GetPropertyFloat(SYSPROP_DISPLAY_SAFE_INSET_LEFT) != 0.0f ||
System_GetPropertyFloat(SYSPROP_DISPLAY_SAFE_INSET_TOP) != 0.0f ||
System_GetPropertyFloat(SYSPROP_DISPLAY_SAFE_INSET_RIGHT) != 0.0f ||
System_GetPropertyFloat(SYSPROP_DISPLAY_SAFE_INSET_BOTTOM) != 0.0f)) {
rightColumn->Add(new CheckBox(&g_Config.bIgnoreScreenInsets, gr->T("Ignore camera notch when centering")));
}
supportsInsets = System_GetPropertyInt(SYSPROP_SYSTEMVERSION) >= 28;
#elif PPSSPP_PLATFORM(IOS)
supportsInsets = true;
#endif
// Hide insets option if no insets, or OS too old.
if (supportsInsets && System_GetPropertyFloat(SYSPROP_DISPLAY_SAFE_INSET_LEFT) != 0.0f ||
System_GetPropertyFloat(SYSPROP_DISPLAY_SAFE_INSET_TOP) != 0.0f ||
System_GetPropertyFloat(SYSPROP_DISPLAY_SAFE_INSET_RIGHT) != 0.0f ||
System_GetPropertyFloat(SYSPROP_DISPLAY_SAFE_INSET_BOTTOM) != 0.0f) {
rightColumn->Add(new CheckBox(&config.bIgnoreScreenInsets, gr->T("Ignore camera notch when centering")));
}
mode_ = new ChoiceStrip(ORIENT_HORIZONTAL, new LinearLayoutParams(WRAP_CONTENT, WRAP_CONTENT));
mode_->AddChoice(di->T("Inactive"));
@@ -273,7 +281,7 @@ void DisplayLayoutScreen::CreateViews() {
bottomControls->Add(mode_);
static const char *displayRotation[] = { "Landscape", "Portrait", "Landscape Reversed", "Portrait Reversed" };
auto rotation = new PopupMultiChoice(&g_Config.iInternalScreenRotation, gr->T("Rotation"), displayRotation, 1, ARRAY_SIZE(displayRotation), I18NCat::CONTROLS, screenManager());
auto rotation = new PopupMultiChoice(&config.iInternalScreenRotation, gr->T("Rotation"), displayRotation, 1, ARRAY_SIZE(displayRotation), I18NCat::CONTROLS, screenManager());
rotation->SetEnabledFunc([] {
return !g_Config.bSkipBufferEffects || g_Config.bSoftwareRendering;
});
@@ -281,11 +289,11 @@ void DisplayLayoutScreen::CreateViews() {
rightColumn->Add(rotation);
Choice *center = new Choice(di->T("Reset"));
center->OnClick.Add([&](UI::EventParams &) {
g_Config.fDisplayAspectRatio = 1.0f;
g_Config.fDisplayScale = 1.0f;
g_Config.fDisplayOffsetX = 0.5f;
g_Config.fDisplayOffsetY = 0.5f;
center->OnClick.Add([&config](UI::EventParams &) {
config.fDisplayAspectRatio = 1.0f;
config.fDisplayScale = 1.0f;
config.fDisplayOffsetX = 0.5f;
config.fDisplayOffsetY = 0.5f;
});
rightColumn->Add(center);
@@ -302,7 +310,7 @@ void DisplayLayoutScreen::CreateViews() {
if (!IsVREnabled()) {
static const char *bufFilters[] = { "Linear", "Nearest", };
leftColumn->Add(new PopupMultiChoice(&g_Config.iDisplayFilter, gr->T("Screen Scaling Filter"), bufFilters, 1, ARRAY_SIZE(bufFilters), I18NCat::GRAPHICS, screenManager()));
leftColumn->Add(new PopupMultiChoice(&config.iDisplayFilter, gr->T("Screen Scaling Filter"), bufFilters, 1, ARRAY_SIZE(bufFilters), I18NCat::GRAPHICS, screenManager()));
}
Draw::DrawContext *draw = screenManager()->getDrawContext();
@@ -464,7 +472,7 @@ void DisplayLayoutScreen::CreateViews() {
}
}
root_->Add(new DisplayLayoutBackground(mode_, new AnchorLayoutParams(FILL_PARENT, FILL_PARENT, 0.0f, 0.0f, 0.0f, 0.0f)));
root_->Add(new DisplayLayoutBackground(mode_, GetDeviceOrientation(), new AnchorLayoutParams(FILL_PARENT, FILL_PARENT, 0.0f, 0.0f, 0.0f, 0.0f)));
}
void PostProcScreen::CreateViews() {