diff --git a/Common/System/Display.cpp b/Common/System/Display.cpp index 9904e020ec..aae1776a57 100644 --- a/Common/System/Display.cpp +++ b/Common/System/Display.cpp @@ -10,6 +10,17 @@ DeviceOrientation DisplayProperties::GetDeviceOrientation() const { return (dp_yres > dp_xres * 1.1f) ? DeviceOrientation::Portrait : DeviceOrientation::Landscape; } +std::string_view DeviceOrientationToString(DeviceOrientation orientation) { + switch (orientation) { + case DeviceOrientation::Landscape: + return "Landscape"; + case DeviceOrientation::Portrait: + return "Portrait"; + default: + return "N/A"; + } +} + template void RotateRectToDisplayImpl(DisplayRect &rect, T curRTWidth, T curRTHeight) { switch (g_display.rotation) { diff --git a/Common/System/Display.h b/Common/System/Display.h index 0ecef7d910..edf15c6320 100644 --- a/Common/System/Display.h +++ b/Common/System/Display.h @@ -1,5 +1,7 @@ #pragma once +#include + #include "Common/Math/lin/matrix4x4.h" #include "Common/GPU/MiscTypes.h" #include "Common/Math/geom2d.h" @@ -60,3 +62,6 @@ void RotateRectToDisplay(DisplayRect &rect, float rtWidth, float rtHeight void RotateRectToDisplay(DisplayRect &rect, int rtWidth, int rtHeight); Lin::Matrix4x4 ComputeOrthoMatrix(float xres, float yres, CoordConvention coordConvention); + +// Take this and run through translation. Returns "Portrait", "Landscape" or later "Square" (the latter being the square shape you get when you open a foldable phone). +std::string_view DeviceOrientationToString(DeviceOrientation orientation); diff --git a/Core/Config.cpp b/Core/Config.cpp index eac033342f..1a8f0143b0 100644 --- a/Core/Config.cpp +++ b/Core/Config.cpp @@ -844,6 +844,31 @@ static const float defaultControlScale = 1.15f; static const ConfigTouchPos defaultTouchPosShow = { -1.0f, -1.0f, defaultControlScale, true }; static const ConfigTouchPos defaultTouchPosHide = { -1.0f, -1.0f, defaultControlScale, false }; +void TouchControlConfig::ResetLayout() { + // reset puts the settings in a state so they'll then get properly reinitialized in InitPadLayout. + auto reset = [](ConfigTouchPos &pos) { + pos.x = defaultTouchPosShow.x; + pos.y = defaultTouchPosShow.y; + pos.scale = defaultTouchPosShow.scale; + }; + reset(touchActionButtonCenter); + fActionButtonSpacing = 1.0f; + reset(touchDpad); + fDpadSpacing = 1.0f; + reset(touchStartKey); + reset(touchSelectKey); + reset(touchFastForwardKey); + reset(touchLKey); + reset(touchRKey); + reset(touchAnalogStick); + reset(touchRightAnalogStick); + for (int i = 0; i < CUSTOM_BUTTON_COUNT; i++) { + reset(touchCustom[i]); + } + fLeftStickHeadScale = 1.0f; + fRightStickHeadScale = 1.0f; +} + bool TouchControlConfig::ResetToDefault(std::string_view blockName) { // We do this traditionally for now. return false; @@ -1802,33 +1827,6 @@ void Config::LoadStandardControllerIni() { } } -// Is this even meaningful to have here? -void Config::ResetControlLayout() { - /* - auto reset = [](ConfigTouchPos &pos) { - pos.x = defaultTouchPosShow.x; - pos.y = defaultTouchPosShow.y; - pos.scale = defaultTouchPosShow.scale; - }; - reset(g_Config.touchActionButtonCenter); - g_Config.fActionButtonSpacing = 1.0f; - reset(g_Config.touchDpad); - g_Config.fDpadSpacing = 1.0f; - reset(g_Config.touchStartKey); - reset(g_Config.touchSelectKey); - reset(g_Config.touchFastForwardKey); - reset(g_Config.touchLKey); - reset(g_Config.touchRKey); - reset(g_Config.touchAnalogStick); - reset(g_Config.touchRightAnalogStick); - for (int i = 0; i < CUSTOM_BUTTON_COUNT; i++) { - reset(g_Config.touchCustom[i]); - } - g_Config.fLeftStickHeadScale = 1.0f; - g_Config.fRightStickHeadScale = 1.0f; - */ -} - void Config::GetReportingInfo(UrlEncoder &data) const { for (const ConfigSectionMeta &meta : g_sectionMeta) { const std::string prefix = join("config.", meta.section); diff --git a/Core/Config.h b/Core/Config.h index 737bc9259c..cb8219299b 100644 --- a/Core/Config.h +++ b/Core/Config.h @@ -127,6 +127,8 @@ struct TouchControlConfig : public ConfigBlock { bool bShowTouchTriangle = true; bool bShowTouchSquare = true; + void ResetLayout(); + bool CanResetToDefault() const override { return true; } bool ResetToDefault(std::string_view blockName) override; size_t Size() const override { return sizeof(TouchControlConfig); } // For sanity checks @@ -675,8 +677,6 @@ public: void UpdateIniLocation(const char *iniFileName = nullptr, const char *controllerIniFilename = nullptr); - void ResetControlLayout(); - void GetReportingInfo(UrlEncoder &data) const; int NextValidBackend(); diff --git a/Qt/mainwindow.cpp b/Qt/mainwindow.cpp index 5c0963cc1b..99b7f6ba4b 100644 --- a/Qt/mainwindow.cpp +++ b/Qt/mainwindow.cpp @@ -379,7 +379,6 @@ void MainWindow::SetFullScreen(bool fullscreen) { #endif showFullScreen(); - InitPadLayout(g_display.dp_xres, g_display.dp_yres); if (GetUIState() == UISTATE_INGAME && !g_Config.bShowTouchControls) QApplication::setOverrideCursor(QCursor(Qt::BlankCursor)); @@ -391,7 +390,6 @@ void MainWindow::SetFullScreen(bool fullscreen) { showNormal(); SetWindowScale(-1); - InitPadLayout(g_display.dp_xres, g_display.dp_yres); if (GetUIState() == UISTATE_INGAME && QApplication::overrideCursor()) QApplication::restoreOverrideCursor(); diff --git a/UI/EmuScreen.cpp b/UI/EmuScreen.cpp index da11c0159e..b404ff6ae5 100644 --- a/UI/EmuScreen.cpp +++ b/UI/EmuScreen.cpp @@ -1245,10 +1245,12 @@ void EmuScreen::CreateViews() { auto dev = GetI18NCategory(I18NCat::DEVELOPER); auto sc = GetI18NCategory(I18NCat::SCREEN); - TouchControlConfig &touch = g_Config.GetTouchControlsConfig(GetDeviceOrientation()); + const DeviceOrientation deviceOrientation = GetDeviceOrientation(); + + TouchControlConfig &touch = g_Config.GetTouchControlsConfig(deviceOrientation); const Bounds &bounds = screenManager()->getUIContext()->GetLayoutBounds(); - InitPadLayout(&touch, bounds.w, bounds.h); + InitPadLayout(&touch, deviceOrientation, bounds.w, bounds.h); // Devices without a back button like iOS need an on-screen touch back button. bool showPauseButton = !System_GetPropertyBool(SYSPROP_HAS_BACK_BUTTON) || g_Config.bShowTouchPause; @@ -1288,8 +1290,8 @@ void EmuScreen::CreateViews() { cardboardDisableButton_ = root_->Add(new Button(sc->T("Cardboard VR OFF"), new AnchorLayoutParams(bounds.centerX(), NONE, NONE, 30, true))); DeviceOrientation orientation = GetDeviceOrientation(); - cardboardDisableButton_->OnClick.Add([orientation](UI::EventParams &) { - DisplayLayoutConfig &config = g_Config.GetDisplayLayoutConfig(orientation); + cardboardDisableButton_->OnClick.Add([deviceOrientation](UI::EventParams &) { + DisplayLayoutConfig &config = g_Config.GetDisplayLayoutConfig(deviceOrientation); config.bEnableCardboardVR = false; }); cardboardDisableButton_->SetVisibility(V_GONE); diff --git a/UI/GamepadEmu.cpp b/UI/GamepadEmu.cpp index a2fe339af4..ea242c1e85 100644 --- a/UI/GamepadEmu.cpp +++ b/UI/GamepadEmu.cpp @@ -750,7 +750,7 @@ void PSPCustomStick::ProcessTouch(float x, float y, bool down) { } } -void InitPadLayout(TouchControlConfig *config, float xres, float yres, float globalScale) { +void InitPadLayout(TouchControlConfig *config, DeviceOrientation orientation, float xres, float yres, float globalScale) { const float scale = globalScale; const int halfW = xres / 2; @@ -814,17 +814,31 @@ void InitPadLayout(TouchControlConfig *config, float xres, float yres, float glo const float bottom_button_Y = 60.0f; #endif - int start_key_X = halfW + bottom_key_spacing * scale; - int start_key_Y = yres - bottom_button_Y * scale; - initTouchPos(&config->touchStartKey, start_key_X, start_key_Y); + if (orientation == DeviceOrientation::Portrait) { + int start_key_X = halfW; + int start_key_Y = yres - bottom_button_Y * scale; + initTouchPos(&config->touchStartKey, start_key_X, start_key_Y); - int select_key_X = halfW; - int select_key_Y = yres - bottom_button_Y * scale; - initTouchPos(&config->touchSelectKey, select_key_X, select_key_Y); + int select_key_X = halfW; + int select_key_Y = yres - bottom_button_Y * scale - 50; + initTouchPos(&config->touchSelectKey, select_key_X, select_key_Y); - int fast_forward_key_X = halfW - bottom_key_spacing * scale; - int fast_forward_key_Y = yres - bottom_button_Y * scale; - initTouchPos(&config->touchFastForwardKey, fast_forward_key_X, fast_forward_key_Y); + int fast_forward_key_X = halfW; + int fast_forward_key_Y = yres - bottom_button_Y * scale - 100; + initTouchPos(&config->touchFastForwardKey, fast_forward_key_X, fast_forward_key_Y); + } else { + int start_key_X = halfW + bottom_key_spacing * scale; + int start_key_Y = yres - bottom_button_Y * scale; + initTouchPos(&config->touchStartKey, start_key_X, start_key_Y); + + int select_key_X = halfW; + int select_key_Y = yres - bottom_button_Y * scale; + initTouchPos(&config->touchSelectKey, select_key_X, select_key_Y); + + int fast_forward_key_X = halfW - bottom_key_spacing * scale; + int fast_forward_key_Y = yres - bottom_button_Y * scale; + initTouchPos(&config->touchFastForwardKey, fast_forward_key_X, fast_forward_key_Y); + } // L and R------------------------------------------------------------ // Put them above the analog stick / above the buttons to the right. diff --git a/UI/GamepadEmu.h b/UI/GamepadEmu.h index 3ca7724751..52acf16ae5 100644 --- a/UI/GamepadEmu.h +++ b/UI/GamepadEmu.h @@ -158,7 +158,7 @@ private: struct TouchControlConfig; // Initializes the layout from Config. if a default layout does not exist, it sets up default values -void InitPadLayout(TouchControlConfig *config, float xres, float yres, float globalScale = 1.15f); +void InitPadLayout(TouchControlConfig *config, DeviceOrientation orientation, float xres, float yres, float globalScale = 1.15f); UI::ViewGroup *CreatePadLayout(const TouchControlConfig &config, float xres, float yres, bool *pause, bool showPauseButton, ControlMapper *controlMapper); const int D_pad_Radius = 50; diff --git a/UI/TouchControlLayoutScreen.cpp b/UI/TouchControlLayoutScreen.cpp index 9c2e9e3095..e8c1b3e143 100644 --- a/UI/TouchControlLayoutScreen.cpp +++ b/UI/TouchControlLayoutScreen.cpp @@ -592,10 +592,13 @@ void TouchControlLayoutScreen::OnVisibility(UI::EventParams &e) { } void TouchControlLayoutScreen::OnReset(UI::EventParams &e) { - INFO_LOG(Log::G3D, "Resetting touch control layout"); - g_Config.ResetControlLayout(); + INFO_LOG(Log::G3D, "Resetting touch control layout to default."); + const Bounds &bounds = screenManager()->getUIContext()->GetBounds(); - InitPadLayout(&g_Config.GetTouchControlsConfig(GetDeviceOrientation()), bounds.w, bounds.h); + const DeviceOrientation orientation = GetDeviceOrientation(); + TouchControlConfig &touch = g_Config.GetTouchControlsConfig(orientation); + touch.ResetLayout(); + InitPadLayout(&touch, orientation, bounds.w, bounds.h); RecreateViews(); }; @@ -637,9 +640,10 @@ void TouchControlLayoutScreen::CreateViews() { // setup g_Config for button layout const Bounds &bounds = screenManager()->getUIContext()->GetBounds(); - InitPadLayout(&g_Config.GetTouchControlsConfig(GetDeviceOrientation()), bounds.w, bounds.h); + const DeviceOrientation orientation = GetDeviceOrientation(); + InitPadLayout(&g_Config.GetTouchControlsConfig(orientation), orientation, bounds.w, bounds.h); - bool portrait = GetDeviceOrientation() == DeviceOrientation::Portrait; + // const bool portrait = GetDeviceOrientation() == DeviceOrientation::Portrait; const float leftColumnWidth = 200.0f; layoutAreaScale = 1.0f - (leftColumnWidth + 10.0f) / std::max(bounds.w, 1.0f); @@ -675,6 +679,7 @@ void TouchControlLayoutScreen::CreateViews() { leftColumn->Add(new Spacer(0.0f)); LinearLayout* rightColumn = root_->Add(new LinearLayout(ORIENT_VERTICAL, new LinearLayoutParams(1.0f, Margins(0.0f, 12.0f, 12.0f, 12.0f)))); + rightColumn->Add(new TextView(co->T(DeviceOrientationToString(orientation)))); rightColumn->Add(new Spacer(new LinearLayoutParams(1.0))); float previewHeight = bounds.h * layoutAreaScale; layoutView_ = rightColumn->Add(new ControlLayoutView(GetDeviceOrientation(), new LinearLayoutParams(FILL_PARENT, previewHeight)));