diff options
author | Charles Lombardo <clombardo169@gmail.com> | 2023-04-04 22:01:54 +0200 |
---|---|---|
committer | bunnei <bunneidev@gmail.com> | 2023-06-03 09:05:50 +0200 |
commit | 78f02ab9a62658c3cdc29c61368443b619c770ad (patch) | |
tree | 59fe12739bfb347fa0a9281589f0370e7c716faa /src/android | |
parent | android: Use apply instead of commit for shared preferences (diff) | |
download | yuzu-78f02ab9a62658c3cdc29c61368443b619c770ad.tar yuzu-78f02ab9a62658c3cdc29c61368443b619c770ad.tar.gz yuzu-78f02ab9a62658c3cdc29c61368443b619c770ad.tar.bz2 yuzu-78f02ab9a62658c3cdc29c61368443b619c770ad.tar.lz yuzu-78f02ab9a62658c3cdc29c61368443b619c770ad.tar.xz yuzu-78f02ab9a62658c3cdc29c61368443b619c770ad.tar.zst yuzu-78f02ab9a62658c3cdc29c61368443b619c770ad.zip |
Diffstat (limited to 'src/android')
-rw-r--r-- | src/android/app/src/main/java/org/yuzu/yuzu_emu/overlay/InputOverlay.kt | 49 | ||||
-rw-r--r-- | src/android/app/src/main/res/values/integers.xml | 22 |
2 files changed, 41 insertions, 30 deletions
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.kt index 9b27ff1e3..895d33abf 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 @@ -35,6 +35,8 @@ import org.yuzu.yuzu_emu.R import org.yuzu.yuzu_emu.YuzuApplication import org.yuzu.yuzu_emu.features.settings.model.Settings import org.yuzu.yuzu_emu.utils.EmulationMenuSettings +import kotlin.math.max +import kotlin.math.min /** * Draws the interactive input overlay on top of the @@ -769,28 +771,37 @@ class InputOverlay(context: Context, attrs: AttributeSet?) : SurfaceView(context /** * Resizes a [Bitmap] by a given scale factor * - * @param vectorDrawable The {@link Bitmap} to scale. - * @param scale The scale factor for the bitmap. - * @return The scaled [Bitmap] + * @param context Context for getting the vector drawable + * @param drawableId The ID of the drawable to scale. + * @param scale The scale factor for the bitmap. + * @return The scaled [Bitmap] */ - private fun getBitmap(vectorDrawable: VectorDrawable, scale: Float): Bitmap { + private fun getBitmap(context: Context, drawableId: Int, scale: Float): Bitmap { + val vectorDrawable = ContextCompat.getDrawable(context, drawableId) as VectorDrawable + val bitmap = Bitmap.createBitmap( (vectorDrawable.intrinsicWidth * scale).toInt(), (vectorDrawable.intrinsicHeight * scale).toInt(), Bitmap.Config.ARGB_8888 ) - val canvas = Canvas(bitmap) + + val dm = context.resources.displayMetrics + val minScreenDimension = min(dm.widthPixels, dm.heightPixels) + + val maxBitmapDimension = max(bitmap.width, bitmap.height) + val bitmapScale = scale * minScreenDimension / maxBitmapDimension + + val scaledBitmap = Bitmap.createScaledBitmap( + bitmap, + (bitmap.width * bitmapScale).toInt(), + (bitmap.height * bitmapScale).toInt(), + true + ) + + val canvas = Canvas(scaledBitmap) vectorDrawable.setBounds(0, 0, canvas.width, canvas.height) vectorDrawable.draw(canvas) - return bitmap - } - - private fun getBitmap(context: Context, drawableId: Int, scale: Float): Bitmap { - return when (val drawable = ContextCompat.getDrawable(context, drawableId)) { - is BitmapDrawable -> BitmapFactory.decodeResource(context.resources, drawableId) - is VectorDrawable -> getBitmap(drawable, scale) - else -> throw IllegalArgumentException("Unsupported drawable type") - } + return scaledBitmap } /** @@ -845,12 +856,12 @@ class InputOverlay(context: Context, attrs: AttributeSet?) : SurfaceView(context ButtonType.BUTTON_HOME, ButtonType.BUTTON_CAPTURE, ButtonType.BUTTON_PLUS, - ButtonType.BUTTON_MINUS -> 0.35f + ButtonType.BUTTON_MINUS -> 0.07f ButtonType.TRIGGER_L, ButtonType.TRIGGER_R, ButtonType.TRIGGER_ZL, - ButtonType.TRIGGER_ZR -> 0.38f - else -> 0.43f + ButtonType.TRIGGER_ZR -> 0.26f + else -> 0.11f } scale *= (sPrefs.getInt(Settings.PREF_CONTROL_SCALE, 50) + 50).toFloat() scale /= 100f @@ -910,7 +921,7 @@ class InputOverlay(context: Context, attrs: AttributeSet?) : SurfaceView(context val sPrefs = PreferenceManager.getDefaultSharedPreferences(YuzuApplication.appContext) // Decide scale based on button ID and user preference - var scale = 0.40f + var scale = 0.25f scale *= (sPrefs.getInt(Settings.PREF_CONTROL_SCALE, 50) + 50).toFloat() scale /= 100f @@ -980,7 +991,7 @@ class InputOverlay(context: Context, attrs: AttributeSet?) : SurfaceView(context val sPrefs = PreferenceManager.getDefaultSharedPreferences(YuzuApplication.appContext) // Decide scale based on user preference - var scale = 0.40f + var scale = 0.3f scale *= (sPrefs.getInt(Settings.PREF_CONTROL_SCALE, 50) + 50).toFloat() scale /= 100f diff --git a/src/android/app/src/main/res/values/integers.xml b/src/android/app/src/main/res/values/integers.xml index 79b64192f..bc614b81d 100644 --- a/src/android/app/src/main/res/values/integers.xml +++ b/src/android/app/src/main/res/values/integers.xml @@ -4,13 +4,13 @@ <!-- Default SWITCH landscape layout --> <integer name="SWITCH_BUTTON_A_X">760</integer> - <integer name="SWITCH_BUTTON_A_Y">810</integer> + <integer name="SWITCH_BUTTON_A_Y">790</integer> <integer name="SWITCH_BUTTON_B_X">710</integer> - <integer name="SWITCH_BUTTON_B_Y">920</integer> + <integer name="SWITCH_BUTTON_B_Y">900</integer> <integer name="SWITCH_BUTTON_X_X">710</integer> - <integer name="SWITCH_BUTTON_X_Y">700</integer> + <integer name="SWITCH_BUTTON_X_Y">680</integer> <integer name="SWITCH_BUTTON_Y_X">660</integer> - <integer name="SWITCH_BUTTON_Y_Y">810</integer> + <integer name="SWITCH_BUTTON_Y_Y">790</integer> <integer name="SWITCH_STICK_L_X">100</integer> <integer name="SWITCH_STICK_L_Y">670</integer> <integer name="SWITCH_STICK_R_X">900</integer> @@ -24,14 +24,14 @@ <integer name="SWITCH_TRIGGER_ZR_X">930</integer> <integer name="SWITCH_TRIGGER_ZR_Y">90</integer> <integer name="SWITCH_BUTTON_MINUS_X">460</integer> - <integer name="SWITCH_BUTTON_MINUS_Y">955</integer> + <integer name="SWITCH_BUTTON_MINUS_Y">950</integer> <integer name="SWITCH_BUTTON_PLUS_X">540</integer> - <integer name="SWITCH_BUTTON_PLUS_Y">955</integer> - <integer name="SWITCH_BUTTON_HOME_X">620</integer> - <integer name="SWITCH_BUTTON_HOME_Y">960</integer> - <integer name="SWITCH_BUTTON_CAPTURE_X">380</integer> - <integer name="SWITCH_BUTTON_CAPTURE_Y">960</integer> + <integer name="SWITCH_BUTTON_PLUS_Y">950</integer> + <integer name="SWITCH_BUTTON_HOME_X">600</integer> + <integer name="SWITCH_BUTTON_HOME_Y">950</integer> + <integer name="SWITCH_BUTTON_CAPTURE_X">400</integer> + <integer name="SWITCH_BUTTON_CAPTURE_Y">950</integer> <integer name="SWITCH_BUTTON_DPAD_X">260</integer> - <integer name="SWITCH_BUTTON_DPAD_Y">810</integer> + <integer name="SWITCH_BUTTON_DPAD_Y">790</integer> </resources> |