44 explicit Color(
float aR = 0.0f,
float aG = 0.0f,
float aB = 0.0f,
float aA = 0.0f)
45 : r(aR), g(aG), b(aB), a(aA) {}
47 inline Color Inverse()
const
49 return Color(1.0f - r, 1.0f - g, 1.0f - b, 1.0f - a);
55 return reinterpret_cast<float*
>(
this);
59 inline const float*
Array()
const
61 return reinterpret_cast<const float*
>(
this);
69 s <<
"(" << r <<
", " << g <<
", " << b <<
", " << a <<
")";
73 inline bool operator==(
const Color &other)
const
75 return r == other.
r && g == other.g && b == other.b && a == other.a;
78 inline bool operator!=(
const Color &other)
const
80 return ! this->operator==(other);
83 inline Color operator*(
float scale)
const
103 unsigned char r, g, b, a;
106 explicit IntColor(
unsigned char aR = 0,
unsigned char aG = 0,
unsigned char aB = 0,
unsigned char aA = 0)
107 : r(aR), g(aG), b(aB), a(aA) {}
110 inline Color IntColorToColor(IntColor color)
112 return Color(color.r / 255.0f, color.g / 255.0f, color.b / 255.0f, color.a / 255.0f);
115 inline IntColor ColorToIntColor(Color color)
117 return IntColor(static_cast<unsigned char>(color.r * 255.0f),
118 static_cast<unsigned char>(color.g * 255.0f),
119 static_cast<unsigned char>(color.b * 255.0f),
120 static_cast<unsigned char>(color.a * 255.0f));
123 inline Color IntensityToColor(
float intensity)
125 if (intensity <= 0.0f)
return Color(0.0f, 0.0f, 0.0f, 0.0f);
126 if (intensity >= 1.0f)
return Color(1.0f, 1.0f, 1.0f, 1.0f);
128 return Color(intensity, intensity, intensity, intensity);
139 ColorHSV(
float aH = 0.0f,
float aS = 0.0f,
float aV = 0.0f)
140 : h(aH), s(aS), v(aV) {}
145 std::stringstream str;
147 str <<
"(" << h <<
", " << s <<
", " << v <<
")";
float r
Red, green, blue and alpha components.
Definition: color.h:41
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:44
Color HSV2RGB(ColorHSV color)
Converts a HSV color to RGB color.
Definition: color.cpp:70
std::string ToString() const
Returns a string "(h, s, v)".
Definition: color.h:143
std::string ToString() const
Returns a string (r, g, b, a)
Definition: color.h:65
Color with integer values.
Definition: color.h:100
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:106
ColorHSV RGB2HSV(Color color)
Converts a RGB color to HSV color.
Definition: color.cpp:30
Namespace for (new) graphics code.
Definition: app.h:49
float * Array()
Returns the struct cast to float* array; use with care!
Definition: color.h:53
RGBA color.
Definition: color.h:38
HSV color.
Definition: color.h:135
unsigned char r
Red, green, blue and alpha components.
Definition: color.h:103
const float * Array() const
Returns the struct cast to const float* array; use with care!
Definition: color.h:59