提交 a2a69588 编写于 作者: P pbansal

8226964: [Yaru] GTK L&F: There is no difference between menu selected and de-selected

Reviewed-by: prr, kcr
上级 e8506980
......@@ -535,6 +535,34 @@ class GTKPainter extends SynthPainter {
}
}
private int getBrightness(Color c) {
return Math.max(c.getRed(), Math.max(c.getGreen(), c.getBlue()));
}
private int getMaxColorDiff(Color c1, Color c2) {
return Math.max(Math.abs(c1.getRed() - c2.getRed()),
Math.max(Math.abs(c1.getGreen() - c2.getGreen()),
Math.abs(c1.getBlue() - c2.getBlue())));
}
private int scaleColorComponent(int color, double scaleFactor) {
return (int)(color + color * scaleFactor);
}
private Color deriveColor(Color originalColor, int originalBrightness,
int targetBrightness) {
int r, g, b;
if (originalBrightness == 0) {
r = g = b = targetBrightness;
} else {
double scaleFactor = (targetBrightness - originalBrightness)
/ originalBrightness ;
r = scaleColorComponent(originalColor.getRed(), scaleFactor);
g = scaleColorComponent(originalColor.getGreen(), scaleFactor);
b = scaleColorComponent(originalColor.getBlue(), scaleFactor);
}
return new Color(r, g, b);
}
//
// MENU
//
......@@ -551,6 +579,57 @@ class GTKPainter extends SynthPainter {
int gtkState = GTKLookAndFeel.synthStateToGTKState(
context.getRegion(), context.getComponentState());
if (gtkState == SynthConstants.MOUSE_OVER) {
if (GTKLookAndFeel.is3() && context.getRegion() == Region.MENU) {
GTKStyle style = (GTKStyle)context.getStyle();
Color highlightColor = style.getGTKColor(
GTKEngine.WidgetType.MENU_ITEM.ordinal(),
gtkState, ColorType.BACKGROUND.getID());
Color backgroundColor = style.getGTKColor(
GTKEngine.WidgetType.MENU_BAR.ordinal(),
SynthConstants.ENABLED, ColorType.BACKGROUND.getID());
int minBrightness = 0, maxBrightness = 255;
int minBrightnessDifference = 100;
int actualBrightnessDifference =
getMaxColorDiff(highlightColor, backgroundColor);
if (actualBrightnessDifference < minBrightnessDifference) {
int highlightBrightness =
getBrightness(highlightColor);
int backgroundBrightness =
getBrightness(backgroundColor);
int originalHighlightBrightness =
highlightBrightness;
if (highlightBrightness >= backgroundBrightness) {
if (backgroundBrightness + minBrightnessDifference <=
maxBrightness) {
highlightBrightness =
backgroundBrightness +
minBrightnessDifference;
} else {
highlightBrightness =
backgroundBrightness -
minBrightnessDifference;
}
} else {
if (backgroundBrightness - minBrightnessDifference >=
minBrightness) {
highlightBrightness =
backgroundBrightness -
minBrightnessDifference;
} else {
highlightBrightness =
backgroundBrightness +
minBrightnessDifference;
}
}
g.setColor(deriveColor(highlightColor,
originalHighlightBrightness,
highlightBrightness));
g.fillRect(x, y, w, h);
return;
}
}
Region id = Region.MENU_ITEM;
synchronized (UNIXToolkit.GTK_LOCK) {
if (! ENGINE.paintCachedImage(g, x, y, w, h, id)) {
......
......@@ -205,6 +205,14 @@ class GTKStyle extends SynthStyle implements GTKConstants {
return getGTKColor(null, state, type);
}
Color getGTKColor(int widgetType, int state, int colorType) {
synchronized (sun.awt.UNIXToolkit.GTK_LOCK) {
int rgb = nativeGetColorForState(widgetType, state,
colorType);
return new ColorUIResource(rgb);
}
}
/**
* Returns the color for the specified state.
*
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册