91 lines
2.9 KiB
Kotlin

package center.sciprog.maps.scheme
import androidx.compose.runtime.Composable
import androidx.compose.ui.graphics.Color
import androidx.compose.ui.graphics.drawscope.DrawScope
import androidx.compose.ui.graphics.painter.Painter
import androidx.compose.ui.graphics.vector.ImageVector
import androidx.compose.ui.unit.Dp
import androidx.compose.ui.unit.DpSize
import androidx.compose.ui.unit.dp
import center.sciprog.maps.features.*
internal fun Pair<Number, Number>.toCoordinates(): XY = XY(first.toFloat(), second.toFloat())
fun FeatureBuilder<XY>.background(
width: Float,
height: Float,
offset: XY = XY(0f, 0f),
id: String? = null,
painter: @Composable () -> Painter,
): FeatureId<ScalableImageFeature<XY>> {
val box = XYRectangle(
offset,
XY(width + offset.x, height + offset.y)
)
return feature(
id,
ScalableImageFeature(coordinateSpace, box, zoomRange = defaultZoomRange, painter = painter).apply {
z = -100f
}
)
}
fun FeatureBuilder<XY>.circle(
centerCoordinates: Pair<Number, Number>,
zoomRange: FloatRange = defaultZoomRange,
size: Dp = 5.dp,
color: Color = Color.Red,
id: String? = null,
): FeatureId<CircleFeature<XY>> = circle(centerCoordinates.toCoordinates(), zoomRange, size, color, id = id)
fun FeatureBuilder<XY>.draw(
position: Pair<Number, Number>,
zoomRange: FloatRange = defaultZoomRange,
id: String? = null,
draw: DrawScope.() -> Unit,
): FeatureId<DrawFeature<XY>> = draw(position.toCoordinates(), zoomRange = zoomRange, id = id, draw = draw)
fun FeatureBuilder<XY>.line(
aCoordinates: Pair<Number, Number>,
bCoordinates: Pair<Number, Number>,
scaleRange: FloatRange = defaultZoomRange,
color: Color = Color.Red,
id: String? = null,
): FeatureId<LineFeature<XY>> = line(aCoordinates.toCoordinates(), bCoordinates.toCoordinates(), scaleRange, color, id)
public fun FeatureBuilder<XY>.arc(
center: Pair<Double, Double>,
radius: Float,
startAngle: Float,
arcLength: Float,
zoomRange: FloatRange = defaultZoomRange,
color: Color = Color.Red,
id: String? = null,
): FeatureId<ArcFeature<XY>> = arc(
oval = XYCoordinateSpace.Rectangle(center.toCoordinates(), radius, radius),
startAngle = startAngle,
arcLength = arcLength,
zoomRange = zoomRange,
color = color
)
fun FeatureBuilder<XY>.image(
position: Pair<Number, Number>,
image: ImageVector,
size: DpSize = DpSize(image.defaultWidth, image.defaultHeight),
zoomRange: FloatRange = defaultZoomRange,
id: String? = null,
): FeatureId<VectorImageFeature<XY>> =
image(position.toCoordinates(), image, size = size, zoomRange = zoomRange, id = id)
fun FeatureBuilder<XY>.text(
position: Pair<Number, Number>,
text: String,
zoomRange: FloatRange = defaultZoomRange,
color: Color = Color.Red,
id: String? = null,
): FeatureId<TextFeature<XY>> = text(position.toCoordinates(), text, zoomRange, color, id = id)