Skip to content

Instantly share code, notes, and snippets.

@V-Abhilash-1999
Created May 23, 2023 12:29
Show Gist options
  • Save V-Abhilash-1999/fe284d579514b9224e94b9420eb95e5e to your computer and use it in GitHub Desktop.
Save V-Abhilash-1999/fe284d579514b9224e94b9420eb95e5e to your computer and use it in GitHub Desktop.
Converting Point to sat val
fun pointToSatVal(pointX: Float, pointY: Float): Pair<Float, Float> {
val width = satValPanel.width()
val height = satValPanel.height()
val x = when {
pointX < satValPanel.left -> 0f
pointX > satValPanel.right -> width
else -> pointX - satValPanel.left
}
val y = when {
pointY < satValPanel.top -> 0f
pointY > satValPanel.bottom -> height
else -> pointY - satValPanel.top
}
val satPoint = 1f / width * x
val valuePoint = 1f - 1f / height * y
return satPoint to valuePoint
}
scope.collectForPress(interactionSource) { pressPosition ->
val pressPositionOffset = Offset(
pressPosition.x.coerceIn(0f..satValSize.width),
pressPosition.y.coerceIn(0f..satValSize.height)
)
pressOffset.value = pressPositionOffset
val (satPoint, valuePoint) = pointToSatVal(pressPositionOffset.x, pressPositionOffset.y)
sat = satPoint
value = valuePoint
setSatVal(sat, value)
}
drawCircle(
color = Color.White,
radius = 8.dp.toPx(),
center = pressOffset.value,
style = Stroke(
width = 2.dp.toPx()
)
)
drawCircle(
color = Color.White,
radius = 2.dp.toPx(),
center = pressOffset.value,
)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment