diff --git a/app/src/main/java/emu/skyline/EmulationActivity.kt b/app/src/main/java/emu/skyline/EmulationActivity.kt index 6aeed44c..4a74732f 100644 --- a/app/src/main/java/emu/skyline/EmulationActivity.kt +++ b/app/src/main/java/emu/skyline/EmulationActivity.kt @@ -12,6 +12,7 @@ import android.content.res.AssetManager import android.graphics.PointF import android.os.* import android.util.Log +import android.util.Rational import android.view.* import androidx.appcompat.app.AppCompatActivity import androidx.core.view.isGone @@ -221,9 +222,6 @@ class EmulationActivity : AppCompatActivity(), SurfaceHolder.Callback, View.OnTo returnFromEmulation() } - /** - * This makes the window fullscreen, sets up the performance statistics and finally calls [executeApplication] for executing the application - */ @SuppressLint("SetTextI18n", "ClickableViewAccessibility") override fun onCreate(savedInstanceState : Bundle?) { super.onCreate(savedInstanceState) @@ -237,6 +235,14 @@ class EmulationActivity : AppCompatActivity(), SurfaceHolder.Callback, View.OnTo binding.gameView.holder.addCallback(this) + binding.gameView.setAspectRatio( + when (settings.aspectRatio) { + 0 -> Rational(16, 9) + 1 -> Rational(21, 9) + else -> null + } + ) + if (settings.perfStats) { binding.perfStats.apply { postDelayed(object : Runnable { diff --git a/app/src/main/java/emu/skyline/utils/Settings.kt b/app/src/main/java/emu/skyline/utils/Settings.kt index cd822d8e..d1a0de53 100644 --- a/app/src/main/java/emu/skyline/utils/Settings.kt +++ b/app/src/main/java/emu/skyline/utils/Settings.kt @@ -38,5 +38,7 @@ class Settings @Inject constructor(@ApplicationContext private val context : Con var maxRefreshRate by sharedPreferences(context, false) + var aspectRatio by sharedPreferences(context, 0) + var systemLanguage by sharedPreferences(context, 1) } diff --git a/app/src/main/java/emu/skyline/views/FixedRatioSurfaceView.kt b/app/src/main/java/emu/skyline/views/FixedRatioSurfaceView.kt new file mode 100644 index 00000000..b9dabb86 --- /dev/null +++ b/app/src/main/java/emu/skyline/views/FixedRatioSurfaceView.kt @@ -0,0 +1,39 @@ +package emu.skyline.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/app/src/main/res/layout/emu_activity.xml b/app/src/main/res/layout/emu_activity.xml index 16dfa2ae..fca9db06 100644 --- a/app/src/main/res/layout/emu_activity.xml +++ b/app/src/main/res/layout/emu_activity.xml @@ -1,39 +1,39 @@ + + - - + android:layout_gravity="center" /> + android:id="@+id/on_screen_controller_view" + android:layout_width="match_parent" + android:layout_height="match_parent" /> + android:id="@+id/perf_stats" + android:layout_width="wrap_content" + android:layout_height="wrap_content" + android:layout_marginStart="5dp" + android:layout_marginTop="5dp" + android:textColor="#9fffff00" /> + android:id="@+id/on_screen_controller_toggle" + android:layout_width="40dp" + android:layout_height="40dp" + android:layout_gravity="bottom|end" + android:background="?attr/selectableItemBackgroundBorderless" + android:src="@drawable/ic_show" + app:tint="#40FFFFFF" + tools:ignore="ContentDescription" /> diff --git a/app/src/main/res/values/array.xml b/app/src/main/res/values/array.xml index 212434a3..a17d9179 100644 --- a/app/src/main/res/values/array.xml +++ b/app/src/main/res/values/array.xml @@ -74,4 +74,9 @@ 7 11 + + 16:9 (Switch, Recommended) + 21:9 (Ultrawide Mods) + Device Aspect Ratio (Stretch to fit) + diff --git a/app/src/main/res/values/strings.xml b/app/src/main/res/values/strings.xml index d9174901..051bab70 100644 --- a/app/src/main/res/values/strings.xml +++ b/app/src/main/res/values/strings.xml @@ -61,6 +61,7 @@ Use Maximum Display Refresh Rate Sets the display refresh rate as high as possible (Will break most games) Sets the display refresh rate to 60Hz + Aspect Ratio Input On-Screen Controls diff --git a/app/src/main/res/xml/preferences.xml b/app/src/main/res/xml/preferences.xml index 5fc45571..101399b2 100644 --- a/app/src/main/res/xml/preferences.xml +++ b/app/src/main/res/xml/preferences.xml @@ -103,6 +103,12 @@ android:summaryOn="@string/max_refresh_rate_enabled" app:key="max_refresh_rate" app:title="@string/max_refresh_rate" /> +