Fixed quick scaling
This commit is contained in:
parent
be85e92397
commit
47cd68fcfe
1 changed files with 16 additions and 10 deletions
|
|
@ -21,6 +21,7 @@ import androidx.compose.ui.text.drawText
|
|||
import androidx.compose.ui.text.rememberTextMeasurer
|
||||
import androidx.compose.ui.text.style.TextAlign
|
||||
import androidx.compose.ui.text.withStyle
|
||||
import kotlin.math.absoluteValue
|
||||
|
||||
@Composable
|
||||
fun MapCanvas(
|
||||
|
|
@ -48,17 +49,22 @@ fun MapCanvas(
|
|||
)
|
||||
val oldLevel = tileContainer.getLevel()
|
||||
val level = scale.floatValue.toInt()
|
||||
val levelDiff = level - oldLevel
|
||||
|
||||
if (oldLevel > level) {
|
||||
offsetX.floatValue -= size.width / 2F + TILE_SIZE
|
||||
offsetY.floatValue -= size.height / 2F + TILE_SIZE
|
||||
offsetX.floatValue /= 2F
|
||||
offsetY.floatValue /= 2F
|
||||
} else if (oldLevel < level) {
|
||||
offsetX.floatValue *= 2F
|
||||
offsetY.floatValue *= 2F
|
||||
offsetX.floatValue += size.width / 2F + TILE_SIZE
|
||||
offsetY.floatValue += size.height / 2F + TILE_SIZE
|
||||
if (levelDiff < 0) {
|
||||
repeat (levelDiff.absoluteValue) {
|
||||
offsetX.floatValue -= size.width / 2F + TILE_SIZE
|
||||
offsetY.floatValue -= size.height / 2F + TILE_SIZE
|
||||
offsetX.floatValue /= 2F
|
||||
offsetY.floatValue /= 2F
|
||||
}
|
||||
} else if (levelDiff > 0) {
|
||||
repeat (levelDiff) {
|
||||
offsetX.floatValue *= 2F
|
||||
offsetY.floatValue *= 2F
|
||||
offsetX.floatValue += size.width / 2F + TILE_SIZE
|
||||
offsetY.floatValue += size.height / 2F + TILE_SIZE
|
||||
}
|
||||
}
|
||||
val tileOffsetX = (offsetX.floatValue / TILE_SIZE).toInt()
|
||||
val tileOffsetY = (offsetY.floatValue / TILE_SIZE).toInt()
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue