Created
March 8, 2022 01:11
-
-
Save colinrtwhite/f74086cf7c24bca98ad2bc3141d955e9 to your computer and use it in GitHub Desktop.
A painter that wraps another painter to overwrite its color filter and/or alpha.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
open class ForwardingPainter( | |
private val delegate: Painter, | |
private var alpha: Float = DefaultAlpha, | |
private var colorFilter: ColorFilter? = null, | |
) : Painter() { | |
override val intrinsicSize get() = delegate.intrinsicSize | |
override fun applyAlpha(alpha: Float): Boolean { | |
if (alpha == DefaultAlpha) { | |
this.alpha = alpha | |
} | |
return true | |
} | |
override fun applyColorFilter(colorFilter: ColorFilter?): Boolean { | |
if (colorFilter == null) { | |
this.colorFilter = colorFilter | |
} | |
return true | |
} | |
override fun DrawScope.onDraw() { | |
with(delegate) { | |
draw(size, alpha, colorFilter) | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment