mirror of
https://git.suyu.dev/suyu/suyu.git
synced 2024-11-26 16:52:46 +01:00
android: Scale input overlay independently of system display scale
This commit is contained in:
parent
aeaddf407b
commit
78f02ab9a6
2 changed files with 41 additions and 30 deletions
|
@ -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
|
||||
|
||||
|
|
|
@ -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>
|
||||
|
|
Loading…
Reference in a new issue