Package totalcross.ui.gfx
Class Color
- java.lang.Object
-
- totalcross.ui.gfx.Color
-
public final class Color extends java.lang.ObjectThe Color class is just an utility class used to do operations in a color, which is actually represented by anintin the format 0x00RRGGBB.A color is defined as a mixture of red, green and blue color values. Each value is in the range of 0 to 255 where 0 is darkest and 255 is brightest. For example, Color(255, 0, 0) is the color red.
Here are some more examples:
- Color(0, 0, 0) is black
- Color(255, 255, 255) is white
- Color(255, 0, 0 ) is red
- Color(0, 255, 0) is green
- Color(0, 0, 255) is blue
-
-
Field Summary
Fields Modifier and Type Field Description static intBLACKstatic intBLUEstatic intBRIGHTstatic intCYANstatic intDARKstatic intFULL_STEPIncrease or decrease all RGB values by 96.static intGREENstatic intHALF_STEPIncrease or decrease all RGB values by 48.static intLESS_STEPIncrease or decrease all RGB values by 32.static intMAGENTAstatic intORANGEstatic intPINKstatic intREDstatic intWHITEstatic intYELLOW
-
Method Summary
All Methods Static Methods Concrete Methods Deprecated Methods Modifier and Type Method Description static intbrighter(int rgb)Returns a color that is brighter than the current one.static intbrighter(int rgb, int step)Returns a color that is brighter than the current one.static intdarker(int rgb)Return a color that is darker than the current one.static intdarker(int rgb, int step)Returns a color that is darker than the current one.static intgetAlpha(int rgb)Deprecated.static intgetBetterContrast(int original, int color1, int color2)Returns a color that better contrasts with the given original color.static intgetBlue(int rgb)Returns the blue value of the color.static intgetBrightness(int rgb)Returns the brightness value of a color, in the range 0-255.static intgetCursorColor(int rgb)Returns the best cursor color depending on this colorstatic intgetCursorColor(int rgb, int step)Returns the best cursor color depending on this colorstatic intgetGray(int c)Returns a gray color based on the given onestatic intgetGreen(int rgb)Returns the green value of the color.static intgetInvertedGray(int c)Returns an inverted gray color based on the given one (255 - gray)static intgetRandomColor(Random r)Returns a random color.static intgetRed(int rgb)Returns the red value of the color.static intgetRGB(int red, int green, int blue)Returns a color integer value with the given red, green and blue components.static intgetRGB(java.lang.String rrggbb)Returns a color integer value parsing the given rgb.static intgetRGBEnsureRange(int red, int green, int blue)Returns a color integer value with the given red, green and blue components, ensuring that the values are within the 0-255 range.static intinterpolate(int color1, int color2)Interpolates the given colors.static intinterpolate(int color1, int color2, int factor)Interpolates the given colors by the given factor, ranging from 0 to 100.static intinterpolateA(int color1, int color2, int factor)Interpolates the given colors by the given factor, ranging from 0 to 255.static intPremultiplyAlpha(int color, int backColor, int alpha)static java.lang.StringtoString(int rgb)Returns the string representation of this color: the rgb in hexadecimal
-
-
-
Field Detail
-
WHITE
public static final int WHITE
- See Also:
- Constant Field Values
-
BRIGHT
public static final int BRIGHT
- See Also:
- Constant Field Values
-
DARK
public static final int DARK
- See Also:
- Constant Field Values
-
BLACK
public static final int BLACK
- See Also:
- Constant Field Values
-
RED
public static final int RED
- See Also:
- Constant Field Values
-
PINK
public static final int PINK
- See Also:
- Constant Field Values
-
ORANGE
public static final int ORANGE
- See Also:
- Constant Field Values
-
YELLOW
public static final int YELLOW
- See Also:
- Constant Field Values
-
GREEN
public static final int GREEN
- See Also:
- Constant Field Values
-
MAGENTA
public static final int MAGENTA
- See Also:
- Constant Field Values
-
CYAN
public static final int CYAN
- See Also:
- Constant Field Values
-
BLUE
public static final int BLUE
- See Also:
- Constant Field Values
-
FULL_STEP
public static final int FULL_STEP
Increase or decrease all RGB values by 96. To be used in the darker(step) and brighter(step) methods.- See Also:
- Constant Field Values
-
LESS_STEP
public static final int LESS_STEP
Increase or decrease all RGB values by 32. To be used in the darker(step) and brighter(step) methods.- See Also:
- Constant Field Values
-
HALF_STEP
public static final int HALF_STEP
Increase or decrease all RGB values by 48. To be used in the darker(step) and brighter(step) methods.- See Also:
- Constant Field Values
-
-
Method Detail
-
getRGB
public static int getRGB(int red, int green, int blue)Returns a color integer value with the given red, green and blue components.- Parameters:
red- the red value in the range of 0 to 255green- the green value in the range of 0 to 255blue- the blue value in the range of 0 to 255- Since:
- SuperWaba 5.8
-
getRGBEnsureRange
public static int getRGBEnsureRange(int red, int green, int blue)Returns a color integer value with the given red, green and blue components, ensuring that the values are within the 0-255 range.- Parameters:
red- the red value in any rangegreen- the green value in any rangeblue- the blue value in any range- Since:
- SuperWaba 5.8
-
getRGB
public static int getRGB(java.lang.String rrggbb)
Returns a color integer value parsing the given rgb. Note that this method is rather slow.- Parameters:
rrggbb- a string in the format RRGGBB (colors in hex).- Since:
- SuperWaba 5.8
-
getAlpha
@Deprecated public static int getAlpha(int rgb)
Deprecated.Returns the alpha channel (brightness) of the color value in a value from 0 to 255.
-
getBlue
public static int getBlue(int rgb)
Returns the blue value of the color.
-
getGreen
public static int getGreen(int rgb)
Returns the green value of the color.
-
getRed
public static int getRed(int rgb)
Returns the red value of the color.
-
brighter
public static int brighter(int rgb)
Returns a color that is brighter than the current one.
-
darker
public static int darker(int rgb)
Return a color that is darker than the current one.
-
getBrightness
public static int getBrightness(int rgb)
Returns the brightness value of a color, in the range 0-255. Source: https://stackoverflow.com/questions/596216/formula-to-determine-brightness-of-rgb-color
-
getCursorColor
public static int getCursorColor(int rgb)
Returns the best cursor color depending on this color
-
getCursorColor
public static int getCursorColor(int rgb, int step)Returns the best cursor color depending on this color
-
brighter
public static int brighter(int rgb, int step)Returns a color that is brighter than the current one.
-
darker
public static int darker(int rgb, int step)Returns a color that is darker than the current one.
-
toString
public static java.lang.String toString(int rgb)
Returns the string representation of this color: the rgb in hexadecimal
-
interpolate
public static int interpolate(int color1, int color2)Interpolates the given colors.- Since:
- TotalCross 1.0 beta 4
-
interpolate
public static int interpolate(int color1, int color2, int factor)Interpolates the given colors by the given factor, ranging from 0 to 100.- Since:
- TotalCross 1.23
-
interpolateA
public static int interpolateA(int color1, int color2, int factor)Interpolates the given colors by the given factor, ranging from 0 to 255.- Since:
- TotalCross 1.23
-
getBetterContrast
public static int getBetterContrast(int original, int color1, int color2)Returns a color that better contrasts with the given original color.- Since:
- TotalCross 1.23
-
getRandomColor
public static int getRandomColor(Random r)
Returns a random color. Example:Random r = new Random(); for (int i = 0; i < tt.length; i++) tabPanel.getContainer(i).setBackColor(Color.getRandomColor(r));- Since:
- TotalCross 3.0
-
getGray
public static int getGray(int c)
Returns a gray color based on the given one
-
getInvertedGray
public static int getInvertedGray(int c)
Returns an inverted gray color based on the given one (255 - gray)
-
PremultiplyAlpha
public static int PremultiplyAlpha(int color, int backColor, int alpha)
-
-