diff --git a/include/core/Color.hpp b/include/core/Color.hpp index 0f93a55d..e4116f2b 100644 --- a/include/core/Color.hpp +++ b/include/core/Color.hpp @@ -5,6 +5,7 @@ #include +#include "Defs.hpp" #include "String.hpp" namespace godot { @@ -73,6 +74,23 @@ public: return components[idx]; } + Color operator+(const Color &p_color) const; + void operator+=(const Color &p_color); + + Color operator-() const; + Color operator-(const Color &p_color) const; + void operator-=(const Color &p_color); + + Color operator*(const Color &p_color) const; + Color operator*(const real_t &rvalue) const; + void operator*=(const Color &p_color); + void operator*=(const real_t &rvalue); + + Color operator/(const Color &p_color) const; + Color operator/(const real_t &rvalue) const; + void operator/=(const Color &p_color); + void operator/=(const real_t &rvalue); + void invert(); void contrast(); diff --git a/src/core/Color.cpp b/src/core/Color.cpp index f6a061a0..23b77eb4 100644 --- a/src/core/Color.cpp +++ b/src/core/Color.cpp @@ -527,4 +527,122 @@ bool Color::operator<(const Color &p_color) const { return r < p_color.r; } +Color Color::operator+(const Color &p_color) const { + + return Color( + r + p_color.r, + g + p_color.g, + b + p_color.b, + a + p_color.a); +} + +void Color::operator+=(const Color &p_color) { + + r = r + p_color.r; + g = g + p_color.g; + b = b + p_color.b; + a = a + p_color.a; +} + +Color Color::operator-(const Color &p_color) const { + + return Color( + r - p_color.r, + g - p_color.g, + b - p_color.b, + a - p_color.a); +} + +void Color::operator-=(const Color &p_color) { + + r = r - p_color.r; + g = g - p_color.g; + b = b - p_color.b; + a = a - p_color.a; +} + +Color Color::operator*(const Color &p_color) const { + + return Color( + r * p_color.r, + g * p_color.g, + b * p_color.b, + a * p_color.a); +} + +Color Color::operator*(const real_t &rvalue) const { + + return Color( + r * rvalue, + g * rvalue, + b * rvalue, + a * rvalue); +} + +void Color::operator*=(const Color &p_color) { + + r = r * p_color.r; + g = g * p_color.g; + b = b * p_color.b; + a = a * p_color.a; +} + +void Color::operator*=(const real_t &rvalue) { + + r = r * rvalue; + g = g * rvalue; + b = b * rvalue; + a = a * rvalue; +} + +Color Color::operator/(const Color &p_color) const { + + return Color( + r / p_color.r, + g / p_color.g, + b / p_color.b, + a / p_color.a); +} + +Color Color::operator/(const real_t &rvalue) const { + + return Color( + r / rvalue, + g / rvalue, + b / rvalue, + a / rvalue); +} + +void Color::operator/=(const Color &p_color) { + + r = r / p_color.r; + g = g / p_color.g; + b = b / p_color.b; + a = a / p_color.a; +} + +void Color::operator/=(const real_t &rvalue) { + + if (rvalue == 0) { + r = 1.0; + g = 1.0; + b = 1.0; + a = 1.0; + } else { + r = r / rvalue; + g = g / rvalue; + b = b / rvalue; + a = a / rvalue; + } +} + +Color Color::operator-() const { + + return Color( + 1.0 - r, + 1.0 - g, + 1.0 - b, + 1.0 - a); +} + } // namespace godot