Package com.avrix.ui
Class NanoColor
java.lang.Object
com.avrix.ui.NanoColor
NanoColor is a class representing a color with RGBA components. It provides methods to create and manipulate colors,
as well as to convert them to NVGColor objects for use with NanoVG.-
Nested Class Summary
Nested ClassesModifier and TypeClassDescriptionstatic interfaceFunctional interface for performing actions with anNVGColorinstance. -
Field Summary
FieldsModifier and TypeFieldDescriptionstatic final NanoColorPredefined color constant for aqua (#00FFFF).static final NanoColorPredefined color constant for baby blue (#0078D7).static final NanoColorPredefined color constant for black (#000000).static final NanoColorPredefined color constant for blue (#0000FF).static final NanoColorPredefined color constant for coral (#FF7F50).static final NanoColorPredefined color constant for cyan (#00FFFF).static final NanoColorPredefined color constant for dark gray (#A9A9A9).static final NanoColorPredefined color constant for dark violet (#8A2BE2).static final NanoColorPredefined color constant for gray (#808080).static final NanoColorPredefined color constant for green (#00FF00).static final NanoColorPredefined color constant for light black (#0A0A0A).static final NanoColorPredefined color constant for light blue (#ADD8E6).static final NanoColorPredefined color constant for light gray (#D3D3D3).static final NanoColorPredefined color constant for light yellow (#FFFFE0).static final NanoColorPredefined color constant for magenta (#FF00FF).static final NanoColorPredefined color constant for orange (#E59400).static final NanoColorPredefined color constant for pink (#FFC0CB).static final NanoColorPredefined color constant for red (#FF0000).static final NanoColorPredefined color constant for silver (#C0C0C0).static final NanoColorPredefined color constant for transparency.static final NanoColorPredefined color constant for violet (#EE82EE).static final NanoColorPredefined color constant for white (#FFFFFF).static final NanoColorPredefined color constant for white smoke (#F5F5F5).static final NanoColorPredefined color constant for yellow (#FFFF00). -
Constructor Summary
ConstructorsConstructorDescriptionNanoColor(float r, float g, float b, float a) Creates aNanoColorwith the specified RGBA values.NanoColor(int r, int g, int b, int a) Creates aNanoColorwith the specified RGBA values.Creates aNanoColorby copying another NanoColor.Creates aNanoColorfrom a hexadecimal string. -
Method Summary
Modifier and TypeMethodDescriptionalpha(float a) Sets the alpha component of thisNanoColor.blue(float b) Sets the blue component of thisNanoColor.org.lwjgl.nanovg.NVGColorAllocates and returns a newNVGColorsynchronized with this NanoColor.copy()Creates a copy of thisNanoColor.divide(float quotient) Divides the RGB components of thisNanoColorby the specified quotient.floatgetAlpha()Returns the alpha component of thisNanoColor.floatgetBlue()Returns the blue component of thisNanoColor.floatgetGreen()Returns the green component of thisNanoColor.floatgetRed()Returns the red component of thisNanoColor.green(float g) Sets the green component of thisNanoColor.Makes thisNanoColorimmutable.org.lwjgl.nanovg.NVGColormallocNVG(org.lwjgl.system.MemoryStack stack) Allocates and returns a newNVGColorsynchronized with thisNanoColorusing the specified MemoryStack.multiply(float factor) Multiplies the RGB components of thisNanoColorby the specified factor.red(float r) Sets the red component of thisNanoColor.booleanrgbMatches(NanoColor color) Checks if the RGB components of this NanoColor match those of anotherNanoColor.set(float r, float g, float b, float a) Sets the RGBA values of thisNanoColor.voidtallocNVG(NanoColor.ColorAction action) Temporarily allocates anNVGColorand executes the given action with it.toHEX()Converts the color to its HEX representation including alpha.
-
Field Details
-
WHITE
Predefined color constant for white (#FFFFFF). -
TRANSPARENT
Predefined color constant for transparency. -
LIGHT_GRAY
Predefined color constant for light gray (#D3D3D3). -
SILVER
Predefined color constant for silver (#C0C0C0). -
GRAY
Predefined color constant for gray (#808080). -
DARK_GRAY
Predefined color constant for dark gray (#A9A9A9). -
LIGHT_BLACK
Predefined color constant for light black (#0A0A0A). -
WHITE_SMOKE
Predefined color constant for white smoke (#F5F5F5). -
BLACK
Predefined color constant for black (#000000). -
RED
Predefined color constant for red (#FF0000). -
PINK
Predefined color constant for pink (#FFC0CB). -
ORANGE
Predefined color constant for orange (#E59400). -
YELLOW
Predefined color constant for yellow (#FFFF00). -
LIGHT_YELLOW
Predefined color constant for light yellow (#FFFFE0). -
LIGHT_BLUE
Predefined color constant for light blue (#ADD8E6). -
GREEN
Predefined color constant for green (#00FF00). -
MAGENTA
Predefined color constant for magenta (#FF00FF). -
VIOLET
Predefined color constant for violet (#EE82EE). -
DARK_VIOLET
Predefined color constant for dark violet (#8A2BE2). -
CYAN
Predefined color constant for cyan (#00FFFF). -
BLUE
Predefined color constant for blue (#0000FF). -
BABY_BLUE
Predefined color constant for baby blue (#0078D7). -
AQUA
Predefined color constant for aqua (#00FFFF). -
CORAL
Predefined color constant for coral (#FF7F50).
-
-
Constructor Details
-
NanoColor
public NanoColor(int r, int g, int b, int a) Creates aNanoColorwith the specified RGBA values.- Parameters:
r- the red component (0-255)g- the green component (0-255)b- the blue component (0-255)a- the alpha component (0-255)
-
NanoColor
Creates aNanoColorfrom a hexadecimal string.- Parameters:
hex- the hexadecimal color string (e.g., "#FFFFFF" for RGB or "#FFFFFFFF" for RGBA)
-
NanoColor
Creates aNanoColorby copying another NanoColor.- Parameters:
color- the NanoColor to copy
-
NanoColor
public NanoColor(float r, float g, float b, float a) Creates aNanoColorwith the specified RGBA values.- Parameters:
r- the red component (0.0-1.0)g- the green component (0.0-1.0)b- the blue component (0.0-1.0)a- the alpha component (0.0-1.0)
-
-
Method Details
-
immutable
- Returns:
- this
NanoColorinstance
-
copy
Creates a copy of thisNanoColor.- Returns:
- a new
NanoColorinstance with the same color values
-
red
Sets the red component of thisNanoColor. -
green
Sets the green component of thisNanoColor. -
blue
Sets the blue component of thisNanoColor. -
alpha
Sets the alpha component of thisNanoColor. -
set
-
set
Sets the RGBA values of thisNanoColor.- Parameters:
r- the red component (0.0-1.0)g- the green component (0.0-1.0)b- the blue component (0.0-1.0)a- the alpha component (0.0-1.0)- Returns:
- this
NanoColorinstance
-
callocNVG
public org.lwjgl.nanovg.NVGColor callocNVG()Allocates and returns a newNVGColorsynchronized with this NanoColor.- Returns:
- the allocated
NVGColorinstance
-
mallocNVG
public org.lwjgl.nanovg.NVGColor mallocNVG(org.lwjgl.system.MemoryStack stack) Allocates and returns a newNVGColorsynchronized with thisNanoColorusing the specified MemoryStack.- Parameters:
stack- the MemoryStack to use for allocation- Returns:
- the allocated
NVGColorinstance
-
tallocNVG
Temporarily allocates anNVGColorand executes the given action with it. TheNVGColorwill be automatically cleaned up after the action is executed.
Usage example:
uiColor.tallocNVG(nvgColor -> {
nvgFillColor(contextID, nvgColor);
});- Parameters:
action- the action to execute with the NanoColor
-
toHEX
Converts the color to its HEX representation including alpha. The HEX format is #RRGGBBAA.- Returns:
- the HEX representation of the color with alpha
-
getRed
public float getRed()Returns the red component of thisNanoColor.- Returns:
- the red component (0.0-1.0)
-
getGreen
public float getGreen()Returns the green component of thisNanoColor.- Returns:
- the green component (0.0-1.0)
-
getBlue
public float getBlue()Returns the blue component of thisNanoColor.- Returns:
- the blue component (0.0-1.0)
-
getAlpha
public float getAlpha()Returns the alpha component of thisNanoColor.- Returns:
- the alpha component (0.0-1.0)
-
multiply
Multiplies the RGB components of thisNanoColorby the specified factor.- Parameters:
factor- the factor to multiply by- Returns:
- a new
NanoColorinstance with the modified color values
-
divide
Divides the RGB components of thisNanoColorby the specified quotient.- Parameters:
quotient- the quotient to divide by- Returns:
- a new
NanoColorinstance with the modified color values
-
rgbMatches
Checks if the RGB components of this NanoColor match those of anotherNanoColor.- Parameters:
color- theNanoColorto compare with- Returns:
- true if the RGB components match, false otherwise
-