Package com.avrix.ui

Class NanoColor

java.lang.Object
com.avrix.ui.NanoColor

public class NanoColor extends Object
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.
  • Field Details

    • WHITE

      public static final NanoColor WHITE
      Predefined color constant for white (#FFFFFF).
    • TRANSPARENT

      public static final NanoColor TRANSPARENT
      Predefined color constant for transparency.
    • LIGHT_GRAY

      public static final NanoColor LIGHT_GRAY
      Predefined color constant for light gray (#D3D3D3).
    • SILVER

      public static final NanoColor SILVER
      Predefined color constant for silver (#C0C0C0).
    • GRAY

      public static final NanoColor GRAY
      Predefined color constant for gray (#808080).
    • DARK_GRAY

      public static final NanoColor DARK_GRAY
      Predefined color constant for dark gray (#A9A9A9).
    • LIGHT_BLACK

      public static final NanoColor LIGHT_BLACK
      Predefined color constant for light black (#0A0A0A).
    • WHITE_SMOKE

      public static final NanoColor WHITE_SMOKE
      Predefined color constant for white smoke (#F5F5F5).
    • BLACK

      public static final NanoColor BLACK
      Predefined color constant for black (#000000).
    • RED

      public static final NanoColor RED
      Predefined color constant for red (#FF0000).
    • PINK

      public static final NanoColor PINK
      Predefined color constant for pink (#FFC0CB).
    • ORANGE

      public static final NanoColor ORANGE
      Predefined color constant for orange (#E59400).
    • YELLOW

      public static final NanoColor YELLOW
      Predefined color constant for yellow (#FFFF00).
    • LIGHT_YELLOW

      public static final NanoColor LIGHT_YELLOW
      Predefined color constant for light yellow (#FFFFE0).
    • LIGHT_BLUE

      public static final NanoColor LIGHT_BLUE
      Predefined color constant for light blue (#ADD8E6).
    • GREEN

      public static final NanoColor GREEN
      Predefined color constant for green (#00FF00).
    • MAGENTA

      public static final NanoColor MAGENTA
      Predefined color constant for magenta (#FF00FF).
    • VIOLET

      public static final NanoColor VIOLET
      Predefined color constant for violet (#EE82EE).
    • DARK_VIOLET

      public static final NanoColor DARK_VIOLET
      Predefined color constant for dark violet (#8A2BE2).
    • CYAN

      public static final NanoColor CYAN
      Predefined color constant for cyan (#00FFFF).
    • BLUE

      public static final NanoColor BLUE
      Predefined color constant for blue (#0000FF).
    • BABY_BLUE

      public static final NanoColor BABY_BLUE
      Predefined color constant for baby blue (#0078D7).
    • AQUA

      public static final NanoColor AQUA
      Predefined color constant for aqua (#00FFFF).
    • CORAL

      public static final NanoColor CORAL
      Predefined color constant for coral (#FF7F50).
  • Constructor Details

    • NanoColor

      public NanoColor(int r, int g, int b, int a)
      Creates a NanoColor 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

      public NanoColor(String hex)
      Creates a NanoColor from a hexadecimal string.
      Parameters:
      hex - the hexadecimal color string (e.g., "#FFFFFF" for RGB or "#FFFFFFFF" for RGBA)
    • NanoColor

      public NanoColor(NanoColor color)
      Creates a NanoColor by copying another NanoColor.
      Parameters:
      color - the NanoColor to copy
    • NanoColor

      public NanoColor(float r, float g, float b, float a)
      Creates a NanoColor 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

      public NanoColor immutable()
      Makes this NanoColor immutable. Any further modifications will create a new NanoColor instance.
      Returns:
      this NanoColor instance
    • copy

      public NanoColor copy()
      Creates a copy of this NanoColor.
      Returns:
      a new NanoColor instance with the same color values
    • red

      public NanoColor red(float r)
      Sets the red component of this NanoColor.
      Parameters:
      r - the red component (0.0-1.0)
      Returns:
      this NanoColor instance if mutable, otherwise a new NanoColor instance
    • green

      public NanoColor green(float g)
      Sets the green component of this NanoColor.
      Parameters:
      g - the green component (0.0-1.0)
      Returns:
      this NanoColor instance if mutable, otherwise a new NanoColor instance
    • blue

      public NanoColor blue(float b)
      Sets the blue component of this NanoColor.
      Parameters:
      b - the blue component (0.0-1.0)
      Returns:
      this NanoColor instance if mutable, otherwise a new NanoColor instance
    • alpha

      public NanoColor alpha(float a)
      Sets the alpha component of this NanoColor.
      Parameters:
      a - the alpha component (0.0-1.0)
      Returns:
      this NanoColor instance if mutable, otherwise a new NanoColor instance
    • set

      public NanoColor set(NanoColor color)
      Sets the RGBA values of this NanoColor to match another NanoColor.
      Parameters:
      color - the NanoColor to copy values from
      Returns:
      this NanoColor instance if mutable, otherwise a new NanoColor instance
    • set

      public NanoColor set(float r, float g, float b, float a)
      Sets the RGBA values of this NanoColor.
      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 new NVGColor 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 new NVGColor synchronized with this NanoColor using the specified MemoryStack.
      Parameters:
      stack - the MemoryStack to use for allocation
      Returns:
      the allocated NVGColor instance
    • tallocNVG

      public void tallocNVG(NanoColor.ColorAction action)
      Temporarily allocates an NVGColor and executes the given action with it. The NVGColor 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

      public String 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 this NanoColor.
      Returns:
      the red component (0.0-1.0)
    • getGreen

      public float getGreen()
      Returns the green component of this NanoColor.
      Returns:
      the green component (0.0-1.0)
    • getBlue

      public float getBlue()
      Returns the blue component of this NanoColor.
      Returns:
      the blue component (0.0-1.0)
    • getAlpha

      public float getAlpha()
      Returns the alpha component of this NanoColor.
      Returns:
      the alpha component (0.0-1.0)
    • multiply

      public NanoColor multiply(float factor)
      Multiplies the RGB components of this NanoColor by the specified factor.
      Parameters:
      factor - the factor to multiply by
      Returns:
      a new NanoColor instance with the modified color values
    • divide

      public NanoColor divide(float quotient)
      Divides the RGB components of this NanoColor by the specified quotient.
      Parameters:
      quotient - the quotient to divide by
      Returns:
      a new NanoColor instance with the modified color values
    • rgbMatches

      public boolean rgbMatches(NanoColor color)
      Checks if the RGB components of this NanoColor match those of another NanoColor.
      Parameters:
      color - the NanoColor to compare with
      Returns:
      true if the RGB components match, false otherwise