When writing the X11 (linux) implementation there was a problem with X11 defining a "Display" type and we also have a Display class in the engine. So to fix that problem and minimize the risk for running into other name conflicts. We move everything from global namespace.
132 lines
No EOL
2.6 KiB
C++
132 lines
No EOL
2.6 KiB
C++
|
|
#include <Spectre/Math/Color.h>
|
|
|
|
namespace sp {
|
|
|
|
const Color Color::Black (0 , 0 , 0 , 255);
|
|
const Color Color::White (255, 255, 255, 255);
|
|
const Color Color::Red (255, 0 , 0 , 255);
|
|
const Color Color::Green (0 , 255, 0 , 255);
|
|
const Color Color::Blue (0 , 0 , 255, 255);
|
|
const Color Color::Transparant (0 , 0 , 0 , 0 );
|
|
|
|
Color::Color(unsigned char red, unsigned char green, unsigned char blue, unsigned char alpha)
|
|
{
|
|
r = red; g = green; b = blue; a = alpha;
|
|
}
|
|
|
|
Color::Color(const Color& color)
|
|
{
|
|
r = color.r; g = color.g; b = color.b; a = color.a;
|
|
}
|
|
|
|
Color& Color::operator=(const Color& color)
|
|
{
|
|
if (*this != color) {
|
|
r = color.r;
|
|
g = color.g;
|
|
b = color.b;
|
|
a = color.a;
|
|
}
|
|
return *this;
|
|
}
|
|
|
|
Vector3f Color::toRGBf() const
|
|
{
|
|
Vector3f v(r, g, b);
|
|
return v / 255.0f;
|
|
}
|
|
|
|
Vector4f Color::toRGBAf() const
|
|
{
|
|
Vector4f v(r, g, b, a);
|
|
return v / 255.0f;
|
|
}
|
|
|
|
// ---------
|
|
// Compare
|
|
// ---------
|
|
|
|
bool operator ==(const Color& c1, const Color& c2)
|
|
{
|
|
return c1.r == c2.r && c1.g == c2.g && c1.b == c2.b && c1.a == c2.b;
|
|
}
|
|
|
|
bool operator !=(const Color& c1, const Color& c2)
|
|
{
|
|
return !(c1.r == c2.r && c1.g == c2.g && c1.b == c2.b && c1.a == c2.b);
|
|
}
|
|
|
|
// ------------
|
|
// Arithmetic
|
|
// ------------
|
|
|
|
Color operator +(const Color& c1, const Color& c2)
|
|
{
|
|
return Color(c1.r + c2.r, c1.g + c2.g, c1.b + c2.b, c1.a + c2.a);
|
|
}
|
|
|
|
Color operator -(const Color& c1, const Color& c2)
|
|
{
|
|
return Color(c1.r - c2.r, c1.g - c2.g, c1.b - c2.b, c1.a - c2.a);
|
|
}
|
|
|
|
Color operator /(const Color& c1, const Color& c2)
|
|
{
|
|
return Color(c1.r / c2.r, c1.g / c2.g, c1.b / c2.b, c1.a / c2.a);
|
|
}
|
|
|
|
Color operator *(const Color& c1, const Color& c2)
|
|
{
|
|
return Color(c1.r * c2.r, c1.g * c2.g, c1.b * c2.b, c1.a * c2.a);
|
|
}
|
|
|
|
Color& operator +=(Color& c1, const Color& c2)
|
|
{
|
|
c1.r += c2.r; c1.g += c2.g; c1.b += c2.b; c1.a += c2.a;
|
|
return c1;
|
|
}
|
|
|
|
Color& operator -=(Color& c1, const Color& c2)
|
|
{
|
|
c1.r -= c2.r; c1.g -= c2.g; c1.b -= c2.b; c1.a -= c2.a;
|
|
return c1;
|
|
}
|
|
|
|
Color& operator /=(Color& c1, const Color& c2)
|
|
{
|
|
c1.r /= c2.r; c1.g /= c2.g; c1.b /= c2.b; c1.a /= c2.a;
|
|
return c1;
|
|
}
|
|
|
|
Color& operator *=(Color& c1, const Color& c2)
|
|
{
|
|
c1.r *= c2.r; c1.g *= c2.g; c1.b *= c2.b; c1.a *= c2.a;
|
|
return c1;
|
|
}
|
|
|
|
// -------------------
|
|
// Scalar arithmetic
|
|
// -------------------
|
|
|
|
Color operator +(const Color& c, unsigned int s)
|
|
{
|
|
return Color(c.r + s, c.g + s, c.b + s, c.a + s);
|
|
}
|
|
|
|
Color operator -(const Color& c, unsigned int s)
|
|
{
|
|
return Color(c.r - s, c.g - s, c.b - s, c.a - s);
|
|
}
|
|
|
|
Color operator /(const Color& c, unsigned int s)
|
|
{
|
|
return Color(c.r / s, c.g / s, c.b / s, c.a / s);
|
|
}
|
|
|
|
Color operator *(const Color& c, unsigned int s)
|
|
{
|
|
return Color(c.r * s, c.g * s, c.b * s, c.a * s);
|
|
}
|
|
|
|
} // namespace sp
|