diff options
3 files changed, 62 insertions, 1 deletions
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.kt index 41b1a6e23..9523381cd 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 | |||
| @@ -14,6 +14,7 @@ import android.graphics.Color | |||
| 14 | import android.os.Bundle | 14 | import android.os.Bundle |
| 15 | import android.os.Handler | 15 | import android.os.Handler |
| 16 | import android.os.Looper | 16 | import android.os.Looper |
| 17 | import android.util.Rational | ||
| 17 | import android.util.TypedValue | 18 | import android.util.TypedValue |
| 18 | import android.view.* | 19 | import android.view.* |
| 19 | import android.widget.TextView | 20 | import android.widget.TextView |
| @@ -36,6 +37,7 @@ import org.yuzu.yuzu_emu.YuzuApplication | |||
| 36 | import org.yuzu.yuzu_emu.activities.EmulationActivity | 37 | import org.yuzu.yuzu_emu.activities.EmulationActivity |
| 37 | import org.yuzu.yuzu_emu.databinding.DialogOverlayAdjustBinding | 38 | import org.yuzu.yuzu_emu.databinding.DialogOverlayAdjustBinding |
| 38 | import org.yuzu.yuzu_emu.databinding.FragmentEmulationBinding | 39 | import org.yuzu.yuzu_emu.databinding.FragmentEmulationBinding |
| 40 | import org.yuzu.yuzu_emu.features.settings.model.IntSetting | ||
| 39 | import org.yuzu.yuzu_emu.features.settings.model.Settings | 41 | import org.yuzu.yuzu_emu.features.settings.model.Settings |
| 40 | import org.yuzu.yuzu_emu.features.settings.ui.SettingsActivity | 42 | import org.yuzu.yuzu_emu.features.settings.ui.SettingsActivity |
| 41 | import org.yuzu.yuzu_emu.features.settings.utils.SettingsFile | 43 | import org.yuzu.yuzu_emu.features.settings.utils.SettingsFile |
| @@ -158,6 +160,18 @@ class EmulationFragment : Fragment(), SurfaceHolder.Callback { | |||
| 158 | if (!DirectoryInitialization.areDirectoriesReady) { | 160 | if (!DirectoryInitialization.areDirectoriesReady) { |
| 159 | DirectoryInitialization.start(requireContext()) | 161 | DirectoryInitialization.start(requireContext()) |
| 160 | } | 162 | } |
| 163 | |||
| 164 | binding.surfaceEmulation.setAspectRatio( | ||
| 165 | when (IntSetting.RENDERER_ASPECT_RATIO.int) { | ||
| 166 | 0 -> Rational(16, 9) | ||
| 167 | 1 -> Rational(4, 3) | ||
| 168 | 2 -> Rational(21, 9) | ||
| 169 | 3 -> Rational(16, 10) | ||
| 170 | 4 -> null // Stretch | ||
| 171 | else -> Rational(16, 9) | ||
| 172 | } | ||
| 173 | ) | ||
| 174 | |||
| 161 | emulationState.run(emulationActivity!!.isActivityRecreated) | 175 | emulationState.run(emulationActivity!!.isActivityRecreated) |
| 162 | } | 176 | } |
| 163 | 177 | ||
diff --git a/src/android/app/src/main/java/org/yuzu/yuzu_emu/views/FixedRatioSurfaceView.kt b/src/android/app/src/main/java/org/yuzu/yuzu_emu/views/FixedRatioSurfaceView.kt new file mode 100644 index 000000000..c8ef8c1fd --- /dev/null +++ b/src/android/app/src/main/java/org/yuzu/yuzu_emu/views/FixedRatioSurfaceView.kt | |||
| @@ -0,0 +1,46 @@ | |||
| 1 | // SPDX-FileCopyrightText: 2023 yuzu Emulator Project | ||
| 2 | // SPDX-License-Identifier: GPL-2.0-or-later | ||
| 3 | |||
| 4 | package org.yuzu.yuzu_emu.views | ||
| 5 | |||
| 6 | import android.content.Context | ||
| 7 | import android.util.AttributeSet | ||
| 8 | import android.util.Rational | ||
| 9 | import android.view.SurfaceView | ||
| 10 | import kotlin.math.roundToInt | ||
| 11 | |||
| 12 | class FixedRatioSurfaceView @JvmOverloads constructor( | ||
| 13 | context: Context, | ||
| 14 | attrs: AttributeSet? = null, | ||
| 15 | defStyleAttr: Int = 0 | ||
| 16 | ) : SurfaceView(context, attrs, defStyleAttr) { | ||
| 17 | private var aspectRatio: Float = 0f // (width / height), 0f is a special value for stretch | ||
| 18 | |||
| 19 | /** | ||
| 20 | * Sets the desired aspect ratio for this view | ||
| 21 | * @param ratio the ratio to force the view to, or null to stretch to fit | ||
| 22 | */ | ||
| 23 | fun setAspectRatio(ratio: Rational?) { | ||
| 24 | aspectRatio = ratio?.toFloat() ?: 0f | ||
| 25 | } | ||
| 26 | |||
| 27 | override fun onMeasure(widthMeasureSpec: Int, heightMeasureSpec: Int) { | ||
| 28 | super.onMeasure(widthMeasureSpec, heightMeasureSpec) | ||
| 29 | val width = MeasureSpec.getSize(widthMeasureSpec) | ||
| 30 | val height = MeasureSpec.getSize(heightMeasureSpec) | ||
| 31 | if (aspectRatio != 0f) { | ||
| 32 | val newWidth: Int | ||
| 33 | val newHeight: Int | ||
| 34 | if (height * aspectRatio < width) { | ||
| 35 | newWidth = (height * aspectRatio).roundToInt() | ||
| 36 | newHeight = height | ||
| 37 | } else { | ||
| 38 | newWidth = width | ||
| 39 | newHeight = (width / aspectRatio).roundToInt() | ||
| 40 | } | ||
| 41 | setMeasuredDimension(newWidth, newHeight) | ||
| 42 | } else { | ||
| 43 | setMeasuredDimension(width, height) | ||
| 44 | } | ||
| 45 | } | ||
| 46 | } | ||
diff --git a/src/android/app/src/main/res/layout/fragment_emulation.xml b/src/android/app/src/main/res/layout/fragment_emulation.xml index 940dbd4bf..09b789b6b 100644 --- a/src/android/app/src/main/res/layout/fragment_emulation.xml +++ b/src/android/app/src/main/res/layout/fragment_emulation.xml | |||
| @@ -13,10 +13,11 @@ | |||
| 13 | android:layout_height="match_parent"> | 13 | android:layout_height="match_parent"> |
| 14 | 14 | ||
| 15 | <!-- This is what everything is rendered to during emulation --> | 15 | <!-- This is what everything is rendered to during emulation --> |
| 16 | <SurfaceView | 16 | <org.yuzu.yuzu_emu.views.FixedRatioSurfaceView |
| 17 | android:id="@+id/surface_emulation" | 17 | android:id="@+id/surface_emulation" |
| 18 | android:layout_width="match_parent" | 18 | android:layout_width="match_parent" |
| 19 | android:layout_height="match_parent" | 19 | android:layout_height="match_parent" |
| 20 | android:layout_gravity="center" | ||
| 20 | android:focusable="false" | 21 | android:focusable="false" |
| 21 | android:focusableInTouchMode="false" /> | 22 | android:focusableInTouchMode="false" /> |
| 22 | 23 | ||