NovaSVG 0.10.0
A header-only SVG library
Loading...
Searching...
No Matches
novasvg::Color Class Reference

Represents a color in RGBA format (0xRRGGBBAA). More...

#include <color.h>

Collaboration diagram for novasvg::Color:

Public Member Functions

 Color (uint8_t r=0, uint8_t g=0, uint8_t b=0, uint8_t a=255)
 Construct a new Color object from RGBA components.
 
 Color (const std::string &str)
 Construct a new Color object from a string.
 
template<typename OtherColor , typename = decltype(std::declval<const OtherColor&>().red()), typename = decltype(std::declval<const OtherColor&>().green()), typename = decltype(std::declval<const OtherColor&>().blue()), typename = decltype(std::declval<const OtherColor&>().alpha())>
constexpr Color (const OtherColor &other)
 Construct a Color from any "color-like" type.
 
template<typename OtherColor >
constexpr OtherColor as () const
 Convert this Color to any "color-like" type constructible from four (r, g, b, a) components.
 
uint8_t getR () const
 Get the red component of the color.
 
uint8_t getG () const
 Get the green component of the color.
 
uint8_t getB () const
 Get the blue component of the color.
 
uint8_t getA () const
 Get the alpha component of the color.
 
void setR (uint8_t value)
 Set the red component of the color.
 
void setG (uint8_t value)
 Set the green component of the color.
 
void setB (uint8_t value)
 Set the blue component of the color.
 
void setA (uint8_t value)
 Set the alpha component of the color.
 
float getRF () const
 Red component as a 0..1 float.
 
float getGF () const
 Green component as a 0..1 float.
 
float getBF () const
 Blue component as a 0..1 float.
 
float getAF () const
 Alpha component as a 0..1 float.
 
bool isOpaque () const
 True if fully opaque (alpha == 255).
 
bool isVisible () const
 True if not fully transparent (alpha > 0).
 
Color opaqueColor () const
 This color with alpha forced to fully opaque (255).
 
Color colorWithAlpha (float opacity) const
 This color with its alpha scaled by opacity (0..1).
 
uint32_t value () const
 Convert the color to a 32-bit unsigned integer.
 
 operator std::string () const
 Implicit conversion to std::string.
 
std::string toString () const
 Convert the color to a human-readable string.
 
ColorBlend operator| (int percentage) const
 Blend this color with transparent by a percentage.
 
Color operator| (const Color &other) const
 Blend this color with another color (50% each).
 
Color blend (const Color &other, int percentage) const
 Blend this color with another color by a specific percentage.
 

Static Public Member Functions

static Color fromString (const std::string &str)
 Create a color from a string (auto-detects hex or name).
 
static Color rgba (uint8_t r, uint8_t g, uint8_t b, uint8_t a=255)
 Create a color from RGBA components.
 
static Color fromHash (const std::string &hex_code)
 Create a color from a hexadecimal string.
 
static Color fromName (const std::string &name)
 Create a color from a standard CSS color name.
 
static Color fromValue (uint32_t value)
 Create a color from a 32-bit integer value.
 
static Color black ()
 Returns the color black (0, 0, 0, 255).
 
static Color white ()
 Returns the color white (255, 255, 255, 255).
 
static Color red ()
 Returns the color red (255, 0, 0, 255).
 
static Color green ()
 Returns the color green (0, 128, 0, 255).
 
static Color lime ()
 Returns the color lime (0, 255, 0, 255).
 
static Color blue ()
 Returns the color blue (0, 0, 255, 255).
 
static Color yellow ()
 Returns the color yellow (255, 255, 0, 255).
 
static Color cyan ()
 Returns the color cyan (0, 255, 255, 255).
 
static Color magenta ()
 Returns the color magenta (255, 0, 255, 255).
 
static Color silver ()
 Returns the color silver (192, 192, 192, 255).
 
static Color gray ()
 Returns the color gray (128, 128, 128, 255).
 
static Color maroon ()
 Returns the color maroon (128, 0, 0, 255).
 
static Color olive ()
 Returns the color olive (128, 128, 0, 255).
 
static Color purple ()
 Returns the color purple (128, 0, 128, 255).
 
