Core/Color: Add some operators

This commit is contained in:
SirLynix 2024-01-16 14:06:45 +01:00
parent bbef5cfd1d
commit 8ca7c2e8ee
2 changed files with 32 additions and 1 deletions

View File

@ -33,6 +33,8 @@ namespace Nz
inline std::string ToString() const;
constexpr Color operator+(const Color& color) const;
constexpr Color operator-(const Color& color) const;
constexpr Color operator*(float scale) const;
constexpr Color operator*(const Color& color) const;
constexpr Color& operator=(const Color&) = default;
@ -88,7 +90,9 @@ namespace Nz
inline bool Serialize(SerializationContext& context, const Color& color, TypeTag<Color>);
inline bool Unserialize(SerializationContext& context, Color* color, TypeTag<Color>);
std::ostream& operator<<(std::ostream& out, const Color& color);
inline std::ostream& operator<<(std::ostream& out, const Color& color);
constexpr Color operator*(float scale, const Color& color);
}
#include <Nazara/Core/Color.inl>

View File

@ -85,6 +85,28 @@ namespace Nz
return Color(r + color.r, g + color.g, b + color.b, a + color.a);
}
/*!
* \brief Subtracts two colors together
* \return Color which is the subtraction
*
* \param color Other color
*/
constexpr Color Color::operator-(const Color& color) const
{
return Color(r - color.r, g - color.g, b - color.b, a - color.a);
}
/*!
* \brief Scales a color
* \return Color which is the product
*
* \param color Other color
*/
constexpr Color Color::operator*(float scale) const
{
return Color(r * scale, g * scale, b * scale, a * scale);
}
/*!
* \brief Multiplies two colors together
* \return Color which is the product
@ -725,6 +747,11 @@ namespace Nz
{
return out << color.ToString();
}
constexpr Color operator*(float scale, const Color& color)
{
return color * scale;
}
}
#include <Nazara/Core/DebugOff.hpp>