mirror of
https://github.com/skyline-emu/skyline.git
synced 2024-11-23 05:39:18 +01:00
Fix OSC alpha not changing on button press
This commit is contained in:
parent
8fb4e62c28
commit
cfa5f0e030
@ -72,14 +72,16 @@ abstract class OnScreenButton(
|
||||
var touchPointerId = -1
|
||||
var partnerPointerId = -1
|
||||
|
||||
var isPressed = false
|
||||
|
||||
var isEditing = false
|
||||
private set
|
||||
|
||||
protected open fun renderCenteredText(canvas : Canvas, text : String, size : Float, x : Float, y : Float) {
|
||||
protected open fun renderCenteredText(canvas : Canvas, text : String, size : Float, x : Float, y : Float, alpha : Int) {
|
||||
buttonSymbolPaint.apply {
|
||||
textSize = size
|
||||
textAlign = Paint.Align.LEFT
|
||||
alpha = (config.opacity / 100.0 * 255).toInt()
|
||||
this.alpha = alpha
|
||||
getTextBounds(text, 0, text.length, textBoundsRect)
|
||||
}
|
||||
canvas.drawText(text, x - textBoundsRect.width() / 2f - textBoundsRect.left, y + textBoundsRect.height() / 2f - textBoundsRect.bottom, buttonSymbolPaint)
|
||||
@ -87,20 +89,25 @@ abstract class OnScreenButton(
|
||||
|
||||
open fun render(canvas : Canvas) {
|
||||
val bounds = currentBounds
|
||||
val alpha = if (isPressed) (config.alpha - 130).coerceIn(30..255) else config.alpha
|
||||
drawable.apply {
|
||||
this.bounds = bounds
|
||||
alpha = (config.opacity / 100.0 * 255).toInt()
|
||||
this.alpha = alpha
|
||||
draw(canvas)
|
||||
}
|
||||
|
||||
renderCenteredText(canvas, buttonId.short!!, itemWidth.coerceAtMost(itemHeight) * 0.4f, bounds.centerX().toFloat(), bounds.centerY().toFloat())
|
||||
renderCenteredText(canvas, buttonId.short!!, itemWidth.coerceAtMost(itemHeight) * 0.4f, bounds.centerX().toFloat(), bounds.centerY().toFloat(), alpha)
|
||||
}
|
||||
|
||||
abstract fun isTouched(x : Float, y : Float) : Boolean
|
||||
|
||||
abstract fun onFingerDown(x : Float, y : Float)
|
||||
open fun onFingerDown(x : Float, y : Float) {
|
||||
isPressed = true
|
||||
}
|
||||
|
||||
abstract fun onFingerUp(x : Float, y : Float)
|
||||
open fun onFingerUp(x : Float, y : Float) {
|
||||
isPressed = false
|
||||
}
|
||||
|
||||
fun loadConfigValues() {
|
||||
relativeX = config.relativeX
|
||||
|
@ -10,7 +10,7 @@ import emu.skyline.input.ButtonId
|
||||
import emu.skyline.utils.sharedPreferences
|
||||
|
||||
interface ControllerConfiguration {
|
||||
var opacity : Int
|
||||
var alpha : Int
|
||||
var enabled : Boolean
|
||||
var globalScale : Float
|
||||
var relativeX : Float
|
||||
@ -21,7 +21,7 @@ interface ControllerConfiguration {
|
||||
* 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 opacity : Int = 100
|
||||
override var alpha : Int = 255
|
||||
override var enabled = true
|
||||
override var globalScale = 1f
|
||||
override var relativeX = defaultRelativeX
|
||||
@ -31,7 +31,7 @@ class ControllerConfigurationDummy(defaultRelativeX : Float, 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")
|
||||
|
||||
override var opacity by config(100)
|
||||
override var alpha by config(255, "")
|
||||
override var enabled by config(true)
|
||||
override var globalScale by config(1.15f, "")
|
||||
override var relativeX by config(defaultRelativeX)
|
||||
|
@ -35,6 +35,10 @@ class OnScreenControllerView @JvmOverloads constructor(context : Context, attrs
|
||||
private val controllerTypeMappings = mapOf(*ControllerType.values().map {
|
||||
it to (setOf(*it.buttons) to setOf(*it.sticks))
|
||||
}.toTypedArray())
|
||||
|
||||
private const val SCALE_STEP = 0.05f
|
||||
private const val ALPHA_STEP = 25
|
||||
private val ALPHA_RANGE = 55..255
|
||||
}
|
||||
|
||||
private val controls = Controls(this)
|
||||
@ -249,22 +253,22 @@ class OnScreenControllerView @JvmOverloads constructor(context : Context, attrs
|
||||
}
|
||||
|
||||
fun increaseScale() {
|
||||
controls.globalScale += 0.05f
|
||||
controls.globalScale += SCALE_STEP
|
||||
invalidate()
|
||||
}
|
||||
|
||||
fun decreaseScale() {
|
||||
controls.globalScale -= 0.05f
|
||||
controls.globalScale -= SCALE_STEP
|
||||
invalidate()
|
||||
}
|
||||
|
||||
fun changeOpacity(delta : Int) {
|
||||
controls.allButtons.forEach {
|
||||
val newOpacity = (it.config.opacity + delta).coerceIn(0, 100)
|
||||
it.config.opacity = newOpacity
|
||||
if (it is JoystickButton)
|
||||
it.innerButton.config.opacity = newOpacity
|
||||
}
|
||||
fun increaseOpacity() {
|
||||
controls.alpha = (controls.alpha + ALPHA_STEP).coerceIn(ALPHA_RANGE)
|
||||
invalidate()
|
||||
}
|
||||
|
||||
fun decreaseOpacity() {
|
||||
controls.alpha = (controls.alpha - ALPHA_STEP).coerceIn(ALPHA_RANGE)
|
||||
invalidate()
|
||||
}
|
||||
|
||||
|
@ -13,7 +13,6 @@ import androidx.core.content.ContextCompat
|
||||
import com.google.android.material.dialog.MaterialAlertDialogBuilder
|
||||
import com.google.android.material.floatingactionbutton.FloatingActionButton
|
||||
import dagger.hilt.android.AndroidEntryPoint
|
||||
import emu.skyline.MainViewModel
|
||||
import emu.skyline.R
|
||||
import emu.skyline.databinding.OnScreenEditActivityBinding
|
||||
import emu.skyline.utils.PreferenceSettings
|
||||
@ -21,9 +20,6 @@ import javax.inject.Inject
|
||||
|
||||
@AndroidEntryPoint
|
||||
class OnScreenEditActivity : AppCompatActivity() {
|
||||
companion object {
|
||||
private const val OPACITY_DELTA_STEP = 10
|
||||
}
|
||||
private val binding by lazy { OnScreenEditActivityBinding.inflate(layoutInflater) }
|
||||
|
||||
private var fullEditVisible = true
|
||||
@ -84,8 +80,8 @@ class OnScreenEditActivity : AppCompatActivity() {
|
||||
Pair(R.drawable.ic_edit, editAction),
|
||||
Pair(R.drawable.ic_zoom_out, { binding.onScreenControllerView.decreaseScale() }),
|
||||
Pair(R.drawable.ic_zoom_in, { binding.onScreenControllerView.increaseScale() }),
|
||||
Pair(R.drawable.ic_opacity_minus) { binding.onScreenControllerView.changeOpacity(-OPACITY_DELTA_STEP) },
|
||||
Pair(R.drawable.ic_opacity_plus) { binding.onScreenControllerView.changeOpacity(OPACITY_DELTA_STEP) },
|
||||
Pair(R.drawable.ic_opacity_minus) { binding.onScreenControllerView.decreaseOpacity() },
|
||||
Pair(R.drawable.ic_opacity_plus) { binding.onScreenControllerView.increaseOpacity() },
|
||||
Pair(R.drawable.ic_close, closeAction)
|
||||
)
|
||||
|
||||
|
@ -40,14 +40,6 @@ open class CircularButton(
|
||||
* Checks if [x] and [y] are within circle
|
||||
*/
|
||||
override fun isTouched(x : Float, y : Float) : Boolean = (PointF(currentX, currentY) - (PointF(x, y))).length() <= radius
|
||||
|
||||
override fun onFingerDown(x : Float, y : Float) {
|
||||
drawable.alpha = 125
|
||||
}
|
||||
|
||||
override fun onFingerUp(x : Float, y : Float) {
|
||||
drawable.alpha = 255
|
||||
}
|
||||
}
|
||||
|
||||
class JoystickButton(
|
||||
@ -64,7 +56,7 @@ class JoystickButton(
|
||||
defaultRelativeRadiusToX,
|
||||
R.drawable.ic_button
|
||||
) {
|
||||
internal val innerButton = CircularButton(onScreenControllerView, buttonId, config.relativeX, config.relativeY, defaultRelativeRadiusToX * 0.75f, R.drawable.ic_stick)
|
||||
private val innerButton = CircularButton(onScreenControllerView, buttonId, config.relativeX, config.relativeY, defaultRelativeRadiusToX * 0.75f, R.drawable.ic_stick)
|
||||
|
||||
var recenterSticks = false
|
||||
private lateinit var initialTapPosition : PointF
|
||||
@ -73,7 +65,7 @@ class JoystickButton(
|
||||
var shortDoubleTapped = false
|
||||
private set
|
||||
|
||||
override fun renderCenteredText(canvas : Canvas, text : String, size : Float, x : Float, y : Float) = Unit
|
||||
override fun renderCenteredText(canvas : Canvas, text : String, size : Float, x : Float, y : Float, alpha : Int) = Unit
|
||||
|
||||
override fun render(canvas : Canvas) {
|
||||
super.render(canvas)
|
||||
@ -101,7 +93,7 @@ class JoystickButton(
|
||||
if (firstTapDiff in 0..500 && secondTapDiff in 0..500) {
|
||||
shortDoubleTapped = true
|
||||
// Indicate stick being pressed with lower alpha value
|
||||
drawable.alpha = 50
|
||||
isPressed = true
|
||||
}
|
||||
fingerDownTime = currentTime
|
||||
}
|
||||
@ -113,7 +105,7 @@ class JoystickButton(
|
||||
|
||||
fingerUpTime = SystemClock.elapsedRealtime()
|
||||
shortDoubleTapped = false
|
||||
drawable.alpha = 255
|
||||
isPressed = false
|
||||
}
|
||||
|
||||
fun onFingerMoved(x : Float, y : Float, manualMove : Boolean = true) : PointF {
|
||||
@ -174,14 +166,6 @@ open class RectangularButton(
|
||||
drawableId
|
||||
) {
|
||||
override fun isTouched(x : Float, y : Float) = currentBounds.contains(x.roundToInt(), y.roundToInt())
|
||||
|
||||
override fun onFingerDown(x : Float, y : Float) {
|
||||
drawable.alpha = 125
|
||||
}
|
||||
|
||||
override fun onFingerUp(x : Float, y : Float) {
|
||||
drawable.alpha = 255
|
||||
}
|
||||
}
|
||||
|
||||
class TriggerButton(
|
||||
@ -248,11 +232,20 @@ class Controls(onScreenControllerView : OnScreenControllerView) {
|
||||
val allButtons = circularButtons + joysticks + rectangularButtons + triggerButtons
|
||||
|
||||
/**
|
||||
* We can take any of the global scale variables from the buttons
|
||||
* We can take any of the global scale variables from the buttons since the value is shared across all buttons
|
||||
*/
|
||||
var globalScale
|
||||
get() = circularButtons.first().config.globalScale
|
||||
set(value) {
|
||||
circularButtons.first().config.globalScale = value
|
||||
}
|
||||
|
||||
/**
|
||||
* We can take any of the alpha variables from the buttons since the value is shared across all buttons
|
||||
*/
|
||||
var alpha
|
||||
get() = circularButtons.first().config.alpha
|
||||
set(value) {
|
||||
circularButtons.first().config.alpha = value
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user