From 3407f6d5303cf7e02ac3f74e0216a10fee0191c8 Mon Sep 17 00:00:00 2001 From: KikiManjaro Date: Sun, 31 Jul 2022 17:35:28 +0200 Subject: [PATCH] Add OSC opacity adjustment --- .../emu/skyline/input/onscreen/OnScreenButton.kt | 2 ++ .../input/onscreen/OnScreenConfiguration.kt | 3 +++ .../input/onscreen/OnScreenControllerView.kt | 10 ++++++++++ .../skyline/input/onscreen/OnScreenEditActivity.kt | 6 ++++++ .../input/onscreen/OnScreenItemDefinitions.kt | 2 +- app/src/main/res/drawable/ic_opacity_minus.xml | 13 +++++++++++++ app/src/main/res/drawable/ic_opacity_plus.xml | 14 ++++++++++++++ 7 files changed, 49 insertions(+), 1 deletion(-) create mode 100644 app/src/main/res/drawable/ic_opacity_minus.xml create mode 100644 app/src/main/res/drawable/ic_opacity_plus.xml diff --git a/app/src/main/java/emu/skyline/input/onscreen/OnScreenButton.kt b/app/src/main/java/emu/skyline/input/onscreen/OnScreenButton.kt index f21c0adc..fa596a4c 100644 --- a/app/src/main/java/emu/skyline/input/onscreen/OnScreenButton.kt +++ b/app/src/main/java/emu/skyline/input/onscreen/OnScreenButton.kt @@ -79,6 +79,7 @@ abstract class OnScreenButton( buttonSymbolPaint.apply { textSize = size textAlign = Paint.Align.LEFT + alpha = (config.opacity / 100.0 * 255).toInt() getTextBounds(text, 0, text.length, textBoundsRect) } 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 drawable.apply { this.bounds = bounds + alpha = (config.opacity / 100.0 * 255).toInt() draw(canvas) } diff --git a/app/src/main/java/emu/skyline/input/onscreen/OnScreenConfiguration.kt b/app/src/main/java/emu/skyline/input/onscreen/OnScreenConfiguration.kt index 259948bb..ba68c9a5 100644 --- a/app/src/main/java/emu/skyline/input/onscreen/OnScreenConfiguration.kt +++ b/app/src/main/java/emu/skyline/input/onscreen/OnScreenConfiguration.kt @@ -10,6 +10,7 @@ import emu.skyline.input.ButtonId import emu.skyline.utils.sharedPreferences interface ControllerConfiguration { + var opacity : Int var enabled : Boolean var globalScale : 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 */ class ControllerConfigurationDummy(defaultRelativeX : Float, defaultRelativeY : Float) : ControllerConfiguration { + override var opacity : Int = 100 override var enabled = true override var globalScale = 1f 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 { private inline fun 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 globalScale by config(1.15f, "") override var relativeX by config(defaultRelativeX) diff --git a/app/src/main/java/emu/skyline/input/onscreen/OnScreenControllerView.kt b/app/src/main/java/emu/skyline/input/onscreen/OnScreenControllerView.kt index 9b581589..19dae6a3 100644 --- a/app/src/main/java/emu/skyline/input/onscreen/OnScreenControllerView.kt +++ b/app/src/main/java/emu/skyline/input/onscreen/OnScreenControllerView.kt @@ -258,6 +258,16 @@ class OnScreenControllerView @JvmOverloads constructor(context : Context, attrs 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) { onButtonStateChangedListener = listener } diff --git a/app/src/main/java/emu/skyline/input/onscreen/OnScreenEditActivity.kt b/app/src/main/java/emu/skyline/input/onscreen/OnScreenEditActivity.kt index ba91c444..d52fb133 100644 --- a/app/src/main/java/emu/skyline/input/onscreen/OnScreenEditActivity.kt +++ b/app/src/main/java/emu/skyline/input/onscreen/OnScreenEditActivity.kt @@ -13,6 +13,7 @@ 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 @@ -20,6 +21,9 @@ 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 @@ -80,6 +84,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_close, closeAction) ) diff --git a/app/src/main/java/emu/skyline/input/onscreen/OnScreenItemDefinitions.kt b/app/src/main/java/emu/skyline/input/onscreen/OnScreenItemDefinitions.kt index 9d9ea616..63e2c54f 100644 --- a/app/src/main/java/emu/skyline/input/onscreen/OnScreenItemDefinitions.kt +++ b/app/src/main/java/emu/skyline/input/onscreen/OnScreenItemDefinitions.kt @@ -64,7 +64,7 @@ class JoystickButton( defaultRelativeRadiusToX, 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 private lateinit var initialTapPosition : PointF diff --git a/app/src/main/res/drawable/ic_opacity_minus.xml b/app/src/main/res/drawable/ic_opacity_minus.xml new file mode 100644 index 00000000..76d123c9 --- /dev/null +++ b/app/src/main/res/drawable/ic_opacity_minus.xml @@ -0,0 +1,13 @@ + + + + + + diff --git a/app/src/main/res/drawable/ic_opacity_plus.xml b/app/src/main/res/drawable/ic_opacity_plus.xml new file mode 100644 index 00000000..17270673 --- /dev/null +++ b/app/src/main/res/drawable/ic_opacity_plus.xml @@ -0,0 +1,14 @@ + + + +