Added operator - for sf::Color (#114)

This commit is contained in:
Laurent Gomila 2013-08-09 14:57:32 +02:00
parent c697623689
commit 6d4c844959
2 changed files with 56 additions and 8 deletions

View file

@ -87,20 +87,30 @@ bool operator !=(const Color& left, const Color& right)
////////////////////////////////////////////////////////////
Color operator +(const Color& left, const Color& right)
{
return Color(static_cast<Uint8>(std::min(left.r + right.r, 255)),
static_cast<Uint8>(std::min(left.g + right.g, 255)),
static_cast<Uint8>(std::min(left.b + right.b, 255)),
static_cast<Uint8>(std::min(left.a + right.a, 255)));
return Color(Uint8(std::min(int(left.r) + right.r, 255)),
Uint8(std::min(int(left.g) + right.g, 255)),
Uint8(std::min(int(left.b) + right.b, 255)),
Uint8(std::min(int(left.a) + right.a, 255)));
}
////////////////////////////////////////////////////////////
Color operator -(const Color& left, const Color& right)
{
return Color(Uint8(std::max(int(left.r) - right.r, 0)),
Uint8(std::max(int(left.g) - right.g, 0)),
Uint8(std::max(int(left.b) - right.b, 0)),
Uint8(std::max(int(left.a) - right.a, 0)));
}
////////////////////////////////////////////////////////////
Color operator *(const Color& left, const Color& right)
{
return Color(static_cast<Uint8>(left.r * right.r / 255),
static_cast<Uint8>(left.g * right.g / 255),
static_cast<Uint8>(left.b * right.b / 255),
static_cast<Uint8>(left.a * right.a / 255));
return Color(Uint8(int(left.r) * right.r / 255),
Uint8(int(left.g) * right.g / 255),
Uint8(int(left.b) * right.b / 255),
Uint8(int(left.a) * right.a / 255));
}
@ -111,6 +121,13 @@ Color& operator +=(Color& left, const Color& right)
}
////////////////////////////////////////////////////////////
Color& operator -=(Color& left, const Color& right)
{
return left = left - right;
}
////////////////////////////////////////////////////////////
Color& operator *=(Color& left, const Color& right)
{