45 explicit Color(
float aR = 0.0f,
float aG = 0.0f,
float aB = 0.0f,
float aA = 0.0f)
46 : r(aR), g(aG), b(aB), a(aA) {}
48 inline Color Inverse()
const 50 return Color(1.0f - r, 1.0f - g, 1.0f - b, 1.0f - a);
56 return reinterpret_cast<float*
>(
this);
60 inline const float*
Array()
const 62 return reinterpret_cast<const float*
>(
this);
70 s <<
"(" << r <<
", " << g <<
", " << b <<
", " << a <<
")";
74 inline bool operator==(
const Color &other)
const 76 return r == other.
r && g == other.g && b == other.b && a == other.a;
79 inline bool operator!=(
const Color &other)
const 81 return ! this->operator==(other);
84 inline Color operator*(
float scale)
const 104 unsigned char r, g, b, a;
107 explicit IntColor(
unsigned char aR = 0,
unsigned char aG = 0,
unsigned char aB = 0,
unsigned char aA = 0)
108 : r(aR), g(aG), b(aB), a(aA) {}
113 return Color(color.
r / 255.0f, color.g / 255.0f, color.b / 255.0f, color.a / 255.0f);
118 return IntColor(static_cast<unsigned char>(color.
r * 255.0f),
119 static_cast<unsigned char>(color.g * 255.0f),
120 static_cast<unsigned char>(color.b * 255.0f),
121 static_cast<unsigned char>(color.a * 255.0f));
124 inline Color IntensityToColor(
float intensity)
126 if (intensity <= 0.0f)
return Color(0.0f, 0.0f, 0.0f, 0.0f);
127 if (intensity >= 1.0f)
return Color(1.0f, 1.0f, 1.0f, 1.0f);
129 return Color(intensity, intensity, intensity, intensity);
140 ColorHSV(
float aH = 0.0f,
float aS = 0.0f,
float aV = 0.0f)
141 : h(aH), s(aS), v(aV) {}
146 std::stringstream str;
148 str <<
"(" << h <<
", " << s <<
", " << v <<
")";
float r
Red, green, blue and alpha components.
Definition: color.h:42
Color(float aR=0.0f, float aG=0.0f, float aB=0.0f, float aA=0.0f)
Constructor; default values are (0,0,0,0) = black.
Definition: color.h:45
Color HSV2RGB(ColorHSV color)
Converts a HSV color to RGB color.
Definition: color.cpp:71
std::string ToString() const
Returns a string "(h, s, v)".
Definition: color.h:144
std::string ToString() const
Returns a string (r, g, b, a)
Definition: color.h:66
Color with integer values.
Definition: color.h:101
IntColor(unsigned char aR=0, unsigned char aG=0, unsigned char aB=0, unsigned char aA=0)
Constructor; default values are (0,0,0,0) = black.
Definition: color.h:107
ColorHSV RGB2HSV(Color color)
Converts a RGB color to HSV color.
Definition: color.cpp:31
Namespace for (new) graphics code.
Definition: app.h:49
float * Array()
Returns the struct cast to float* array; use with care!
Definition: color.h:54
RGBA color.
Definition: color.h:39
HSV color.
Definition: color.h:136
unsigned char r
Red, green, blue and alpha components.
Definition: color.h:104
const float * Array() const
Returns the struct cast to const float* array; use with care!
Definition: color.h:60