Add depth attribute

This commit is contained in:
Alexander Nozik 2022-12-25 14:51:34 +03:00
parent 5ed46b278c
commit 42dbbeea58
No known key found for this signature in database
GPG Key ID: F7FCF2DD25C71357
5 changed files with 25 additions and 17 deletions

View File

@ -15,10 +15,7 @@ import androidx.compose.ui.unit.IntOffset
import androidx.compose.ui.unit.IntSize
import androidx.compose.ui.unit.dp
import center.sciprog.maps.coordinates.Gmc
import center.sciprog.maps.features.FeaturesState
import center.sciprog.maps.features.PainterFeature
import center.sciprog.maps.features.ViewConfig
import center.sciprog.maps.features.drawFeature
import center.sciprog.maps.features.*
import kotlinx.coroutines.launch
import kotlinx.coroutines.supervisorScope
import mu.KotlinLogging
@ -130,7 +127,7 @@ public actual fun MapView(
)
}
featuresState.features.values.filter { viewPoint.zoom in it.zoomRange }.forEach { feature ->
featuresState.features.values.filter { viewPoint.zoom in it.zoomRange }.sortedBy { it.depth }.forEach { feature ->
drawFeature(state, painterCache, feature)
}
}

View File

@ -3,6 +3,8 @@ package center.sciprog.maps.features
import androidx.compose.runtime.mutableStateMapOf
import androidx.compose.ui.graphics.Color
public object DepthAttribute : Feature.Attribute<Float>
public object DraggableAttribute : Feature.Attribute<DragHandle<*>>
public object SelectableAttribute : Feature.Attribute<(FeatureId<*>, SelectableFeature<*>) -> Unit>
@ -14,7 +16,7 @@ public object ColorAttribute : Feature.Attribute<Color>
public class AttributeMap {
public val map: MutableMap<Feature.Attribute<*>, Any> = mutableStateMapOf()
public fun <T, A : Feature.Attribute<T>> setAttribute(
public operator fun <T, A : Feature.Attribute<T>> set(
attribute: A,
attrValue: T?,
) {
@ -42,4 +44,10 @@ public class AttributeMap {
override fun hashCode(): Int = map.hashCode()
override fun toString(): String = "AttributeMap(value=${map.entries})"
}
}
public var Feature<*>.depth: Float
get() = attributes[DepthAttribute] ?: 0f
set(value) {
attributes[DepthAttribute] = value
}

View File

@ -44,7 +44,7 @@ public class FeaturesState<T : Any>(public val coordinateSpace: CoordinateSpace<
public fun <F : Feature<T>, V> setAttribute(id: FeatureId<F>, key: Feature.Attribute<V>, value: V?) {
getFeature(id).attributes.setAttribute(key, value)
getFeature(id).attributes.set(key, value)
}
//TODO use context receiver for that

View File

@ -23,7 +23,12 @@ fun FeaturesState<XY>.background(
offset,
XY(width + offset.x, height + offset.y)
)
return scalableImage(box, id = id, painter = painter)
return feature(
id,
ScalableImageFeature(coordinateSpace, box, painter = painter).apply {
depth = -100f
}
)
}
fun FeaturesState<XY>.circle(

View File

@ -48,14 +48,12 @@ public fun SchemeView(
}
clipRect {
featuresState.features.values.filterIsInstance<ScalableImageFeature<XY>>().forEach { background ->
drawFeature(state, painterCache, background)
}
featuresState.features.values.filter {
it !is ScalableImageFeature && viewPoint.zoom in it.zoomRange
}.forEach { feature ->
drawFeature(state, painterCache, feature)
}
featuresState.features.values
.filter { viewPoint.zoom in it.zoomRange }
.sortedBy { it.depth }
.forEach { background ->
drawFeature(state, painterCache, background)
}
}
selectRect?.let { dpRect ->
val rect = dpRect.toRect()