Add operator overloads for Color taking Color references

This commit is contained in:
Eryn Wells 2013-09-13 18:23:25 -07:00
parent cae8b21068
commit dea1967344
2 changed files with 87 additions and 0 deletions

View file

@ -391,3 +391,78 @@ Color::operator=(const Color &rhs)
alpha = rhs.alpha;
return *this;
}
Color &
Color::operator*=(const Color &rhs)
{
red *= rhs.red;
green *= rhs.green;
blue *= rhs.blue;
return *this;
}
Color &
Color::operator/=(const Color &rhs)
{
red *= (1.0 / rhs.red);
green *= (1.0 / rhs.green);
blue *= (1.0 / rhs.blue);
return *this;
}
Color &
Color::operator+=(const Color &rhs)
{
red += rhs.red;
green += rhs.green;
blue += rhs.blue;
alpha += rhs.alpha;
return *this;
}
Color &
Color::operator-=(const Color &rhs)
{
red -= rhs.red;
green -= rhs.green;
blue -= rhs.blue;
alpha -= rhs.alpha;
return *this;
}
Color
Color::operator*(const Color &rhs)
const
{
return Color(*this) *= rhs;
}
Color
Color::operator/(const Color &rhs)
const
{
return Color(*this) /= rhs;
}
Color
Color::operator+(const Color &rhs)
const
{
return Color(*this) += rhs;
}
Color
Color::operator-(const Color &rhs)
const
{
return Color(*this) -= rhs;
}
const Color
operator*(const float &lhs, const Color &rhs)
{
return rhs * lhs;
}

View file

@ -72,6 +72,16 @@ struct Color
Color &operator=(const Color &rhs);
// These operators blend the two colors.
Color &operator*=(const Color &rhs);
Color &operator/=(const Color &rhs);
Color &operator+=(const Color &rhs);
Color &operator-=(const Color &rhs);
Color operator*(const Color &rhs) const;
Color operator/(const Color &rhs) const;
Color operator+(const Color &rhs) const;
Color operator-(const Color &rhs) const;
static const Color Black;
static const Color White;
static const Color Red;
@ -81,4 +91,6 @@ struct Color
float red, green, blue, alpha;
};
const Color operator*(const float &lhs, const Color &rhs);
#endif