diff --git a/packages/kilo-jetbrains/frontend/src/main/kotlin/ai/kilocode/client/session/scroll/ScrollButtonIcon.kt b/packages/kilo-jetbrains/frontend/src/main/kotlin/ai/kilocode/client/session/scroll/ScrollButtonIcon.kt index 73205135298..323e32f6db3 100644 --- a/packages/kilo-jetbrains/frontend/src/main/kotlin/ai/kilocode/client/session/scroll/ScrollButtonIcon.kt +++ b/packages/kilo-jetbrains/frontend/src/main/kotlin/ai/kilocode/client/session/scroll/ScrollButtonIcon.kt @@ -1,52 +1,17 @@ package ai.kilocode.client.session.scroll +import ai.kilocode.client.ui.colorizeIfPossible import com.intellij.openapi.util.IconLoader -import com.intellij.ui.icons.CachedImageIcon -import com.intellij.ui.svg.SvgAttributePatcher -import com.intellij.util.SVGLoader import com.intellij.util.ui.JBUI -import java.awt.Color import javax.swing.Icon -private const val OPAQUE_ALPHA = 255 - internal object ScrollButtonIcon { private val icon = IconLoader.getIcon("/icons/scroll-bottom.svg", ScrollButtonIcon::class.java) fun create(): Icon = icon.colorizeIfPossible( fillColor = JBUI.CurrentTheme.Button.defaultButtonColorStart(), borderColor = JBUI.CurrentTheme.Button.defaultButtonForeground(), + fillId = "ScrollButton.Background", + strokeId = "ScrollButton.Foreground", ) } - -private fun Icon.colorizeIfPossible(fillColor: Color, borderColor: Color = fillColor): Icon = - (this as? CachedImageIcon)?.createWithPatcher(colorPatcher = object : SVGLoader.SvgElementColorPatcherProvider, SvgAttributePatcher { - private val digest = longArrayOf(0L, 440413911775177385) - - override fun digest(): LongArray { - digest[0] = toLong(fillColor.rgb, borderColor.rgb) - return digest - } - - override fun patchColors(attributes: MutableMap) { - when (attributes["id"]) { - "ScrollButton.Background" -> setAttribute(attributes, "fill", fillColor) - "ScrollButton.Foreground" -> setAttribute(attributes, "stroke", borderColor) - } - } - - override fun attributeForPath(path: String) = this - - private fun setAttribute(attributes: MutableMap, key: String, color: Color) { - if (!attributes.containsKey(key) || attributes[key] == "none") return - attributes[key] = "rgb(${color.red},${color.green},${color.blue})" - val alpha = color.alpha - if (alpha != OPAQUE_ALPHA) { - attributes["$key-opacity"] = "${alpha / OPAQUE_ALPHA.toFloat()}" - } - } - - private fun toLong(high: Int, low: Int): Long { - return (high.toLong() shl 32) or (low.toLong() and 0xFFFFFFFFL) - } - }) ?: this diff --git a/packages/kilo-jetbrains/frontend/src/main/kotlin/ai/kilocode/client/ui/SvgIconColorizer.kt b/packages/kilo-jetbrains/frontend/src/main/kotlin/ai/kilocode/client/ui/SvgIconColorizer.kt new file mode 100644 index 00000000000..f51a7d9b880 --- /dev/null +++ b/packages/kilo-jetbrains/frontend/src/main/kotlin/ai/kilocode/client/ui/SvgIconColorizer.kt @@ -0,0 +1,46 @@ +package ai.kilocode.client.ui + +import com.intellij.ui.icons.CachedImageIcon +import com.intellij.ui.svg.SvgAttributePatcher +import com.intellij.util.SVGLoader +import java.awt.Color +import javax.swing.Icon + +private const val OPAQUE_ALPHA = 255 + +internal fun Icon.colorizeIfPossible( + fillColor: Color, + borderColor: Color = fillColor, + fillId: String? = null, + strokeId: String? = null, +): Icon = (this as? CachedImageIcon)?.createWithPatcher( + colorPatcher = object : SVGLoader.SvgElementColorPatcherProvider, SvgAttributePatcher { + private val digest = longArrayOf(0L, 440413911775177385) + + override fun digest(): LongArray { + digest[0] = toLong(fillColor.rgb, borderColor.rgb) + return digest + } + + override fun patchColors(attributes: MutableMap) { + val id = attributes["id"] + if (fillId == null || id == fillId) setAttribute(attributes, "fill", fillColor) + if (strokeId == null || id == strokeId) setAttribute(attributes, "stroke", borderColor) + } + + override fun attributeForPath(path: String) = this + + private fun setAttribute(attributes: MutableMap, key: String, color: Color) { + if (!attributes.containsKey(key) || attributes[key] == "none") return + attributes[key] = "rgb(${color.red},${color.green},${color.blue})" + val alpha = color.alpha + if (alpha != OPAQUE_ALPHA) { + attributes["$key-opacity"] = "${alpha / OPAQUE_ALPHA.toFloat()}" + } + } + + private fun toLong(high: Int, low: Int): Long { + return (high.toLong() shl 32) or (low.toLong() and 0xFFFFFFFFL) + } + }, +) ?: this