Package de.gurkenlabs.litiengine.util
Class ColorHelper
java.lang.Object
de.gurkenlabs.litiengine.util.ColorHelper
-
Method Summary
Modifier and TypeMethodDescriptionstatic ColorDecodes the specified color string to an actualColorinstance.static Colorstatic StringEncodes the specified color to a hexadecimal string representation.static intensureColorValueRange(float value) Ensures that the specified value lies within the accepted range for Color values (0-255).static intensureColorValueRange(int value) Ensures that the specified value lies within the accepted range for Color values (0-255).static ColorgetTransparentVariant(Color color, int newAlpha) static Colorinterpolate(Color color1, Color color2, double factor) static Colorpremultiply(Color color) Premultiplies the alpha on the given color.
-
Method Details
-
encode
Encodes the specified color to a hexadecimal string representation. The output format is:- #RRGGBB - For colors without alpha
- #AARRGGBB - For colors with alpha
Examples:
Color.RED= "#ff0000"
new Color(255, 0, 0, 200)= "#c8ff0000"- Parameters:
color- The color that is encoded.- Returns:
- An hexadecimal string representation of the specified color.
- See Also:
-
decode
Decodes the specified color string to an actualColorinstance. The accepted format is:Note: This returns null if the format of the provided color string is invalid.
- #RRGGBB - For colors without alpha
- #AARRGGBB - For colors with alpha
Examples:
"#ff0000" =Color.RED
"#c8ff0000" =new Color(255, 0, 0, 200)- Parameters:
colorHexString- The hexadecimal encodes color string representation.- Returns:
- The decoded color.
- See Also:
-
decode
-
ensureColorValueRange
public static int ensureColorValueRange(float value) Ensures that the specified value lies within the accepted range for Color values (0-255). Smaller values will be forced to be 0 and larger values will result in 255.- Parameters:
value- The value to check for.- Returns:
- An integer value that fits the color value restrictions.
-
ensureColorValueRange
public static int ensureColorValueRange(int value) Ensures that the specified value lies within the accepted range for Color values (0-255). Smaller values will be forced to be 0 and larger values will result in 255.- Parameters:
value- The value to check for.- Returns:
- An integer value that fits the color value restrictions.
-
premultiply
Premultiplies the alpha on the given color.- Parameters:
color- The color to premultiply- Returns:
- The color given, with alpha replaced with a black background.
-
interpolate
-
getTransparentVariant
-