IDEA-187834 Replace translucent text rendering in tab pane with opaque

Used premultiplied alpha and srcOver rules to replace translucent text
This commit is contained in:
Alexey Ushakov
2018-03-07 11:05:05 +03:00
parent 05746df1ca
commit 5be28ade9e
3 changed files with 23 additions and 2 deletions
@@ -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);
}
@@ -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();
}
@@ -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);