Slide 24
Slide 24 text
🟥 Offset(0, 0)
private fun calculateOffset(
scale: Float, >/ 拡大率
screenSize: IntSize, >/ 画面サイズ
offset: Offset >/ 移動したい距離
): Offset {
val maxOffsetX = max(0f, screenSize.width.toFloat() * (scale - 1f) / 2)
val maxOffsetY = max(0f, screenSize.height.toFloat() * (scale - 1f) / 2)
return Offset(
offset.x.coerceIn(-maxOffsetX, maxOffsetX),
offset.y.coerceIn(-maxOffsetY, maxOffsetY)
)
}
Image
Screen
F
D
C
B
A
E
③ 移動可能な範囲を絞る(Restrict the movable area)
scale = B / A
C = scale × screenSize.x
D = scale × screenSize.y
maxOffsetX = E = (C - screenSize.x) / 2
maxOffsetY = F = (D - screenSize.y) / 2
24