Avara3D 0.2.0
C++ API reference
Color.h
1//
2// Color.h
3// avara3d
4//
5// Created by Morgan Davis on 10/21/16.
6// Copyright © 2026 Morgan K Davis. All rights reserved.
7//
8
9#ifndef AVARA3D_COLOR_H
10#define AVARA3D_COLOR_H
11
12#include <cstdint>
13#include <string>
14
15#include "a3d/Math.h"
16
17namespace a3d {
18
27 class Color {
28
29 public:
30 // [Public Static Member Functions]
31
33 static Color Black();
34
36 static Color DarkGray();
37
39 static Color Gray();
40
42 static Color LightGray();
43
45 static Color White();
46
48 static Color Maroon();
49
51 static Color Red();
52
54 static Color Orange();
55
57 static Color Yellow();
58
60 static Color Olive();
61
63 static Color Lime();
64
66 static Color Green();
67
69 static Color Cyan();
70
72 static Color Blue();
73
75 static Color Navy();
76
78 static Color Teal();
79
81 static Color Magenta();
82
84 static Color Purple();
85
87 static Color Brown();
88
90 static Color Random();
91
92 // [Public Lifecycle Functions]
93
96
98 explicit Color(const math::vec3& rgb);
99
101 Color(float r, float g, float b);
102
104 explicit Color(const math::vec4& rgba);
105
107 Color(float r, float g, float b, float a);
108
110 explicit Color(const math::u8vec3& irgb);
111
113 explicit Color(const math::u8vec4& irgba);
114
116 explicit Color(float white);
117
119 explicit Color(uint32_t color);
120
126 explicit Color(const std::string& hexString);
127
128 // TODO: operator*, operator[]
129
130 // [Public Member Functions]
131
133 float r() const;
134
136 float g() const;
137
139 float b() const;
140
142 float a() const;
143
145 uint8_t u8r() const;
146
148 uint8_t u8g() const;
149
151 uint8_t u8b() const;
152
154 uint8_t u8a() const;
155
158
161
164
167
168 private:
169 // [Private Member Variables]
170
171 math::vec4 _rgba;
172 };
173
174}
175
176#endif // AVARA3D_COLOR_H
Represents a normalized RGBA color.
Definition: Color.h:27
math::vec4 rgba() const
Returns the floating-point RGBA components.
static Color Olive()
Returns opaque olive.
Color()
Creates opaque white.
static Color Magenta()
Returns opaque magenta.
float r() const
Returns the floating-point red component.
Color(const math::vec3 &rgb)
Creates an opaque color from floating-point RGB components.
static Color Black()
Returns opaque black.
Color(float r, float g, float b)
Creates an opaque color from floating-point RGB components.
Color(float r, float g, float b, float a)
Creates a color from floating-point RGBA components.
Color(uint32_t color)
Creates a color from a packed 0xRRGGBBAA value.
static Color Brown()
Returns opaque brown.
Color(const math::u8vec4 &irgba)
Creates a color from 8-bit RGBA components.
static Color Lime()
Returns opaque lime.
uint8_t u8a() const
Returns the alpha component converted to 8-bit form.
Color(const std::string &hexString)
Creates a color from hexadecimal RGB or RGBA text.
uint8_t u8r() const
Returns the red component converted to 8-bit form.
float a() const
Returns the floating-point alpha component.
static Color Orange()
Returns opaque orange.
Color(float white)
Creates an opaque grayscale color with all RGB components set to white.
static Color Maroon()
Returns opaque maroon.
static Color Teal()
Returns opaque teal.
static Color Navy()
Returns opaque navy.
math::u8vec3 u8rgb() const
Returns the RGB components converted to 8-bit form.
static Color Random()
Returns an opaque color with independently randomized 8-bit RGB channels.
math::u8vec4 u8rgba() const
Returns the RGBA components converted to 8-bit form.
static Color Purple()
Returns opaque purple.
float g() const
Returns the floating-point green component.
static Color Red()
Returns opaque red.
static Color DarkGray()
Returns opaque dark gray.
float b() const
Returns the floating-point blue component.
Color(const math::u8vec3 &irgb)
Creates an opaque color from 8-bit RGB components.
static Color LightGray()
Returns opaque light gray.
math::vec3 rgb() const
Returns the floating-point RGB components.
static Color Blue()
Returns opaque blue.
uint8_t u8b() const
Returns the blue component converted to 8-bit form.
static Color Yellow()
Returns opaque yellow.
static Color Gray()
Returns opaque gray.
static Color Cyan()
Returns opaque cyan.
static Color Green()
Returns opaque green.
static Color White()
Returns opaque white.
Color(const math::vec4 &rgba)
Creates a color from floating-point RGBA components.
uint8_t u8g() const
Returns the green component converted to 8-bit form.