Add color utility class
In addition to creating `colorTag`, `prependColorTag`, and `wrapWithColorTag` functions, this commit moves `SwingUtil::toHexColor` and `SwingUtil::colorLerp` to this new class.
This commit is contained in:
@@ -140,14 +140,6 @@ public class SwingUtil
|
||||
return op.filter(image, null);
|
||||
}
|
||||
|
||||
/**
|
||||
* Converts a given color to it's hexidecimal equivalent.
|
||||
*/
|
||||
public static String toHexColor(Color color)
|
||||
{
|
||||
return "#" + Integer.toHexString(color.getRGB()).substring(2);
|
||||
}
|
||||
|
||||
/**
|
||||
* Safely sets Swing theme
|
||||
*
|
||||
@@ -373,26 +365,4 @@ public class SwingUtil
|
||||
return SubstanceCoreUtilities.getTitlePaneComponent(frame) != null;
|
||||
}
|
||||
|
||||
/**
|
||||
* Linearly interpolates between colors a and b by t.
|
||||
* @param a first color
|
||||
* @param b second color
|
||||
* @param t factor
|
||||
* @return interpolated color
|
||||
*/
|
||||
public static Color colorLerp(Color a, Color b, double t)
|
||||
{
|
||||
final double r1 = a.getRed();
|
||||
final double r2 = b.getRed();
|
||||
final double g1 = a.getGreen();
|
||||
final double g2 = b.getGreen();
|
||||
final double b1 = a.getBlue();
|
||||
final double b2 = b.getBlue();
|
||||
|
||||
return new Color(
|
||||
(int) Math.round(r1 + (t * (r2 - r1))),
|
||||
(int) Math.round(g1 + (t * (g2 - g1))),
|
||||
(int) Math.round(b1 + (t * (b2 - b1)))
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user