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
Modifier and TypeClassDescriptionstatic interface
Functional interface for performing actions with anNVGColor
instance. -
Field Summary
Modifier and TypeFieldDescriptionstatic final NanoColor
Predefined color constant for aqua (#00FFFF).static final NanoColor
Predefined color constant for baby blue (#0078D7).static final NanoColor
Predefined color constant for black (#000000).static final NanoColor
Predefined color constant for blue (#0000FF).static final NanoColor
Predefined color constant for coral (#FF7F50).static final NanoColor
Predefined color constant for cyan (#00FFFF).static final NanoColor
Predefined color constant for dark gray (#A9A9A9).static final NanoColor
Predefined color constant for dark violet (#8A2BE2).static final NanoColor
Predefined color constant for gray (#808080).static final NanoColor
Predefined color constant for green (#00FF00).static final NanoColor
Predefined color constant for light black (#0A0A0A).static final NanoColor
Predefined color constant for light blue (#ADD8E6).static final NanoColor
Predefined color constant for light gray (#D3D3D3).static final NanoColor
Predefined color constant for light yellow (#FFFFE0).static final NanoColor
Predefined color constant for magenta (#FF00FF).static final NanoColor
Predefined color constant for orange (#E59400).static final NanoColor
Predefined color constant for pink (#FFC0CB).static final NanoColor
Predefined color constant for red (#FF0000).static final NanoColor
Predefined color constant for silver (#C0C0C0).static final NanoColor
Predefined color constant for transparency.static final NanoColor
Predefined color constant for violet (#EE82EE).static final NanoColor
Predefined color constant for white (#FFFFFF).static final NanoColor
Predefined color constant for white smoke (#F5F5F5).static final NanoColor
Predefined color constant for yellow (#FFFF00). -
Constructor Summary
ConstructorDescriptionNanoColor
(float r, float g, float b, float a) Creates aNanoColor
with the specified RGBA values.NanoColor
(int r, int g, int b, int a) Creates aNanoColor
with the specified RGBA values.Creates aNanoColor
by copying another NanoColor.Creates aNanoColor
from 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.NVGColor
Allocates and returns a newNVGColor
synchronized with this NanoColor.copy()
Creates a copy of thisNanoColor
.divide
(float quotient) Divides the RGB components of thisNanoColor
by the specified quotient.float
getAlpha()
Returns the alpha component of thisNanoColor
.float
getBlue()
Returns the blue component of thisNanoColor
.float
getGreen()
Returns the green component of thisNanoColor
.float
getRed()
Returns the red component of thisNanoColor
.green
(float g) Sets the green component of thisNanoColor
.Makes thisNanoColor
immutable.org.lwjgl.nanovg.NVGColor
mallocNVG
(org.lwjgl.system.MemoryStack stack) Allocates and returns a newNVGColor
synchronized with thisNanoColor
using the specified MemoryStack.multiply
(float factor) Multiplies the RGB components of thisNanoColor
by the specified factor.red
(float r) Sets the red component of thisNanoColor
.boolean
rgbMatches
(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
.void
tallocNVG
(NanoColor.ColorAction action) Temporarily allocates anNVGColor
and 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 aNanoColor
with 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 aNanoColor
from a hexadecimal string.- Parameters:
hex
- the hexadecimal color string (e.g., "#FFFFFF" for RGB or "#FFFFFFFF" for RGBA)
-
NanoColor
Creates aNanoColor
by copying another NanoColor.- Parameters:
color
- the NanoColor to copy
-
NanoColor
public NanoColor(float r, float g, float b, float a) Creates aNanoColor
with 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
NanoColor
instance
-
copy
Creates a copy of thisNanoColor
.- Returns:
- a new
NanoColor
instance 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
NanoColor
instance
-
callocNVG
public org.lwjgl.nanovg.NVGColor callocNVG()Allocates and returns a newNVGColor
synchronized with this NanoColor.- Returns:
- the allocated
NVGColor
instance
-
mallocNVG
public org.lwjgl.nanovg.NVGColor mallocNVG(org.lwjgl.system.MemoryStack stack) Allocates and returns a newNVGColor
synchronized with thisNanoColor
using the specified MemoryStack.- Parameters:
stack
- the MemoryStack to use for allocation- Returns:
- the allocated
NVGColor
instance
-
tallocNVG
Temporarily allocates anNVGColor
and executes the given action with it. TheNVGColor
will 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 thisNanoColor
by the specified factor.- Parameters:
factor
- the factor to multiply by- Returns:
- a new
NanoColor
instance with the modified color values
-
divide
Divides the RGB components of thisNanoColor
by the specified quotient.- Parameters:
quotient
- the quotient to divide by- Returns:
- a new
NanoColor
instance with the modified color values
-
rgbMatches
Checks if the RGB components of this NanoColor match those of anotherNanoColor
.- Parameters:
color
- theNanoColor
to compare with- Returns:
- true if the RGB components match, false otherwise
-