VERY experimental Nintendo Switch 2 emulator
C++
android: Set portrait default control params
Abandoned Cartdf42e34dfb9e
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 4da54c28f7..c65db59f80 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@@ -334,6 +334,8 @@ class EmulationFragment : Fragment(), SurfaceHolder.Callback {// Prevent touch regions from being displayed in the hingebinding.overlayContainer.layoutParams.height = it.bounds.bottom - 48.toPxbinding.overlayContainer.updatePadding(0, 0, 0, 24.toPx)+ binding.inGameMenu.layoutParams.height = it.bounds.bottom+ refreshInputOverlay()}}it.isSeparating@@ -342,10 +344,12 @@ class EmulationFragment : Fragment(), SurfaceHolder.Callback {binding.emulationContainer.layoutParams.height = ViewGroup.LayoutParams.MATCH_PARENTbinding.overlayContainer.layoutParams.height = ViewGroup.LayoutParams.MATCH_PARENTbinding.overlayContainer.updatePadding(0, 0, 0, 0)+ binding.inGameMenu.layoutParams.height = ViewGroup.LayoutParams.MATCH_PARENTupdateScreenLayout()}binding.emulationContainer.requestLayout()binding.overlayContainer.requestLayout()+ binding.inGameMenu.requestLayout()}override fun surfaceCreated(holder: SurfaceHolder) {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 ed84ba5f0f..ae5d935d0a 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@@ -3,7 +3,6 @@package org.yuzu.yuzu_emu.overlay-import android.annotation.SuppressLintimport android.app.Activityimport android.content.Contextimport android.content.SharedPreferences@@ -16,14 +15,12 @@ import android.graphics.drawable.Drawableimport android.graphics.drawable.VectorDrawableimport android.os.Buildimport android.util.AttributeSet-import android.util.Rationalimport android.view.HapticFeedbackConstantsimport android.view.MotionEventimport android.view.SurfaceViewimport android.view.Viewimport android.view.View.OnTouchListenerimport android.view.WindowInsets-import android.view.WindowManagerimport androidx.core.content.ContextCompatimport androidx.preference.PreferenceManagerimport androidx.window.layout.WindowMetricsCalculator@@ -36,7 +33,6 @@ import org.yuzu.yuzu_emu.features.settings.model.Settingsimport org.yuzu.yuzu_emu.utils.EmulationMenuSettingsimport kotlin.math.maximport kotlin.math.min-import kotlin.math.roundToInt/*** Draws the interactive input overlay on top of the@@ -237,11 +233,6 @@ class InputOverlay(context: Context, attrs: AttributeSet?) : SurfaceView(contextval fingerPositionX = event.getX(pointerIndex).toInt()val fingerPositionY = event.getY(pointerIndex).toInt()- val orientation = if (resources.configuration.orientation == Configuration.ORIENTATION_PORTRAIT)- "-Portrait"- else- ""-for (button in overlayButtons) {// Determine the button state to apply based on the MotionEvent action flag.when (event.action and MotionEvent.ACTION_MASK) {@@ -538,10 +529,6 @@ class InputOverlay(context: Context, attrs: AttributeSet?) : SurfaceView(contextoverlayButtons.clear()overlayDpads.clear()overlayJoysticks.clear()- val orientation = if (resources.configuration.orientation == Configuration.ORIENTATION_PORTRAIT)- "-Portrait"- else- ""// Add all the enabled overlay items back to the HashSet.if (EmulationMenuSettings.showOverlay) {@@ -566,7 +553,10 @@ class InputOverlay(context: Context, attrs: AttributeSet?) : SurfaceView(contextprivate fun defaultOverlay() {if (!preferences.getBoolean(Settings.PREF_OVERLAY_INIT, false)) {- defaultOverlayLandscape()+ if (orientation == portrait)+ defaultOverlayPortrait()+ else+ defaultOverlayLandscape()}resetButtonPlacement()@@ -576,10 +566,141 @@ class InputOverlay(context: Context, attrs: AttributeSet?) : SurfaceView(context}fun resetButtonPlacement() {- defaultOverlayLandscape()+ if (orientation == portrait)+ defaultOverlayPortrait()+ else+ defaultOverlayLandscape()refreshControls()}+ private fun defaultOverlayPortrait() {+ // Each value represents the position of the button in relation to the screen size without insets.+ preferences.edit()+ .putFloat(+ ButtonType.BUTTON_A.toString() + "$portrait-X",+ resources.getInteger(R.integer.SWITCH_BUTTON_A_PORTRAIT_X).toFloat() / 1000+ )+ .putFloat(+ ButtonType.BUTTON_A.toString() + "$portrait-Y",+ resources.getInteger(R.integer.SWITCH_BUTTON_A_PORTRAIT_Y).toFloat() / 1000+ )+ .putFloat(+ ButtonType.BUTTON_B.toString() + "$portrait-X",+ resources.getInteger(R.integer.SWITCH_BUTTON_B_PORTRAIT_X).toFloat() / 1000+ )+ .putFloat(+ ButtonType.BUTTON_B.toString() + "$portrait-Y",+ resources.getInteger(R.integer.SWITCH_BUTTON_B_PORTRAIT_Y).toFloat() / 1000+ )+ .putFloat(+ ButtonType.BUTTON_X.toString() + "$portrait-X",+ resources.getInteger(R.integer.SWITCH_BUTTON_X_PORTRAIT_X).toFloat() / 1000+ )+ .putFloat(+ ButtonType.BUTTON_X.toString() + "$portrait-Y",+ resources.getInteger(R.integer.SWITCH_BUTTON_X_PORTRAIT_Y).toFloat() / 1000+ )+ .putFloat(+ ButtonType.BUTTON_Y.toString() + "$portrait-X",+ resources.getInteger(R.integer.SWITCH_BUTTON_Y_PORTRAIT_X).toFloat() / 1000+ )+ .putFloat(+ ButtonType.BUTTON_Y.toString() + "$portrait-Y",+ resources.getInteger(R.integer.SWITCH_BUTTON_Y_PORTRAIT_Y).toFloat() / 1000+ )+ .putFloat(+ ButtonType.TRIGGER_ZL.toString() + "$portrait-X",+ resources.getInteger(R.integer.SWITCH_TRIGGER_ZL_PORTRAIT_X).toFloat() / 1000+ )+ .putFloat(+ ButtonType.TRIGGER_ZL.toString() + "$portrait-Y",+ resources.getInteger(R.integer.SWITCH_TRIGGER_ZL_PORTRAIT_Y).toFloat() / 1000+ )+ .putFloat(+ ButtonType.TRIGGER_ZR.toString() + "$portrait-X",+ resources.getInteger(R.integer.SWITCH_TRIGGER_ZR_PORTRAIT_X).toFloat() / 1000+ )+ .putFloat(+ ButtonType.TRIGGER_ZR.toString() + "$portrait-Y",+ resources.getInteger(R.integer.SWITCH_TRIGGER_ZR_PORTRAIT_Y).toFloat() / 1000+ )+ .putFloat(+ ButtonType.DPAD_UP.toString() + "$portrait-X",+ resources.getInteger(R.integer.SWITCH_BUTTON_DPAD_PORTRAIT_X).toFloat() / 1000+ )+ .putFloat(+ ButtonType.DPAD_UP.toString() + "$portrait-Y",+ resources.getInteger(R.integer.SWITCH_BUTTON_DPAD_PORTRAIT_Y).toFloat() / 1000+ )+ .putFloat(+ ButtonType.TRIGGER_L.toString() + "$portrait-X",+ resources.getInteger(R.integer.SWITCH_TRIGGER_L_PORTRAIT_X).toFloat() / 1000+ )+ .putFloat(+ ButtonType.TRIGGER_L.toString() + "$portrait-Y",+ resources.getInteger(R.integer.SWITCH_TRIGGER_L_PORTRAIT_Y).toFloat() / 1000+ )+ .putFloat(+ ButtonType.TRIGGER_R.toString() + "$portrait-X",+ resources.getInteger(R.integer.SWITCH_TRIGGER_R_PORTRAIT_X).toFloat() / 1000+ )+ .putFloat(+ ButtonType.TRIGGER_R.toString() + "$portrait-Y",+ resources.getInteger(R.integer.SWITCH_TRIGGER_R_PORTRAIT_Y).toFloat() / 1000+ )+ .putFloat(+ ButtonType.BUTTON_PLUS.toString() + "$portrait-X",+ resources.getInteger(R.integer.SWITCH_BUTTON_PLUS_PORTRAIT_X).toFloat() / 1000+ )+ .putFloat(+ ButtonType.BUTTON_PLUS.toString() + "$portrait-Y",+ resources.getInteger(R.integer.SWITCH_BUTTON_PLUS_PORTRAIT_Y).toFloat() / 1000+ )+ .putFloat(+ ButtonType.BUTTON_MINUS.toString() + "$portrait-X",+ resources.getInteger(R.integer.SWITCH_BUTTON_MINUS_PORTRAIT_X).toFloat() / 1000+ )+ .putFloat(+ ButtonType.BUTTON_MINUS.toString() + "$portrait-Y",+ resources.getInteger(R.integer.SWITCH_BUTTON_MINUS_PORTRAIT_Y).toFloat() / 1000+ )+ .putFloat(+ ButtonType.BUTTON_HOME.toString() + "$portrait-X",+ resources.getInteger(R.integer.SWITCH_BUTTON_HOME_PORTRAIT_X).toFloat() / 1000+ )+ .putFloat(+ ButtonType.BUTTON_HOME.toString() + "$portrait-Y",+ resources.getInteger(R.integer.SWITCH_BUTTON_HOME_PORTRAIT_Y).toFloat() / 1000+ )+ .putFloat(+ ButtonType.BUTTON_CAPTURE.toString() + "$portrait-X",+ resources.getInteger(R.integer.SWITCH_BUTTON_CAPTURE_PORTRAIT_X)+ .toFloat() / 1000+ )+ .putFloat(+ ButtonType.BUTTON_CAPTURE.toString() + "$portrait-Y",+ resources.getInteger(R.integer.SWITCH_BUTTON_CAPTURE_PORTRAIT_Y)+ .toFloat() / 1000+ )+ .putFloat(+ ButtonType.STICK_R.toString() + "$portrait-X",+ resources.getInteger(R.integer.SWITCH_STICK_R_PORTRAIT_X).toFloat() / 1000+ )+ .putFloat(+ ButtonType.STICK_R.toString() + "$portrait-Y",+ resources.getInteger(R.integer.SWITCH_STICK_R_PORTRAIT_Y).toFloat() / 1000+ )+ .putFloat(+ ButtonType.STICK_L.toString() + "$portrait-X",+ resources.getInteger(R.integer.SWITCH_STICK_L_PORTRAIT_X).toFloat() / 1000+ )+ .putFloat(+ ButtonType.STICK_L.toString() + "$portrait-Y",+ resources.getInteger(R.integer.SWITCH_STICK_L_PORTRAIT_Y).toFloat() / 1000+ )+ .apply()+ }+private fun defaultOverlayLandscape() {// Each value represents the position of the button in relation to the screen size without insets.preferences.edit()@@ -712,10 +833,22 @@ class InputOverlay(context: Context, attrs: AttributeSet?) : SurfaceView(contextreturn inEditMode}+ override fun onConfigurationChanged(newConfig: Configuration?) {+ super.onConfigurationChanged(newConfig)+ orientation =+ if (newConfig?.orientation == Configuration.ORIENTATION_PORTRAIT)+ portrait+ else+ ""+ }+companion object {private val preferences: SharedPreferences =PreferenceManager.getDefaultSharedPreferences(YuzuApplication.appContext)+ private const val portrait = "-Portrait"+ private var orientation = ""+/*** Resizes a [Bitmap] by a given scale factor*diff --git a/src/android/app/src/main/res/layout/fragment_emulation.xml b/src/android/app/src/main/res/layout/fragment_emulation.xmlindex ccd0f4c50b..01f6b9fe48 100644--- a/src/android/app/src/main/res/layout/fragment_emulation.xml+++ b/src/android/app/src/main/res/layout/fragment_emulation.xml@@ -39,7 +39,7 @@android:id="@+id/surface_input_overlay"android:layout_width="match_parent"android:layout_height="match_parent"- android:layout_gravity="bottom"+ android:layout_gravity="center"android:focusable="true"android:focusableInTouchMode="true" />@@ -72,7 +72,7 @@android:id="@+id/in_game_menu"android:layout_width="wrap_content"android:layout_height="match_parent"- android:layout_gravity="start"+ android:layout_gravity="start|bottom"app:headerLayout="@layout/header_in_game"app:menu="@menu/menu_in_game" />diff --git a/src/android/app/src/main/res/values/integers.xml b/src/android/app/src/main/res/values/integers.xmlindex bc614b81d7..326867664c 100644--- a/src/android/app/src/main/res/values/integers.xml+++ b/src/android/app/src/main/res/values/integers.xml@@ -2,6 +2,38 @@<resources><integer name="game_title_lines">2</integer>+ <!-- Default SWITCH portrait layout -->+ <integer name="SWITCH_BUTTON_A_PORTRAIT_X">830</integer>+ <integer name="SWITCH_BUTTON_A_PORTRAIT_Y">820</integer>+ <integer name="SWITCH_BUTTON_B_PORTRAIT_X">730</integer>+ <integer name="SWITCH_BUTTON_B_PORTRAIT_Y">870</integer>+ <integer name="SWITCH_BUTTON_X_PORTRAIT_X">730</integer>+ <integer name="SWITCH_BUTTON_X_PORTRAIT_Y">770</integer>+ <integer name="SWITCH_BUTTON_Y_PORTRAIT_X">630</integer>+ <integer name="SWITCH_BUTTON_Y_PORTRAIT_Y">820</integer>+ <integer name="SWITCH_STICK_L_PORTRAIT_X">170</integer>+ <integer name="SWITCH_STICK_L_PORTRAIT_Y">640</integer>+ <integer name="SWITCH_STICK_R_PORTRAIT_X">820</integer>+ <integer name="SWITCH_STICK_R_PORTRAIT_Y">640</integer>+ <integer name="SWITCH_TRIGGER_L_PORTRAIT_X">140</integer>+ <integer name="SWITCH_TRIGGER_L_PORTRAIT_Y">240</integer>+ <integer name="SWITCH_TRIGGER_R_PORTRAIT_X">860</integer>+ <integer name="SWITCH_TRIGGER_R_PORTRAIT_Y">240</integer>+ <integer name="SWITCH_TRIGGER_ZL_PORTRAIT_X">140</integer>+ <integer name="SWITCH_TRIGGER_ZL_PORTRAIT_Y">180</integer>+ <integer name="SWITCH_TRIGGER_ZR_PORTRAIT_X">860</integer>+ <integer name="SWITCH_TRIGGER_ZR_PORTRAIT_Y">180</integer>+ <integer name="SWITCH_BUTTON_MINUS_PORTRAIT_X">440</integer>+ <integer name="SWITCH_BUTTON_MINUS_PORTRAIT_Y">950</integer>+ <integer name="SWITCH_BUTTON_PLUS_PORTRAIT_X">560</integer>+ <integer name="SWITCH_BUTTON_PLUS_PORTRAIT_Y">950</integer>+ <integer name="SWITCH_BUTTON_HOME_PORTRAIT_X">600</integer>+ <integer name="SWITCH_BUTTON_HOME_PORTRAIT_Y">950</integer>+ <integer name="SWITCH_BUTTON_CAPTURE_PORTRAIT_X">400</integer>+ <integer name="SWITCH_BUTTON_CAPTURE_PORTRAIT_Y">950</integer>+ <integer name="SWITCH_BUTTON_DPAD_PORTRAIT_X">240</integer>+ <integer name="SWITCH_BUTTON_DPAD_PORTRAIT_Y">820</integer>+<!-- Default SWITCH landscape layout --><integer name="SWITCH_BUTTON_A_X">760</integer><integer name="SWITCH_BUTTON_A_Y">790</integer>