VERY experimental Nintendo Switch 2 emulator
C++
android: Move overlays to their own layout
Abandoned Cartdfa23c70c6d3
diff --git a/src/android/app/src/main/AndroidManifest.xml b/src/android/app/src/main/AndroidManifest.xmlindex e31ad69e20..a6f87fc2ec 100644--- a/src/android/app/src/main/AndroidManifest.xml+++ b/src/android/app/src/main/AndroidManifest.xml@@ -53,7 +53,6 @@ SPDX-License-Identifier: GPL-3.0-or-later<activityandroid:name="org.yuzu.yuzu_emu.activities.EmulationActivity"android:theme="@style/Theme.Yuzu.Main"- android:screenOrientation="userLandscape"android:supportsPictureInPicture="true"android:configChanges="orientation|screenSize|smallestScreenSize|screenLayout|uiMode"android:exported="true">diff --git a/src/android/app/src/main/java/org/yuzu/yuzu_emu/fragments/EmulationFragment.kt b/src/android/app/src/main/java/org/yuzu/yuzu_emu/fragments/EmulationFragment.ktindex d5725abe77..4b23058928 100644--- a/src/android/app/src/main/java/org/yuzu/yuzu_emu/fragments/EmulationFragment.kt+++ b/src/android/app/src/main/java/org/yuzu/yuzu_emu/fragments/EmulationFragment.kt@@ -11,13 +11,11 @@ import android.content.Intentimport android.content.SharedPreferencesimport android.content.pm.ActivityInfoimport android.content.res.Configuration-import android.content.res.Resourcesimport android.graphics.Colorimport android.os.Bundleimport android.os.Handlerimport android.os.Looperimport android.util.Rational-import android.util.TypedValueimport android.view.*import android.widget.TextViewimport androidx.activity.OnBackPressedCallback@@ -29,11 +27,11 @@ import androidx.core.graphics.Insetsimport androidx.core.view.ViewCompatimport androidx.core.view.WindowInsetsCompatimport androidx.core.view.isVisible-import androidx.core.view.updatePaddingimport androidx.fragment.app.Fragmentimport androidx.lifecycle.Lifecycleimport androidx.lifecycle.lifecycleScopeimport androidx.lifecycle.repeatOnLifecycle+import androidx.navigation.fragment.navArgsimport androidx.preference.PreferenceManagerimport androidx.window.layout.FoldingFeatureimport androidx.window.layout.WindowInfoTracker@@ -328,10 +326,13 @@ class EmulationFragment : Fragment(), SurfaceHolder.Callback {if (it.isSeparating) {emulationActivity.requestedOrientation = ActivityInfo.SCREEN_ORIENTATION_UNSPECIFIEDif (it.orientation == FoldingFeature.Orientation.HORIZONTAL) {+ // Restrict emulation and overlays to the top of the screenbinding.emulationContainer.layoutParams.height = it.bounds.top- // Prevent touch regions from being displayed in the hinge- binding.overlayContainer.layoutParams.height = it.bounds.bottom+ binding.overlayContainer.layoutParams.height = it.bounds.top+ // Restrict input and menu drawer to the bottom of the screen+ binding.inputContainer.layoutParams.height = it.bounds.bottombinding.inGameMenu.layoutParams.height = it.bounds.bottom+isInFoldableLayout = truebinding.surfaceInputOverlay.orientation = InputOverlay.FOLDABLErefreshInputOverlay()@@ -341,12 +342,14 @@ class EmulationFragment : Fragment(), SurfaceHolder.Callback {} ?: falseif (!isFolding) {binding.emulationContainer.layoutParams.height = ViewGroup.LayoutParams.MATCH_PARENT+ binding.inputContainer.layoutParams.height = ViewGroup.LayoutParams.MATCH_PARENTbinding.overlayContainer.layoutParams.height = ViewGroup.LayoutParams.MATCH_PARENTbinding.inGameMenu.layoutParams.height = ViewGroup.LayoutParams.MATCH_PARENTisInFoldableLayout = falseupdateScreenLayout()}binding.emulationContainer.requestLayout()+ binding.inputContainer.requestLayout()binding.overlayContainer.requestLayout()binding.inGameMenu.requestLayout()}diff --git a/src/android/app/src/main/java/org/yuzu/yuzu_emu/overlay/InputOverlay.kt b/src/android/app/src/main/java/org/yuzu/yuzu_emu/overlay/InputOverlay.ktindex aeef7731b3..d12d08e9fe 100644--- a/src/android/app/src/main/java/org/yuzu/yuzu_emu/overlay/InputOverlay.kt+++ b/src/android/app/src/main/java/org/yuzu/yuzu_emu/overlay/InputOverlay.kt@@ -668,136 +668,136 @@ class InputOverlay(context: Context, attrs: AttributeSet?) : SurfaceView(contextR.integer.SWITCH_STICK_L_Y_FOLDABLE)- private fun getResourceValue(descriptor: String, position: Int) : Float {- return when (descriptor) {+ private fun getResourceValue(orientation: String, position: Int) : Float {+ return when (orientation) {PORTRAIT -> resources.getInteger(portraitResources[position]).toFloat() / 1000FOLDABLE -> resources.getInteger(foldableResources[position]).toFloat() / 1000else -> resources.getInteger(landscapeResources[position]).toFloat() / 1000}}- private fun defaultOverlayByLayout(descriptor: String) {+ private fun defaultOverlayByLayout(orientation: String) {// Each value represents the position of the button in relation to the screen size without insets.preferences.edit().putFloat(- ButtonType.BUTTON_A.toString() + "$descriptor-X",- getResourceValue(descriptor, 0)+ ButtonType.BUTTON_A.toString() + "-X$orientation",+ getResourceValue(orientation, 0)).putFloat(- ButtonType.BUTTON_A.toString() + "$descriptor-Y",- getResourceValue(descriptor, 1)+ ButtonType.BUTTON_A.toString() + "-Y$orientation",+ getResourceValue(orientation, 1)).putFloat(- ButtonType.BUTTON_B.toString() + "$descriptor-X",- getResourceValue(descriptor, 2)+ ButtonType.BUTTON_B.toString() + "-X$orientation",+ getResourceValue(orientation, 2)).putFloat(- ButtonType.BUTTON_B.toString() + "$descriptor-Y",- getResourceValue(descriptor, 3)+ ButtonType.BUTTON_B.toString() + "-Y$orientation",+ getResourceValue(orientation, 3)).putFloat(- ButtonType.BUTTON_X.toString() + "$descriptor-X",- getResourceValue(descriptor, 4)+ ButtonType.BUTTON_X.toString() + "-X$orientation",+ getResourceValue(orientation, 4)).putFloat(- ButtonType.BUTTON_X.toString() + "$descriptor-Y",- getResourceValue(descriptor, 5)+ ButtonType.BUTTON_X.toString() + "-Y$orientation",+ getResourceValue(orientation, 5)).putFloat(- ButtonType.BUTTON_Y.toString() + "$descriptor-X",- getResourceValue(descriptor, 6)+ ButtonType.BUTTON_Y.toString() + "-X$orientation",+ getResourceValue(orientation, 6)).putFloat(- ButtonType.BUTTON_Y.toString() + "$descriptor-Y",- getResourceValue(descriptor, 7)+ ButtonType.BUTTON_Y.toString() + "-Y$orientation",+ getResourceValue(orientation, 7)).putFloat(- ButtonType.TRIGGER_ZL.toString() + "$descriptor-X",- getResourceValue(descriptor, 8)+ ButtonType.TRIGGER_ZL.toString() + "-X$orientation",+ getResourceValue(orientation, 8)).putFloat(- ButtonType.TRIGGER_ZL.toString() + "$descriptor-Y",- getResourceValue(descriptor, 9)+ ButtonType.TRIGGER_ZL.toString() + "-Y$orientation",+ getResourceValue(orientation, 9)).putFloat(- ButtonType.TRIGGER_ZR.toString() + "$descriptor-X",- getResourceValue(descriptor, 10)+ ButtonType.TRIGGER_ZR.toString() + "-X$orientation",+ getResourceValue(orientation, 10)).putFloat(- ButtonType.TRIGGER_ZR.toString() + "$descriptor-Y",- getResourceValue(descriptor, 11)+ ButtonType.TRIGGER_ZR.toString() + "-Y$orientation",+ getResourceValue(orientation, 11)).putFloat(- ButtonType.DPAD_UP.toString() + "$descriptor-X",- getResourceValue(descriptor, 12)+ ButtonType.DPAD_UP.toString() + "-X$orientation",+ getResourceValue(orientation, 12)).putFloat(- ButtonType.DPAD_UP.toString() + "$descriptor-Y",- getResourceValue(descriptor, 13)+ ButtonType.DPAD_UP.toString() + "-Y$orientation",+ getResourceValue(orientation, 13)).putFloat(- ButtonType.TRIGGER_L.toString() + "$descriptor-X",- getResourceValue(descriptor, 14)+ ButtonType.TRIGGER_L.toString() + "-X$orientation",+ getResourceValue(orientation, 14)).putFloat(- ButtonType.TRIGGER_L.toString() + "$descriptor-Y",- getResourceValue(descriptor, 15)+ ButtonType.TRIGGER_L.toString() + "-Y$orientation",+ getResourceValue(orientation, 15)).putFloat(- ButtonType.TRIGGER_R.toString() + "$descriptor-X",- getResourceValue(descriptor, 16)+ ButtonType.TRIGGER_R.toString() + "-X$orientation",+ getResourceValue(orientation, 16)).putFloat(- ButtonType.TRIGGER_R.toString() + "$descriptor-Y",- getResourceValue(descriptor, 17)+ ButtonType.TRIGGER_R.toString() + "-Y$orientation",+ getResourceValue(orientation, 17)).putFloat(- ButtonType.BUTTON_PLUS.toString() + "$descriptor-X",- getResourceValue(descriptor, 18)+ ButtonType.BUTTON_PLUS.toString() + "-X$orientation",+ getResourceValue(orientation, 18)).putFloat(- ButtonType.BUTTON_PLUS.toString() + "$descriptor-Y",- getResourceValue(descriptor, 19)+ ButtonType.BUTTON_PLUS.toString() + "-Y$orientation",+ getResourceValue(orientation, 19)).putFloat(- ButtonType.BUTTON_MINUS.toString() + "$descriptor-X",- getResourceValue(descriptor, 20)+ ButtonType.BUTTON_MINUS.toString() + "-X$orientation",+ getResourceValue(orientation, 20)).putFloat(- ButtonType.BUTTON_MINUS.toString() + "$descriptor-Y",- getResourceValue(descriptor, 21)+ ButtonType.BUTTON_MINUS.toString() + "-Y$orientation",+ getResourceValue(orientation, 21)).putFloat(- ButtonType.BUTTON_HOME.toString() + "$descriptor-X",- getResourceValue(descriptor, 22)+ ButtonType.BUTTON_HOME.toString() + "-X$orientation",+ getResourceValue(orientation, 22)).putFloat(- ButtonType.BUTTON_HOME.toString() + "$descriptor-Y",- getResourceValue(descriptor, 23)+ ButtonType.BUTTON_HOME.toString() + "-Y$orientation",+ getResourceValue(orientation, 23)).putFloat(- ButtonType.BUTTON_CAPTURE.toString() + "$descriptor-X",- getResourceValue(descriptor, 24)+ ButtonType.BUTTON_CAPTURE.toString() + "-X$orientation",+ getResourceValue(orientation, 24)).putFloat(- ButtonType.BUTTON_CAPTURE.toString() + "$descriptor-Y",- getResourceValue(descriptor, 25)+ ButtonType.BUTTON_CAPTURE.toString() + "-Y$orientation",+ getResourceValue(orientation, 25)).putFloat(- ButtonType.STICK_R.toString() + "$descriptor-X",- getResourceValue(descriptor, 26)+ ButtonType.STICK_R.toString() + "-X$orientation",+ getResourceValue(orientation, 26)).putFloat(- ButtonType.STICK_R.toString() + "$descriptor-Y",- getResourceValue(descriptor, 27)+ ButtonType.STICK_R.toString() + "-Y$orientation",+ getResourceValue(orientation, 27)).putFloat(- ButtonType.STICK_L.toString() + "$descriptor-X",- getResourceValue(descriptor, 28)+ ButtonType.STICK_L.toString() + "-X$orientation",+ getResourceValue(orientation, 28)).putFloat(- ButtonType.STICK_L.toString() + "$descriptor-Y",- getResourceValue(descriptor, 29)+ ButtonType.STICK_L.toString() + "-Y$orientation",+ getResourceValue(orientation, 29)).apply()}diff --git a/src/android/app/src/main/res/layout/fragment_emulation.xml b/src/android/app/src/main/res/layout/fragment_emulation.xmlindex ffe5f48822..e54a10e8ff 100644--- a/src/android/app/src/main/res/layout/fragment_emulation.xml+++ b/src/android/app/src/main/res/layout/fragment_emulation.xml@@ -26,22 +26,10 @@android:focusable="false"android:focusableInTouchMode="false" />- <TextView- android:id="@+id/show_fps_text"- android:layout_width="wrap_content"- android:layout_height="wrap_content"- android:layout_gravity="left"- android:clickable="false"- android:focusable="false"- android:shadowColor="@android:color/black"- android:textColor="@android:color/white"- android:textSize="12sp"- tools:ignore="RtlHardcoded" />-</FrameLayout><FrameLayout- android:id="@+id/overlay_container"+ android:id="@+id/input_container"android:layout_width="match_parent"android:layout_height="match_parent"android:layout_gravity="bottom">@@ -66,6 +54,25 @@</FrameLayout>+ <FrameLayout+ android:id="@+id/overlay_container"+ android:layout_width="match_parent"+ android:layout_height="match_parent">++ <TextView+ android:id="@+id/show_fps_text"+ android:layout_width="wrap_content"+ android:layout_height="wrap_content"+ android:layout_gravity="left"+ android:clickable="false"+ android:focusable="false"+ android:shadowColor="@android:color/black"+ android:textColor="@android:color/white"+ android:textSize="12sp"+ tools:ignore="RtlHardcoded" />++ </FrameLayout>+</androidx.coordinatorlayout.widget.CoordinatorLayout><com.google.android.material.navigation.NavigationViewdiff --git a/src/android/app/src/main/res/values/integers.xml b/src/android/app/src/main/res/values/integers.xmlindex a149002a04..2e93b408cc 100644--- a/src/android/app/src/main/res/values/integers.xml+++ b/src/android/app/src/main/res/values/integers.xml@@ -36,25 +36,25 @@<!-- Default SWITCH portrait layout --><integer name="SWITCH_BUTTON_A_X_PORTRAIT">840</integer>- <integer name="SWITCH_BUTTON_A_Y_PORTRAIT">820</integer>+ <integer name="SWITCH_BUTTON_A_Y_PORTRAIT">840</integer><integer name="SWITCH_BUTTON_B_X_PORTRAIT">740</integer>- <integer name="SWITCH_BUTTON_B_Y_PORTRAIT">860</integer>+ <integer name="SWITCH_BUTTON_B_Y_PORTRAIT">880</integer><integer name="SWITCH_BUTTON_X_X_PORTRAIT">740</integer>- <integer name="SWITCH_BUTTON_X_Y_PORTRAIT">780</integer>+ <integer name="SWITCH_BUTTON_X_Y_PORTRAIT">800</integer><integer name="SWITCH_BUTTON_Y_X_PORTRAIT">640</integer>- <integer name="SWITCH_BUTTON_Y_Y_PORTRAIT">820</integer>+ <integer name="SWITCH_BUTTON_Y_Y_PORTRAIT">840</integer><integer name="SWITCH_STICK_L_X_PORTRAIT">180</integer>- <integer name="SWITCH_STICK_L_Y_PORTRAIT">640</integer>+ <integer name="SWITCH_STICK_L_Y_PORTRAIT">660</integer><integer name="SWITCH_STICK_R_X_PORTRAIT">820</integer>- <integer name="SWITCH_STICK_R_Y_PORTRAIT">640</integer>+ <integer name="SWITCH_STICK_R_Y_PORTRAIT">660</integer><integer name="SWITCH_TRIGGER_L_X_PORTRAIT">140</integer>- <integer name="SWITCH_TRIGGER_L_Y_PORTRAIT">240</integer>+ <integer name="SWITCH_TRIGGER_L_Y_PORTRAIT">260</integer><integer name="SWITCH_TRIGGER_R_X_PORTRAIT">860</integer>- <integer name="SWITCH_TRIGGER_R_Y_PORTRAIT">240</integer>+ <integer name="SWITCH_TRIGGER_R_Y_PORTRAIT">260</integer><integer name="SWITCH_TRIGGER_ZL_X_PORTRAIT">140</integer>- <integer name="SWITCH_TRIGGER_ZL_Y_PORTRAIT">180</integer>+ <integer name="SWITCH_TRIGGER_ZL_Y_PORTRAIT">200</integer><integer name="SWITCH_TRIGGER_ZR_X_PORTRAIT">860</integer>- <integer name="SWITCH_TRIGGER_ZR_Y_PORTRAIT">180</integer>+ <integer name="SWITCH_TRIGGER_ZR_Y_PORTRAIT">200</integer><integer name="SWITCH_BUTTON_MINUS_X_PORTRAIT">440</integer><integer name="SWITCH_BUTTON_MINUS_Y_PORTRAIT">950</integer><integer name="SWITCH_BUTTON_PLUS_X_PORTRAIT">560</integer>@@ -64,38 +64,38 @@<integer name="SWITCH_BUTTON_CAPTURE_X_PORTRAIT">320</integer><integer name="SWITCH_BUTTON_CAPTURE_Y_PORTRAIT">950</integer><integer name="SWITCH_BUTTON_DPAD_X_PORTRAIT">240</integer>- <integer name="SWITCH_BUTTON_DPAD_Y_PORTRAIT">820</integer>+ <integer name="SWITCH_BUTTON_DPAD_Y_PORTRAIT">840</integer><!-- Default SWITCH foldable layout --><integer name="SWITCH_BUTTON_A_X_FOLDABLE">840</integer>- <integer name="SWITCH_BUTTON_A_Y_FOLDABLE">340</integer>+ <integer name="SWITCH_BUTTON_A_Y_FOLDABLE">390</integer><integer name="SWITCH_BUTTON_B_X_FOLDABLE">740</integer>- <integer name="SWITCH_BUTTON_B_Y_FOLDABLE">380</integer>+ <integer name="SWITCH_BUTTON_B_Y_FOLDABLE">430</integer><integer name="SWITCH_BUTTON_X_X_FOLDABLE">740</integer>- <integer name="SWITCH_BUTTON_X_Y_FOLDABLE">300</integer>+ <integer name="SWITCH_BUTTON_X_Y_FOLDABLE">350</integer><integer name="SWITCH_BUTTON_Y_X_FOLDABLE">640</integer>- <integer name="SWITCH_BUTTON_Y_Y_FOLDABLE">340</integer>+ <integer name="SWITCH_BUTTON_Y_Y_FOLDABLE">390</integer><integer name="SWITCH_STICK_L_X_FOLDABLE">180</integer>- <integer name="SWITCH_STICK_L_Y_FOLDABLE">200</integer>+ <integer name="SWITCH_STICK_L_Y_FOLDABLE">250</integer><integer name="SWITCH_STICK_R_X_FOLDABLE">820</integer>- <integer name="SWITCH_STICK_R_Y_FOLDABLE">200</integer>+ <integer name="SWITCH_STICK_R_Y_FOLDABLE">250</integer><integer name="SWITCH_TRIGGER_L_X_FOLDABLE">140</integer>- <integer name="SWITCH_TRIGGER_L_Y_FOLDABLE">80</integer>+ <integer name="SWITCH_TRIGGER_L_Y_FOLDABLE">130</integer><integer name="SWITCH_TRIGGER_R_X_FOLDABLE">860</integer>- <integer name="SWITCH_TRIGGER_R_Y_FOLDABLE">80</integer>+ <integer name="SWITCH_TRIGGER_R_Y_FOLDABLE">130</integer><integer name="SWITCH_TRIGGER_ZL_X_FOLDABLE">140</integer>- <integer name="SWITCH_TRIGGER_ZL_Y_FOLDABLE">20</integer>+ <integer name="SWITCH_TRIGGER_ZL_Y_FOLDABLE">70</integer><integer name="SWITCH_TRIGGER_ZR_X_FOLDABLE">860</integer>- <integer name="SWITCH_TRIGGER_ZR_Y_FOLDABLE">20</integer>+ <integer name="SWITCH_TRIGGER_ZR_Y_FOLDABLE">70</integer><integer name="SWITCH_BUTTON_MINUS_X_FOLDABLE">440</integer>- <integer name="SWITCH_BUTTON_MINUS_Y_FOLDABLE">420</integer>+ <integer name="SWITCH_BUTTON_MINUS_Y_FOLDABLE">470</integer><integer name="SWITCH_BUTTON_PLUS_X_FOLDABLE">560</integer>- <integer name="SWITCH_BUTTON_PLUS_Y_FOLDABLE">420</integer>+ <integer name="SWITCH_BUTTON_PLUS_Y_FOLDABLE">470</integer><integer name="SWITCH_BUTTON_HOME_X_FOLDABLE">680</integer>- <integer name="SWITCH_BUTTON_HOME_Y_FOLDABLE">420</integer>+ <integer name="SWITCH_BUTTON_HOME_Y_FOLDABLE">470</integer><integer name="SWITCH_BUTTON_CAPTURE_X_FOLDABLE">320</integer>- <integer name="SWITCH_BUTTON_CAPTURE_Y_FOLDABLE">420</integer>+ <integer name="SWITCH_BUTTON_CAPTURE_Y_FOLDABLE">470</integer><integer name="SWITCH_BUTTON_DPAD_X_FOLDABLE">240</integer>- <integer name="SWITCH_BUTTON_DPAD_Y_FOLDABLE">340</integer>+ <integer name="SWITCH_BUTTON_DPAD_Y_FOLDABLE">390</integer></resources>