static Color teal ()
 Returns the color teal (0, 128, 128, 255).
 
static Color navy ()
 Returns the color navy (0, 0, 128, 255).
 
static Color orange ()
 Returns the color orange (255, 165, 0, 255).
 
static Color pink ()
 Returns the color pink (255, 192, 203, 255).
 
static Color brown ()
 Returns the color brown (165, 42, 42, 255).
 
static Color transparent ()
 Returns the color transparent (0, 0, 0, 0).
 

Static Public Attributes

static const Color Black
 
static const Color White
 
static const Color Transparent
 

Friends

bool operator== (const Color &lhs, const Color &rhs)
 Equality comparison operator.
 
bool operator!= (const Color &lhs, const Color &rhs)
 Inequality comparison operator.
 

Detailed Description

Represents a color in RGBA format (0xRRGGBBAA).

This class provides a comprehensive color representation with support for various color creation methods and manipulation operations.

Features

  • RGBA format storage (0xRRGGBBAA)
  • Implicit conversion to std::string
  • Stream output operator (<<)
  • String literal operator (_c)
  • Blend operator (|) for mixing colors

Usage Examples

// Constructor from hex string
Color c1("#FF0000");
// Constructor from color name
Color c2("skyblue");
// Using literal operator
Color c3 = "red"_c;
// Blend with transparent (LaTeX style)
Color c4 = "gray"_c | 50;
// Blend with another color
Color c5 = "gray"_c | "black"_c;
// Chain blends
Color c6 = "gray"_c | 50 | "black"_c;
// Convert to integer
uint32_t val = c1.value();
// Stream output
std::cout << c1 << std::endl;
// Implicit string conversion
std::string s = c1;
Represents a color in RGBA format (0xRRGGBBAA).
Definition color.h:85
uint32_t value() const
Convert the color to a 32-bit unsigned integer.
Definition color.h:308
Note
The alpha component defaults to 255 (opaque) when not specified.
Author
NovaSVG Team
Version
1.0.0

Definition at line 85 of file color.h.

Constructor & Destructor Documentation

◆ Color() [1/3]

novasvg::Color::Color ( uint8_t  r = 0,
uint8_t  g = 0,
uint8_t  b = 0,
uint8_t  a = 255 
)
inlineexplicit

Construct a new Color object from RGBA components.

Creates a color with specified red, green, blue, and alpha components.

Parameters
rRed component (0-255). Default is 0.
gGreen component (0-255). Default is 0.
bBlue component (0-255). Default is 0.
aAlpha component (0-255). Default is 255 (fully opaque).
Note
Values outside the 0-255 range are clamped automatically.
Example
Color c1; // Black, opaque (0, 0, 0, 255)
Color c2(255, 0, 0); // Red, opaque
Color c3(0, 255, 0, 128); // Green, semi-transparent

Definition at line 114 of file color.h.

◆ Color() [2/3]

novasvg::Color::Color ( const std::string &  str)
inline

Construct a new Color object from a string.

Automatically detects whether the string is a hex color code or a color name and delegates to the appropriate parser.

Parameters
strHex color string (e.g., "#FF0000", "#F00") or color name (e.g., "red", "skyblue")
Exceptions
std::invalid_argumentIf the format is invalid or the color name is not recognized.
Example
Color c1("#FF0000"); // Red from hex
Color c2("#F00"); // Red from shorthand hex
Color c3("blue"); // Blue from name
Color c4("invalid"); // throws std::invalid_argument
See also
fromString()
fromHash()
fromName()

Definition at line 141 of file color.h.

◆ Color() [3/3]

template<typename OtherColor , typename = decltype(std::declval<const OtherColor&>().red()), typename = decltype(std::declval<const OtherColor&>().green()), typename = decltype(std::declval<const OtherColor&>().blue()), typename = decltype(std::declval<const OtherColor&>().alpha())>
constexpr novasvg::Color::Color ( const OtherColor &  other)
inlineconstexpr

Construct a Color from any "color-like" type.

This constructor lets Color be built (implicitly) from any other color type that exposes red()/green()/blue()/alpha() accessors returning integral values – for example novasvg::Color from graphics.h. It exists so that novasvg::Color can be used as a drop-in replacement for novasvg::Color throughout the engine.

