summaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
authorbunnei <bunneidev@gmail.com>2023-06-06 05:27:58 +0200
committerGitHub <noreply@github.com>2023-06-06 05:27:58 +0200
commit036996429e1766231c5002bb333ee4e67d216c2c (patch)
tree9857f23a7ff48fdfdfa5c3a2968b29c1ccffe9af /src
parentMerge pull request #10578 from PabloG02/lime-firmware&logs (diff)
parentandroid: Use a custom view for changing emulation aspect ratio (diff)
downloadyuzu-036996429e1766231c5002bb333ee4e67d216c2c.tar
yuzu-036996429e1766231c5002bb333ee4e67d216c2c.tar.gz
yuzu-036996429e1766231c5002bb333ee4e67d216c2c.tar.bz2
yuzu-036996429e1766231c5002bb333ee4e67d216c2c.tar.lz
yuzu-036996429e1766231c5002bb333ee4e67d216c2c.tar.xz
yuzu-036996429e1766231c5002bb333ee4e67d216c2c.tar.zst
yuzu-036996429e1766231c5002bb333ee4e67d216c2c.zip
Diffstat (limited to 'src')
-rw-r--r--src/android/app/src/main/java/org/yuzu/yuzu_emu/fragments/EmulationFragment.kt14
-rw-r--r--src/android/app/src/main/java/org/yuzu/yuzu_emu/views/FixedRatioSurfaceView.kt46
-rw-r--r--src/android/app/src/main/res/layout/fragment_emulation.xml3
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
import android.os.Bundle
import android.os.Handler
import android.os.Looper
+import android.util.Rational
import android.util.TypedValue
import android.view.*
import android.widget.TextView
@@ -36,6 +37,7 @@ import org.yuzu.yuzu_emu.YuzuApplication
import org.yuzu.yuzu_emu.activities.EmulationActivity
import org.yuzu.yuzu_emu.databinding.DialogOverlayAdjustBinding
import org.yuzu.yuzu_emu.databinding.FragmentEmulationBinding
+import org.yuzu.yuzu_emu.features.settings.model.IntSetting
import org.yuzu.yuzu_emu.features.settings.model.Settings
import org.yuzu.yuzu_emu.features.settings.ui.SettingsActivity
import org.yuzu.yuzu_emu.features.settings.utils.SettingsFile
@@ -158,6 +160,18 @@ class EmulationFragment : Fragment(), SurfaceHolder.Callback {
if (!DirectoryInitialization.areDirectoriesReady) {
DirectoryInitialization.start(requireContext())
}
+
+ binding.surfaceEmulation.setAspectRatio(
+ when (IntSetting.RENDERER_ASPECT_RATIO.int) {
+ 0 -> Rational(16, 9)
+ 1 -> Rational(4, 3)
+ 2 -> Rational(21, 9)
+ 3 -> Rational(16, 10)
+ 4 -> null // Stretch
+ else -> Rational(16, 9)
+ }
+ )
+
emulationState.run(emulationActivity!!.isActivityRecreated)
}
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 @@
+// SPDX-FileCopyrightText: 2023 yuzu Emulator Project
+// SPDX-License-Identifier: GPL-2.0-or-later
+
+package org.yuzu.yuzu_emu.views
+
+import android.content.Context
+import android.util.AttributeSet
+import android.util.Rational
+import android.view.SurfaceView
+import kotlin.math.roundToInt
+
+class FixedRatioSurfaceView @JvmOverloads constructor(
+ context: Context,
+ attrs: AttributeSet? = null,
+ defStyleAttr: Int = 0
+) : SurfaceView(context, attrs, defStyleAttr) {
+ private var aspectRatio: Float = 0f // (width / height), 0f is a special value for stretch
+
+ /**
+ * Sets the desired aspect ratio for this view
+ * @param ratio the ratio to force the view to, or null to stretch to fit
+ */
+ fun setAspectRatio(ratio: Rational?) {
+ aspectRatio = ratio?.toFloat() ?: 0f
+ }
+
+ override fun onMeasure(widthMeasureSpec: Int, heightMeasureSpec: Int) {
+ super.onMeasure(widthMeasureSpec, heightMeasureSpec)
+ val width = MeasureSpec.getSize(widthMeasureSpec)
+ val height = MeasureSpec.getSize(heightMeasureSpec)
+ if (aspectRatio != 0f) {
+ val newWidth: Int
+ val newHeight: Int
+ if (height * aspectRatio < width) {
+ newWidth = (height * aspectRatio).roundToInt()
+ newHeight = height
+ } else {
+ newWidth = width
+ newHeight = (width / aspectRatio).roundToInt()
+ }
+ setMeasuredDimension(newWidth, newHeight)
+ } else {
+ setMeasuredDimension(width, height)
+ }
+ }
+}
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 @@
android:layout_height="match_parent">
<!-- This is what everything is rendered to during emulation -->
- <SurfaceView
+ <org.yuzu.yuzu_emu.views.FixedRatioSurfaceView
android:id="@+id/surface_emulation"
android:layout_width="match_parent"
android:layout_height="match_parent"
+ android:layout_gravity="center"
android:focusable="false"
android:focusableInTouchMode="false" />