From 5be28ade9ee5fedfcdcd52cb17d2f993e2f06bc6 Mon Sep 17 00:00:00 2001 From: Alexey Ushakov Date: Wed, 7 Mar 2018 11:02:58 +0300 Subject: [PATCH] IDEA-187834 Replace translucent text rendering in tab pane with opaque Used premultiplied alpha and srcOver rules to replace translucent text --- .../intellij/ui/SimpleColoredComponent.java | 2 +- .../ui/tabs/impl/singleRow/MoreTabsIcon.java | 2 +- .../util/src/com/intellij/ui/ColorUtil.java | 21 +++++++++++++++++++ 3 files changed, 23 insertions(+), 2 deletions(-) diff --git a/platform/platform-api/src/com/intellij/ui/SimpleColoredComponent.java b/platform/platform-api/src/com/intellij/ui/SimpleColoredComponent.java index 443910d8ea1c..5efa3a310daf 100644 --- a/platform/platform-api/src/com/intellij/ui/SimpleColoredComponent.java +++ b/platform/platform-api/src/com/intellij/ui/SimpleColoredComponent.java @@ -830,7 +830,7 @@ public class SimpleColoredComponent extends JComponent implements Accessible, Co if (!secondPass) { if (shouldDrawMacShadow()) { - g.setColor(SHADOW_COLOR); + g.setColor(ColorUtil.srcOver(SHADOW_COLOR, getBackground())); doDrawString(g, i, offset, textBaseline + 1); } diff --git a/platform/platform-api/src/com/intellij/ui/tabs/impl/singleRow/MoreTabsIcon.java b/platform/platform-api/src/com/intellij/ui/tabs/impl/singleRow/MoreTabsIcon.java index 7eef9f3c1c64..4a119f64e09e 100644 --- a/platform/platform-api/src/com/intellij/ui/tabs/impl/singleRow/MoreTabsIcon.java +++ b/platform/platform-api/src/com/intellij/ui/tabs/impl/singleRow/MoreTabsIcon.java @@ -52,7 +52,7 @@ public abstract class MoreTabsIcon { iconX + AllIcons.General.MoreTabs.getIconWidth() + 2, iconY + AllIcons.General.MoreTabs.getIconHeight() - 5, JBColor.BLACK, - ColorUtil.withAlpha(JBColor.WHITE, .9)); + ColorUtil.withPreAlpha(JBColor.WHITE, .9)); } finally { g.dispose(); } diff --git a/platform/util/src/com/intellij/ui/ColorUtil.java b/platform/util/src/com/intellij/ui/ColorUtil.java index 3a1d18734cae..dc738b102862 100644 --- a/platform/util/src/com/intellij/ui/ColorUtil.java +++ b/platform/util/src/com/intellij/ui/ColorUtil.java @@ -32,6 +32,7 @@ import java.lang.annotation.Annotation; * @author max * @author Konstantin Bulenkov */ +@SuppressWarnings("UseJBColor") public class ColorUtil { private ColorUtil() { } @@ -126,6 +127,26 @@ public class ColorUtil { return toAlpha(c, (int)(255 * a)); } + public static Color srcOver(Color c, Color b) { + float [] rgba = new float[4]; + float [] brgba = new float[4]; + + rgba = c.getRGBComponents(rgba); + brgba = b.getRGBComponents(brgba); + float dsta = 1.0f - rgba[3]; + // Applying SrcOver rule + return new Color(rgba[0]*rgba[3] + dsta*brgba[0], + rgba[1]*rgba[3] + dsta*brgba[1], + rgba[2]*rgba[3] + dsta*brgba[2], 1.0f); + } + + public static Color withPreAlpha(Color c, double a) { + float [] rgba = new float[4]; + + rgba = withAlpha(c, a).getRGBComponents(rgba); + return new Color(rgba[0]*rgba[3], rgba[1]*rgba[3], rgba[2]*rgba[3], 1.0f); + } + public static Color toAlpha(Color color, int a) { Color c = color != null ? color : Color.black; return new Color(c.getRed(), c.getGreen(), c.getBlue(), a);