From 5ee6c17faa7ef712b97f68f20f9a577e9cb68345 Mon Sep 17 00:00:00 2001 From: Bob Polis Date: Wed, 28 Sep 2022 17:32:51 +0200 Subject: [PATCH] Added assignment operators for rgb and hsb --- src/Color.cpp | 11 +++++++++++ src/Color.hpp | 3 +++ 2 files changed, 14 insertions(+) diff --git a/src/Color.cpp b/src/Color.cpp index b7bc6aa..4fe7ce5 100644 --- a/src/Color.cpp +++ b/src/Color.cpp @@ -96,3 +96,14 @@ Color::Color(const std::string& hex) { iss >> std::hex >> val; _rgb.b = val / 256.0; } + +Color& Color::operator=(const RGB& rgb) { + _rgb = rgb; + return *this; +} + +Color& Color::operator=(const HSB& hsb) { + Color tmp {hsb}; + _rgb = tmp._rgb; + return *this; +} diff --git a/src/Color.hpp b/src/Color.hpp index 151dd41..bf31da9 100644 --- a/src/Color.hpp +++ b/src/Color.hpp @@ -24,6 +24,9 @@ class Color { operator RGB() const { return _rgb; } operator HSB() const; + Color& operator=(const RGB& rgb); + Color& operator=(const HSB& hsb); + private: RGB _rgb; };