Add OSC opacity adjustment

This commit is contained in:
KikiManjaro 2022-07-31 17:35:28 +02:00 committed by Niccolò Betto
parent d129fb09cd
commit 3407f6d530
7 changed files with 49 additions and 1 deletions

View File

@ -79,6 +79,7 @@ abstract class OnScreenButton(
buttonSymbolPaint.apply { buttonSymbolPaint.apply {
textSize = size textSize = size
textAlign = Paint.Align.LEFT textAlign = Paint.Align.LEFT
alpha = (config.opacity / 100.0 * 255).toInt()
getTextBounds(text, 0, text.length, textBoundsRect) getTextBounds(text, 0, text.length, textBoundsRect)
} }
canvas.drawText(text, x - textBoundsRect.width() / 2f - textBoundsRect.left, y + textBoundsRect.height() / 2f - textBoundsRect.bottom, buttonSymbolPaint) canvas.drawText(text, x - textBoundsRect.width() / 2f - textBoundsRect.left, y + textBoundsRect.height() / 2f - textBoundsRect.bottom, buttonSymbolPaint)
@ -88,6 +89,7 @@ abstract class OnScreenButton(
val bounds = currentBounds val bounds = currentBounds
drawable.apply { drawable.apply {
this.bounds = bounds this.bounds = bounds
alpha = (config.opacity / 100.0 * 255).toInt()
draw(canvas) draw(canvas)
} }

View File

@ -10,6 +10,7 @@ import emu.skyline.input.ButtonId
import emu.skyline.utils.sharedPreferences import emu.skyline.utils.sharedPreferences
interface ControllerConfiguration { interface ControllerConfiguration {
var opacity : Int
var enabled : Boolean var enabled : Boolean
var globalScale : Float var globalScale : Float
var relativeX : Float var relativeX : Float
@ -20,6 +21,7 @@ interface ControllerConfiguration {
* Dummy implementation so layout editor is able to render [OnScreenControllerView] when [android.view.View.isInEditMode] is true * Dummy implementation so layout editor is able to render [OnScreenControllerView] when [android.view.View.isInEditMode] is true
*/ */
class ControllerConfigurationDummy(defaultRelativeX : Float, defaultRelativeY : Float) : ControllerConfiguration { class ControllerConfigurationDummy(defaultRelativeX : Float, defaultRelativeY : Float) : ControllerConfiguration {
override var opacity : Int = 100
override var enabled = true override var enabled = true
override var globalScale = 1f override var globalScale = 1f
override var relativeX = defaultRelativeX override var relativeX = defaultRelativeX
@ -29,6 +31,7 @@ class ControllerConfigurationDummy(defaultRelativeX : Float, defaultRelativeY :
class ControllerConfigurationImpl(private val context : Context, private val buttonId : ButtonId, defaultRelativeX : Float, defaultRelativeY : Float) : ControllerConfiguration { 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 opacity by config(100)
override var enabled by config(true) override var enabled by config(true)
override var globalScale by config(1.15f, "") override var globalScale by config(1.15f, "")
override var relativeX by config(defaultRelativeX) override var relativeX by config(defaultRelativeX)

View File

@ -258,6 +258,16 @@ class OnScreenControllerView @JvmOverloads constructor(context : Context, attrs
invalidate() 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
}
invalidate()
}
fun setOnButtonStateChangedListener(listener : OnButtonStateChangedListener) { fun setOnButtonStateChangedListener(listener : OnButtonStateChangedListener) {
onButtonStateChangedListener = listener onButtonStateChangedListener = listener
} }

View File

@ -13,6 +13,7 @@ import androidx.core.content.ContextCompat
import com.google.android.material.dialog.MaterialAlertDialogBuilder import com.google.android.material.dialog.MaterialAlertDialogBuilder
import com.google.android.material.floatingactionbutton.FloatingActionButton import com.google.android.material.floatingactionbutton.FloatingActionButton
import dagger.hilt.android.AndroidEntryPoint import dagger.hilt.android.AndroidEntryPoint
import emu.skyline.MainViewModel
import emu.skyline.R import emu.skyline.R
import emu.skyline.databinding.OnScreenEditActivityBinding import emu.skyline.databinding.OnScreenEditActivityBinding
import emu.skyline.utils.PreferenceSettings import emu.skyline.utils.PreferenceSettings
@ -20,6 +21,9 @@ import javax.inject.Inject
@AndroidEntryPoint @AndroidEntryPoint
class OnScreenEditActivity : AppCompatActivity() { class OnScreenEditActivity : AppCompatActivity() {
companion object {
private const val OPACITY_DELTA_STEP = 10
}
private val binding by lazy { OnScreenEditActivityBinding.inflate(layoutInflater) } private val binding by lazy { OnScreenEditActivityBinding.inflate(layoutInflater) }
private var fullEditVisible = true private var fullEditVisible = true
@ -80,6 +84,8 @@ class OnScreenEditActivity : AppCompatActivity() {
Pair(R.drawable.ic_edit, editAction), Pair(R.drawable.ic_edit, editAction),
Pair(R.drawable.ic_zoom_out, { binding.onScreenControllerView.decreaseScale() }), Pair(R.drawable.ic_zoom_out, { binding.onScreenControllerView.decreaseScale() }),
Pair(R.drawable.ic_zoom_in, { binding.onScreenControllerView.increaseScale() }), 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_close, closeAction) Pair(R.drawable.ic_close, closeAction)
) )

View File

@ -64,7 +64,7 @@ class JoystickButton(
defaultRelativeRadiusToX, defaultRelativeRadiusToX,
R.drawable.ic_button R.drawable.ic_button
) { ) {
private val innerButton = CircularButton(onScreenControllerView, buttonId, config.relativeX, config.relativeY, defaultRelativeRadiusToX * 0.75f, R.drawable.ic_stick) internal val innerButton = CircularButton(onScreenControllerView, buttonId, config.relativeX, config.relativeY, defaultRelativeRadiusToX * 0.75f, R.drawable.ic_stick)
var recenterSticks = false var recenterSticks = false
private lateinit var initialTapPosition : PointF private lateinit var initialTapPosition : PointF

View File

@ -0,0 +1,13 @@
<vector xmlns:android="http://schemas.android.com/apk/res/android"
android:width="20.000126dp"
android:height="24dp"
android:viewportWidth="5.2917"
android:viewportHeight="6.35">
<group>
<clip-path android:pathData="m-5,-5h15.2917v16.35L-5,11.35ZM3.1295,4.9028v-0.2806h-0.9674v0.2806z" />
<path
android:fillColor="#FF000000"
android:pathData="m0.6649,3.8379h3.9613c0,-0.565 -0.1958,-1.0432 -0.5881,-1.4333L2.6458,0.9557l-1.3929,1.4333c-0.3916,0.3901 -0.5881,0.8734 -0.5881,1.4488zM4.5182,1.8648c0.5159,0.5138 0.7735,1.13 0.7735,1.8493 0,0.7296 -0.2576,1.351 -0.7735,1.8648 -0.5159,0.5145 -1.1398,0.7711 -1.8723,0.7711 -0.7325,0 -1.3564,-0.2566 -1.8723,-0.7704 -0.5159,-0.5138 -0.7735,-1.1359 -0.7735,-1.8648 0,-0.7192 0.2576,-1.3354 0.7735,-1.8493L2.6458,0Z"
android:strokeWidth="0.00649258" />
</group>
</vector>

View File

@ -0,0 +1,14 @@
<vector xmlns:android="http://schemas.android.com/apk/res/android"
android:width="20.000126dp"
android:height="24dp"
android:viewportWidth="5.2917"
android:viewportHeight="6.35">
<path
android:fillColor="#FF000000"
android:pathData="m3.5064,2.7555h-0.7469v0.7469h-0.2275v-0.7469h-0.7469v-0.2193h0.7469v-0.7469h0.2275v0.7469h0.7469z"
android:strokeWidth="0.233883" />
<path
android:fillColor="#FF000000"
android:pathData="m0.6649,3.8379h3.9613c0,-0.565 -0.1958,-1.0432 -0.5881,-1.4333L2.6458,0.9557l-1.3929,1.4333c-0.3916,0.3901 -0.5881,0.8734 -0.5881,1.4488zM4.5182,1.8648c0.5159,0.5138 0.7735,1.13 0.7735,1.8493 0,0.7296 -0.2576,1.351 -0.7735,1.8648 -0.5159,0.5145 -1.1398,0.7711 -1.8723,0.7711 -0.7325,0 -1.3564,-0.2566 -1.8723,-0.7704 -0.5159,-0.5138 -0.7735,-1.1359 -0.7735,-1.8648 0,-0.7192 0.2576,-1.3354 0.7735,-1.8493L2.6458,0Z"
android:strokeWidth="0.00649258" />
</vector>