|
NovaSVG 0.10.0
A header-only SVG library
|
Represents a color in RGBA format (0xRRGGBBAA). More...
#include <color.h>

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. | |
Represents a color in RGBA format (0xRRGGBBAA).
This class provides a comprehensive color representation with support for various color creation methods and manipulation operations.
|
inlineexplicit |
Construct a new Color object from RGBA components.
Creates a color with specified red, green, blue, and alpha components.
| r | Red component (0-255). Default is 0. |
| g | Green component (0-255). Default is 0. |
| b | Blue component (0-255). Default is 0. |
| a | Alpha component (0-255). Default is 255 (fully opaque). |
|
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.
| str | Hex color string (e.g., "#FF0000", "#F00") or color name (e.g., "red", "skyblue") |
| std::invalid_argument | If the format is invalid or the color name is not recognized. |
|
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.
| OtherColor | Any type providing red()/green()/blue()/alpha(). |
|
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.
| OtherColor | Target type, constructible as OtherColor(r, g, b, a). |
|
inlinestatic |
Returns the color black (0, 0, 0, 255).
Definition at line 706 of file color.h.
Referenced by fromName().
Blend this color with another color by a specific percentage.
Linear interpolation between this color and another color.
| other | The color to blend with. |
| percentage | Percentage of the other color to include (0-100).
|
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|().
|
inlinestatic |
Returns the color blue (0, 0, 255, 255).
Definition at line 736 of file color.h.
Referenced by fromName().
|
inlinestatic |
Returns the color brown (165, 42, 42, 255).
Definition at line 814 of file color.h.
Referenced by fromName().
|
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().
|
inlinestatic |
Returns the color cyan (0, 255, 255, 255).
Definition at line 748 of file color.h.
Referenced by fromName().
|
inlinestatic |
Create a color from a hexadecimal string.
Parses a hex color string in various formats.
| hex_code | Hexadecimal string representing the color. |
| std::invalid_argument | If the hex string format is invalid. |
| 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) |
Definition at line 575 of file color.h.
Referenced by fromString().
|
inlinestatic |
Create a color from a standard CSS color name.
Looks up a color by its name and returns the corresponding color.
| name | The name of the color (case-insensitive). |
| std::invalid_argument | If the color name is not recognized. |
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().
|
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.
| str | Hex color string or color name. |
| std::invalid_argument | If the format is invalid or the color name is not recognized. |
Definition at line 519 of file color.h.
References fromHash(), and fromName().
Referenced by novasvg::color_literals::operator""_c().
|
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.
| value | 32-bit integer representing the color. Expected format: 0xRRGGBBAA
|
Definition at line 692 of file color.h.
References value().
|
inline |
Get the alpha component of the color.
Definition at line 232 of file color.h.
Referenced by novasvg::SVGPaintServer::isRenderable().
|
inline |
Alpha component as a 0..1 float.
Definition at line 271 of file color.h.
Referenced by novasvg::SVGStopElement::gradientStop().
|
inline |
|
inline |
Blue component as a 0..1 float.
Definition at line 269 of file color.h.
Referenced by novasvg::SVGStopElement::gradientStop().
|
inline |
|
inline |
Green component as a 0..1 float.
Definition at line 267 of file color.h.
Referenced by novasvg::SVGStopElement::gradientStop().
|
inline |
|
inline |
Red component as a 0..1 float.
Definition at line 265 of file color.h.
Referenced by novasvg::SVGStopElement::gradientStop().
|
inlinestatic |
Returns the color gray (128, 128, 128, 255).
Definition at line 766 of file color.h.
Referenced by fromName().
|
inlinestatic |
Returns the color green (0, 128, 0, 255).
Definition at line 724 of file color.h.
Referenced by fromName().
|
inline |
|
inline |
True if not fully transparent (alpha > 0).
Definition at line 276 of file color.h.
Referenced by novasvg::Paint::isNone().
|
inlinestatic |
Returns the color lime (0, 255, 0, 255).
Definition at line 730 of file color.h.
Referenced by fromName().
|
inlinestatic |
Returns the color magenta (255, 0, 255, 255).
Definition at line 754 of file color.h.
Referenced by fromName().
|
inlinestatic |
Returns the color maroon (128, 0, 0, 255).
Definition at line 772 of file color.h.
Referenced by fromName().
|
inlinestatic |
Returns the color navy (0, 0, 128, 255).
Definition at line 796 of file color.h.
Referenced by fromName().
|
inlinestatic |
Returns the color olive (128, 128, 0, 255).
Definition at line 778 of file color.h.
Referenced by fromName().
|
inline |
|
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.
Definition at line 384 of file color.h.
References toString().
|
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.
| percentage | Percentage of transparent to mix (0-100).
|
Creates a ColorBlend that can be further chained with other colors.
| color | The base color. |
| percentage | Percentage of transparent to mix (0-100). |
|
inlinestatic |
Returns the color orange (255, 165, 0, 255).
Definition at line 802 of file color.h.
Referenced by fromName().
|
inlinestatic |
Returns the color pink (255, 192, 203, 255).
Definition at line 808 of file color.h.
Referenced by fromName().
|
inlinestatic |
Returns the color purple (128, 0, 128, 255).
Definition at line 784 of file color.h.
Referenced by fromName().
|
inlinestatic |
Returns the color red (255, 0, 0, 255).
Definition at line 718 of file color.h.
Referenced by fromName().
|
inlinestatic |
Create a color from RGBA components.
Convenience factory method for creating colors from individual RGBA components.
| r | Red component (0-255). |
| g | Green component (0-255). |
| b | Blue component (0-255). |
| a | Alpha component (0-255). Default is 255 (opaque). |
|
inline |
|
inline |
|
inline |
|
inline |
|
inlinestatic |
Returns the color silver (192, 192, 192, 255).
Definition at line 760 of file color.h.
Referenced by fromName().
|
inlinestatic |
Returns the color teal (0, 128, 128, 255).
Definition at line 790 of file color.h.
Referenced by fromName().
|
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)"
Definition at line 400 of file color.h.
Referenced by operator std::string().
|
inlinestatic |
Returns the color transparent (0, 0, 0, 0).
Definition at line 820 of file color.h.
Referenced by fromName(), novasvg::ColorBlend::operator Color(), and novasvg::ColorBlend::operator|().
|
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).
Definition at line 308 of file color.h.
Referenced by novasvg::Bitmap::clear(), fromValue(), novasvg::Element::renderToBitmap(), setA(), setB(), setG(), and setR().
|
inlinestatic |
Returns the color white (255, 255, 255, 255).
Definition at line 712 of file color.h.
Referenced by fromName().
|
inlinestatic |
Returns the color yellow (255, 255, 0, 255).
Definition at line 742 of file color.h.
Referenced by fromName().
Inequality comparison operator.
Compares two colors for inequality. Two colors are not equal if any of their RGBA components differ.
| lhs | Left-hand side color. |
| rhs | Right-hand side color. |
Equality comparison operator.
Compares two colors for equality. Two colors are equal if all their RGBA components are identical.
| lhs | Left-hand side color. |
| rhs | Right-hand side color. |
|
inlinestatic |
Definition at line 825 of file color.h.
Referenced by novasvg::SVGLayoutState::SVGLayoutState().
|
inlinestatic |
Definition at line 827 of file color.h.
Referenced by novasvg::parseColorOrNone(), novasvg::parsePaint(), and novasvg::SVGLayoutState::SVGLayoutState().
|
inlinestatic |
Definition at line 826 of file color.h.
Referenced by novasvg::SVGTextElement::render(), and novasvg::SVGGeometryElement::render().