83 lines
2.4 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.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
2023-01-05 12:15:52 +03:00
import center.sciprog.attributes.Attributes
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
2023-01-02 14:08:20 +03:00
fun FeatureGroup<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
)
2022-12-25 14:51:34 +03:00
return feature(
id,
2023-01-01 09:10:01 +03:00
ScalableImageFeature(
space,
box,
painter = painter,
attributes = Attributes(ZAttribute, -100f)
)
2022-12-25 14:51:34 +03:00
)
2022-07-23 10:27:58 +03:00
}
2023-01-02 14:08:20 +03:00
fun FeatureGroup<XY>.circle(
2022-07-23 10:27:58 +03:00
centerCoordinates: Pair<Number, Number>,
size: Dp = 5.dp,
id: String? = null,
2023-01-05 17:24:27 +03:00
): FeatureId<CircleFeature<XY>> = circle(centerCoordinates.toCoordinates(), size, id = id)
2022-07-23 10:27:58 +03:00
2023-01-02 14:08:20 +03:00
fun FeatureGroup<XY>.draw(
2022-07-23 10:27:58 +03:00
position: Pair<Number, Number>,
id: String? = null,
draw: DrawScope.() -> Unit,
2023-01-05 17:24:27 +03:00
): FeatureId<DrawFeature<XY>> = draw(position.toCoordinates(), id = id, draw = draw)
2022-07-23 10:27:58 +03:00
2023-01-02 14:08:20 +03:00
fun FeatureGroup<XY>.line(
2022-07-23 10:27:58 +03:00
aCoordinates: Pair<Number, Number>,
bCoordinates: Pair<Number, Number>,
id: String? = null,
2023-01-05 17:24:27 +03:00
): FeatureId<LineFeature<XY>> = line(aCoordinates.toCoordinates(), bCoordinates.toCoordinates(), id)
2022-07-23 10:27:58 +03:00
2022-09-17 11:44:34 +03:00
2023-01-02 14:08:20 +03:00
public fun FeatureGroup<XY>.arc(
2022-09-17 11:44:34 +03:00
center: Pair<Double, Double>,
radius: Float,
startAngle: Float,
arcLength: Float,
id: String? = null,
): FeatureId<ArcFeature<XY>> = arc(
oval = XYCoordinateSpace.Rectangle(center.toCoordinates(), radius, radius),
startAngle = startAngle,
arcLength = arcLength,
2023-01-01 09:10:01 +03:00
id = id
2022-09-17 11:44:34 +03:00
)
2023-01-02 14:08:20 +03:00
fun FeatureGroup<XY>.image(
position: Pair<Number, Number>,
image: ImageVector,
size: DpSize = DpSize(image.defaultWidth, image.defaultHeight),
id: String? = null,
): FeatureId<VectorImageFeature<XY>> =
2023-01-05 17:24:27 +03:00
image(position.toCoordinates(), image, size = size, id = id)
2022-07-23 10:27:58 +03:00
2023-01-02 14:08:20 +03:00
fun FeatureGroup<XY>.text(
2022-07-23 10:27:58 +03:00
position: Pair<Number, Number>,
text: String,
id: String? = null,
2023-01-05 17:24:27 +03:00
): FeatureId<TextFeature<XY>> = text(position.toCoordinates(), text, id = id)
2022-07-23 10:27:58 +03:00