Move SSD review interaction math to typed Kotlin
ober
76beb39c1b0edea1f010ec5fa662a605b095725b
--- a/templates/ssd-review.ss +++ b/templates/ssd-review.ss @@ -1143,7 +1143,8 @@ fitImageScale fitImageOffsetX fitImageOffsetY rotatedDisplayWidth rotatedDisplayHeight rotatedDisplayWidthFloat rotatedDisplayHeightFloat - viewportCenterOffsetDelta) + viewportCenterOffsetDelta nextRotationDegrees + touchMoveExceeded) (type Int32) (type Float32) (type FloatArray) @@ -1228,6 +1229,11 @@ (def (viewportCenterOffsetDelta (viewportSize : Int32) (center : Float32)) : Float32 (- (/ (float32 viewportSize) (float32 2.0)) center)) + (def (nextRotationDegrees (rotationDegrees : Int32)) : Int32 + (mod (+ rotationDegrees (int32 90)) (int32 360))) + (def (touchMoveExceeded (dx : Float32) (dy : Float32)) : Bool + (or (> (float32-abs dx) (float32 2.0)) + (> (float32-abs dy) (float32 2.0)))) (def (maxFloat32Value (a : Float32) (b : Float32)) : Float32 (if (> a b) a b)) (def (minFloat32Value (a : Float32) (b : Float32)) : Float32 @@ -6722,7 +6728,6 @@ "import android.view.MotionEvent" "import android.view.ScaleGestureDetector" "import android.view.View" - "import kotlin.math.abs" "" "class SsdReviewView(context: Context) : View(context) {" " var bitmap: Bitmap? = null" @@ -6836,7 +6841,7 @@ " MotionEvent.ACTION_MOVE -> {" " val dx = event.x - lastX" " val dy = event.y - lastY" - " if (abs(dx) > 2f || abs(dy) > 2f) moved = true" + " if (touchMoveExceeded(dx, dy)) moved = true" " if (selectMode) {" " pointerX = event.x" " pointerY = event.y" @@ -6891,7 +6896,7 @@ " }" "" " fun rotateClockwise() {" - " rotationDegrees = (rotationDegrees + 90) % 360" + " rotationDegrees = nextRotationDegrees(rotationDegrees)" " fitImage()" " }" ""