From 5b84b15ed2bdcb702c96fbd47e5cf5b5ce1ae6b7 Mon Sep 17 00:00:00 2001 From: Robert Date: Sun, 17 May 2020 15:11:53 +0200 Subject: [PATCH] Added color arithmetics --- SDLU/structures/Color.cpp | 82 ++++++++++++++++++++++++++++++++++ SDLU/structures/Color.hpp | 93 +++++++++++++++++++++++++++++++++++++++ 2 files changed, 175 insertions(+) diff --git a/SDLU/structures/Color.cpp b/SDLU/structures/Color.cpp index 7c8a829..bd57926 100644 --- a/SDLU/structures/Color.cpp +++ b/SDLU/structures/Color.cpp @@ -93,4 +93,86 @@ namespace sdlu return output; } + + Color operator+(const Color& left, const Color& right) + { + return Color(left.r + right.r, + left.g + right.g, + left.b + right.b, + left.a + right.a); + } + + Color operator-(const Color& left, const Color& right) + { + return Color(left.r - right.r, + left.g - right.g, + left.b - right.b, + left.a - right.a); + } + + Color operator*(const Color& left, const Color& right) + { + return Color(left.r * right.r, + left.g * right.g, + left.b * right.b, + left.a * right.a); + } + + Color operator/(const Color& left, const Color& right) + { + return Color(left.r / right.r, + left.g / right.g, + left.b / right.b, + left.a / right.a); + } + + Color& operator+=(Color& left, const Color& right) + { + left.r += right.r; + left.g += right.g; + left.b += right.b; + left.a += right.a; + + return left; + } + + Color& operator-=(Color& left, const Color& right) + { + left.r -= right.r; + left.g -= right.g; + left.b -= right.b; + left.a -= right.a; + + return left; + } + + Color& operator*=(Color& left, const Color& right) + { + left.r *= right.r; + left.g *= right.g; + left.b *= right.b; + left.a *= right.a; + + return left; + } + + Color& operator/=(Color& left, const Color& right) + { + left.r /= right.r; + left.g /= right.g; + left.b /= right.b; + left.a /= right.a; + + return left; + } + + bool operator==(const Color& left, const Color& right) + { + return ((left.r == right.r) && (left.g == right.g) && (left.b == right.b) && (left.a == right.a)); + } + + bool operator!=(const Color& left, const Color& right) + { + return !(left == right); + } } \ No newline at end of file diff --git a/SDLU/structures/Color.hpp b/SDLU/structures/Color.hpp index a1d1d51..e710d32 100644 --- a/SDLU/structures/Color.hpp +++ b/SDLU/structures/Color.hpp @@ -73,5 +73,98 @@ namespace sdlu static const Color White; ///< Default Color White (#FFFFFFFF) static const Color Transparent; ///< Default Color Transparent (#00000000) + + + /////////////////// OPERATOR OVERLOADS /////////////////// + + /** + * @brief Componentwise color addition + * + * @param[in] left Left operand + * @param[in] right Right operand + * @return left + right + */ + friend Color operator+(const Color& left, const Color& right); + + /** + * @brief Componentwise color subtraction + * + * @param[in] left Left operand + * @param[in] right Right operand + * @return left - right + */ + friend Color operator-(const Color& left, const Color& right); + + /** + * @brief Componentwise color multiplication + * + * @param[in] left Left operand + * @param[in] right Right operand + * @return left * right + */ + friend Color operator*(const Color& left, const Color& right); + + /** + * @brief Componentwise color division + * + * @param[in] left Left operand + * @param[in] right Right operand + * @return left / right + */ + friend Color operator/(const Color& left, const Color& right); + + /** + * @brief Componentwise color addition + * + * @param[in] left Left operand + * @param[in] right Right operand + * @return left += right + */ + friend Color& operator+=(Color& left, const Color& right); + + /** + * @brief Componentwise color subtraction + * + * @param[in] left Left operand + * @param[in] right Right operand + * @return left -= right + */ + friend Color& operator-=(Color& left, const Color& right); + + /** + * @brief Componentwise color multiplication + * + * @param[in] left Left operand + * @param[in] right Right operand + * @return left *= right + */ + friend Color& operator*=(Color& left, const Color& right); + + /** + * @brief Componentwise color division + * + * @param[in] left Left operand + * @param[in] right Right operand + * @return left /= right + */ + friend Color& operator/=(Color& left, const Color& right); + + /** + * @brief Componentwise color comparison + * + * @param[in] left Left operand + * @param[in] right Right operand + * @return True if the respective color components are equal, False if not + */ + friend bool operator==(const Color& left, const Color& right); + + /** + * @brief Componentwise color comparison + * + * @param[in] left Left operand + * @param[in] right Right operand + * @return False if the respective color components are equal, True if not + */ + friend bool operator!=(const Color& left, const Color& right); }; } \ No newline at end of file