mirror of
https://github.com/skyline-emu/skyline.git
synced 2024-12-27 16:35:29 +03:00
Implement OSC per-button scale functionality
This commit is contained in:
parent
2794af6d06
commit
88084016a1
@ -7,6 +7,7 @@ package emu.skyline.input.onscreen
|
|||||||
|
|
||||||
import android.graphics.Canvas
|
import android.graphics.Canvas
|
||||||
import android.graphics.Paint
|
import android.graphics.Paint
|
||||||
|
import android.graphics.PointF
|
||||||
import android.graphics.Rect
|
import android.graphics.Rect
|
||||||
import android.graphics.Typeface
|
import android.graphics.Typeface
|
||||||
import android.graphics.drawable.Drawable
|
import android.graphics.drawable.Drawable
|
||||||
@ -48,8 +49,8 @@ abstract class OnScreenButton(
|
|||||||
|
|
||||||
var relativeX = config.relativeX
|
var relativeX = config.relativeX
|
||||||
var relativeY = config.relativeY
|
var relativeY = config.relativeY
|
||||||
private val relativeWidth get() = defaultRelativeWidth * config.globalScale
|
private val relativeWidth get() = defaultRelativeWidth * (config.globalScale + config.scale)
|
||||||
private val relativeHeight get() = defaultRelativeHeight * config.globalScale
|
private val relativeHeight get() = defaultRelativeHeight * (config.globalScale + config.scale)
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* The width of the view this button is in, populated by the view during draw
|
* The width of the view this button is in, populated by the view during draw
|
||||||
@ -98,6 +99,16 @@ abstract class OnScreenButton(
|
|||||||
*/
|
*/
|
||||||
protected var editInfo = onScreenControllerView.editInfo
|
protected var editInfo = onScreenControllerView.editInfo
|
||||||
|
|
||||||
|
/**
|
||||||
|
* The touch point when the edit session started
|
||||||
|
*/
|
||||||
|
protected var editInitialTouchPoint = PointF()
|
||||||
|
|
||||||
|
/**
|
||||||
|
* The scale of the button when the edit session started
|
||||||
|
*/
|
||||||
|
private var editInitialScale = 0f
|
||||||
|
|
||||||
protected open fun renderCenteredText(canvas : Canvas, text : String, size : Float, x : Float, y : Float, alpha : Int) {
|
protected open fun renderCenteredText(canvas : Canvas, text : String, size : Float, x : Float, y : Float, alpha : Int) {
|
||||||
buttonSymbolPaint.apply {
|
buttonSymbolPaint.apply {
|
||||||
textSize = size
|
textSize = size
|
||||||
@ -152,11 +163,14 @@ abstract class OnScreenButton(
|
|||||||
* @param y The y coordinate of the initial touch
|
* @param y The y coordinate of the initial touch
|
||||||
*/
|
*/
|
||||||
open fun startEdit(x : Float, y : Float) {
|
open fun startEdit(x : Float, y : Float) {
|
||||||
|
editInitialTouchPoint.set(x, y)
|
||||||
|
editInitialScale = config.scale
|
||||||
}
|
}
|
||||||
|
|
||||||
open fun edit(x : Float, y : Float) {
|
open fun edit(x : Float, y : Float) {
|
||||||
when (editInfo.editMode) {
|
when (editInfo.editMode) {
|
||||||
EditMode.Move -> move(x, y)
|
EditMode.Move -> move(x, y)
|
||||||
|
EditMode.Resize -> resize(x, y)
|
||||||
else -> return
|
else -> return
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -169,6 +183,15 @@ abstract class OnScreenButton(
|
|||||||
relativeY = (y - heightDiff) / adjustedHeight
|
relativeY = (y - heightDiff) / adjustedHeight
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Resizes this button based on the distance of the given Y coordinate from the initial Y coordinate
|
||||||
|
*/
|
||||||
|
open fun resize(x : Float, y : Float) {
|
||||||
|
// Invert the distance because the Y coordinate increases as you move down the screen
|
||||||
|
val verticalDistance = editInitialTouchPoint.y - y
|
||||||
|
config.scale = editInitialScale + verticalDistance / 200f
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Ends the current edit session
|
* Ends the current edit session
|
||||||
*/
|
*/
|
||||||
@ -188,5 +211,6 @@ abstract class OnScreenButton(
|
|||||||
open fun resetConfig() {
|
open fun resetConfig() {
|
||||||
resetRelativeValues()
|
resetRelativeValues()
|
||||||
config.enabled = true
|
config.enabled = true
|
||||||
|
config.scale = 0f
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -13,11 +13,23 @@ import emu.skyline.utils.sharedPreferences
|
|||||||
class OnScreenConfiguration(private val context : Context, private val buttonId : ButtonId, defaultRelativeX : Float, defaultRelativeY : Float) {
|
class OnScreenConfiguration(private val context : Context, private val buttonId : ButtonId, defaultRelativeX : Float, defaultRelativeY : Float) {
|
||||||
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")
|
||||||
|
|
||||||
|
var enabled by config(true)
|
||||||
|
|
||||||
var alpha by config(155, "")
|
var alpha by config(155, "")
|
||||||
var textColor by config(SwitchColors.BLACK.color)
|
var textColor by config(SwitchColors.BLACK.color)
|
||||||
var backgroundColor by config(SwitchColors.WHITE.color)
|
var backgroundColor by config(SwitchColors.WHITE.color)
|
||||||
var enabled by config(true)
|
|
||||||
|
/**
|
||||||
|
* The global scale applied to all buttons
|
||||||
|
*/
|
||||||
var globalScale by config(1.15f, "")
|
var globalScale by config(1.15f, "")
|
||||||
|
|
||||||
|
/**
|
||||||
|
* The scale of each button, this is added to the global scale
|
||||||
|
* Allows buttons to have their own size, while still be controlled by the global scale
|
||||||
|
*/
|
||||||
|
var scale by config(0.0f)
|
||||||
|
|
||||||
var relativeX by config(defaultRelativeX)
|
var relativeX by config(defaultRelativeX)
|
||||||
var relativeY by config(defaultRelativeY)
|
var relativeY by config(defaultRelativeY)
|
||||||
}
|
}
|
||||||
|
@ -58,6 +58,11 @@ class OnScreenEditActivity : AppCompatActivity() {
|
|||||||
toggleFabVisibility(false)
|
toggleFabVisibility(false)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private val resizeAction = {
|
||||||
|
binding.onScreenControllerView.setEditMode(EditMode.Resize)
|
||||||
|
toggleFabVisibility(false)
|
||||||
|
}
|
||||||
|
|
||||||
private val toggleAction : () -> Unit = {
|
private val toggleAction : () -> Unit = {
|
||||||
val buttonProps = binding.onScreenControllerView.getButtonProps()
|
val buttonProps = binding.onScreenControllerView.getButtonProps()
|
||||||
val checkedButtonsArray = buttonProps.map { it.enabled }.toBooleanArray()
|
val checkedButtonsArray = buttonProps.map { it.enabled }.toBooleanArray()
|
||||||
@ -107,7 +112,8 @@ class OnScreenEditActivity : AppCompatActivity() {
|
|||||||
Pair(R.drawable.ic_palette, paletteAction),
|
Pair(R.drawable.ic_palette, paletteAction),
|
||||||
Pair(R.drawable.ic_restore) { binding.onScreenControllerView.resetControls() },
|
Pair(R.drawable.ic_restore) { binding.onScreenControllerView.resetControls() },
|
||||||
Pair(R.drawable.ic_toggle, toggleAction),
|
Pair(R.drawable.ic_toggle, toggleAction),
|
||||||
Pair(R.drawable.ic_edit, moveAction),
|
Pair(R.drawable.ic_move, moveAction),
|
||||||
|
Pair(R.drawable.ic_resize, resizeAction),
|
||||||
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.decreaseOpacity() },
|
Pair(R.drawable.ic_opacity_minus) { binding.onScreenControllerView.decreaseOpacity() },
|
||||||
|
@ -8,6 +8,7 @@ package emu.skyline.input.onscreen
|
|||||||
enum class EditMode {
|
enum class EditMode {
|
||||||
None,
|
None,
|
||||||
Move,
|
Move,
|
||||||
|
Resize
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
10
app/src/main/res/drawable/ic_move.xml
Normal file
10
app/src/main/res/drawable/ic_move.xml
Normal file
@ -0,0 +1,10 @@
|
|||||||
|
<vector xmlns:android="http://schemas.android.com/apk/res/android"
|
||||||
|
android:width="24dp"
|
||||||
|
android:height="24dp"
|
||||||
|
android:tint="#000000"
|
||||||
|
android:viewportWidth="24"
|
||||||
|
android:viewportHeight="24">
|
||||||
|
<path
|
||||||
|
android:fillColor="@android:color/white"
|
||||||
|
android:pathData="M10,9h4L14,6h3l-5,-5 -5,5h3v3zM9,10L6,10L6,7l-5,5 5,5v-3h3v-4zM23,12l-5,-5v3h-3v4h3v3l5,-5zM14,15h-4v3L7,18l5,5 5,-5h-3v-3z" />
|
||||||
|
</vector>
|
10
app/src/main/res/drawable/ic_resize.xml
Normal file
10
app/src/main/res/drawable/ic_resize.xml
Normal file
@ -0,0 +1,10 @@
|
|||||||
|
<vector xmlns:android="http://schemas.android.com/apk/res/android"
|
||||||
|
android:width="24dp"
|
||||||
|
android:height="24dp"
|
||||||
|
android:tint="#000000"
|
||||||
|
android:viewportWidth="24"
|
||||||
|
android:viewportHeight="24">
|
||||||
|
<path
|
||||||
|
android:fillColor="@android:color/white"
|
||||||
|
android:pathData="M21,11l0,-8l-8,0l3.29,3.29l-10,10l-3.29,-3.29l0,8l8,0l-3.29,-3.29l10,-10z" />
|
||||||
|
</vector>
|
Loading…
Reference in New Issue
Block a user