|
|
@ -1,9 +1,16 @@
|
|
|
|
package com.iqball.app.component
|
|
|
|
package com.iqball.app.component
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
import androidx.compose.animation.animateContentSize
|
|
|
|
import androidx.compose.foundation.Image
|
|
|
|
import androidx.compose.foundation.Image
|
|
|
|
import androidx.compose.foundation.background
|
|
|
|
import androidx.compose.foundation.background
|
|
|
|
import androidx.compose.foundation.layout.Box
|
|
|
|
import androidx.compose.foundation.layout.Box
|
|
|
|
|
|
|
|
import androidx.compose.foundation.layout.IntrinsicSize
|
|
|
|
import androidx.compose.foundation.layout.fillMaxSize
|
|
|
|
import androidx.compose.foundation.layout.fillMaxSize
|
|
|
|
|
|
|
|
import androidx.compose.foundation.layout.height
|
|
|
|
|
|
|
|
import androidx.compose.foundation.layout.requiredHeight
|
|
|
|
|
|
|
|
import androidx.compose.foundation.layout.requiredWidth
|
|
|
|
|
|
|
|
import androidx.compose.foundation.layout.width
|
|
|
|
|
|
|
|
import androidx.compose.foundation.layout.wrapContentSize
|
|
|
|
import androidx.compose.runtime.Composable
|
|
|
|
import androidx.compose.runtime.Composable
|
|
|
|
import androidx.compose.runtime.MutableState
|
|
|
|
import androidx.compose.runtime.MutableState
|
|
|
|
import androidx.compose.runtime.getValue
|
|
|
|
import androidx.compose.runtime.getValue
|
|
|
@ -50,6 +57,7 @@ fun BasketCourt(
|
|
|
|
CourtType.Half -> R.drawable.half_court
|
|
|
|
CourtType.Half -> R.drawable.half_court
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
var courtArea by state.courtArea
|
|
|
|
val zoomState = state.zoomState
|
|
|
|
val zoomState = state.zoomState
|
|
|
|
|
|
|
|
|
|
|
|
Box(
|
|
|
|
Box(
|
|
|
@ -58,6 +66,8 @@ fun BasketCourt(
|
|
|
|
) {
|
|
|
|
) {
|
|
|
|
Box(
|
|
|
|
Box(
|
|
|
|
modifier = Modifier
|
|
|
|
modifier = Modifier
|
|
|
|
|
|
|
|
.wrapContentSize()
|
|
|
|
|
|
|
|
.background(Color.Yellow)
|
|
|
|
.zoomable(zoomState),
|
|
|
|
.zoomable(zoomState),
|
|
|
|
contentAlignment = Alignment.Center,
|
|
|
|
contentAlignment = Alignment.Center,
|
|
|
|
) {
|
|
|
|
) {
|
|
|
@ -67,17 +77,21 @@ fun BasketCourt(
|
|
|
|
contentDescription = "court",
|
|
|
|
contentDescription = "court",
|
|
|
|
modifier = Modifier
|
|
|
|
modifier = Modifier
|
|
|
|
.background(Color.White)
|
|
|
|
.background(Color.White)
|
|
|
|
|
|
|
|
.onGloballyPositioned {
|
|
|
|
|
|
|
|
if (courtArea == Rect.Zero)
|
|
|
|
|
|
|
|
courtArea = it.boundsInRoot()
|
|
|
|
|
|
|
|
}
|
|
|
|
)
|
|
|
|
)
|
|
|
|
|
|
|
|
|
|
|
|
CourtContent(
|
|
|
|
CourtContent(
|
|
|
|
courtAreaState = state.courtArea,
|
|
|
|
courtArea = courtArea,
|
|
|
|
content = content,
|
|
|
|
content = content,
|
|
|
|
offsets = state.stepComponentsOffsets,
|
|
|
|
offsets = state.stepComponentsOffsets,
|
|
|
|
isFromParent = false
|
|
|
|
isFromParent = false
|
|
|
|
)
|
|
|
|
)
|
|
|
|
if (parentContent != null) {
|
|
|
|
if (parentContent != null) {
|
|
|
|
CourtContent(
|
|
|
|
CourtContent(
|
|
|
|
courtAreaState = state.courtArea,
|
|
|
|
courtArea = courtArea,
|
|
|
|
content = parentContent,
|
|
|
|
content = parentContent,
|
|
|
|
offsets = state.parentComponentsOffsets,
|
|
|
|
offsets = state.parentComponentsOffsets,
|
|
|
|
isFromParent = true
|
|
|
|
isFromParent = true
|
|
|
@ -89,22 +103,17 @@ fun BasketCourt(
|
|
|
|
|
|
|
|
|
|
|
|
@Composable
|
|
|
|
@Composable
|
|
|
|
private fun CourtContent(
|
|
|
|
private fun CourtContent(
|
|
|
|
courtAreaState: MutableState<Rect>,
|
|
|
|
courtArea: Rect,
|
|
|
|
content: StepContent,
|
|
|
|
content: StepContent,
|
|
|
|
offsets: MutableMap<ComponentId, Offset>,
|
|
|
|
offsets: MutableMap<ComponentId, Offset>,
|
|
|
|
isFromParent: Boolean
|
|
|
|
isFromParent: Boolean
|
|
|
|
) {
|
|
|
|
) {
|
|
|
|
var courtArea by courtAreaState
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
val playersPixelsRadius = LocalDensity.current.run { PlayerPieceDiameterDp.dp.toPx() / 2 }
|
|
|
|
val playersPixelsRadius = LocalDensity.current.run { PlayerPieceDiameterDp.dp.toPx() / 2 }
|
|
|
|
|
|
|
|
|
|
|
|
Box(
|
|
|
|
Box(
|
|
|
|
modifier = Modifier
|
|
|
|
modifier = Modifier
|
|
|
|
.fillMaxSize()
|
|
|
|
.height(LocalDensity.current.run {courtArea.height.toDp() } )
|
|
|
|
.onGloballyPositioned {
|
|
|
|
.width(LocalDensity.current.run {courtArea.width.toDp() } )
|
|
|
|
if (courtArea == Rect.Zero)
|
|
|
|
|
|
|
|
courtArea = it.boundsInRoot()
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
.drawWithContent {
|
|
|
|
.drawWithContent {
|
|
|
|
val relativeOffsets =
|
|
|
|
val relativeOffsets =
|
|
|
|
offsets.mapValues { (it.value - courtArea.topLeft).toVector() }
|
|
|
|
offsets.mapValues { (it.value - courtArea.topLeft).toVector() }
|
|
|
|