Warning
The conversion is always done component-by-component (r, g, b, a), NEVER via value()/raw 32-bit integers. Different Color types are free to pack RGBA into a 32-bit value using different byte orders – this class uses 0xRRGGBBAA, while e.g. novasvg::Color uses 0xAARRGGBB. Converting through the packed value would silently corrupt colors.
Template Parameters
OtherColorAny type providing red()/green()/blue()/alpha().
Example
novasvg::Color engine_color(255, 0, 0); // engine's own Color
novasvg::Color c = engine_color; // implicit conversion in

Definition at line 175 of file color.h.

Member Function Documentation

◆ as()

template<typename OtherColor >
constexpr OtherColor novasvg::Color::as ( ) const
inlineconstexpr

Convert this Color to any "color-like" type constructible from four (r, g, b, a) components.

Symmetric counterpart to the templated constructor above. Lets this Color be handed to APIs expecting a different Color type (e.g. the engine's novasvg::Color) without ever touching value()/raw bit layout. Kept explicit (a named method, not an implicit conversion operator) since an unconstrained implicit operator T() would be far too eager to match unrelated types and would also collide with the existing operator std::string() below.

Template Parameters
OtherColorTarget type, constructible as OtherColor(r, g, b, a).
Example
using namespace novasvg::color_literals;
novasvg::Color c = "red"_c;
novasvg::Color engine_color = c.as<novasvg::Color>(); // out
constexpr OtherColor as() const
Convert this Color to any "color-like" type constructible from four (r, g, b, a) components.
Definition color.h:203
String literal operators for creating Color instances.

Definition at line 203 of file color.h.

◆ black()

static Color novasvg::Color::black ( )
inlinestatic

Returns the color black (0, 0, 0, 255).

Returns
Color instance representing black.

Definition at line 706 of file color.h.

Referenced by fromName().

◆ blend()

Color novasvg::Color::blend ( const Color &  other,
int  percentage 
) const
inline

Blend this color with another color by a specific percentage.

Linear interpolation between this color and another color.

Parameters
otherThe color to blend with.
percentagePercentage of the other color to include (0-100).
  • 0 = this color only
  • 100 = other color only
Returns
The blended color.
Example
Color c = Color::red().blend(Color::blue(), 25); // 75% red + 25% blue
Color blend(const Color &other, int percentage) const
Blend this color with another color by a specific percentage.
Definition color.h:470
static Color blue()
Returns the color blue (0, 0, 255, 255).
Definition color.h:736
static Color red()
Returns the color red (255, 0, 0, 255).
Definition color.h:718

Definition at line 470 of file color.h.

References NOVASVG_MAX, and NOVASVG_MIN.

Referenced by novasvg::ColorBlend::operator Color(), operator|(), novasvg::ColorBlend::operator|(), and novasvg::ColorBlend::operator|().

◆ blue()

static Color novasvg::Color::blue ( )
inlinestatic

Returns the color blue (0, 0, 255, 255).

Returns
Color instance representing blue.

Definition at line 736 of file color.h.

Referenced by fromName().

◆ brown()

static Color novasvg::Color::brown ( )
inlinestatic

Returns the color brown (165, 42, 42, 255).

Returns
Color instance representing brown.

Definition at line 814 of file color.h.

Referenced by fromName().

◆ colorWithAlpha()

Color novasvg::Color::colorWithAlpha ( float  opacity) const
inline

This color with its alpha scaled by opacity (0..1).

Definition at line 282 of file color.h.

Referenced by novasvg::SVGPaintServer::applyPaint(), and novasvg::SVGStopElement::gradientStop().

◆ cyan()

static Color novasvg::Color::cyan ( )
inlinestatic

Returns the color cyan (0, 255, 255, 255).

Returns
Color instance representing cyan.

Definition at line 748 of file color.h.

Referenced by fromName().

◆ fromHash()

static Color novasvg::Color::fromHash ( const std::string &  hex_code)
inlinestatic

Create a color from a hexadecimal string.

Parses a hex color string in various formats.

Parameters
hex_codeHexadecimal string representing the color.
Returns
A Color instance.
Exceptions
std::invalid_argumentIf the hex string format is invalid.
Supported Formats
Format Example Description
#RRGGBB #FF0000 Full hex (red)
#RGB #F00 Shorthand (red)
#RRGGBBAA #FF000080 Full hex with alpha (50% red)
#RGBA #F008 Shorthand with alpha (50% red)
Example
Color c1 = Color::fromHash("#FF0000"); // Red
Color c2 = Color::fromHash("#F00"); // Red (shorthand)
Color c3 = Color::fromHash("#FF000080"); // 50% alpha red
static Color fromHash(const std::string &hex_code)
Create a color from a hexadecimal string.
Definition color.h:575

Definition at line 575 of file color.h.

Referenced by fromString().

◆ fromName()

static Color novasvg::Color::fromName ( const std::string &  name)
inlinestatic

Create a color from a standard CSS color name.

Looks up a color by its name and returns the corresponding color.

Parameters
nameThe name of the color (case-insensitive).
Returns
A Color instance.
Exceptions
std::invalid_argumentIf the color name is not recognized.
Supported Colors
  • Basic: black, white, red, green, blue, yellow, cyan, magenta
  • Extended: silver, gray, maroon, olive, purple, teal, navy
  • Additional: lime, orange, pink, brown, transparent
Note
Both "gray" and "grey" spellings are supported.
Example
Color c1 = Color::fromName("red");
Color c2 = Color::fromName("SkyBlue"); // Case insensitive
Color c3 = Color::fromName("grey"); // British spelling
static Color fromName(const std::string &name)
Create a color from a standard CSS color name.
Definition color.h:636

Definition at line 636 of file color.h.

References black(), blue(), brown(), cyan(), gray(), green(), lime(), magenta(), maroon(), navy(), olive(), orange(), pink(), purple(), red(), silver(), teal(), transparent(), white(), and yellow().

Referenced by fromString().

◆ fromString()

static Color novasvg::Color::fromString ( const std::string &  str)
inlinestatic

Create a color from a string (auto-detects hex or name).

This method automatically detects whether the input is a hex color code or a color name and delegates to the appropriate parser.

Parameters
strHex color string or color name.
Returns
A Color instance.
Exceptions
std::invalid_argumentIf the format is invalid or the color name is not recognized.
Supported Hex Formats
  • #RRGGBB (e.g., "#FF0000" = red)
  • #RGB (e.g., "#F00" = red)
  • #RRGGBBAA (e.g., "#FF000080" = red with 50% alpha)
  • #RGBA (e.g., "#F008" = red with 50% alpha)
Supported Color Names
All standard CSS color names are supported: black, white, red, green, lime, blue, yellow, cyan, magenta, silver, gray, maroon, olive, purple, teal, navy, orange, pink, brown, transparent
Example
Color c1 = Color::fromString("#FF0000"); // Red from hex
Color c2 = Color::fromString("blue"); // Blue from name
static Color fromString(const std::string &str)
Create a color from a string (auto-detects hex or name).
Definition color.h:519
See also
fromHash()
fromName()

Definition at line 519 of file color.h.

References fromHash(), and fromName().

Referenced by novasvg::color_literals::operator""_c().

◆ fromValue()

static Color novasvg::Color::fromValue ( uint32_t  value)
inlinestatic

Create a color from a 32-bit integer value.

Parses a 32-bit integer in the format 0xRRGGBBAA (or 0xAABBGGRR depending on system endianness) and creates a Color instance.

Parameters
value32-bit integer representing the color. Expected format: 0xRRGGBBAA
  • Bits 24-31: Red component
  • Bits 16-23: Green component
  • Bits 8-15: Blue component
  • Bits 0-7: Alpha component
Returns
A Color instance with the parsed RGBA components.
Example
Color c1 = Color::fromValue(0xFF0000FF); // Red, opaque
Color c2 = Color::fromValue(0x00000080); // Black, 50% alpha
Color c3 = Color::fromValue(0xFF00FF00); // Green, opaque
static Color fromValue(uint32_t value)
Create a color from a 32-bit integer value.
Definition color.h:692
Note
The expected format is 0xRRGGBBAA where:
  • RR = Red (bits 24-31)
  • GG = Green (bits 16-23)
  • BB = Blue (bits 8-15)
  • AA = Alpha (bits 0-7)

Definition at line 692 of file color.h.

References value().

◆ getA()

uint8_t novasvg::Color::getA ( ) const
inline

Get the alpha component of the color.

Returns
Alpha component value (0-255), where 0 is fully transparent and 255 is fully opaque.

Definition at line 232 of file color.h.

Referenced by novasvg::SVGPaintServer::isRenderable().

◆ getAF()

float novasvg::Color::getAF ( ) const
inline

Alpha component as a 0..1 float.

Definition at line 271 of file color.h.

Referenced by novasvg::SVGStopElement::gradientStop().

◆ getB()

uint8_t novasvg::Color::getB ( ) const
inline

Get the blue component of the color.

Returns
Blue component value (0-255).

Definition at line 225 of file color.h.

◆ getBF()

float novasvg::Color::getBF ( ) const
inline

Blue component as a 0..1 float.

Definition at line 269 of file color.h.

Referenced by novasvg::SVGStopElement::gradientStop().

◆ getG()

uint8_t novasvg::Color::getG ( ) const
inline

Get the green component of the color.

Returns
Green component value (0-255).

Definition at line 219 of file color.h.

◆ getGF()

float novasvg::Color::getGF ( ) const
inline

Green component as a 0..1 float.

Definition at line 267 of file color.h.

Referenced by novasvg::SVGStopElement::gradientStop().

◆ getR()

uint8_t novasvg::Color::getR ( ) const
inline

Get the red component of the color.

Returns
Red component value (0-255).

Definition at line 213 of file color.h.

◆ getRF()

float novasvg::Color::getRF ( ) const
inline

Red component as a 0..1 float.

Definition at line 265 of file color.h.

Referenced by novasvg::SVGStopElement::gradientStop().

◆ gray()

static Color novasvg::Color::gray ( )
inlinestatic

Returns the color gray (128, 128, 128, 255).

Returns
Color instance representing gray.

Definition at line 766 of file color.h.

Referenced by fromName().

◆ green()

static Color novasvg::Color::green ( )
inlinestatic

Returns the color green (0, 128, 0, 255).

Returns
Color instance representing green.

Definition at line 724 of file color.h.

Referenced by fromName().

◆ isOpaque()

bool novasvg::Color::isOpaque ( ) const
inline

True if fully opaque (alpha == 255).

Definition at line 274 of file color.h.

◆ isVisible()

bool novasvg::Color::isVisible ( ) const
inline

True if not fully transparent (alpha > 0).

Definition at line 276 of file color.h.

Referenced by novasvg::Paint::isNone().

◆ lime()

static Color novasvg::Color::lime ( )
inlinestatic

Returns the color lime (0, 255, 0, 255).

Returns
Color instance representing lime.

Definition at line 730 of file color.h.

Referenced by fromName().

◆ magenta()

static Color novasvg::Color::magenta ( )
inlinestatic

Returns the color magenta (255, 0, 255, 255).

Returns
Color instance representing magenta.

Definition at line 754 of file color.h.

Referenced by fromName().

◆ maroon()

static Color novasvg::Color::maroon ( )
inlinestatic

Returns the color maroon (128, 0, 0, 255).

Returns
Color instance representing maroon.

Definition at line 772 of file color.h.

Referenced by fromName().

◆ navy()

static Color novasvg::Color::navy ( )
inlinestatic

Returns the color navy (0, 0, 128, 255).

Returns
Color instance representing navy.

Definition at line 796 of file color.h.

Referenced by fromName().

◆ olive()

static Color novasvg::Color::olive ( )
inlinestatic

Returns the color olive (128, 128, 0, 255).

Returns
Color instance representing olive.

Definition at line 778 of file color.h.

Referenced by fromName().

◆ opaqueColor()

Color novasvg::Color::opaqueColor ( ) const
inline

This color with alpha forced to fully opaque (255).

Definition at line 279 of file color.h.

◆ operator std::string()

novasvg::Color::operator std::string ( ) const
inline

Implicit conversion to std::string.

Allows automatic conversion of Color to std::string in contexts that require a string, such as function parameters or string concatenation.

Returns
String representation of the color.
Example
Color c(255, 0, 0);
std::string s = c; // Uses implicit conversion
std::cout << "Color: " + c << std::endl; // Concatenation works

Definition at line 384 of file color.h.

References toString().

◆ operator|() [1/2]

Color novasvg::Color::operator| ( const Color &  other) const
inline

Blend this color with another color (50% each).

Creates a new color that is an equal blend of this color and the specified color.

Parameters
otherThe color to blend with.
Returns
The blended color (50% this + 50% other).
Example
Color c = "gray"_c | "black"_c; // 50% gray + 50% black

Definition at line 449 of file color.h.

References blend().

◆ operator|() [2/2]

ColorBlend novasvg::Color::operator| ( int  percentage) const
inline

Blend this color with transparent by a percentage.

Blend a color with transparent by a percentage.

Similar to LaTeX's color!percentage syntax. Creates a new color that is a blend of this color and transparent.

Parameters
percentagePercentage of transparent to mix (0-100).
  • 0 = original color (fully opaque)
  • 100 = fully transparent
Returns
A ColorBlend object that can be further chained with other colors.
Example
Color c = "gray"_c | 50; // 50% gray + 50% transparent
Note
This returns a ColorBlend to allow chaining with another color. Use ColorBlend|Color to finalize the blend.
See also
operator|(const Color&) for direct blending with another color

Creates a ColorBlend that can be further chained with other colors.

Parameters
colorThe base color.
percentagePercentage of transparent to mix (0-100).
Returns
ColorBlend object for further chaining.

Definition at line 923 of file color.h.

◆ orange()

static Color novasvg::Color::orange ( )
inlinestatic

Returns the color orange (255, 165, 0, 255).

Returns
Color instance representing orange.

Definition at line 802 of file color.h.

Referenced by fromName().

◆ pink()

static Color novasvg::Color::pink ( )
inlinestatic

Returns the color pink (255, 192, 203, 255).

Returns
Color instance representing pink.

Definition at line 808 of file color.h.

Referenced by fromName().

◆ purple()

static Color novasvg::Color::purple ( )
inlinestatic

Returns the color purple (128, 0, 128, 255).

Returns
Color instance representing purple.

Definition at line 784 of file color.h.

Referenced by fromName().

◆ red()

static Color novasvg::Color::red ( )
inlinestatic

Returns the color red (255, 0, 0, 255).

Returns
Color instance representing red.

Definition at line 718 of file color.h.

Referenced by fromName().

◆ rgba()

static Color novasvg::Color::rgba ( uint8_t  r,
uint8_t  g,
uint8_t  b,
uint8_t  a = 255 
)
inlinestatic

Create a color from RGBA components.

Convenience factory method for creating colors from individual RGBA components.

Parameters
rRed component (0-255).
gGreen component (0-255).
bBlue component (0-255).
aAlpha component (0-255). Default is 255 (opaque).
Returns
A Color instance.
Example
Color c = Color::rgba(255, 0, 0, 255); // Red, opaque
static Color rgba(uint8_t r, uint8_t g, uint8_t b, uint8_t a=255)
Create a color from RGBA components.
Definition color.h:545

Definition at line 545 of file color.h.

◆ setA()

void novasvg::Color::setA ( uint8_t  value)
inline

Set the alpha component of the color.

Parameters
valueNew alpha component value (0-255).

Definition at line 256 of file color.h.

References value().

◆ setB()

void novasvg::Color::setB ( uint8_t  value)
inline

Set the blue component of the color.

Parameters
valueNew blue component value (0-255).

Definition at line 250 of file color.h.

References value().

◆ setG()

void novasvg::Color::setG ( uint8_t  value)
inline

Set the green component of the color.

Parameters
valueNew green component value (0-255).

Definition at line 244 of file color.h.

References value().

◆ setR()

void novasvg::Color::setR ( uint8_t  value)
inline

Set the red component of the color.

Parameters
valueNew red component value (0-255).

Definition at line 238 of file color.h.

References value().

◆ silver()

static Color novasvg::Color::silver ( )
inlinestatic

Returns the color silver (192, 192, 192, 255).

Returns
Color instance representing silver.

Definition at line 760 of file color.h.

Referenced by fromName().

◆ teal()

static Color novasvg::Color::teal ( )
inlinestatic

Returns the color teal (0, 128, 128, 255).

Returns
Color instance representing teal.

Definition at line 790 of file color.h.

Referenced by fromName().

◆ toString()

std::string novasvg::Color::toString ( ) const
inline

Convert the color to a human-readable string.

Returns a string representation of the color in the format: "Color(r=RR, g=GG, b=BB, a=AA)"

Returns
String representation of the color.
Example
Color c(255, 0, 0, 255);
std::string s = c.toString(); // "Color(r=255, g=0, b=0, a=255)"

Definition at line 400 of file color.h.

Referenced by operator std::string().

◆ transparent()

static Color novasvg::Color::transparent ( )
inlinestatic

Returns the color transparent (0, 0, 0, 0).

Returns
Color instance representing fully transparent.

Definition at line 820 of file color.h.

Referenced by fromName(), novasvg::ColorBlend::operator Color(), and novasvg::ColorBlend::operator|().

◆ value()

uint32_t novasvg::Color::value ( ) const
inline

Convert the color to a 32-bit unsigned integer.

Converts the RGBA color components to a single 32-bit integer in the format 0xRRGGBBAA (little-endian: 0xAABBGGRR on some systems).

Returns
32-bit integer representation of the color.
Example
Color c(255, 0, 0, 255); // Red
uint32_t val = c.value(); // 0xFF0000FF
Note
The format is 0xRRGGBBAA where:
  • RR = Red (bits 24-31)
  • GG = Green (bits 16-23)
  • BB = Blue (bits 8-15)
  • AA = Alpha (bits 0-7)

Definition at line 308 of file color.h.

Referenced by novasvg::Bitmap::clear(), fromValue(), novasvg::Element::renderToBitmap(), setA(), setB(), setG(), and setR().

◆ white()

static Color novasvg::Color::white ( )
inlinestatic

Returns the color white (255, 255, 255, 255).

Returns
Color instance representing white.

Definition at line 712 of file color.h.

Referenced by fromName().

◆ yellow()

static Color novasvg::Color::yellow ( )
inlinestatic

Returns the color yellow (255, 255, 0, 255).

Returns
Color instance representing yellow.

Definition at line 742 of file color.h.

Referenced by fromName().

Friends And Related Symbol Documentation

◆ operator!=

bool operator!= ( const Color &  lhs,
const Color &  rhs 
)
friend

Inequality comparison operator.

Compares two colors for inequality. Two colors are not equal if any of their RGBA components differ.

Parameters
lhsLeft-hand side color.
rhsRight-hand side color.
Returns
true if any of the R, G, B, or A components differ.
Example
Color c1(255, 0, 0, 255);
Color c2(255, 0, 0, 255);
Color c3(0, 0, 0, 255);
bool neq1 = (c1 != c2); // false
bool neq2 = (c1 != c3); // true

Definition at line 362 of file color.h.

◆ operator==

bool operator== ( const Color &  lhs,
const Color &  rhs 
)
friend

Equality comparison operator.

Compares two colors for equality. Two colors are equal if all their RGBA components are identical.

Parameters
lhsLeft-hand side color.
rhsRight-hand side color.
Returns
true if both colors have identical R, G, B, and A components.
Example
Color c1(255, 0, 0, 255);
Color c2(255, 0, 0, 255);
Color c3(0, 0, 0, 255);
bool eq1 = (c1 == c2); // true
bool eq2 = (c1 == c3); // false

Definition at line 335 of file color.h.

Member Data Documentation

◆ Black

const Color novasvg::Color::Black
inlinestatic

Definition at line 825 of file color.h.

Referenced by novasvg::SVGLayoutState::SVGLayoutState().

◆ Transparent

const Color novasvg::Color::Transparent
inlinestatic

◆ White

const Color novasvg::Color::White
inlinestatic

The documentation for this class was generated from the following file: