mirror of
https://github.com/JFormDesigner/FlatLaf.git
synced 2025-12-08 15:00:54 +03:00
reduce derived colors calculations
This commit is contained in:
@@ -32,13 +32,28 @@ public class DerivedColor
|
|||||||
{
|
{
|
||||||
private final ColorFunction[] functions;
|
private final ColorFunction[] functions;
|
||||||
|
|
||||||
|
private boolean hasBaseOfDefaultColor;
|
||||||
|
private int baseOfDefaultColorRGB;
|
||||||
|
|
||||||
public DerivedColor( Color defaultColor, ColorFunction... functions ) {
|
public DerivedColor( Color defaultColor, ColorFunction... functions ) {
|
||||||
super( (defaultColor != null) ? defaultColor : Color.red );
|
super( (defaultColor != null) ? defaultColor : Color.red );
|
||||||
this.functions = functions;
|
this.functions = functions;
|
||||||
}
|
}
|
||||||
|
|
||||||
public Color derive( Color baseColor ) {
|
public Color derive( Color baseColor ) {
|
||||||
return ColorFunctions.applyFunctions( baseColor, functions );
|
if( hasBaseOfDefaultColor && baseOfDefaultColorRGB == baseColor.getRGB() )
|
||||||
|
return this; // return default color
|
||||||
|
|
||||||
|
Color result = ColorFunctions.applyFunctions( baseColor, functions );
|
||||||
|
|
||||||
|
// if the result is equal to the default color, then the original base color
|
||||||
|
// was passed and we can cache this to avoid color calculations
|
||||||
|
if( !hasBaseOfDefaultColor && result.getRGB() == this.getRGB() ) {
|
||||||
|
hasBaseOfDefaultColor = true;
|
||||||
|
baseOfDefaultColorRGB = baseColor.getRGB();
|
||||||
|
}
|
||||||
|
|
||||||
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
public ColorFunction[] getFunctions() {
|
public ColorFunction[] getFunctions() {
|
||||||
|
|||||||
Reference in New Issue
Block a user