From c30f586120d7b0707a049127c5490c153966d2fe Mon Sep 17 00:00:00 2001 From: Alexander Nozik Date: Fri, 7 Jun 2024 12:07:49 +0300 Subject: [PATCH] add alpha for remaining features --- CHANGELOG.md | 2 ++ build.gradle.kts | 2 +- .../kscience/maps/features/drawFeature.kt | 18 +++++++++++------- .../maps/features/mapFeatureAttributes.kt | 5 +++++ 4 files changed, 19 insertions(+), 8 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index f5ebf11..d779069 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -3,6 +3,7 @@ ## Unreleased ### Added +- `alpha` extension for feature attribute builder ### Changed @@ -11,6 +12,7 @@ ### Removed ### Fixed +- Add alpha attribute comprehension for all standard features. ### Security diff --git a/build.gradle.kts b/build.gradle.kts index 9707bcd..fdc4c25 100644 --- a/build.gradle.kts +++ b/build.gradle.kts @@ -9,7 +9,7 @@ val kmathVersion: String by extra("0.4.0") allprojects { group = "space.kscience" - version = "0.3.0" + version = "0.3.1-dev" repositories { mavenLocal() diff --git a/maps-kt-features/src/commonMain/kotlin/space/kscience/maps/features/drawFeature.kt b/maps-kt-features/src/commonMain/kotlin/space/kscience/maps/features/drawFeature.kt index 6ac6bf9..4453b51 100644 --- a/maps-kt-features/src/commonMain/kotlin/space/kscience/maps/features/drawFeature.kt +++ b/maps-kt-features/src/commonMain/kotlin/space/kscience/maps/features/drawFeature.kt @@ -29,7 +29,8 @@ public fun FeatureDrawScope.drawFeature( is CircleFeature -> drawCircle( color, feature.radius.toPx(), - center = feature.center.toOffset() + center = feature.center.toOffset(), + alpha = alpha ) is RectangleFeature -> drawRect( @@ -38,7 +39,8 @@ public fun FeatureDrawScope.drawFeature( feature.size.width.toPx() / 2, feature.size.height.toPx() / 2 ), - size = feature.size.toSize() + size = feature.size.toSize(), + alpha = alpha ) is LineFeature -> drawLine( @@ -46,7 +48,8 @@ public fun FeatureDrawScope.drawFeature( feature.a.toOffset(), feature.b.toOffset(), strokeWidth = feature.attributes[StrokeAttribute] ?: Stroke.HairlineWidth, - pathEffect = feature.attributes[PathEffectAttribute] + pathEffect = feature.attributes[PathEffectAttribute], + alpha = alpha ) is ArcFeature -> { @@ -67,14 +70,14 @@ public fun FeatureDrawScope.drawFeature( } - is BitmapIconFeature -> drawImage(feature.image, feature.center.toOffset()) + is BitmapIconFeature -> drawImage(feature.image, feature.center.toOffset(), alpha = alpha) is VectorIconFeature -> { val offset = feature.center.toOffset() val size = feature.size.toSize() translate(offset.x - size.width / 2, offset.y - size.height / 2) { with(this@drawFeature.painterFor(feature)) { - draw(size, colorFilter = feature.color?.let { ColorFilter.tint(it) }) + draw(size, colorFilter = feature.color?.let { ColorFilter.tint(it) }, alpha = alpha) } } } @@ -152,7 +155,7 @@ public fun FeatureDrawScope.drawFeature( translate(offset.x, offset.y) { with(this@drawFeature.painterFor(feature)) { - draw(rect.size) + draw(rect.size, alpha = alpha) } } } @@ -175,7 +178,8 @@ public fun FeatureDrawScope.drawFeature( x = i * xStep, y = rect.height - j * yStep ), - size = pixelSize + size = pixelSize, + alpha = alpha ) } } diff --git a/maps-kt-features/src/commonMain/kotlin/space/kscience/maps/features/mapFeatureAttributes.kt b/maps-kt-features/src/commonMain/kotlin/space/kscience/maps/features/mapFeatureAttributes.kt index 053dbb9..8c10a05 100644 --- a/maps-kt-features/src/commonMain/kotlin/space/kscience/maps/features/mapFeatureAttributes.kt +++ b/maps-kt-features/src/commonMain/kotlin/space/kscience/maps/features/mapFeatureAttributes.kt @@ -46,6 +46,11 @@ public fun > FeatureRef.zoomRange(range: FloatRang public object AlphaAttribute : Attribute +public fun > FeatureRef.alpha(alpha: Float): FeatureRef { + require(alpha in 0f..1f) { "Alpha value must be between 0 and 1" } + return modifyAttribute(AlphaAttribute, alpha) +} + public fun > FeatureRef.modifyAttributes( modification: AttributesBuilder.() -> Unit, ): FeatureRef {