mirror of
https://github.com/skyline-emu/skyline.git
synced 2024-11-22 15:09:17 +01:00
Fix inconsistent OSC button movements when using the arrow buttons
A combination of factors caused inconsistent button movements when using the arrow buttons to move it, namely floating point approximation and the round down performed when snapping a button to the grid. Sometimes the layman solution is the best one: adding/subtracting one to the move amount depending on the direction ensures that the button always ends up on a grid line.
This commit is contained in:
parent
1d6b075d5c
commit
37a2a2fbad
@ -209,23 +209,34 @@ abstract class OnScreenButton(
|
||||
saveConfigValues()
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the amount to move the button when the user presses an arrow key
|
||||
* @param gridOffset The offset to apply to the grid size so that the button always ends up on a grid line
|
||||
*/
|
||||
private fun getMoveAmount(gridOffset : Int) : Int {
|
||||
return if (editInfo.snapToGrid)
|
||||
editInfo.gridSize + gridOffset
|
||||
else
|
||||
OnScreenEditInfo.ArrowKeyMoveAmount
|
||||
}
|
||||
|
||||
override fun moveUp() {
|
||||
move(currentX, currentY - editInfo.arrowKeyMoveAmount)
|
||||
move(currentX, currentY - getMoveAmount(-1))
|
||||
saveConfigValues()
|
||||
}
|
||||
|
||||
override fun moveDown() {
|
||||
move(currentX, currentY + editInfo.arrowKeyMoveAmount)
|
||||
move(currentX, currentY + getMoveAmount(+1))
|
||||
saveConfigValues()
|
||||
}
|
||||
|
||||
override fun moveLeft() {
|
||||
move(currentX - editInfo.arrowKeyMoveAmount, currentY)
|
||||
move(currentX - getMoveAmount(-1), currentY)
|
||||
saveConfigValues()
|
||||
}
|
||||
|
||||
override fun moveRight() {
|
||||
move(currentX + editInfo.arrowKeyMoveAmount, currentY)
|
||||
move(currentX + getMoveAmount(+1), currentY)
|
||||
saveConfigValues()
|
||||
}
|
||||
|
||||
|
@ -373,7 +373,6 @@ class OnScreenControllerView @JvmOverloads constructor(context : Context, attrs
|
||||
|
||||
fun setSnapToGrid(snap : Boolean) {
|
||||
editInfo.snapToGrid = snap
|
||||
editInfo.arrowKeyMoveAmount = if (snap) editInfo.gridSize else OnScreenEditInfo.ArrowKeyMoveAmount
|
||||
}
|
||||
|
||||
fun resetButton() {
|
||||
|
@ -40,8 +40,6 @@ class OnScreenEditInfo {
|
||||
|
||||
var gridSize : Int = GridSize
|
||||
|
||||
var arrowKeyMoveAmount : Int = ArrowKeyMoveAmount
|
||||
|
||||
companion object {
|
||||
/**
|
||||
* The size of the grid, calculated from the value of 8dp
|
||||
|
Loading…
Reference in New Issue
Block a user