Simplify OnScreenConfiguration

`ControllerConfigurationDummy` was removed as it isn't needed anymore, and the remaining classes simplified.
This commit is contained in:
lynxnb 2023-03-05 19:09:43 +01:00 committed by Niccolò Betto
parent 17f45c0366
commit c4d0d02509
3 changed files with 10 additions and 35 deletions

View File

@ -35,12 +35,11 @@ abstract class OnScreenButton(
const val CONFIGURED_ASPECT_RATIO = 2074f / 874f const val CONFIGURED_ASPECT_RATIO = 2074f / 874f
} }
val config = if (onScreenControllerView.isInEditMode) ControllerConfigurationDummy(defaultRelativeX, defaultRelativeY) val config = OnScreenConfiguration(onScreenControllerView.context, buttonId, defaultRelativeX, defaultRelativeY)
else ControllerConfigurationImpl(onScreenControllerView.context, buttonId, defaultRelativeX, defaultRelativeY)
protected val drawable = ContextCompat.getDrawable(onScreenControllerView.context, drawableId)!! protected val drawable = ContextCompat.getDrawable(onScreenControllerView.context, drawableId)!!
internal val buttonSymbolPaint = Paint().apply { private val buttonSymbolPaint = Paint().apply {
color = config.textColor color = config.textColor
typeface = Typeface.create(Typeface.DEFAULT, Typeface.BOLD) typeface = Typeface.create(Typeface.DEFAULT, Typeface.BOLD)
isAntiAlias = true isAntiAlias = true

View File

@ -10,37 +10,14 @@ import emu.skyline.input.ButtonId
import emu.skyline.utils.SwitchColors import emu.skyline.utils.SwitchColors
import emu.skyline.utils.sharedPreferences import emu.skyline.utils.sharedPreferences
interface ControllerConfiguration { class OnScreenConfiguration(private val context : Context, private val buttonId : ButtonId, defaultRelativeX : Float, defaultRelativeY : Float) {
var alpha : Int
var textColor : Int
var backgroundColor : Int
var enabled : Boolean
var globalScale : Float
var relativeX : Float
var relativeY : Float
}
/**
* Dummy implementation so layout editor is able to render [OnScreenControllerView] when [android.view.View.isInEditMode] is true
*/
class ControllerConfigurationDummy(defaultRelativeX : Float, defaultRelativeY : Float) : ControllerConfiguration {
override var alpha : Int = 155
override var textColor = SwitchColors.BLACK.color
override var backgroundColor = SwitchColors.WHITE.color
override var enabled = true
override var globalScale = 1f
override var relativeX = defaultRelativeX
override var relativeY = defaultRelativeY
}
class ControllerConfigurationImpl(private val context : Context, private val buttonId : ButtonId, defaultRelativeX : Float, defaultRelativeY : Float) : ControllerConfiguration {
private inline fun <reified T> config(default : T, prefix : String = "${buttonId.name}_") = sharedPreferences(context, default, prefix, "controller_config") private inline fun <reified T> config(default : T, prefix : String = "${buttonId.name}_") = sharedPreferences(context, default, prefix, "controller_config")
override var alpha by config(155, "") var alpha by config(155, "")
override var textColor by config(SwitchColors.BLACK.color) var textColor by config(SwitchColors.BLACK.color)
override var backgroundColor by config(SwitchColors.WHITE.color) var backgroundColor by config(SwitchColors.WHITE.color)
override var enabled by config(true) var enabled by config(true)
override var globalScale by config(1.15f, "") var globalScale by config(1.15f, "")
override var relativeX by config(defaultRelativeX) var relativeX by config(defaultRelativeX)
override var relativeY by config(defaultRelativeY) var relativeY by config(defaultRelativeY)
} }

View File

@ -7,7 +7,6 @@ package emu.skyline.input.onscreen
import android.graphics.Canvas import android.graphics.Canvas
import android.graphics.PointF import android.graphics.PointF
import android.graphics.Typeface
import android.os.SystemClock import android.os.SystemClock
import androidx.core.graphics.minus import androidx.core.graphics.minus
import emu.skyline.R import emu.skyline.R