86 lines
2.9 KiB
Kotlin
Raw Normal View History

2022-07-23 11:24:37 +03:00
package center.sciprog.maps.scheme
2022-07-23 10:27:58 +03:00
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
2022-07-23 10:27:58 +03:00
import androidx.compose.ui.unit.DpSize
import androidx.compose.ui.unit.dp
import center.sciprog.maps.features.*
2022-07-23 10:27:58 +03:00
internal fun Pair<Number, Number>.toCoordinates(): XY = XY(first.toFloat(), second.toFloat())
2022-07-23 10:27:58 +03:00
fun FeaturesState<XY>.background(
2022-09-17 10:32:28 +03:00
width: Float,
height: Float,
offset: XY = XY(0f, 0f),
id: String? = null,
2022-09-17 10:32:28 +03:00
painter: @Composable () -> Painter,
): FeatureId<ScalableImageFeature<XY>> {
val box = XYRectangle(
2022-07-23 10:27:58 +03:00
offset,
XY(width + offset.x, height + offset.y)
2022-07-23 10:27:58 +03:00
)
return scalableImage(box, id = id, painter = painter)
2022-07-23 10:27:58 +03:00
}
fun FeaturesState<XY>.circle(
2022-07-23 10:27:58 +03:00
centerCoordinates: Pair<Number, Number>,
zoomRange: FloatRange = Feature.defaultZoomRange,
size: Dp = 5.dp,
2022-07-23 10:27:58 +03:00
color: Color = Color.Red,
id: String? = null,
): FeatureId<CircleFeature<XY>> = circle(centerCoordinates.toCoordinates(), zoomRange, size, color, id = id)
2022-07-23 10:27:58 +03:00
fun FeaturesState<XY>.draw(
2022-07-23 10:27:58 +03:00
position: Pair<Number, Number>,
zoomRange: FloatRange = Feature.defaultZoomRange,
id: String? = null,
draw: DrawScope.() -> Unit,
): FeatureId<DrawFeature<XY>> = draw(position.toCoordinates(), zoomRange = zoomRange, id = id, draw = draw)
2022-07-23 10:27:58 +03:00
fun FeaturesState<XY>.line(
2022-07-23 10:27:58 +03:00
aCoordinates: Pair<Number, Number>,
bCoordinates: Pair<Number, Number>,
scaleRange: FloatRange = Feature.defaultZoomRange,
2022-07-23 10:27:58 +03:00
color: Color = Color.Red,
id: String? = null,
): FeatureId<LineFeature<XY>> = line(aCoordinates.toCoordinates(), bCoordinates.toCoordinates(), scaleRange, color, id)
2022-07-23 10:27:58 +03:00
2022-09-17 11:44:34 +03:00
public fun FeaturesState<XY>.arc(
2022-09-17 11:44:34 +03:00
center: Pair<Double, Double>,
radius: Float,
startAngle: Float,
arcLength: Float,
zoomRange: FloatRange = Feature.defaultZoomRange,
2022-09-17 11:44:34 +03:00
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
2022-09-17 11:44:34 +03:00
)
fun FeaturesState<XY>.image(
position: Pair<Number, Number>,
image: ImageVector,
size: DpSize = DpSize(image.defaultWidth, image.defaultHeight),
zoomRange: FloatRange = Feature.defaultZoomRange,
id: String? = null,
): FeatureId<VectorImageFeature<XY>> =
image(position.toCoordinates(), image, size = size, zoomRange = zoomRange, id = id)
2022-07-23 10:27:58 +03:00
fun FeaturesState<XY>.text(
2022-07-23 10:27:58 +03:00
position: Pair<Number, Number>,
text: String,
zoomRange: FloatRange = Feature.defaultZoomRange,
2022-07-23 10:27:58 +03:00
color: Color = Color.Red,
id: String? = null,
): FeatureId<TextFeature<XY>> = text(position.toCoordinates(), text, zoomRange, color, id = id)
2022-07-23 10:27:58 +03:00