From 596ace81fb53eeb18bb0407eec853e3fda14bb3d Mon Sep 17 00:00:00 2001 From: Edouard DUPIN Date: Tue, 14 Aug 2012 17:33:17 +0200 Subject: [PATCH] Add color capacity --- Sources/libetk/etk/Color.cpp | 48 ++++++++++++++++++++++++++++++++++++ Sources/libetk/etk/Color.h | 7 ++++++ 2 files changed, 55 insertions(+) diff --git a/Sources/libetk/etk/Color.cpp b/Sources/libetk/etk/Color.cpp index 8af53007..4931553a 100644 --- a/Sources/libetk/etk/Color.cpp +++ b/Sources/libetk/etk/Color.cpp @@ -515,6 +515,54 @@ etk::CCout& etk::operator <<(etk::CCout &os, const etk::Color &obj) return os; } +etk::Color etk::Color::operator *(const etk::Color& _input) +{ + etk::Color tmp(*this); + tmp *= _input; + return tmp; +} + +etk::Color etk::Color::operator +(const etk::Color& _input) +{ + etk::Color tmp(*this); + tmp += _input; + return tmp; +} + +etk::Color etk::Color::operator -(const etk::Color& _input) +{ + etk::Color tmp(*this); + tmp -= _input; + return tmp; +} + +etk::Color& etk::Color::operator *=(const etk::Color& _input) +{ + red = (int32_t)red * (int32_t)_input.red / 255; + green = (int32_t)green * (int32_t)_input.green / 255; + blue = (int32_t)blue * (int32_t)_input.blue / 255; + alpha = (int32_t)alpha * (int32_t)_input.alpha / 255; + return *this; +} + +etk::Color& etk::Color::operator +=(const etk::Color& _input) +{ + red = etk_min((int32_t)red + (int32_t)_input.red, 255); + green = etk_min((int32_t)green + (int32_t)_input.green, 255); + blue = etk_min((int32_t)blue + (int32_t)_input.blue, 255); + alpha = etk_min((int32_t)alpha + (int32_t)_input.alpha, 255); + return *this; +} + +etk::Color& etk::Color::operator -=(const etk::Color& _input) +{ + red = etk_min((int32_t)red - (int32_t)_input.red, 255); + green = etk_min((int32_t)green - (int32_t)_input.green, 255); + blue = etk_min((int32_t)blue - (int32_t)_input.blue, 255); + alpha = etk_min((int32_t)alpha - (int32_t)_input.alpha, 255); + return *this; +} + etk::Color& etk::Color::operator= (const etk::Color &_input ) { //TK_INFO("OPERATOR de recopie"); diff --git a/Sources/libetk/etk/Color.h b/Sources/libetk/etk/Color.h index 88473dbd..27ad83d2 100644 --- a/Sources/libetk/etk/Color.h +++ b/Sources/libetk/etk/Color.h @@ -50,6 +50,13 @@ namespace etk { Color(etk::UString data); Color(const char * data); // operator : + etk::Color operator *(const etk::Color& _input); + etk::Color operator +(const etk::Color& _input); + etk::Color operator -(const etk::Color& _input); + etk::Color& operator *=(const etk::Color& _input); + etk::Color& operator +=(const etk::Color& _input); + etk::Color& operator -=(const etk::Color& _input); + etk::Color& operator=(const uint32_t _input); etk::Color& operator=(const etk::Color& _input); bool operator==(const etk::Color& _input) const;